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

Last change on this file since 675 was 675, checked in by plg, 19 years ago

all headers adapted to new year 2005, happy new year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
Line 
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-01-07 23:10:51 +0000 (Fri, 07 Jan 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 675 $
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
28if (!defined('IN_UPGRADE') or !IN_UPGRADE)
29{
30  die('Hacking attempt!');
31}
32
33$last_time = get_moment();
34
35// save data before deletion
36$query = '
37SELECT prefix_thumbnail, mail_webmaster
38  FROM '.PREFIX_TABLE.'config
39;';
40$save = mysql_fetch_array(mysql_query($query));
41
42$queries = array(
43  "
44DROP TABLE phpwebgallery_config
45;",
46
47  "
48CREATE TABLE phpwebgallery_config (
49  param varchar(40) NOT NULL default '',
50  value varchar(255) default NULL,
51  comment varchar(255) default NULL,
52  PRIMARY KEY  (param)
53) TYPE=MyISAM COMMENT='configuration table'
54;",
55
56  "
57ALTER TABLE phpwebgallery_categories
58  CHANGE COLUMN site_id site_id tinyint(4) unsigned default '1',
59  ADD COLUMN commentable enum('true','false') NOT NULL default 'true',
60  ADD COLUMN global_rank varchar(255) default NULL,
61  DROP INDEX id,
62  DROP INDEX id_uppercat,
63  ADD INDEX categories_i2 (id_uppercat)
64;",
65
66  "
67ALTER TABLE phpwebgallery_comments
68  ADD COLUMN date_temp int(11) unsigned
69;",
70
71  "
72UPDATE phpwebgallery_comments
73  SET date_temp = date
74;",
75 
76  "
77ALTER TABLE phpwebgallery_comments
78  CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00'
79;",
80
81  "
82UPDATE phpwebgallery_comments
83  SET date = FROM_UNIXTIME(date_temp)
84;",
85
86  "
87ALTER TABLE phpwebgallery_comments
88  DROP COLUMN date_temp
89;",
90
91  "
92ALTER TABLE phpwebgallery_favorites
93  DROP INDEX user_id,
94  ADD PRIMARY KEY (user_id,image_id)
95;",
96
97  "
98ALTER TABLE phpwebgallery_history
99  ADD COLUMN date_temp int(11) unsigned
100;",
101
102  "
103UPDATE phpwebgallery_history
104  SET date_temp = date
105;",
106 
107  "
108ALTER TABLE phpwebgallery_history
109  CHANGE COLUMN date date datetime NOT NULL default '0000-00-00 00:00:00'
110;",
111
112  "
113UPDATE phpwebgallery_history
114  SET date = FROM_UNIXTIME(date_temp)
115;",
116
117  "
118ALTER TABLE phpwebgallery_history
119  DROP COLUMN date_temp
120;",
121
122  "
123ALTER TABLE phpwebgallery_history
124  ADD INDEX history_i1 (date)
125;",
126
127  "
128ALTER TABLE phpwebgallery_image_category
129  DROP INDEX image_id,
130  DROP INDEX category_id,
131  ADD INDEX image_category_i1 (image_id),
132  ADD INDEX image_category_i2 (category_id)
133;",
134
135  "
136ALTER TABLE phpwebgallery_images
137  CHANGE COLUMN tn_ext tn_ext varchar(4) default '',
138  ADD COLUMN path varchar(255) NOT NULL default '',
139  ADD COLUMN date_metadata_update date default NULL,
140  ADD COLUMN average_rate float(5,2) unsigned default NULL,
141  ADD COLUMN representative_ext varchar(4) default NULL,
142  DROP INDEX storage_category_id,
143  ADD INDEX images_i1 (storage_category_id),
144  ADD INDEX images_i2 (date_available),
145  ADD INDEX images_i3 (average_rate),
146  ADD INDEX images_i4 (hit),
147  ADD INDEX images_i5 (date_creation)
148;",
149 
150  "
151ALTER TABLE phpwebgallery_sessions
152  DROP COLUMN ip
153;",
154
155    "
156ALTER TABLE phpwebgallery_sessions
157  ADD COLUMN expiration_temp int(11) unsigned
158;",
159
160  "
161UPDATE phpwebgallery_sessions
162  SET expiration_temp = expiration
163;",
164 
165  "
166ALTER TABLE phpwebgallery_sessions
167  CHANGE COLUMN expiration expiration datetime NOT NULL default '0000-00-00 00:00:00'
168;",
169
170  "
171UPDATE phpwebgallery_sessions
172  SET expiration = FROM_UNIXTIME(expiration_temp)
173;",
174
175  "
176ALTER TABLE phpwebgallery_sessions
177  DROP COLUMN expiration_temp
178;",
179 
180  "
181ALTER TABLE phpwebgallery_sites
182  DROP INDEX galleries_url,
183  ADD UNIQUE sites_ui1 (galleries_url)
184;",
185 
186  "
187DROP TABLE phpwebgallery_user_category
188;",
189
190  "
191ALTER TABLE phpwebgallery_users
192  DROP COLUMN long_period,
193  DROP COLUMN short_period,
194  DROP COLUMN forbidden_categories,
195  ADD COLUMN recent_period tinyint(3) unsigned NOT NULL default '7',
196  DROP INDEX username,
197  ADD UNIQUE users_ui1 (username)
198;",
199 
200  "
201CREATE TABLE phpwebgallery_rate (
202  user_id smallint(5) unsigned NOT NULL default '0',
203  element_id mediumint(8) unsigned NOT NULL default '0',
204  rate tinyint(2) unsigned NOT NULL default '0',
205  PRIMARY KEY  (user_id,element_id)
206) TYPE=MyISAM
207;",
208
209  "
210CREATE TABLE phpwebgallery_user_forbidden (
211  user_id smallint(5) unsigned NOT NULL default '0',
212  need_update enum('true','false') NOT NULL default 'true',
213  forbidden_categories text,
214  PRIMARY KEY  (user_id)
215) TYPE=MyISAM
216;",
217
218  "
219UPDATE phpwebgallery_users
220  SET language = 'en_UK.iso-8859-1'
221    , template = 'default'
222;",
223
224  "
225DELETE FROM phpwebgallery_user_access
226;",
227
228  "
229DELETE FROM phpwebgallery_group_access
230;"
231
232  );
233
234foreach ($queries as $query)
235{
236  $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query);
237  pwg_query($query);
238}
239
240$new_time = get_moment();
241echo '<pre>['.get_elapsed_time($last_time, $new_time).']';
242echo ' Basic database structure upgrade done</pre>';
243flush();
244$last_time = $new_time;
245
246execute_sqlfile(PHPWG_ROOT_PATH.'install/config.sql',
247                'phpwebgallery_',
248                PREFIX_TABLE);
249
250$queries = array(
251  "
252UPDATE phpwebgallery_config
253  SET value = '".$save['prefix_thumbnail']."'
254  WHERE param = 'prefix_thumbnail'
255;",
256
257  "
258UPDATE phpwebgallery_config
259  SET value = '".$save['mail_webmaster']."'
260  WHERE param = 'mail_webmaster'
261;"
262  );
263
264foreach ($queries as $query)
265{
266  $query = str_replace('phpwebgallery_', PREFIX_TABLE, $query);
267  pwg_query($query);
268}
269
270$new_time = get_moment();
271echo '<pre>['.get_elapsed_time($last_time, $new_time).']';
272echo ' Saved configuration information restored</pre>';
273flush();
274$last_time = $new_time;
275
276ordering();
277update_global_rank();
278update_category();
279
280$new_time = get_moment();
281echo '<pre>['.get_elapsed_time($last_time, $new_time).']';
282echo ' Calculated data updated (categories.rank, categories.global_rank,
283categories.date_last, categories.representative_picture_id,
284categories.nb_images)</pre>';
285flush();
286$last_time = $new_time;
287
288// update calculated field "images.path"
289$cat_ids = array();
290
291$query = '
292SELECT DISTINCT(storage_category_id) AS unique_storage_category_id
293  FROM '.IMAGES_TABLE.'
294;';
295$result = pwg_query($query);
296while ($row = mysql_fetch_array($result))
297{
298  array_push($cat_ids, $row['unique_storage_category_id']);
299}
300$fulldirs = get_fulldirs($cat_ids);
301
302foreach ($cat_ids as $cat_id)
303{
304  $query = '
305UPDATE '.IMAGES_TABLE.'
306  SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file)
307  WHERE storage_category_id = '.$cat_id.'
308;';
309  pwg_query($query);
310}
311
312$new_time = get_moment();
313echo '<pre>['.get_elapsed_time($last_time, $new_time).']';
314echo ' new column images.path filled</pre>';
315flush();
316$last_time = $new_time;
317
318// all sub-categories of private categories become private
319$cat_ids = array();
320
321$query = '
322SELECT id
323  FROM '.CATEGORIES_TABLE.'
324  WHERE status = \'private\'
325;';
326$result = pwg_query($query);
327while ($row = mysql_fetch_array($result))
328{
329  array_push($cat_ids, $row['id']);
330}
331
332if (count($cat_ids) > 0)
333{
334  $privates = get_subcat_ids($cat_ids);
335
336  $query = '
337UPDATE '.CATEGORIES_TABLE.'
338  SET status = \'private\'
339  WHERE id IN ('.implode(',', $privates).')
340;';
341  pwg_query($query);
342}
343
344$new_time = get_moment();
345echo '<pre>['.get_elapsed_time($last_time, $new_time).']';
346echo ' all sub-categories of private categories become private</pre>';
347flush();
348$last_time = $new_time;
349
350$infos = array(
351  'user permissions and group permissions have been erased',
352
353  'only thumbnails prefix and webmaster mail address have been saved from
354previous configuration',
355
356  'in include/mysql.inc.php, before
357<pre style="background-color:lightgray">?&gt;</pre>
358insert
359<pre style="background-color:lightgray">define(\'PHPWG_INSTALLED\', true);<pre>'
360 
361  );
362
363?>
Note: See TracBrowser for help on using the repository browser.