source: branches/1.4/install/upgrade_1.3.0.php @ 14508

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