source: trunk/upgrade.php @ 2290

Last change on this file since 2290 was 2290, checked in by rvelices, 16 years ago
  • remove compatibility with old template ...
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
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-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: upgrade.php 2290 2008-03-23 00:04:46Z rvelices $
8// | last update   : $Date: 2008-03-23 00:04:46 +0000 (Sun, 23 Mar 2008) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2290 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27define('PHPWG_ROOT_PATH', './');
28
29include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
30include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
31include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php');
32include(PHPWG_ROOT_PATH.'include/template.class.php');
33
34include(PHPWG_ROOT_PATH.'include/mysql.inc.php');
35include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
36@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
37
38check_upgrade();
39
40prepare_conf_upgrade();
41
42include_once(PHPWG_ROOT_PATH.'include/constants.php');
43define('PREFIX_TABLE', $prefixeTable);
44
45// Database connection
46mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
47or die ( "Could not connect to database server" );
48mysql_select_db( $cfgBase )
49or die ( "Could not connect to database" );
50// +-----------------------------------------------------------------------+
51// |                            tricky output                              |
52// +-----------------------------------------------------------------------+
53echo '<!-- This is an HTML comment given in order to make IE outputs';
54echo ' the code.'."\n";
55echo ' Indeed, IE doesn\'t start to send output until a limit';
56echo ' of XXX bytes '."\n";
57echo str_repeat( ' ', 80 )."\n";
58echo str_repeat( ' ', 80 )."\n";
59echo str_repeat( ' ', 80 )."\n";
60echo '-->'."\n";
61flush();
62// +-----------------------------------------------------------------------+
63// |                              functions                                |
64// +-----------------------------------------------------------------------+
65
66/**
67 * list all tables in an array
68 *
69 * @return array
70 */
71function get_tables()
72{
73  $tables = array();
74
75  $query = '
76SHOW TABLES
77;';
78  $result = mysql_query($query);
79
80  while ($row = mysql_fetch_row($result))
81  {
82    if (preg_match('/^'.PREFIX_TABLE.'/', $row[0]))
83    {
84      array_push($tables, $row[0]);
85    }
86  }
87
88  return $tables;
89}
90
91/**
92 * list all columns of each given table
93 *
94 * @return array of array
95 */
96function get_columns_of($tables)
97{
98  $columns_of = array();
99
100  foreach ($tables as $table)
101  {
102    $query = '
103DESC '.$table.'
104;';
105    $result = mysql_query($query);
106
107    $columns_of[$table] = array();
108
109    while ($row = mysql_fetch_row($result))
110    {
111      array_push($columns_of[$table], $row[0]);
112    }
113  }
114
115  return $columns_of;
116}
117
118/**
119 */
120function print_time($message)
121{
122  global $last_time;
123
124  $new_time = get_moment();
125  echo '<pre>['.get_elapsed_time($last_time, $new_time).']';
126  echo ' '.$message;
127  echo '</pre>';
128  flush();
129  $last_time = $new_time;
130}
131
132// +-----------------------------------------------------------------------+
133// |                             playing zone                              |
134// +-----------------------------------------------------------------------+
135
136// echo implode('<br>', get_tables());
137// echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>';
138
139// foreach (get_available_upgrade_ids() as $upgrade_id)
140// {
141//   echo $upgrade_id, '<br>';
142// }
143
144// +-----------------------------------------------------------------------+
145// |                        template initialization                        |
146// +-----------------------------------------------------------------------+
147
148$template = new Template(PHPWG_ROOT_PATH.'template/yoga');
149$template->set_filenames(array('upgrade'=>'upgrade.tpl'));
150$template->assign('RELEASE', PHPWG_VERSION);
151
152// +-----------------------------------------------------------------------+
153// |                            upgrade choice                             |
154// +-----------------------------------------------------------------------+
155
156$tables = get_tables();
157$columns_of = get_columns_of($tables);
158
159if (!isset($_GET['version']))
160{
161  // find the current release
162  if (!in_array('param', $columns_of[PREFIX_TABLE.'config']))
163  {
164    // we're in branch 1.3, important upgrade, isn't it?
165    if (in_array(PREFIX_TABLE.'user_category', $tables))
166    {
167      $current_release = '1.3.1';
168    }
169    else
170    {
171      $current_release = '1.3.0';
172    }
173  }
174  else if (!in_array(PREFIX_TABLE.'user_cache', $tables))
175  {
176    $current_release = '1.4.0';
177  }
178  else if (!in_array(PREFIX_TABLE.'tags', $tables))
179  {
180    $current_release = '1.5.0';
181  }
182  else if ( !in_array(PREFIX_TABLE.'history_summary', $tables) )
183  {
184    if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos']))
185    {
186      $current_release = '1.6.0';
187    }
188    else
189    {
190      $current_release = '1.6.2';
191    }
192  }
193  else
194  {
195    die('No upgrade required, the database structure is up to date');
196  }
197
198  $template->assign(
199    'introduction',
200    array(
201      'CURRENT_RELEASE' => $current_release,
202      'RUN_UPGRADE_URL' =>
203        PHPWG_ROOT_PATH.'upgrade.php?version='.$current_release,
204      )
205    );
206}
207
208// +-----------------------------------------------------------------------+
209// |                            upgrade launch                             |
210// +-----------------------------------------------------------------------+
211
212else
213{
214  if (in_array(PREFIX_TABLE.'history_summary', $tables))
215  {
216    die('No database upgrade required, do not refresh the page');
217  }
218
219  $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$_GET['version'].'.php';
220  if (is_file($upgrade_file))
221  {
222    $page['infos'] = array();
223    $page['upgrade_start'] = get_moment();
224    $conf['die_on_sql_error'] = false;
225    include($upgrade_file);
226
227    // Available upgrades must be ignored after a fresh installation. To
228    // make PWG avoid upgrading, we must tell it upgrades have already been
229    // made.
230    list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
231    define('CURRENT_DATE', $dbnow);
232    $datas = array();
233    foreach (get_available_upgrade_ids() as $upgrade_id)
234    {
235      array_push(
236        $datas,
237        array(
238          'id'          => $upgrade_id,
239          'applied'     => CURRENT_DATE,
240          'description' => 'upgrade included in migration',
241          )
242        );
243    }
244    mass_inserts(
245      UPGRADE_TABLE,
246      array_keys($datas[0]),
247      $datas
248      );
249
250    // Create empty local files to avoid log errors
251    create_empty_local_files();
252
253    $page['upgrade_end'] = get_moment();
254
255    $template->assign(
256      'upgrade',
257      array(
258        'VERSION' => $_GET['version'],
259        'TOTAL_TIME' => get_elapsed_time(
260          $page['upgrade_start'],
261          $page['upgrade_end']
262          ),
263        'SQL_TIME' => number_format(
264          $page['queries_time'],
265          3,
266          '.',
267          ' '
268          ).' s',
269        'NB_QUERIES' => $page['count_queries']
270        )
271      );
272
273    array_push(
274      $page['infos'],
275      '[security] delete files "upgrade.php", "upgrade_feed.php", "install.php" and "install"
276directory'
277      );
278
279    array_push(
280      $page['infos'],
281      'in include/mysql.inc.php, remove
282<pre style="background-color:lightgray">
283define(\'PHPWG_IN_UPGRADE\', true);
284</pre>'
285      );
286
287    array_push(
288      $page['infos'],
289      'Perform a maintenance check in [Administration>General>Maintenance]
290if you encounter any problem.'
291      );
292
293    $template->assign('infos', $page['infos']);
294
295    $query = '
296UPDATE '.USER_CACHE_TABLE.'
297  SET need_update = \'true\'
298;';
299
300    pwg_query($query);
301    $query = '
302REPLACE INTO '.PLUGINS_TABLE.'
303  (id, state)
304  VALUES (\'c13y_upgrade\', \'active\')
305;';
306    pwg_query($query);
307  }
308  else
309  {
310    die('Hacking attempt');
311  }
312}
313
314// +-----------------------------------------------------------------------+
315// |                          sending html code                            |
316// +-----------------------------------------------------------------------+
317
318$template->pparse('upgrade');
319?>
Note: See TracBrowser for help on using the repository browser.