source: trunk/upgrade.php @ 1927

Last change on this file since 1927 was 1927, checked in by plg, 17 years ago

New: release upgrade scripts from 1.3.0 come back from branch 1.6. Only
install/upgrade_1.6.2.php is really new, upgrade 60 was taken into
account. Detection of 1.6.0 or 1.6.2 data model in upgrade.php. Release
upgrade scripts added on trunk to be kept in a safer place.

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