source: branches/2.6/install/upgrade_1.3.1.php @ 26827

Last change on this file since 26827 was 26461, checked in by mistic100, 11 years ago

Update headers to 2014. Happy new year!!

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