Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

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