source: trunk/upgrade.php @ 681

Last change on this file since 681 was 681, checked in by plg, 19 years ago
  • replacement of variable names in include/mysql.inc.php (for upgrades) :

dbname => cfgBase
dbuser => cfgUser
dbpasswd => cfgPassword
dbhost => cfgHote
table_prefix => prefixeTable

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-01-08 23:32:25 +0000 (Sat, 08 Jan 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 681 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28define('IN_UPGRADE', true);
29define('PHPWG_ROOT_PATH', './');
30
31include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
32include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33include(PHPWG_ROOT_PATH.'include/template.php');
34include(PHPWG_ROOT_PATH.'include/mysql.inc.php');
35include_once(PHPWG_ROOT_PATH.'include/constants.php');
36define('PREFIX_TABLE', $prefixeTable);
37
38$conf['show_queries'] = false;
39
40// Database connection
41mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
42or die ( "Could not connect to database server" );
43mysql_select_db( $cfgBase )
44or die ( "Could not connect to database" );
45// +-----------------------------------------------------------------------+
46// |                            tricky output                              |
47// +-----------------------------------------------------------------------+
48echo '<!-- This is an HTML comment given in order to make IE outputs';
49echo ' the code.'."\n";
50echo ' Indeed, IE doesn\'t start to send output until a limit';
51echo ' of XXX bytes '."\n";
52echo str_repeat( ' ', 80 )."\n";
53echo str_repeat( ' ', 80 )."\n";
54echo str_repeat( ' ', 80 )."\n";
55echo '-->'."\n";
56flush();
57// +-----------------------------------------------------------------------+
58// |                              functions                                |
59// +-----------------------------------------------------------------------+
60
61/**
62 * loads an sql file and executes all queries
63 *
64 * Before executing a query, $replaced is... replaced by $replacing. This is
65 * useful when the SQL file contains generic words. Drop table queries are
66 * not executed.
67 *
68 * @param string filepath
69 * @param string replaced
70 * @param string replacing
71 * @return void
72 */
73function execute_sqlfile($filepath, $replaced, $replacing)
74{
75  $sql_lines = file($filepath);
76  $query = '';
77  foreach ($sql_lines as $sql_line)
78  {
79    $sql_line = trim($sql_line);
80    if (preg_match('/(^--|^$)/', $sql_line))
81    {
82      continue;
83    }
84    $query.= ' '.$sql_line;
85    // if we reached the end of query, we execute it and reinitialize the
86    // variable "query"
87    if (preg_match('/;$/', $sql_line))
88    {
89      $query = trim($query);
90      $query = str_replace($replaced, $replacing, $query);
91      // we don't execute "DROP TABLE" queries
92      if (!preg_match('/^DROP TABLE/i', $query))
93      {
94        mysql_query($query);
95      }
96      $query = '';
97    }
98  }
99}
100// +-----------------------------------------------------------------------+
101// |                        template initialization                        |
102// +-----------------------------------------------------------------------+
103$template = setup_style('default');
104$template->set_filenames(array('upgrade'=>'upgrade.tpl'));
105$template->assign_vars(array('RELEASE'=>PHPWG_VERSION));
106// +-----------------------------------------------------------------------+
107// |                          versions upgradable                          |
108// +-----------------------------------------------------------------------+
109$versions = array();
110$path = PHPWG_ROOT_PATH.'install';
111if ($contents = opendir($path))
112{
113  while (($node = readdir($contents)) !== false)
114  {
115    if (is_file($path.'/'.$node)
116        and preg_match('/^upgrade_(.*?)\.php$/', $node, $match))
117    {
118      array_push($versions, $match[1]);
119    }
120  }
121}
122natcasesort($versions);
123// +-----------------------------------------------------------------------+
124// |                            upgrade choice                             |
125// +-----------------------------------------------------------------------+
126if (!isset($_GET['version']))
127{
128  $template->assign_block_vars('choices', array());
129  foreach ($versions as $version)
130  {
131    $template->assign_block_vars(
132      'choices.choice',
133      array(
134        'URL' => PHPWG_ROOT_PATH.'upgrade.php?version='.$version,
135        'VERSION' => $version
136        ));
137  }
138}
139// +-----------------------------------------------------------------------+
140// |                            upgrade launch                             |
141// +-----------------------------------------------------------------------+
142else
143{
144  $upgrade_file = $path.'/upgrade_'.$_GET['version'].'.php';
145  if (is_file($upgrade_file))
146  {
147    $page['upgrade_start'] = get_moment();
148    include($upgrade_file);
149    $page['upgrade_end'] = get_moment();
150
151    $template->assign_block_vars(
152      'upgrade',
153      array(
154        'VERSION' => $_GET['version'],
155        'TOTAL_TIME' => get_elapsed_time($page['upgrade_start'],
156                                         $page['upgrade_end']),
157        'SQL_TIME' => number_format($page['queries_time'], 3, '.', ' ').' s',
158        'NB_QUERIES' => $page['count_queries']
159        ));
160
161    if (!isset($infos))
162    {
163      $infos = array();
164    }
165    array_push(
166      $infos,
167      '[security] delete files "upgrade.php", "install.php" and "install"
168directory');
169   
170    $template->assign_block_vars('upgrade.infos', array());
171   
172    foreach ($infos as $info)
173    {
174      $template->assign_block_vars('upgrade.infos.info',
175                                   array('CONTENT' => $info));
176    }
177  }
178  else
179  {
180    die('Hacking attempt');
181  }
182}
183// +-----------------------------------------------------------------------+
184// |                          sending html code                            |
185// +-----------------------------------------------------------------------+
186$template->pparse('upgrade');
187?>
Note: See TracBrowser for help on using the repository browser.