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

Last change on this file since 1932 was 1932, checked in by rub, 18 years ago

o add missing $lang
o use of l10n_dec
o normalize file header

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