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-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2005-10-23 23:02:21 +0200 (dim, 23 oct 2005) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 911 $ |
---|
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 | |
---|
28 | if (!defined('PHPWG_ROOT_PATH')) |
---|
29 | { |
---|
30 | die ('This page cannot be loaded directly, load upgrade.php'); |
---|
31 | } |
---|
32 | else |
---|
33 | { |
---|
34 | if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE) |
---|
35 | { |
---|
36 | die ('Hacking attempt!'); |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * replace old style #images.keywords by #tags. Requires a big data |
---|
42 | * migration. |
---|
43 | * |
---|
44 | * @return void |
---|
45 | */ |
---|
46 | function tag_replace_keywords() |
---|
47 | { |
---|
48 | // code taken from upgrades 19 and 22 |
---|
49 | |
---|
50 | $query = ' |
---|
51 | CREATE TABLE '.PREFIX_TABLE.'tags ( |
---|
52 | id smallint(5) UNSIGNED NOT NULL auto_increment, |
---|
53 | name varchar(255) BINARY NOT NULL, |
---|
54 | url_name varchar(255) BINARY NOT NULL, |
---|
55 | PRIMARY KEY (id) |
---|
56 | ) |
---|
57 | ;'; |
---|
58 | pwg_query($query); |
---|
59 | |
---|
60 | $query = ' |
---|
61 | CREATE TABLE '.PREFIX_TABLE.'image_tag ( |
---|
62 | image_id mediumint(8) UNSIGNED NOT NULL, |
---|
63 | tag_id smallint(5) UNSIGNED NOT NULL, |
---|
64 | PRIMARY KEY (image_id,tag_id) |
---|
65 | ) |
---|
66 | ;'; |
---|
67 | pwg_query($query); |
---|
68 | |
---|
69 | // |
---|
70 | // Move keywords to tags |
---|
71 | // |
---|
72 | |
---|
73 | // each tag label is associated to a numeric identifier |
---|
74 | $tag_id = array(); |
---|
75 | // to each tag id (key) a list of image ids (value) is associated |
---|
76 | $tag_images = array(); |
---|
77 | |
---|
78 | $current_id = 1; |
---|
79 | |
---|
80 | $query = ' |
---|
81 | SELECT id, keywords |
---|
82 | FROM '.PREFIX_TABLE.'images |
---|
83 | WHERE keywords IS NOT NULL |
---|
84 | ;'; |
---|
85 | $result = pwg_query($query); |
---|
86 | while ($row = mysql_fetch_array($result)) |
---|
87 | { |
---|
88 | foreach(preg_split('/[,]+/', $row['keywords']) as $keyword) |
---|
89 | { |
---|
90 | if (!isset($tag_id[$keyword])) |
---|
91 | { |
---|
92 | $tag_id[$keyword] = $current_id++; |
---|
93 | } |
---|
94 | |
---|
95 | if (!isset($tag_images[ $tag_id[$keyword] ])) |
---|
96 | { |
---|
97 | $tag_images[ $tag_id[$keyword] ] = array(); |
---|
98 | } |
---|
99 | |
---|
100 | array_push( |
---|
101 | $tag_images[ $tag_id[$keyword] ], |
---|
102 | $row['id'] |
---|
103 | ); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | $datas = array(); |
---|
108 | foreach ($tag_id as $tag_name => $tag_id) |
---|
109 | { |
---|
110 | array_push( |
---|
111 | $datas, |
---|
112 | array( |
---|
113 | 'id' => $tag_id, |
---|
114 | 'name' => $tag_name, |
---|
115 | 'url_name' => str2url($tag_name), |
---|
116 | ) |
---|
117 | ); |
---|
118 | } |
---|
119 | |
---|
120 | if (!empty($datas)) |
---|
121 | { |
---|
122 | mass_inserts( |
---|
123 | PREFIX_TABLE.'tags', |
---|
124 | array_keys($datas[0]), |
---|
125 | $datas |
---|
126 | ); |
---|
127 | } |
---|
128 | |
---|
129 | $datas = array(); |
---|
130 | foreach ($tag_images as $tag_id => $images) |
---|
131 | { |
---|
132 | foreach (array_unique($images) as $image_id) |
---|
133 | { |
---|
134 | array_push( |
---|
135 | $datas, |
---|
136 | array( |
---|
137 | 'tag_id' => $tag_id, |
---|
138 | 'image_id' => $image_id, |
---|
139 | ) |
---|
140 | ); |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | if (!empty($datas)) |
---|
145 | { |
---|
146 | mass_inserts( |
---|
147 | PREFIX_TABLE.'image_tag', |
---|
148 | array_keys($datas[0]), |
---|
149 | $datas |
---|
150 | ); |
---|
151 | } |
---|
152 | |
---|
153 | // |
---|
154 | // Delete images.keywords |
---|
155 | // |
---|
156 | $query = ' |
---|
157 | ALTER TABLE '.PREFIX_TABLE.'images DROP COLUMN keywords |
---|
158 | ;'; |
---|
159 | pwg_query($query); |
---|
160 | |
---|
161 | // |
---|
162 | // Add useful indexes |
---|
163 | // |
---|
164 | $query = ' |
---|
165 | ALTER TABLE '.PREFIX_TABLE.'tags |
---|
166 | ADD INDEX tags_i1(url_name) |
---|
167 | ;'; |
---|
168 | pwg_query($query); |
---|
169 | |
---|
170 | |
---|
171 | $query = ' |
---|
172 | ALTER TABLE '.PREFIX_TABLE.'image_tag |
---|
173 | ADD INDEX image_tag_i1(tag_id) |
---|
174 | ;'; |
---|
175 | pwg_query($query); |
---|
176 | |
---|
177 | // print_time('tags have replaced keywords'); |
---|
178 | } |
---|
179 | |
---|
180 | tag_replace_keywords(); |
---|
181 | |
---|
182 | $queries = array( |
---|
183 | " |
---|
184 | CREATE TABLE ".PREFIX_TABLE."search ( |
---|
185 | id int UNSIGNED NOT NULL AUTO_INCREMENT, |
---|
186 | last_seen date DEFAULT NULL, |
---|
187 | rules text, |
---|
188 | PRIMARY KEY (id) |
---|
189 | );", |
---|
190 | |
---|
191 | " |
---|
192 | CREATE TABLE ".PREFIX_TABLE."user_mail_notification ( |
---|
193 | user_id smallint(5) NOT NULL default '0', |
---|
194 | check_key varchar(16) binary NOT NULL default '', |
---|
195 | enabled enum('true','false') NOT NULL default 'false', |
---|
196 | last_send datetime default NULL, |
---|
197 | PRIMARY KEY (user_id), |
---|
198 | UNIQUE KEY uidx_check_key (check_key) |
---|
199 | );", |
---|
200 | |
---|
201 | " |
---|
202 | CREATE TABLE ".PREFIX_TABLE."upgrade ( |
---|
203 | id varchar(20) NOT NULL default '', |
---|
204 | applied datetime NOT NULL default '0000-00-00 00:00:00', |
---|
205 | description varchar(255) default NULL, |
---|
206 | PRIMARY KEY (`id`) |
---|
207 | );", |
---|
208 | |
---|
209 | " |
---|
210 | ALTER TABLE ".PREFIX_TABLE."config |
---|
211 | MODIFY COLUMN value TEXT |
---|
212 | ;", |
---|
213 | |
---|
214 | " |
---|
215 | ALTER TABLE ".PREFIX_TABLE."images |
---|
216 | ADD COLUMN has_high enum('true') default NULL |
---|
217 | ;", |
---|
218 | |
---|
219 | " |
---|
220 | ALTER TABLE ".PREFIX_TABLE."rate |
---|
221 | ADD COLUMN anonymous_id varchar(45) NOT NULL default '' |
---|
222 | ;", |
---|
223 | " |
---|
224 | ALTER TABLE ".PREFIX_TABLE."rate |
---|
225 | ADD COLUMN date date NOT NULL default '0000-00-00' |
---|
226 | ;", |
---|
227 | " |
---|
228 | ALTER TABLE ".PREFIX_TABLE."rate |
---|
229 | DROP PRIMARY KEY |
---|
230 | ;", |
---|
231 | " |
---|
232 | ALTER TABLE ".PREFIX_TABLE."rate |
---|
233 | ADD PRIMARY KEY (element_id,user_id,anonymous_id) |
---|
234 | ;", |
---|
235 | " |
---|
236 | UPDATE ".PREFIX_TABLE."rate |
---|
237 | SET date = CURDATE() |
---|
238 | ;", |
---|
239 | |
---|
240 | " |
---|
241 | DELETE |
---|
242 | FROM ".PREFIX_TABLE."sessions |
---|
243 | ;", |
---|
244 | " |
---|
245 | ALTER TABLE ".PREFIX_TABLE."sessions |
---|
246 | DROP COLUMN user_id |
---|
247 | ;", |
---|
248 | " |
---|
249 | ALTER TABLE ".PREFIX_TABLE."sessions |
---|
250 | ADD COLUMN data text NOT NULL |
---|
251 | ;", |
---|
252 | |
---|
253 | " |
---|
254 | ALTER TABLE ".PREFIX_TABLE."user_cache |
---|
255 | ADD COLUMN nb_total_images mediumint(8) unsigned default NULL |
---|
256 | ;", |
---|
257 | |
---|
258 | " |
---|
259 | ALTER TABLE ".PREFIX_TABLE."user_infos |
---|
260 | CHANGE COLUMN status |
---|
261 | status enum('webmaster','admin','normal','generic','guest') |
---|
262 | NOT NULL default 'guest' |
---|
263 | ;", |
---|
264 | " |
---|
265 | UPDATE ".PREFIX_TABLE."user_infos |
---|
266 | SET status = 'normal' |
---|
267 | WHERE status = 'guest' |
---|
268 | ;", |
---|
269 | " |
---|
270 | UPDATE ".PREFIX_TABLE."user_infos |
---|
271 | SET status = 'guest' |
---|
272 | WHERE user_id = ".$conf['guest_id']." |
---|
273 | ;", |
---|
274 | " |
---|
275 | UPDATE ".PREFIX_TABLE."user_infos |
---|
276 | SET status = 'webmaster' |
---|
277 | WHERE user_id = ".$conf['webmaster_id']." |
---|
278 | ;", |
---|
279 | |
---|
280 | " |
---|
281 | ALTER TABLE ".PREFIX_TABLE."user_infos |
---|
282 | CHANGE COLUMN template template varchar(255) NOT NULL default 'yoga/clear' |
---|
283 | ;", |
---|
284 | |
---|
285 | " |
---|
286 | UPDATE ".PREFIX_TABLE."user_infos |
---|
287 | SET template = 'yoga/dark' |
---|
288 | WHERE template = 'yoga-dark' |
---|
289 | ;", |
---|
290 | " |
---|
291 | UPDATE ".PREFIX_TABLE."user_infos |
---|
292 | SET template = 'yoga/clear' |
---|
293 | WHERE template != 'yoga/dark' |
---|
294 | ;", |
---|
295 | " |
---|
296 | ALTER TABLE ".PREFIX_TABLE."user_infos |
---|
297 | ADD COLUMN adviser enum('true','false') NOT NULL default 'false' |
---|
298 | ;", |
---|
299 | " |
---|
300 | ALTER TABLE ".PREFIX_TABLE."user_infos |
---|
301 | ADD COLUMN enabled_high enum('true','false') NOT NULL default 'true' |
---|
302 | ;", |
---|
303 | " |
---|
304 | ALTER TABLE ".PREFIX_TABLE."categories |
---|
305 | CHANGE COLUMN rank rank SMALLINT(5) UNSIGNED DEFAULT NULL |
---|
306 | ;", |
---|
307 | // configuration table |
---|
308 | " |
---|
309 | UPDATE ".PREFIX_TABLE."config |
---|
310 | SET value = 'yoga/clear' |
---|
311 | WHERE param = 'default_template' |
---|
312 | ;" |
---|
313 | ); |
---|
314 | |
---|
315 | foreach ($queries as $query) |
---|
316 | { |
---|
317 | pwg_query($query); |
---|
318 | } |
---|
319 | |
---|
320 | // |
---|
321 | // Move rate, rate_anonymous and gallery_url from config file to database |
---|
322 | // |
---|
323 | $params = array( |
---|
324 | 'gallery_url' => array( |
---|
325 | 'http://demo.phpwebgallery.net', |
---|
326 | 'URL given in RSS feed' |
---|
327 | ), |
---|
328 | 'rate' => array( |
---|
329 | 'true', |
---|
330 | 'Rating pictures feature is enabled' |
---|
331 | ), |
---|
332 | 'rate_anonymous' => array( |
---|
333 | 'true', |
---|
334 | 'Rating pictures feature is also enabled for visitors' |
---|
335 | ) |
---|
336 | ); |
---|
337 | // Get real values from config file |
---|
338 | $conf_save = $conf; |
---|
339 | unset($conf); |
---|
340 | @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); |
---|
341 | if ( isset($conf['gallery_url']) ) |
---|
342 | { |
---|
343 | $params['gallery_url'][0] = $conf['gallery_url']; |
---|
344 | } |
---|
345 | if ( isset($conf['rate']) and is_bool($conf['rate']) ) |
---|
346 | { |
---|
347 | $params['rate'][0] = $conf['rate'] ? 'true' : 'false'; |
---|
348 | } |
---|
349 | if ( isset($conf['rate_anonymous']) and is_bool($conf['rate_anonymous']) ) |
---|
350 | { |
---|
351 | $params['rate_anonymous'][0] = $conf['rate_anonymous'] ? 'true' : 'false'; |
---|
352 | } |
---|
353 | $conf = $conf_save; |
---|
354 | |
---|
355 | // Do I already have them in DB ? |
---|
356 | $query = 'SELECT param FROM '.PREFIX_TABLE.'config'; |
---|
357 | $result = pwg_query($query); |
---|
358 | while ($row = mysql_fetch_array($result)) |
---|
359 | { |
---|
360 | unset( $params[ $row['param'] ] ); |
---|
361 | } |
---|
362 | |
---|
363 | // Perform the insert query |
---|
364 | foreach ($params as $param_key => $param_values) |
---|
365 | { |
---|
366 | $query = ' |
---|
367 | INSERT INTO '.PREFIX_TABLE.'config |
---|
368 | (param,value,comment) |
---|
369 | VALUES |
---|
370 | ('."'$param_key','$param_values[0]','$param_values[1]') |
---|
371 | ;"; |
---|
372 | pwg_query($query); |
---|
373 | } |
---|
374 | |
---|
375 | $query = " |
---|
376 | ALTER TABLE ".PREFIX_TABLE."config MODIFY COLUMN `value` TEXT;"; |
---|
377 | pwg_query($query); |
---|
378 | |
---|
379 | |
---|
380 | // |
---|
381 | // replace gallery_description by page_banner |
---|
382 | // |
---|
383 | $query = ' |
---|
384 | SELECT value |
---|
385 | FROM '.PREFIX_TABLE.'config |
---|
386 | WHERE param=\'gallery_title\' |
---|
387 | ;'; |
---|
388 | list($t) = array_from_query($query, 'value'); |
---|
389 | |
---|
390 | $query = ' |
---|
391 | SELECT value |
---|
392 | FROM '.PREFIX_TABLE.'config |
---|
393 | WHERE param=\'gallery_description\' |
---|
394 | ;'; |
---|
395 | list($d) = array_from_query($query, 'value'); |
---|
396 | |
---|
397 | $page_banner='<div id="theHeader"><h1>'.$t.'</h1><p>'.$d.'</p></div>'; |
---|
398 | $page_banner=addslashes($page_banner); |
---|
399 | $query = ' |
---|
400 | INSERT INTO '.PREFIX_TABLE.'config |
---|
401 | (param,value,comment) |
---|
402 | VALUES |
---|
403 | ( |
---|
404 | \'page_banner\', |
---|
405 | \''.$page_banner.'\', |
---|
406 | \'html displayed on the top each page of your gallery\' |
---|
407 | ) |
---|
408 | ;'; |
---|
409 | pwg_query($query); |
---|
410 | |
---|
411 | $query = ' |
---|
412 | DELETE FROM '.PREFIX_TABLE.'config |
---|
413 | WHERE param=\'gallery_description\' |
---|
414 | ;'; |
---|
415 | pwg_query($query); |
---|
416 | |
---|
417 | // |
---|
418 | // configuration for notification by mail |
---|
419 | // |
---|
420 | $query = " |
---|
421 | INSERT INTO ".CONFIG_TABLE." |
---|
422 | (param,value,comment) |
---|
423 | VALUES |
---|
424 | ( |
---|
425 | 'nbm_send_mail_as', |
---|
426 | '', |
---|
427 | 'Send mail as param value for notification by mail' |
---|
428 | ), |
---|
429 | ( |
---|
430 | 'nbm_send_detailed_content', |
---|
431 | 'true', |
---|
432 | 'Send detailed content for notification by mail' |
---|
433 | ), |
---|
434 | ( |
---|
435 | 'nbm_complementary_mail_content', |
---|
436 | '', |
---|
437 | 'Complementary mail content for notification by mail' |
---|
438 | ) |
---|
439 | ; |
---|
440 | "; |
---|
441 | pwg_query($query); |
---|
442 | |
---|
443 | // depending on the way the 1.5.0 was installed (from scratch or by upgrade) |
---|
444 | // the database structure has small differences that should be corrected. |
---|
445 | |
---|
446 | $query = ' |
---|
447 | ALTER TABLE '.PREFIX_TABLE.'users |
---|
448 | CHANGE COLUMN password password varchar(32) default NULL |
---|
449 | ;'; |
---|
450 | pwg_query($query); |
---|
451 | |
---|
452 | $to_keep = array('id', 'username', 'password', 'mail_address'); |
---|
453 | |
---|
454 | $query = ' |
---|
455 | DESC '.PREFIX_TABLE.'users |
---|
456 | ;'; |
---|
457 | |
---|
458 | $result = pwg_query($query); |
---|
459 | |
---|
460 | while ($row = mysql_fetch_array($result)) |
---|
461 | { |
---|
462 | if (!in_array($row['Field'], $to_keep)) |
---|
463 | { |
---|
464 | $query = ' |
---|
465 | ALTER TABLE '.PREFIX_TABLE.'users |
---|
466 | DROP COLUMN '.$row['Field'].' |
---|
467 | ;'; |
---|
468 | pwg_query($query); |
---|
469 | } |
---|
470 | } |
---|
471 | |
---|
472 | ?> |
---|