source: trunk/upgrade.php @ 2836

Last change on this file since 2836 was 2836, checked in by patdenice, 15 years ago
  • Webmaster or administrator can login to run upgrade.
  • Inserting upgrade line in mysql.inc.php still work.
  • Convert espagnol upgrade file to utf8.
  • Minor changes in upgrade processus.
  • Remove all comments in pclzip.lib.php.
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 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
32if (!file_exists(PHPWG_ROOT_PATH.'include/mysql.inc.php'))
33{
34  die('Could not find include/mysql.inc.php file.');
35}
36
37include_once(PHPWG_ROOT_PATH.'include/functions.inc.php');
38include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
39include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php');
40
41include(PHPWG_ROOT_PATH.'include/mysql.inc.php');
42include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
43@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php');
44
45prepare_conf_upgrade();
46
47include_once(PHPWG_ROOT_PATH.'include/constants.php');
48define('PREFIX_TABLE', $prefixeTable);
49
50// Database connection
51mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) or die ( "Could not connect to database server" );
52mysql_select_db( $cfgBase ) or die ( "Could not connect to database" );
53if ( version_compare(mysql_get_server_info(), '4.1.0', '>=')
54    and defined('DB_CHARSET') and DB_CHARSET!='' )
55{
56  pwg_query('SET NAMES "'.DB_CHARSET.'"');
57}
58
59// +-----------------------------------------------------------------------+
60// |                              functions                                |
61// +-----------------------------------------------------------------------+
62
63/**
64 * list all tables in an array
65 *
66 * @return array
67 */
68function get_tables()
69{
70  $tables = array();
71
72  $query = '
73SHOW TABLES
74;';
75  $result = mysql_query($query);
76
77  while ($row = mysql_fetch_row($result))
78  {
79    if (preg_match('/^'.PREFIX_TABLE.'/', $row[0]))
80    {
81      array_push($tables, $row[0]);
82    }
83  }
84
85  return $tables;
86}
87
88/**
89 * list all columns of each given table
90 *
91 * @return array of array
92 */
93function get_columns_of($tables)
94{
95  $columns_of = array();
96
97  foreach ($tables as $table)
98  {
99    $query = '
100DESC '.$table.'
101;';
102    $result = mysql_query($query);
103
104    $columns_of[$table] = array();
105
106    while ($row = mysql_fetch_row($result))
107    {
108      array_push($columns_of[$table], $row[0]);
109    }
110  }
111
112  return $columns_of;
113}
114
115/**
116 */
117function print_time($message)
118{
119  global $last_time;
120
121  $new_time = get_moment();
122  echo '<pre>['.get_elapsed_time($last_time, $new_time).']';
123  echo ' '.$message;
124  echo '</pre>';
125  flush();
126  $last_time = $new_time;
127}
128
129// +-----------------------------------------------------------------------+
130// |                             playing zone                              |
131// +-----------------------------------------------------------------------+
132
133// echo implode('<br>', get_tables());
134// echo '<pre>'; print_r(get_columns_of(get_tables())); echo '</pre>';
135
136// foreach (get_available_upgrade_ids() as $upgrade_id)
137// {
138//   echo $upgrade_id, '<br>';
139// }
140
141// +-----------------------------------------------------------------------+
142// |                             language                                  |
143// +-----------------------------------------------------------------------+
144if (isset($_GET['language']))
145{
146  $language = strip_tags($_GET['language']);
147}
148else
149{
150  $language = 'en_UK';
151  // Try to get browser language
152  foreach (get_languages('utf-8') as $language_code => $language_name)
153  {
154    if (substr($language_code,0,2) == @substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2))
155    {
156      $language = $language_code;
157      break;
158    }
159  }
160}
161
162load_language( 'common.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) );
163load_language( 'admin.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) );
164load_language( 'upgrade.lang', '', array('language'=>$language, 'target_charset'=>'utf-8', 'no_fallback' => true) );
165
166// +-----------------------------------------------------------------------+
167// |                        template initialization                        |
168// +-----------------------------------------------------------------------+
169
170$template = new Template(PHPWG_ROOT_PATH.'admin/template/goto', 'roma');
171$template->set_filenames(array('upgrade'=>'upgrade.tpl'));
172$template->assign('RELEASE', PHPWG_VERSION);
173
174// +-----------------------------------------------------------------------+
175// |                            upgrade choice                             |
176// +-----------------------------------------------------------------------+
177
178$tables = get_tables();
179$columns_of = get_columns_of($tables);
180
181// find the current release
182if (!in_array('param', $columns_of[PREFIX_TABLE.'config']))
183{
184  // we're in branch 1.3, important upgrade, isn't it?
185  if (in_array(PREFIX_TABLE.'user_category', $tables))
186  {
187    $current_release = '1.3.1';
188  }
189  else
190  {
191    $current_release = '1.3.0';
192  }
193}
194else if (!in_array(PREFIX_TABLE.'user_cache', $tables))
195{
196  $current_release = '1.4.0';
197}
198else if (!in_array(PREFIX_TABLE.'tags', $tables))
199{
200  $current_release = '1.5.0';
201}
202else if ( !in_array(PREFIX_TABLE.'history_summary', $tables) )
203{
204  if (!in_array('auto_login_key', $columns_of[PREFIX_TABLE.'user_infos']))
205  {
206    $current_release = '1.6.0';
207  }
208  else
209  {
210    $current_release = '1.6.2';
211  }
212}
213else if (!in_array('md5sum', $columns_of[PREFIX_TABLE.'images']))
214{
215  $current_release = '1.7.0';
216}
217else
218{
219  die('No upgrade required, the database structure is up to date');
220}
221
222// +-----------------------------------------------------------------------+
223// |                            upgrade launch                             |
224// +-----------------------------------------------------------------------+
225$page['infos'] = array();
226$page['errors'] = array();
227
228if (isset($_POST['username']) and isset($_POST['password']))
229{
230  check_upgrade_access_rights($current_release, $_POST['username'], $_POST['password']);
231}
232
233if (isset($_POST['submit']) and check_upgrade())
234{
235  $upgrade_file = PHPWG_ROOT_PATH.'install/upgrade_'.$current_release.'.php';
236  if (is_file($upgrade_file))
237  {
238    $page['upgrade_start'] = get_moment();
239    $conf['die_on_sql_error'] = false;
240    include($upgrade_file);
241
242    // Plugins deactivation
243    if (in_array(PREFIX_TABLE.'plugins', $tables))
244    {
245      deactivate_non_standard_plugins();
246    }
247
248    // Create empty local files to avoid log errors
249    create_empty_local_files();
250
251    $page['upgrade_end'] = get_moment();
252
253    $template->assign(
254      'upgrade',
255      array(
256        'VERSION' => $current_release,
257        'TOTAL_TIME' => get_elapsed_time(
258          $page['upgrade_start'],
259          $page['upgrade_end']
260          ),
261        'SQL_TIME' => number_format(
262          $page['queries_time'],
263          3,
264          '.',
265          ' '
266          ).' s',
267        'NB_QUERIES' => $page['count_queries']
268        )
269      );
270
271    array_push($page['infos'],
272      l10n('delete upgrade files'),
273      l10n('perform a maintenance check')
274      );
275
276    invalidate_user_cache();
277
278    // c13y_upgrade plugin means "check integrity after upgrade", so it
279    // becomes useful just after an upgrade
280    $query = '
281REPLACE INTO '.PLUGINS_TABLE.'
282  (id, state)
283  VALUES (\'c13y_upgrade\', \'active\')
284;';
285    pwg_query($query);
286  }
287}
288
289// +-----------------------------------------------------------------------+
290// |                          start template output                        |
291// +-----------------------------------------------------------------------+
292else
293{
294  foreach (get_languages('utf-8') as $language_code => $language_name)
295  {
296    if ($language == $language_code)
297    {
298      $template->assign('language_selection', $language_code);
299    }
300    $languages_options[$language_code] = $language_name;
301  }
302  $template->assign('language_options', $languages_options);
303
304  $template->assign('introduction', array(
305    'CURRENT_RELEASE' => $current_release,
306    'F_ACTION' => 'upgrade.php?language=' . $language));
307
308  if (!check_upgrade())
309  {
310    $template->assign('login', true);
311  }
312}
313
314if (count($page['errors']) != 0)
315{
316  $template->assign('errors', $page['errors']);
317}
318
319if (count($page['infos']) != 0)
320{
321  $template->assign('infos', $page['infos']);
322}
323
324// +-----------------------------------------------------------------------+
325// |                          sending html code                            |
326// +-----------------------------------------------------------------------+
327
328$template->pparse('upgrade');
329?>
Note: See TracBrowser for help on using the repository browser.