aboutsummaryrefslogtreecommitdiffstats
path: root/install/upgrade_1.6.2.php
blob: 44c479cfa9600c731edc12aab648293804d516eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery                           |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch        : BSF (Best So Far)
// | file          : $RCSfile$
// | last update   : $Date: 2005-10-23 23:02:21 +0200 (dim, 23 oct 2005) $
// | last modifier : $Author: plg $
// | revision      : $Revision: 911 $
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+

if (!defined('PHPWG_ROOT_PATH'))
{
  die ('This page cannot be loaded directly, load upgrade.php');
}
else
{
  if (!defined('PHPWG_IN_UPGRADE') or !PHPWG_IN_UPGRADE)
  {
    die ('Hacking attempt!');
  }
}

$queries = array(
"
ALTER TABLE `".PREFIX_TABLE."categories`
  ADD COLUMN `permalink` varchar(64) default NULL
;",

"
ALTER TABLE `".PREFIX_TABLE."categories`
  ADD COLUMN `image_order` varchar(128) default NULL
;",

"
ALTER TABLE `".PREFIX_TABLE."categories`
  ADD UNIQUE `categories_i3` (`permalink`)
;",

"
ALTER TABLE `".PREFIX_TABLE."groups`
  ADD COLUMN `is_default` enum('true','false') NOT NULL default 'false'
;",

"
RENAME TABLE `".PREFIX_TABLE."history` TO `".PREFIX_TABLE."history_backup`
;",

"
CREATE TABLE `".PREFIX_TABLE."history` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `date` date NOT NULL default '0000-00-00',
  `time` time NOT NULL default '00:00:00',
  `year` smallint(4) NOT NULL default '0',
  `month` tinyint(2) NOT NULL default '0',
  `day` tinyint(2) NOT NULL default '0',
  `hour` tinyint(2) NOT NULL default '0',
  `user_id` smallint(5) NOT NULL default '0',
  `IP` varchar(15) NOT NULL default '',
  `section` enum('categories','tags','search','list','favorites','most_visited','best_rated','recent_pics','recent_cats') default NULL,
  `category_id` smallint(5) default NULL,
  `tag_ids` varchar(50) default NULL,
  `image_id` mediumint(8) default NULL,
  `summarized` enum('true','false') default 'false',
  `image_type` enum('picture','high','other') default NULL,
  PRIMARY KEY  (`id`),
  KEY `history_i1` (`summarized`)
) TYPE=MyISAM
;",

"
ALTER TABLE `".PREFIX_TABLE."image_category`
  DROP INDEX `image_category_i1`
;",

"
ALTER TABLE `".PREFIX_TABLE."image_category`
  ADD INDEX `image_category_i1` (`category_id`)
;",

"
ALTER TABLE `".PREFIX_TABLE."image_category`
  DROP INDEX `image_category_i2`
;",

"
ALTER TABLE `".PREFIX_TABLE."images`
  ADD COLUMN `high_filesize` mediumint(9) unsigned default NULL
;",

"
ALTER TABLE `".PREFIX_TABLE."user_infos`
  CHANGE COLUMN `language`
    `language` varchar(50) NOT NULL default 'en_UK.iso-8859-1'
;",

"
ALTER TABLE `".PREFIX_TABLE."user_infos`
  DROP COLUMN `auto_login_key`
;",

"
ALTER TABLE `".PREFIX_TABLE."user_infos`
  ADD COLUMN `show_nb_hits` enum('true','false') NOT NULL default 'false'
;",

"
ALTER TABLE `".PREFIX_TABLE."user_mail_notification`
  DROP INDEX `uidx_check_key`
;",

"
ALTER TABLE `".PREFIX_TABLE."user_mail_notification`
  ADD UNIQUE `user_mail_notification_ui1` (`check_key`)
;",

"
CREATE TABLE `".PREFIX_TABLE."history_summary` (
  `id` varchar(13) NOT NULL default '',
  `year` smallint(4) NOT NULL default '0',
  `month` tinyint(2) default NULL,
  `day` tinyint(2) default NULL,
  `hour` tinyint(2) default NULL,
  `nb_pages` int(11) default NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM
;",

"
CREATE TABLE `".PREFIX_TABLE."old_permalinks` (
  `cat_id` smallint(5) unsigned NOT NULL default '0',
  `permalink` varchar(64) NOT NULL default '',
  `date_deleted` datetime NOT NULL default '0000-00-00 00:00:00',
  `last_hit` datetime default NULL,
  `hit` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`permalink`)
) TYPE=MyISAM
;",

"
CREATE TABLE `".PREFIX_TABLE."plugins` (
  `id` varchar(64) binary NOT NULL default '',
  `state` enum('inactive','active') NOT NULL default 'inactive',
  `version` varchar(64) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM
;",

"
CREATE TABLE `".PREFIX_TABLE."user_cache_categories` (
  `user_id` smallint(5) NOT NULL default '0',
  `cat_id` smallint(5) unsigned NOT NULL default '0',
  `max_date_last` datetime default NULL,
  `count_images` mediumint(8) unsigned default '0',
  `count_categories` mediumint(8) unsigned default '0',
  PRIMARY KEY  (`user_id`,`cat_id`)
) TYPE=MyISAM
;",

"
CREATE TABLE `".PREFIX_TABLE."ws_access` (
  `id` smallint(5) unsigned NOT NULL auto_increment,
  `name` varchar(32) NOT NULL default '',
  `access` varchar(255) default NULL,
  `start` datetime default NULL,
  `end` datetime default NULL,
  `request` varchar(255) default NULL,
  `limit` smallint(5) unsigned default NULL,
  `comment` varchar(255) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `ws_access_ui1` (`name`)
) TYPE=MyISAM COMMENT='Access for Web Services'
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('show_nb_hits', 'false', 'Show hits count under thumbnails')
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('history_admin','false','keep a history of administrator visits on your website')
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('history_guest','true','keep a history of guest visits on your website')
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('allow_user_registration','true','allow visitors to register?')
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('secret_key', MD5(RAND()), 'a secret key specific to the gallery for internal use')
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('nbm_send_html_mail','true','Send mail on HTML format for notification by mail')
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('nbm_send_recent_post_dates','true','Send recent post by dates for notification by mail')
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('email_admin_on_new_user','false','Send an email to theadministrators when a user registers')
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('email_admin_on_comment','false','Send an email to the administrators when a valid comment is entered')
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('email_admin_on_comment_validation','false','Send an email to the administrators when a comment requires validation')
;",

"
INSERT INTO ".PREFIX_TABLE."config
  (param,value,comment)
  VALUES
  ('email_admin_on_picture_uploaded','false','Send an email to the administrators when a picture is uploaded')
;",

"
UPDATE ".PREFIX_TABLE."user_cache
  SET need_update = 'true'
;",

);

foreach ($queries as $query)
{
  pwg_query($query);
}

$replacements = array(
  array('&#039;', '\''),
  array('&quot;', '"'),
  array('&lt;',   '<'),
  array('&gt;',   '>'),
  array('&amp;',  '&') // <- this must be the last one
  );

foreach ($replacements as $replacement)
{
    $query = '
UPDATE '.PREFIX_TABLE.'comments
  SET content = REPLACE(content, "'.
  addslashes($replacement[0]).
  '", "'.
  addslashes($replacement[1]).
  '")
;';
    pwg_query($query);
}

load_conf_from_db();

$query = "
UPDATE ".USER_INFOS_TABLE."
SET
  template = '".$conf['default_template']."',
  nb_image_line = ".$conf['nb_image_line'].",
  nb_line_page = ".$conf['nb_line_page'].",
  language = '".$conf['default_language']."',
  maxwidth = ".
  (empty($conf['default_maxwidth']) ? "NULL" : $conf['default_maxwidth']).
  ",
  maxheight = ".
  (empty($conf['default_maxheight']) ? "NULL" : $conf['default_maxheight']).
  ",
  recent_period = ".$conf['recent_period'].",
  expand = '".boolean_to_string($conf['auto_expand'])."',
  show_nb_comments = '".boolean_to_string($conf['show_nb_comments'])."',
  show_nb_hits = '".boolean_to_string($conf['show_nb_hits'])."',
  enabled_high = '".boolean_to_string(
    (isset($conf['newuser_default_enabled_high']) ?
      $conf['newuser_default_enabled_high'] : true)
    ).
  "'
WHERE
  user_id = ".$conf['default_user_id'].";";
pwg_query($query);

$query = "
DELETE FROM ".CONFIG_TABLE."
WHERE
  param IN
(
  'default_template',
  'nb_image_line',
  'nb_line_page',
  'default_language',
  'default_maxwidth',
  'default_maxheight',
  'recent_period',
  'auto_expand',
  'show_nb_comments',
  'show_nb_hits'
)
;";
pwg_query($query);

// now we upgrade from 1.7.0
// include_once(PHPWG_ROOT_PATH.'install/upgrade_1.7.0.php');
?>