1 | <?php |
---|
2 | /** |
---|
3 | * @author Eric@piwigo.org |
---|
4 | * |
---|
5 | * Upgrade processes for old plugin version |
---|
6 | * Called from maintain.inc.php on plugin activation |
---|
7 | * |
---|
8 | */ |
---|
9 | |
---|
10 | if(!defined('UAM_PATH')) |
---|
11 | { |
---|
12 | define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
13 | } |
---|
14 | |
---|
15 | include_once (UAM_PATH.'include/constants.php'); |
---|
16 | include_once (UAM_PATH.'include/functions.inc.php'); |
---|
17 | |
---|
18 | // +----------------------------------------------------------+ |
---|
19 | // | Upgrading database from old plugin versions | |
---|
20 | // +----------------------------------------------------------+ |
---|
21 | |
---|
22 | |
---|
23 | /* *************************************** */ |
---|
24 | /* Update plugin version in conf table */ |
---|
25 | /* Used everytime a new version is updated */ |
---|
26 | /* even if no database upgrade is needed */ |
---|
27 | /* *************************************** */ |
---|
28 | function UAM_version_update() |
---|
29 | { |
---|
30 | // Get current plugin version |
---|
31 | $plugin = PluginInfos(UAM_PATH); |
---|
32 | $version = $plugin['version']; |
---|
33 | |
---|
34 | // Update plugin version |
---|
35 | $query = ' |
---|
36 | UPDATE '.CONFIG_TABLE.' |
---|
37 | SET value="'.$version.'" |
---|
38 | WHERE param="UserAdvManager_Version" |
---|
39 | LIMIT 1 |
---|
40 | ;'; |
---|
41 | |
---|
42 | pwg_query($query); |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | /* upgrade from branch 2.10 to 2.11 */ |
---|
47 | /* ******************************** */ |
---|
48 | function upgrade_210_211() |
---|
49 | { |
---|
50 | global $conf; |
---|
51 | |
---|
52 | $q = ' |
---|
53 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
54 | VALUES ("nbc_UserAdvManager_ConfirmMail","false;5;Hello. |
---|
55 | |
---|
56 | This is a reminder message because you registered on our gallery but you do not validate your registration and your validation key has expired. To still allow you to access to our gallery, your validation period has been reset. You have again 5 days to validate your registration. |
---|
57 | |
---|
58 | Note: After this period, your account will be permanently deleted.;false;Hello. |
---|
59 | |
---|
60 | This is a reminder message because you registered on our gallery but you do not validate your registration and your validation key will expire. To allow you access to our gallery, you have 2 days to confirm your registration by clicking on the link in the message you should have received when you registered. |
---|
61 | |
---|
62 | Note: After this period, your account will be permanently deleted.","Parametres nbc_UserAdvManager - ConfirmMail") |
---|
63 | ;'; |
---|
64 | pwg_query($q); |
---|
65 | |
---|
66 | upgrade_211_212(); |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | /* upgrade from branch 2.11 to 2.12 */ |
---|
71 | /* ******************************** */ |
---|
72 | function upgrade_211_212() |
---|
73 | { |
---|
74 | global $conf; |
---|
75 | |
---|
76 | $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
77 | |
---|
78 | if ((!isset($conf_UAM[14]) and !isset($conf_UAM[15])) and !isset($conf_UAM[16]) and !isset($conf_UAM[17])) |
---|
79 | { |
---|
80 | $upgrade_UAM = $conf_UAM[0].';'.$conf_UAM[1].';'.$conf_UAM[2].';'.$conf_UAM[3].';'.$conf_UAM[4].';'.$conf_UAM[5].';'.$conf_UAM[6].';'.$conf_UAM[7].';'.$conf_UAM[8].';'.$conf_UAM[9].';'.$conf_UAM[10].';'.$conf_UAM[11].';'.$conf_UAM[12].';'.$conf_UAM[13].';false;100;false;false;10;Hello. |
---|
81 | |
---|
82 | This is a reminder because a very long time passed since your last visit on our gallery. If you do not want anymore to use your access account, please let us know by replying to this email. Your account will be deleted. |
---|
83 | |
---|
84 | On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account. |
---|
85 | |
---|
86 | Best regards, |
---|
87 | |
---|
88 | The admin of the gallery.'; |
---|
89 | |
---|
90 | $query = ' |
---|
91 | UPDATE '.CONFIG_TABLE.' |
---|
92 | SET value="'.$upgrade_UAM.'" |
---|
93 | WHERE param="nbc_UserAdvManager" |
---|
94 | LIMIT 1 |
---|
95 | ;'; |
---|
96 | pwg_query($query); |
---|
97 | } |
---|
98 | |
---|
99 | $q = " |
---|
100 | CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." ( |
---|
101 | user_id SMALLINT(5) NOT NULL DEFAULT '0', |
---|
102 | lastvisit DATETIME NULL DEFAULT NULL, |
---|
103 | reminder ENUM('true','false') NULL, |
---|
104 | PRIMARY KEY (`user_id`) |
---|
105 | ) |
---|
106 | ;"; |
---|
107 | pwg_query($q); |
---|
108 | |
---|
109 | upgrade_212_213(); |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | /* upgrade from branch 2.12 to 2.13 */ |
---|
114 | /* ******************************** */ |
---|
115 | function upgrade_212_213() |
---|
116 | { |
---|
117 | // Create missing table |
---|
118 | $query = " |
---|
119 | ALTER TABLE ".USER_CONFIRM_MAIL_TABLE." |
---|
120 | ADD reminder ENUM('true', 'false') NULL DEFAULT NULL |
---|
121 | ;"; |
---|
122 | |
---|
123 | pwg_query($query); |
---|
124 | |
---|
125 | // Upgrade plugin configuration |
---|
126 | global $conf; |
---|
127 | |
---|
128 | $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array(); |
---|
129 | |
---|
130 | if ((!isset($conf_UAM[20]))) |
---|
131 | { |
---|
132 | $upgrade_UAM = $conf_UAM[0].';'.$conf_UAM[1].';'.$conf_UAM[2].';'.$conf_UAM[3].';'.$conf_UAM[4].';'.$conf_UAM[5].';'.$conf_UAM[6].';'.$conf_UAM[7].';'.$conf_UAM[8].';'.$conf_UAM[9].';'.$conf_UAM[10].';'.$conf_UAM[11].';'.$conf_UAM[12].';'.$conf_UAM[13].';'.$conf_UAM[14].';'.$conf_UAM[15].';'.$conf_UAM[16].';'.$conf_UAM[17].';'.$conf_UAM[18].';'.$conf_UAM[19].';false'; |
---|
133 | |
---|
134 | $query = ' |
---|
135 | UPDATE '.CONFIG_TABLE.' |
---|
136 | SET value="'.$upgrade_UAM.'" |
---|
137 | WHERE param="nbc_UserAdvManager" |
---|
138 | LIMIT 1 |
---|
139 | ;'; |
---|
140 | pwg_query($query); |
---|
141 | |
---|
142 | upgrade_213_214(); |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | /* upgrade from branch 2.13 to 2.14 */ |
---|
148 | /* ******************************** */ |
---|
149 | function upgrade_213_214() |
---|
150 | { |
---|
151 | global $conf; |
---|
152 | |
---|
153 | $conf_UAM = explode(';', $conf['nbc_UserAdvManager']); |
---|
154 | |
---|
155 | $upgrade_UAM = array($conf_UAM[0],$conf_UAM[1],$conf_UAM[2],$conf_UAM[3],$conf_UAM[4],$conf_UAM[5],$conf_UAM[6],$conf_UAM[7],$conf_UAM[8],$conf_UAM[9],$conf_UAM[10],$conf_UAM[11],$conf_UAM[12],$conf_UAM[13],$conf_UAM[14],$conf_UAM[15],$conf_UAM[16],$conf_UAM[17],$conf_UAM[18],$conf_UAM[19],$conf_UAM[20],'false'); |
---|
156 | |
---|
157 | $query = ' |
---|
158 | UPDATE '.CONFIG_TABLE.' |
---|
159 | SET value = "'.addslashes(serialize($upgrade_UAM)).'" |
---|
160 | WHERE param = "nbc_UserAdvManager" |
---|
161 | ;'; |
---|
162 | pwg_query($query); |
---|
163 | |
---|
164 | if (unserialize($conf['nbc_UserAdvManager_ConfirmMail']) === false) |
---|
165 | { |
---|
166 | $data = explode(';', $conf['nbc_UserAdvManager_ConfirmMail']); |
---|
167 | |
---|
168 | $query = ' |
---|
169 | UPDATE '.CONFIG_TABLE.' |
---|
170 | SET value = "'.addslashes(serialize($data)).'" |
---|
171 | WHERE param = "nbc_UserAdvManager_ConfirmMail" |
---|
172 | ;'; |
---|
173 | pwg_query($query); |
---|
174 | |
---|
175 | upgrade_214_215(); |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | |
---|
180 | /* upgrade from branch 2.14 to 2.15 */ |
---|
181 | /* ******************************** */ |
---|
182 | function upgrade_214_215() |
---|
183 | { |
---|
184 | global $conf; |
---|
185 | |
---|
186 | // Changing parameter name |
---|
187 | $q = ' |
---|
188 | UPDATE '.CONFIG_TABLE.' |
---|
189 | SET param = "UserAdvManager" |
---|
190 | WHERE param = "nbc_UserAdvManager" |
---|
191 | ;'; |
---|
192 | pwg_query($q); |
---|
193 | |
---|
194 | $q = ' |
---|
195 | UPDATE '.CONFIG_TABLE.' |
---|
196 | SET param = "UserAdvManager_ConfirmMail" |
---|
197 | WHERE param = "nbc_UserAdvManager_ConfirmMail" |
---|
198 | ;'; |
---|
199 | pwg_query($q); |
---|
200 | |
---|
201 | // Upgrading ConfirmMail options |
---|
202 | $query = ' |
---|
203 | SELECT value |
---|
204 | FROM '.CONFIG_TABLE.' |
---|
205 | WHERE param = "UserAdvManager_ConfirmMail" |
---|
206 | ;'; |
---|
207 | |
---|
208 | $result = pwg_query($query); |
---|
209 | $conf_UAM_ConfirmMail = pwg_db_fetch_assoc($result); |
---|
210 | |
---|
211 | $conf_ConfirmMail = unserialize($conf_UAM_ConfirmMail['value']); |
---|
212 | |
---|
213 | $conf_ConfirmMail[5] ='Thank you to have confirmed your email address and your registration on the gallery. Have fun !'; |
---|
214 | $conf_ConfirmMail[6] ='Your activation key is incorrect or expired or you have already validated your account, please contact the webmaster to fix this problem.'; |
---|
215 | |
---|
216 | $update_conf = serialize($conf_ConfirmMail); |
---|
217 | |
---|
218 | $query = ' |
---|
219 | UPDATE '.CONFIG_TABLE.' |
---|
220 | SET value="'.addslashes($update_conf).'" |
---|
221 | WHERE param="UserAdvManager_ConfirmMail" |
---|
222 | LIMIT 1 |
---|
223 | ;'; |
---|
224 | |
---|
225 | pwg_query($query); |
---|
226 | |
---|
227 | upgrade_2153_2154(); |
---|
228 | } |
---|
229 | |
---|
230 | |
---|
231 | /* upgrade from 2.15.3 to 2.15.4 */ |
---|
232 | /* ***************************** */ |
---|
233 | function upgrade_2153_2154() |
---|
234 | { |
---|
235 | global $conf; |
---|
236 | |
---|
237 | // Upgrading options |
---|
238 | $query = ' |
---|
239 | SELECT value |
---|
240 | FROM '.CONFIG_TABLE.' |
---|
241 | WHERE param = "UserAdvManager" |
---|
242 | ;'; |
---|
243 | |
---|
244 | $result = pwg_query($query); |
---|
245 | $conf_UAM = pwg_db_fetch_assoc($result); |
---|
246 | |
---|
247 | $Newconf_UAM = unserialize($conf_UAM['value']); |
---|
248 | |
---|
249 | $Newconf_UAM[0] = $Newconf_UAM[0]; |
---|
250 | $Newconf_UAM[1] = $Newconf_UAM[2]; |
---|
251 | $Newconf_UAM[2] = $Newconf_UAM[3]; |
---|
252 | $Newconf_UAM[3] = $Newconf_UAM[4]; |
---|
253 | $Newconf_UAM[4] = $Newconf_UAM[5]; |
---|
254 | $Newconf_UAM[5] = $Newconf_UAM[6]; |
---|
255 | $Newconf_UAM[6] = $Newconf_UAM[7]; |
---|
256 | $Newconf_UAM[7] = $Newconf_UAM[8]; |
---|
257 | $Newconf_UAM[8] = $Newconf_UAM[9]; |
---|
258 | $Newconf_UAM[9] = $Newconf_UAM[10]; |
---|
259 | $Newconf_UAM[10] = $Newconf_UAM[11]; |
---|
260 | $Newconf_UAM[11] = $Newconf_UAM[12]; |
---|
261 | $Newconf_UAM[12] = $Newconf_UAM[13]; |
---|
262 | $Newconf_UAM[13] = $Newconf_UAM[14]; |
---|
263 | $Newconf_UAM[14] = $Newconf_UAM[15]; |
---|
264 | $Newconf_UAM[15] = $Newconf_UAM[16]; |
---|
265 | $Newconf_UAM[16] = $Newconf_UAM[17]; |
---|
266 | $Newconf_UAM[17] = $Newconf_UAM[18]; |
---|
267 | $Newconf_UAM[18] = $Newconf_UAM[19]; |
---|
268 | $Newconf_UAM[19] = $Newconf_UAM[20]; |
---|
269 | $Newconf_UAM[20] = $Newconf_UAM[21]; |
---|
270 | $Newconf_UAM[21] = 'false'; |
---|
271 | |
---|
272 | $update_conf = serialize($Newconf_UAM); |
---|
273 | |
---|
274 | $query = ' |
---|
275 | UPDATE '.CONFIG_TABLE.' |
---|
276 | SET value="'.addslashes($update_conf).'" |
---|
277 | WHERE param="UserAdvManager" |
---|
278 | LIMIT 1 |
---|
279 | ;'; |
---|
280 | |
---|
281 | pwg_query($query); |
---|
282 | |
---|
283 | $query = ' |
---|
284 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
285 | VALUES ("UserAdvManager_Redir","0","UAM Redirections") |
---|
286 | ;'; |
---|
287 | |
---|
288 | pwg_query($query); |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | /* upgrade from 2.15.x to 2.16.0 */ |
---|
293 | /* ***************************** */ |
---|
294 | function upgrade_215_2160() |
---|
295 | { |
---|
296 | global $conf; |
---|
297 | |
---|
298 | // Upgrading options |
---|
299 | $query = ' |
---|
300 | SELECT value |
---|
301 | FROM '.CONFIG_TABLE.' |
---|
302 | WHERE param = "UserAdvManager" |
---|
303 | ;'; |
---|
304 | |
---|
305 | $result = pwg_query($query); |
---|
306 | $conf_UAM = pwg_db_fetch_assoc($result); |
---|
307 | |
---|
308 | $Newconf_UAM = unserialize($conf_UAM['value']); |
---|
309 | |
---|
310 | $Newconf_UAM[22] = 'false'; |
---|
311 | $Newconf_UAM[23] = 'false'; |
---|
312 | $Newconf_UAM[24] = 'Sorry, your account has been deleted due to a too long time passed since your last visit.'; |
---|
313 | $Newconf_UAM[25] = 'Sorry, your account has been deprecated due to a too long time passed since your last visit. Please, use the following link to revalidate your account.'; |
---|
314 | $Newconf_UAM[26] = '-1'; |
---|
315 | $Newconf_UAM[27] = '-1'; |
---|
316 | $Newconf_UAM[28] = 'Thank you to have registered the gallery. Your account has been manually validated by admin. You can now visit all the gallery for free !'; |
---|
317 | |
---|
318 | $update_conf = serialize($Newconf_UAM); |
---|
319 | |
---|
320 | $query = ' |
---|
321 | UPDATE '.CONFIG_TABLE.' |
---|
322 | SET value="'.addslashes($update_conf).'" |
---|
323 | WHERE param="UserAdvManager" |
---|
324 | LIMIT 1 |
---|
325 | ;'; |
---|
326 | |
---|
327 | pwg_query($query); |
---|
328 | |
---|
329 | // Insert a new config entry for futur plugin's version check |
---|
330 | $query = ' |
---|
331 | INSERT INTO '.CONFIG_TABLE.' (param, value, comment) |
---|
332 | VALUES ("UserAdvManager_Version","2.16.0","UAM version check") |
---|
333 | ;'; |
---|
334 | |
---|
335 | pwg_query($query); |
---|
336 | } |
---|
337 | |
---|
338 | |
---|
339 | /* upgrade from 2.16.x to 2.20.0 */ |
---|
340 | /* ***************************** */ |
---|
341 | function upgrade_216_220() |
---|
342 | { |
---|
343 | global $conf; |
---|
344 | |
---|
345 | // Upgrading options |
---|
346 | $query = ' |
---|
347 | SELECT value |
---|
348 | FROM '.CONFIG_TABLE.' |
---|
349 | WHERE param = "UserAdvManager" |
---|
350 | ;'; |
---|
351 | |
---|
352 | $result = pwg_query($query); |
---|
353 | $conf_UAM = pwg_db_fetch_assoc($result); |
---|
354 | |
---|
355 | $Newconf_UAM = unserialize($conf_UAM['value']); |
---|
356 | |
---|
357 | $Newconf_UAM[29] = 'false'; |
---|
358 | $Newconf_UAM[30] = 'You have requested a password reset on our gallery. Please, find below your new connection settings.'; |
---|
359 | $Newconf_UAM[31] = 'false'; |
---|
360 | $Newconf_UAM[32] = 'Sorry, your account has been deleted because you have not validated your registration in requested time. Please, try registration with a valid and non blocked email account.'; |
---|
361 | $Newconf_UAM[33] = 'false'; |
---|
362 | $Newconf_UAM[34] = 'false'; |
---|
363 | |
---|
364 | $update_conf = serialize($Newconf_UAM); |
---|
365 | |
---|
366 | $query = ' |
---|
367 | UPDATE '.CONFIG_TABLE.' |
---|
368 | SET value="'.addslashes($update_conf).'" |
---|
369 | WHERE param="UserAdvManager" |
---|
370 | LIMIT 1 |
---|
371 | ;'; |
---|
372 | |
---|
373 | pwg_query($query); |
---|
374 | |
---|
375 | // Create new UAM entry in plugins table |
---|
376 | $uam_new_version = "2.20.0"; |
---|
377 | |
---|
378 | $query = ' |
---|
379 | INSERT INTO '.PLUGINS_TABLE.' (id, state, version) |
---|
380 | VALUES ("UserAdvManager","active","'.$uam_new_version.'") |
---|
381 | ;'; |
---|
382 | |
---|
383 | pwg_query($query); |
---|
384 | |
---|
385 | // Delete old plugin entry in plugins table |
---|
386 | $query = ' |
---|
387 | DELETE FROM '.PLUGINS_TABLE.' |
---|
388 | WHERE id="NBC_UserAdvManager" |
---|
389 | LIMIT 1 |
---|
390 | ;'; |
---|
391 | |
---|
392 | pwg_query($query); |
---|
393 | |
---|
394 | // rename directory |
---|
395 | if (!rename(PHPWG_PLUGINS_PATH.'NBC_UserAdvManager', PHPWG_PLUGINS_PATH.'UserAdvManager')) |
---|
396 | { |
---|
397 | die('Fatal error on plugin upgrade process : Unable to rename directory ! Please, rename manualy the plugin directory name from ../plugins/NBC_UserAdvManager to ../plugins/UserAdvManager.'); |
---|
398 | } |
---|
399 | } |
---|
400 | ?> |
---|