source: trunk/upgrade.php @ 2819

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