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