source: trunk/install/upgrade_1.3.1.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 15.1 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// +-----------------------------------------------------------------------+
25// | PhpWebGallery - a PHP based picture gallery                           |
26// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
27// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
28// +-----------------------------------------------------------------------+
29// | file          : $Id: upgrade_1.3.1.php 2297 2008-04-04 22:57:23Z plg $
30// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
31// | last modifier : $Author: plg $
32// | revision      : $Revision: 2297 $
33// +-----------------------------------------------------------------------+
34// | This program is free software; you can redistribute it and/or modify  |
35// | it under the terms of the GNU General Public License as published by  |
36// | the Free Software Foundation                                          |
37// |                                                                       |
38// | This program is distributed in the hope that it will be useful, but   |
39// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
40// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
41// | General Public License for more details.                              |
42// |                                                                       |
43// | You should have received a copy of the GNU General Public License     |
44// | along with this program; if not, write to the Free Software           |
45// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
46// | USA.                                                                  |
47// +-----------------------------------------------------------------------+
48
49/**
50 * Upgrade from 1.3.x (x >= 1) to 1.4.0
51 */
52
53if (!defined('PHPWG_ROOT_PATH'))
54{
55  die ('This page cannot be loaded directly, load upgrade.php');
56}
57else
58{
59  if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE)
60  {
61    die ('Hacking attempt!');
62  }
63}
64
65// save data before deletion
66$query = '
67SELECT prefix_thumbnail, mail_webmaster
68  FROM '.PREFIX_TABLE.'config
69;';
70$save = mysql_fetch_array(mysql_query($query));
71
72$queries = array(
73  "
74DROP TABLE phpwebgallery_config
75;",
76
77  "
78CREATE TABLE phpwebgallery_config (
79  param varchar(40) NOT NULL default '',
80  value varchar(255) default NULL,
81  comment varchar(255) default NULL,
82  PRIMARY KEY  (param)
83) TYPE=MyISAM COMMENT='configuration table'
84;",
85
86  "
87ALTER TABLE phpwebgallery_categories
88  CHANGE COLUMN site_id site_id tinyint(4) unsigned default '1'
89;",
90
91  "
92ALTER TABLE phpwebgallery_categories
93  ADD COLUMN commentable enum('true','false') NOT NULL default 'true'
94;",
95 
96  "
97ALTER TABLE phpwebgallery_categories
98  ADD COLUMN global_rank varchar(255) default NULL
99;",
100
101  "
102ALTER TABLE phpwebgallery_categories
103  ADD INDEX categories_i2 (id_uppercat)
104;",
105
106  "
107ALTER TABLE phpwebgallery_comments
108  ADD COLUMN date_temp int(11) unsigned
109;",
110
111  "
112UPDATE phpwebgallery_comments
113  SET date_temp = date
114;",
115 
116  "
117ALTER TABLE phpwebgallery_comments
118  CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00'
119;",
120
121  "
122UPDATE phpwebgallery_comments
123  SET date = FROM_UNIXTIME(date_temp)
124;",
125
126  "
127ALTER TABLE phpwebgallery_comments
128  DROP COLUMN date_temp
129;",
130
131  "
132ALTER TABLE phpwebgallery_favorites
133  DROP INDEX user_id
134;",
135
136  "
137ALTER TABLE phpwebgallery_favorites
138  ADD PRIMARY KEY (user_id,image_id)
139;",
140
141  "
142ALTER TABLE phpwebgallery_history
143  ADD COLUMN date_temp int(11) unsigned
144;",
145
146  "
147UPDATE phpwebgallery_history
148  SET date_temp = date
149;",
150 
151  "
152ALTER TABLE phpwebgallery_history
153  CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00'
154;",
155
156  "
157UPDATE phpwebgallery_history
158  SET date = FROM_UNIXTIME(date_temp)
159;",
160
161  "
162ALTER TABLE phpwebgallery_history
163  DROP COLUMN date_temp
164;",
165
166  "
167ALTER TABLE phpwebgallery_history
168  ADD INDEX history_i1 (date)
169;",
170
171  "
172ALTER TABLE phpwebgallery_image_category
173  ADD INDEX image_category_i1 (image_id),
174  ADD INDEX image_category_i2 (category_id)
175;",
176
177  "
178ALTER TABLE phpwebgallery_images
179  CHANGE COLUMN tn_ext tn_ext varchar(4) default ''
180;",
181
182  "
183ALTER TABLE phpwebgallery_images
184  ADD COLUMN path varchar(255) NOT NULL default ''
185;",
186
187  "
188ALTER TABLE phpwebgallery_images
189  ADD COLUMN date_metadata_update date default NULL
190;",
191
192  "
193ALTER TABLE phpwebgallery_images
194  ADD COLUMN average_rate float(5,2) unsigned default NULL
195;",
196
197  "
198ALTER TABLE phpwebgallery_images
199  ADD COLUMN representative_ext varchar(4) default NULL
200;",
201
202  "
203ALTER TABLE phpwebgallery_images
204  DROP INDEX storage_category_id
205;",
206
207  "
208ALTER TABLE phpwebgallery_images
209  ADD INDEX images_i1 (storage_category_id)
210;",
211
212  "
213ALTER TABLE phpwebgallery_images
214  ADD INDEX images_i2 (date_available)
215;",
216
217  "
218ALTER TABLE phpwebgallery_images
219  ADD INDEX images_i3 (average_rate)
220;",
221
222  "
223ALTER TABLE phpwebgallery_images
224  ADD INDEX images_i4 (hit)
225;",
226
227  "
228ALTER TABLE phpwebgallery_images
229  ADD INDEX images_i5 (date_creation)
230;",
231 
232  "
233ALTER TABLE phpwebgallery_sessions
234  DROP COLUMN ip
235;",
236
237    "
238ALTER TABLE phpwebgallery_sessions
239  ADD COLUMN expiration_temp int(11) unsigned
240;",
241
242  "
243UPDATE phpwebgallery_sessions
244  SET expiration_temp = expiration
245;",
246 
247  "
248ALTER TABLE phpwebgallery_sessions
249  CHANGE COLUMN expiration expiration datetime NOT NULL default '0000-00-00 00:00:00'
250;",
251
252  "
253UPDATE phpwebgallery_sessions
254  SET expiration = FROM_UNIXTIME(expiration_temp)
255;",
256
257  "
258ALTER TABLE phpwebgallery_sessions
259  DROP COLUMN expiration_temp
260;",
261 
262  "
263ALTER TABLE phpwebgallery_sites
264  DROP INDEX galleries_url
265;",
266
267  "
268ALTER TABLE phpwebgallery_sites
269  ADD UNIQUE sites_ui1 (galleries_url)
270;",
271
272  "
273DROP TABLE phpwebgallery_user_category
274;",
275 
276  "
277ALTER TABLE phpwebgallery_users
278  DROP COLUMN long_period
279;",
280
281  "
282ALTER TABLE phpwebgallery_users
283  DROP COLUMN short_period
284;",
285
286  "
287ALTER TABLE phpwebgallery_users
288  ADD COLUMN recent_period tinyint(3) unsigned NOT NULL default '7'
289;",
290
291  "
292ALTER TABLE phpwebgallery_users
293  DROP INDEX username
294;",
295
296  "
297ALTER TABLE phpwebgallery_users
298  ADD UNIQUE users_ui1 (username)
299;",
300 
301  "
302CREATE TABLE phpwebgallery_rate (
303  user_id smallint(5) unsigned NOT NULL default '0',
304  element_id mediumint(8) unsigned NOT NULL default '0',
305  rate tinyint(2) unsigned NOT NULL default '0',
306  PRIMARY KEY  (user_id,element_id)
307) TYPE=MyISAM
308;",
309
310  "
311CREATE TABLE phpwebgallery_user_forbidden (
312  user_id smallint(5) unsigned NOT NULL default '0',
313  need_update enum('true','false') NOT NULL default 'true',
314  forbidden_categories text,
315  PRIMARY KEY  (user_id)
316) TYPE=MyISAM
317;",
318
319  "
320UPDATE phpwebgallery_users
321  SET language = 'en_UK.iso-8859-1'
322    , template = 'default'
323;",
324
325  "
326DELETE FROM phpwebgallery_user_access
327;",
328
329  "
330DELETE FROM phpwebgallery_group_access
331;"
332
333  );
334
335foreach ($queries as $query)
336{
337  $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query);
338  pwg_query($query);
339}
340
341//
342// check indexes
343//
344$indexes_of = array(
345  'categories' => array(
346    'categories_i2' => array(
347      'columns' => array('id_uppercat'),
348      'unique' => false,
349      )
350    ),
351  'image_category' => array(
352    'image_category_i1' => array(
353      'columns' => array('image_id'),
354      'unique' => false,
355      ),
356    'image_category_i2' => array(
357      'columns' => array('category_id'),
358      'unique' => false,
359      ),
360    ),
361  );
362
363foreach (array_keys($indexes_of) as $table)
364{
365  $existing_indexes = array();
366 
367  $query = '
368SHOW INDEX
369  FROM '.PREFIX_TABLE.$table.'
370;';
371  $result = pwg_query($query);
372  while ($row = mysql_fetch_array($result))
373  {
374    if ($row['Key_name'] != 'PRIMARY')
375    {
376      if (!in_array($row['Key_name'], array_keys($indexes_of[$table])))
377      {
378        $query = '
379ALTER TABLE '.PREFIX_TABLE.$table.'
380  DROP INDEX '.$row['Key_name'].'
381;';
382        pwg_query($query);
383      }
384      else
385      {
386        array_push($existing_indexes, $row['Key_name']);
387      }
388    }
389  }
390
391  foreach ($indexes_of[$table] as $index_name => $index)
392  {
393    if (!in_array($index_name, $existing_indexes))
394    {
395      $query = '
396ALTER TABLE '.PREFIX_TABLE.$table.'
397  ADD '.($index['unique'] ? 'UNIQUE' : 'INDEX').' '
398        .$index_name.' ('.implode(',', $index['columns']).')
399;';
400      pwg_query($query);
401    }
402  }
403}
404
405//
406// insert params in new configuration table
407//
408$params = array(
409  array(
410    'param'   => 'prefix_thumbnail',
411    'value'   => $save['prefix_thumbnail'],
412    'comment' => 'thumbnails filename prefix'
413    ),
414  array(
415    'param'   => 'mail_webmaster',
416    'value'   => $save['mail_webmaster'],
417    'comment' => 'webmaster mail'
418    ),
419  array(
420    'param'   => 'default_language',
421    'value'   => 'en_UK.iso-8859-1',
422    'comment' => 'Default gallery language'
423    ),
424  array(
425    'param'   => 'default_template',
426    'value'   => 'default',
427    'comment' => 'Default gallery style'
428    ),
429  array(
430    'param'   => 'default_maxwidth',
431    'value'   => '',
432    'comment' => 'maximum width authorized for displaying images'
433    ),
434  array(
435    'param'   => 'default_maxheight',
436    'value'   => '',
437    'comment' => 'maximum height authorized for the displaying images'
438    ),
439  array(
440    'param'   => 'nb_comment_page',
441    'value'   => '10',
442    'comment' => 'number of comments to display on each page'
443    ),
444  array(
445    'param'   => 'upload_maxfilesize',
446    'value'   => '150',
447    'comment' => 'maximum filesize for the uploaded pictures'
448    ),
449  array(
450    'param'   => 'upload_maxwidth',
451    'value'   => '800',
452    'comment' => 'maximum width authorized for the uploaded images'
453    ),
454  array(
455    'param'   => 'upload_maxheight',
456    'value'   => '600',
457    'comment' => 'maximum height authorized for the uploaded images'
458    ),
459  array(
460    'param'   => 'upload_maxwidth_thumbnail',
461    'value'   => '150',
462    'comment' => 'maximum width authorized for the uploaded thumbnails'
463    ),
464  array(
465    'param'   => 'upload_maxheight_thumbnail',
466    'value'   => '100',
467    'comment' => 'maximum height authorized for the uploaded thumbnails'
468    ),
469  array(
470    'param'   => 'log',
471    'value'   => 'false',
472    'comment' => 'keep an history of visits on your website'
473    ),
474  array(
475    'param'   => 'comments_validation',
476    'value'   => 'false',
477    'comment' => 'administrators validate users comments before becoming visible'
478    ),
479  array(
480    'param'   => 'comments_forall',
481    'value'   => 'false',
482    'comment' => 'even guest not registered can post comments'
483    ),
484  array(
485    'param'   => 'mail_notification',
486    'value'   => 'false',
487    'comment' => 'automated mail notification for adminsitrators'
488    ),
489  array(
490    'param'   => 'nb_image_line',
491    'value'   => '5',
492    'comment' => 'Number of images displayed per row'
493    ),
494  array(
495    'param'   => 'nb_line_page',
496    'value'   => '3',
497    'comment' => 'Number of rows displayed per page'
498    ),
499  array(
500    'param'   => 'recent_period',
501    'value'   => '7',
502    'comment' => 'Period within which pictures are displayed as new (in days)'
503    ),
504  array(
505    'param'   => 'auto_expand',
506    'value'   => 'false',
507    'comment' => 'Auto expand of the category tree'
508    ),
509  array(
510    'param'   => 'show_nb_comments',
511    'value'   => 'false',
512    'comment' => 'Show the number of comments under the thumbnails'
513    ),
514  array(
515    'param'   => 'use_iptc',
516    'value'   => 'false',
517    'comment' => 'Use IPTC data during database synchronization with files metadata'
518    ),
519  array(
520    'param'   => 'use_exif',
521    'value'   => 'false',
522    'comment' => 'Use EXIF data during database synchronization with files metadata'
523    ),
524  array(
525    'param'   => 'show_iptc',
526    'value'   => 'false',
527    'comment' => 'Show IPTC metadata on picture.php if asked by user'
528    ),
529  array(
530    'param'   => 'show_exif',
531    'value'   => 'true',
532    'comment' => 'Show EXIF metadata on picture.php if asked by user'
533    ),
534  array(
535    'param'   => 'authorize_remembering',
536    'value'   => 'true',
537    'comment' => 'Authorize users to be remembered, see $conf{remember_me_length}'
538    ),
539  array(
540    'param'   => 'gallery_locked',
541    'value'   => 'false',
542    'comment' => 'Lock your gallery temporary for non admin users'
543    ),
544  );
545
546mass_inserts(
547  CONFIG_TABLE,
548  array_keys($params[0]),
549  $params
550  );
551
552// refresh calculated datas
553ordering();
554update_global_rank();
555update_category();
556
557// update calculated field "images.path"
558$cat_ids = array();
559
560$query = '
561SELECT DISTINCT(storage_category_id) AS unique_storage_category_id
562  FROM '.IMAGES_TABLE.'
563;';
564$result = pwg_query($query);
565while ($row = mysql_fetch_array($result))
566{
567  array_push($cat_ids, $row['unique_storage_category_id']);
568}
569$fulldirs = get_fulldirs($cat_ids);
570
571foreach ($cat_ids as $cat_id)
572{
573  $query = '
574UPDATE '.IMAGES_TABLE.'
575  SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file)
576  WHERE storage_category_id = '.$cat_id.'
577;';
578  pwg_query($query);
579}
580
581// all sub-categories of private categories become private
582$cat_ids = array();
583
584$query = '
585SELECT id
586  FROM '.CATEGORIES_TABLE.'
587  WHERE status = \'private\'
588;';
589$result = pwg_query($query);
590while ($row = mysql_fetch_array($result))
591{
592  array_push($cat_ids, $row['id']);
593}
594
595if (count($cat_ids) > 0)
596{
597  $privates = get_subcat_ids($cat_ids);
598
599  $query = '
600UPDATE '.CATEGORIES_TABLE.'
601  SET status = \'private\'
602  WHERE id IN ('.implode(',', $privates).')
603;';
604  pwg_query($query);
605}
606
607$page['infos'] = array_merge(
608  $page['infos'],
609  array(
610    'all sub-categories of private categories become private',
611   
612    'user permissions and group permissions have been erased',
613
614    'only thumbnails prefix and webmaster mail address have been saved from
615previous configuration',
616
617    'in include/mysql.inc.php, before
618<pre style="background-color:lightgray">?&gt;</pre>
619insert
620<pre style="background-color:lightgray">define(\'PHPWG_INSTALLED\', true);<pre>'
621    )
622  );
623
624
625// now we upgrade from 1.4.0
626include_once(PHPWG_ROOT_PATH.'install/upgrade_1.4.0.php');
627?>
Note: See TracBrowser for help on using the repository browser.