source: tags/release-1_6_0RC1/upgrade.php @ 16878

Last change on this file since 16878 was 1209, checked in by plg, 18 years ago

bug fixed: during installation, upgrades from install/db with complex
identifier (X.x) were not correctly inserted.

bug fixed: available upgrades from install/db need to be inserted in
#upgrade table.

deletion: all upgrades from install/db coming from trunk are removed.

new: complete upgrade from any previous release from 1.3.0 to 1.5.2 with
automatic detection detection of the previous release.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-04-19 20:54:13 +0000 (Wed, 19 Apr 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1209 $
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('PHPWG_ROOT_PATH', './');
29
30include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
31include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
32include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php');
33include(PHPWG_ROOT_PATH.'include/template.php');
34
35include(PHPWG_ROOT_PATH.'include/mysql.inc.php');
36include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
37@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
38
39check_upgrade();
40
41// concerning upgrade, we use the default users table
42$conf['users_table'] = $prefixeTable.'users';
43
44include_once(PHPWG_ROOT_PATH.'include/constants.php');
45define('PREFIX_TABLE', $prefixeTable);
46
47// Database connection
48mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
49or die ( "Could not connect to database server" );
50mysql_select_db( $cfgBase )
51or die ( "Could not connect to database" );
52// +-----------------------------------------------------------------------+
53// |                            tricky output                              |
54// +-----------------------------------------------------------------------+
55echo '<!-- This is an HTML comment given in order to make IE outputs';
56echo ' the code.'."\n";
57echo ' Indeed, IE doesn\'t start to send output until a limit';
58echo ' of XXX bytes '."\n";
59echo str_repeat( ' ', 80 )."\n";
60echo str_repeat( ' ', 80 )."\n";
61echo str_repeat( ' ', 80 )."\n";
62echo '-->'."\n";
63flush();
64// +-----------------------------------------------------------------------+
65// |                              functions                                |
66// +-----------------------------------------------------------------------+
67
68/**
69 * list all tables in an array
70 *
71 * @return array
72 */
73function get_tables()
74{
75  $tables = array();
76 
77  $query = '
78SHOW TABLES
79;';
80  $result = mysql_query($query);
81
82  while ($row = mysql_fetch_row($result))
83  {
84    array_push(
85      $tables,
86      preg_replace('/^'.PREFIX_TABLE.'/', '', $row[0])
87      );
88  }
89
90  return $tables;
91}
92
93/**
94 * list all columns of each given table
95 *
96 * @return array of array
97 */
98function get_columns_of($tables)
99{
100  $columns_of = array();
101
102  foreach ($tables as $table)
103  {
104    $query = '
105DESC '.PREFIX_TABLE.$table.'
106;';
107    $result = mysql_query($query);
108
109    $columns_of[$table] = array();
110
111    while ($row = mysql_fetch_row($result))
112    {
113      array_push($columns_of[$table], $row[0]);
114    }
115  }
116
117  return $columns_of;
118}
119
120/**
121 */
122function print_time($message)
123{
124  global $last_time;
125 
126  $new_time = get_moment();
127  echo '<pre>['.get_elapsed_time($last_time, $new_time).']';
128  echo ' '.$message;
129  echo '</pre>';
130  flush();
131  $last_time = $new_time;
132}
133
134// +-----------------------------------------------------------------------+
135// |                             playing zone                              |
136// +-----------------------------------------------------------------------+
137
138// echo implode('<br>', get_tables());
139// echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>';
140
141// foreach (get_available_upgrade_ids() as $upgrade_id)
142// {
143//   echo $upgrade_id, '<br>';
144// }
145
146// +-----------------------------------------------------------------------+
147// |                        template initialization                        |
148// +-----------------------------------------------------------------------+
149
150$template = new Template(PHPWG_ROOT_PATH.'template/yoga');
151$template->set_filenames(array('upgrade'=>'upgrade.tpl'));
152$template->assign_vars(array('RELEASE'=>PHPWG_VERSION));
153
154// +-----------------------------------------------------------------------+
155// |                            upgrade choice                             |
156// +-----------------------------------------------------------------------+
157
158if (!isset($_GET['version']))
159{
160  // find the current release
161  $tables = get_tables();
162  $columns_of = get_columns_of($tables);
163
164  if (!in_array('param', $columns_of['config']))
165  {
166    // we're in branch 1.3, important upgrade, isn't it?
167    if (in_array('user_category', $tables))
168    {
169      $current_release = '1.3.1';
170    }
171    else
172    {
173      $current_release = '1.3.0';
174    }
175  }
176  else if (!in_array('user_cache', $tables))
177  {
178    $current_release = '1.4.0';
179  }
180  else if (!in_array('tags', $tables))
181  {
182    $current_release = '1.5.0';
183  }
184  else
185  {
186    die('You are already on branch 1.6, no upgrade required');
187  }
188 
189  $template->assign_block_vars(
190    'introduction',
191    array(
192      'CURRENT_RELEASE' => $current_release,
193      'RUN_UPGRADE_URL' =>
194        PHPWG_ROOT_PATH.'upgrade.php?version='.$current_release,
195      )
196    );
197}
198
199// +-----------------------------------------------------------------------+
200// |                            upgrade launch                             |
201// +-----------------------------------------------------------------------+
202
203else
204{
205  $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php';
206  if (is_file($upgrade_file))
207  {
208    $page['infos'] = array();
209    $page['upgrade_start'] = get_moment();
210    $conf['die_on_sql_error'] = false;
211    include($upgrade_file);
212
213    // Available upgrades must be ignored after a fresh installation. To
214    // make PWG avoid upgrading, we must tell it upgrades have already been
215    // made.
216    list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
217    define('CURRENT_DATE', $dbnow);
218    $datas = array();
219    foreach (get_available_upgrade_ids() as $upgrade_id)
220    {
221      array_push(
222        $datas,
223        array(
224          'id'          => $upgrade_id,
225          'applied'     => CURRENT_DATE,
226          'description' => 'upgrade included in upgrade',
227          )
228        );
229    }
230    mass_inserts(
231      UPGRADE_TABLE,
232      array_keys($datas[0]),
233      $datas
234      );
235   
236    $page['upgrade_end'] = get_moment();
237
238    $template->assign_block_vars(
239      'upgrade',
240      array(
241        'VERSION' => $_GET['version'],
242        'TOTAL_TIME' => get_elapsed_time(
243          $page['upgrade_start'],
244          $page['upgrade_end']
245          ),
246        'SQL_TIME' => number_format(
247          $page['queries_time'],
248          3,
249          '.',
250          ' '
251          ).' s',
252        'NB_QUERIES' => $page['count_queries']
253        )
254      );
255
256    array_push(
257      $page['infos'],
258      '[security] delete files "upgrade.php", "install.php" and "install"
259directory'
260      );
261
262    array_push(
263      $page['infos'],
264      'in include/mysql.inc.php, remove
265<pre style="background-color:lightgray">
266define(\'PHPWG_IN_UPGRADE\', true);
267</pre>'
268      );
269
270    array_push(
271      $page['infos'],
272      'Perform a maintenance check in [Administration>General>Maintenance]
273if you encounter any problem.'
274      );
275   
276    $template->assign_block_vars('upgrade.infos', array());
277   
278    foreach ($page['infos'] as $info)
279    {
280      $template->assign_block_vars(
281        'upgrade.infos.info',
282        array(
283          'CONTENT' => $info,
284          )
285        );
286    }
287
288    $query = '
289UPDATE '.USER_CACHE_TABLE.'
290  SET need_update = \'true\'
291;';
292    pwg_query($query);
293  }
294  else
295  {
296    die('Hacking attempt');
297  }
298}
299
300// +-----------------------------------------------------------------------+
301// |                          sending html code                            |
302// +-----------------------------------------------------------------------+
303
304$template->pparse('upgrade');
305?>
Note: See TracBrowser for help on using the repository browser.