source: branches/1.6/upgrade.php @ 21849

Last change on this file since 21849 was 1599, checked in by plg, 18 years ago

New: upgrade script from 1.6.0 (or 1.6.1) to 1.6.2.
#user_infos.auto_login_key is added in upgrade_1.6.0.php instead of
upgrade_1.5.0.php.

Bug fixed: the database structure dump was starting with a "1", very
interesting typo!

Bug fixed: the database structure dump was adding #user_infos.auto_login_key
nullable while the upgrade file was adding it not nullable.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 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-11-09 22:13:33 +0000 (Thu, 09 Nov 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1599 $
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    if (preg_match('/^'.PREFIX_TABLE.'/', $row[0]))
85    {
86      array_push($tables, $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 '.$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[PREFIX_TABLE.'config']))
165  {
166    // we're in branch 1.3, important upgrade, isn't it?
167    if (in_array(PREFIX_TABLE.'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(PREFIX_TABLE.'user_cache', $tables))
177  {
178    $current_release = '1.4.0';
179  }
180  else if (!in_array(PREFIX_TABLE.'tags', $tables))
181  {
182    $current_release = '1.5.0';
183  }
184  else if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos']))
185  {
186    $current_release = '1.6.0';
187  }
188  else
189  {
190    die('No upgrade required, the database structure is up to date');
191  }
192 
193  $template->assign_block_vars(
194    'introduction',
195    array(
196      'CURRENT_RELEASE' => $current_release,
197      'RUN_UPGRADE_URL' =>
198        PHPWG_ROOT_PATH.'upgrade.php?version='.$current_release,
199      )
200    );
201}
202
203// +-----------------------------------------------------------------------+
204// |                            upgrade launch                             |
205// +-----------------------------------------------------------------------+
206
207else
208{
209  $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php';
210  if (is_file($upgrade_file))
211  {
212    $page['infos'] = array();
213    $page['upgrade_start'] = get_moment();
214    $conf['die_on_sql_error'] = false;
215    include($upgrade_file);
216
217    // Available upgrades must be ignored after a fresh installation. To
218    // make PWG avoid upgrading, we must tell it upgrades have already been
219    // made.
220    list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
221    define('CURRENT_DATE', $dbnow);
222    $datas = array();
223    foreach (get_available_upgrade_ids() as $upgrade_id)
224    {
225      array_push(
226        $datas,
227        array(
228          'id'          => $upgrade_id,
229          'applied'     => CURRENT_DATE,
230          'description' => 'upgrade included in migration',
231          )
232        );
233    }
234    mass_inserts(
235      UPGRADE_TABLE,
236      array_keys($datas[0]),
237      $datas
238      );
239   
240    $page['upgrade_end'] = get_moment();
241
242    $template->assign_block_vars(
243      'upgrade',
244      array(
245        'VERSION' => $_GET['version'],
246        'TOTAL_TIME' => get_elapsed_time(
247          $page['upgrade_start'],
248          $page['upgrade_end']
249          ),
250        'SQL_TIME' => number_format(
251          $page['queries_time'],
252          3,
253          '.',
254          ' '
255          ).' s',
256        'NB_QUERIES' => $page['count_queries']
257        )
258      );
259
260    array_push(
261      $page['infos'],
262      '[security] delete files "upgrade.php", "install.php" and "install"
263directory'
264      );
265
266    array_push(
267      $page['infos'],
268      'in include/mysql.inc.php, remove
269<pre style="background-color:lightgray">
270define(\'PHPWG_IN_UPGRADE\', true);
271</pre>'
272      );
273
274    array_push(
275      $page['infos'],
276      'Perform a maintenance check in [Administration>General>Maintenance]
277if you encounter any problem.'
278      );
279   
280    $template->assign_block_vars('upgrade.infos', array());
281   
282    foreach ($page['infos'] as $info)
283    {
284      $template->assign_block_vars(
285        'upgrade.infos.info',
286        array(
287          'CONTENT' => $info,
288          )
289        );
290    }
291
292    $query = '
293UPDATE '.USER_CACHE_TABLE.'
294  SET need_update = \'true\'
295;';
296    pwg_query($query);
297  }
298  else
299  {
300    die('Hacking attempt');
301  }
302}
303
304// +-----------------------------------------------------------------------+
305// |                          sending html code                            |
306// +-----------------------------------------------------------------------+
307
308$template->pparse('upgrade');
309?>
Note: See TracBrowser for help on using the repository browser.