source: extensions/UserAdvManager/trunk/include/upgradedb.inc.php @ 14729

Last change on this file since 14729 was 14729, checked in by Eric, 9 years ago

Bug 2623 fixed - Ability to customize email subjects (confirmation, information and ghostTracker email)

  • Property svn:eol-style set to LF
File size: 17.7 KB
Line 
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
10if(!defined('UAM_PATH'))
11{
12  define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
13}
14
15include_once (UAM_PATH.'include/constants.php');
16include_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/* *************************************** */
28function UAM_version_update()
29{
30  // Get current plugin version
31  // --------------------------
32  $plugin =  PluginInfos(UAM_PATH);
33  $version = $plugin['version'];
34
35  // Update plugin version in #_config table
36  // ---------------------------------------
37  $query = '
38UPDATE '.CONFIG_TABLE.'
39SET value="'.$version.'"
40WHERE param="UserAdvManager_Version"
41LIMIT 1
42;';
43
44  pwg_query($query);
45
46
47// Check #_plugin table consistency
48// Only useful if a previous version upgrade has not worked correctly (rare case)
49// ------------------------------------------------------------------------------
50  $query = '
51SELECT version
52  FROM '.PLUGINS_TABLE.'
53WHERE id = "UserAdvManager"
54;';
55 
56  $data = pwg_db_fetch_assoc(pwg_query($query));
57 
58  if (empty($data['version']) or $data['version'] <> $version)
59  {
60    $query = '
61UPDATE '.PLUGINS_TABLE.'
62SET version="'.$version.'"
63WHERE id = "UserAdvManager"
64LIMIT 1
65;';
66
67    pwg_query($query);
68  }
69}
70
71
72/* upgrade from branch 2.10 to 2.11 */
73/* ******************************** */
74function upgrade_210_211()
75{
76        global $conf;
77         
78  $q = '
79INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
80VALUES ("nbc_UserAdvManager_ConfirmMail","false;5;Hello.
81               
82This 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.
83
84Note: After this period, your account will be permanently deleted.;false;Hello.
85
86This 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.
87
88Note: After this period, your account will be permanently deleted.","Parametres nbc_UserAdvManager - ConfirmMail")
89  ;';
90  pwg_query($q);
91
92  upgrade_211_212();
93}
94
95
96/* upgrade from branch 2.11 to 2.12 */
97/* ******************************** */
98function upgrade_211_212()
99{
100        global $conf;
101
102  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
103
104  if ((!isset($conf_UAM[14]) and !isset($conf_UAM[15])) and !isset($conf_UAM[16]) and !isset($conf_UAM[17]))
105  {
106    $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.
107       
108This 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.
109
110On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
111
112Best regards,
113
114The admin of the gallery.';
115
116    conf_update_param('nbc_UserAdvManager', pwg_db_real_escape_string($upgrade_UAM));
117  }
118 
119        $q = "
120CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
121  user_id SMALLINT(5) NOT NULL DEFAULT '0',
122  lastvisit DATETIME NULL DEFAULT NULL,
123  reminder ENUM('true','false') NULL,
124PRIMARY KEY (`user_id`)
125  )
126;";
127  pwg_query($q);
128
129  upgrade_212_213();
130}
131
132
133/* upgrade from branch 2.12 to 2.13 */
134/* ******************************** */
135function upgrade_212_213()
136{
137  // Create missing table
138  // --------------------
139  $query = "
140ALTER TABLE ".USER_CONFIRM_MAIL_TABLE."
141ADD reminder ENUM('true', 'false') NULL DEFAULT NULL
142;";
143 
144  pwg_query($query);
145
146  // Upgrade plugin configuration
147  // ----------------------------
148        global $conf;
149
150  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
151
152  if ((!isset($conf_UAM[20])))
153  {
154    $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';
155               
156                conf_update_param('nbc_UserAdvManager', pwg_db_real_escape_string($upgrade_UAM));
157   
158    upgrade_213_214();
159  }
160}
161
162
163/* upgrade from branch 2.13 to 2.14 */
164/* ******************************** */
165function upgrade_213_214()
166{
167        global $conf;
168 
169  $conf_UAM = explode(';', $conf['nbc_UserAdvManager']);
170
171  $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');
172
173  $query = '
174UPDATE '.CONFIG_TABLE.'
175  SET value = "'.pwg_db_real_escape_string(serialize($upgrade_UAM)).'"
176  WHERE param = "nbc_UserAdvManager"
177;';
178  pwg_query($query);
179 
180  if (unserialize($conf['nbc_UserAdvManager_ConfirmMail']) === false)
181  {
182    $data = explode(';', $conf['nbc_UserAdvManager_ConfirmMail']);
183
184    conf_update_param('nbc_UserAdvManager_ConfirmMail', pwg_db_real_escape_string(serialize($data)));
185   
186    upgrade_214_215();
187  }
188}
189
190
191/* upgrade from branch 2.14 to 2.15 */
192/* ******************************** */
193function upgrade_214_215()
194{
195  global $conf;
196
197  // Changing parameter name
198  // -----------------------
199  $q = '
200UPDATE '.CONFIG_TABLE.'
201SET param = "UserAdvManager"
202WHERE param = "nbc_UserAdvManager"
203;';
204  pwg_query($q);
205 
206  $q = '
207UPDATE '.CONFIG_TABLE.'
208SET param = "UserAdvManager_ConfirmMail"
209WHERE param = "nbc_UserAdvManager_ConfirmMail"
210;';
211  pwg_query($q);
212
213  // Upgrading ConfirmMail options
214  // -----------------------------
215  $query = '
216SELECT value
217  FROM '.CONFIG_TABLE.'
218WHERE param = "UserAdvManager_ConfirmMail"
219;';
220
221  $result = pwg_query($query);
222  $conf_UAM_ConfirmMail = pwg_db_fetch_assoc($result);
223   
224  $conf_ConfirmMail = unserialize($conf_UAM_ConfirmMail['value']);
225 
226  $conf_ConfirmMail[5] ='Thank you to have confirmed your email address and your registration on the gallery. Have fun !';
227  $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.';
228 
229  $update_conf = serialize($conf_ConfirmMail);
230 
231  conf_update_param('UserAdvManager_ConfirmMail', pwg_db_real_escape_string($update_conf));
232   
233  upgrade_2153_2154();
234}
235
236
237/* upgrade from 2.15.3 to 2.15.4 */
238/* ***************************** */
239function upgrade_2153_2154()
240{
241  global $conf;
242
243  // Upgrading options
244  // -----------------
245  $query = '
246SELECT value
247  FROM '.CONFIG_TABLE.'
248WHERE param = "UserAdvManager"
249;';
250
251  $result = pwg_query($query);
252  $conf_UAM = pwg_db_fetch_assoc($result);
253   
254  $Newconf_UAM = unserialize($conf_UAM['value']);
255 
256  $Newconf_UAM[0] = $Newconf_UAM[0];
257  $Newconf_UAM[1] = $Newconf_UAM[2];
258  $Newconf_UAM[2] = $Newconf_UAM[3];
259  $Newconf_UAM[3] = $Newconf_UAM[4];
260  $Newconf_UAM[4] = $Newconf_UAM[5];
261  $Newconf_UAM[5] = $Newconf_UAM[6];
262  $Newconf_UAM[6] = $Newconf_UAM[7];
263  $Newconf_UAM[7] = $Newconf_UAM[8];
264  $Newconf_UAM[8] = $Newconf_UAM[9];
265  $Newconf_UAM[9] = $Newconf_UAM[10];
266  $Newconf_UAM[10] = $Newconf_UAM[11];
267  $Newconf_UAM[11] = $Newconf_UAM[12];
268  $Newconf_UAM[12] = $Newconf_UAM[13];
269  $Newconf_UAM[13] = $Newconf_UAM[14];
270  $Newconf_UAM[14] = $Newconf_UAM[15];
271  $Newconf_UAM[15] = $Newconf_UAM[16];
272  $Newconf_UAM[16] = $Newconf_UAM[17];
273  $Newconf_UAM[17] = $Newconf_UAM[18];
274  $Newconf_UAM[18] = $Newconf_UAM[19];
275  $Newconf_UAM[19] = $Newconf_UAM[20];
276  $Newconf_UAM[20] = $Newconf_UAM[21];
277  $Newconf_UAM[21] = 'false';
278 
279  $update_conf = serialize($Newconf_UAM);
280 
281  conf_update_param('UserAdvManager', pwg_db_real_escape_string($update_conf));
282
283  $query = '
284INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
285VALUES ("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/* ***************************** */
294function upgrade_215_2160()
295{
296  global $conf;
297
298  // Upgrading options
299  // -----------------
300  $query = '
301SELECT value
302  FROM '.CONFIG_TABLE.'
303WHERE param = "UserAdvManager"
304;';
305
306  $result = pwg_query($query);
307  $conf_UAM = pwg_db_fetch_assoc($result);
308   
309  $Newconf_UAM = unserialize($conf_UAM['value']);
310 
311  $Newconf_UAM[22] = 'false';
312  $Newconf_UAM[23] = 'false';
313  $Newconf_UAM[24] = 'Sorry, your account has been deleted due to a too long time passed since your last visit.';
314  $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.';
315  $Newconf_UAM[26] = '-1';
316  $Newconf_UAM[27] = '-1';
317  $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 !';
318 
319  $update_conf = serialize($Newconf_UAM);
320 
321  conf_update_param('UserAdvManager', pwg_db_real_escape_string($update_conf));
322
323  // Insert a new config entry for futur plugin's version check
324  // ----------------------------------------------------------
325  $query = '
326INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
327VALUES ("UserAdvManager_Version","2.16.0","UAM version check")
328  ;';
329 
330  pwg_query($query);
331}
332
333
334/* upgrade from 2.16.x to 2.20.0 */
335/* ***************************** */
336function upgrade_216_220()
337{
338  global $conf;
339
340  // Upgrading options
341  // -----------------
342  $query = '
343SELECT value
344  FROM '.CONFIG_TABLE.'
345WHERE param = "UserAdvManager"
346;';
347
348  $result = pwg_query($query);
349  $conf_UAM = pwg_db_fetch_assoc($result);
350   
351  $Newconf_UAM = unserialize($conf_UAM['value']);
352 
353  $Newconf_UAM[29] = 'false';
354  $Newconf_UAM[30] = 'You have requested a password reset on our gallery. Please, find below your new connection settings.';
355  $Newconf_UAM[31] = 'false';
356  $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.';
357  $Newconf_UAM[33] = 'false';
358  $Newconf_UAM[34] = 'false';
359 
360  $update_conf = serialize($Newconf_UAM);
361 
362  conf_update_param('UserAdvManager', pwg_db_real_escape_string($update_conf));
363
364  // Create new UAM entry in plugins table
365  // -------------------------------------
366  $uam_new_version = "2.20.0";
367
368  $query = '
369INSERT INTO '.PLUGINS_TABLE.' (id, state, version)
370VALUES ("UserAdvManager","active","'.$uam_new_version.'")
371;';
372 
373  pwg_query($query);
374
375  // Delete old plugin entry in plugins table
376  // ----------------------------------------
377  $query = '
378DELETE FROM '.PLUGINS_TABLE.'
379WHERE id="NBC_UserAdvManager"
380LIMIT 1
381;';
382 
383  pwg_query($query);
384
385  // Rename directory
386  // ----------------
387  if (!rename(PHPWG_PLUGINS_PATH.'NBC_UserAdvManager', PHPWG_PLUGINS_PATH.'UserAdvManager'))
388  {
389    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.');
390  }
391}
392
393/* upgrade from 2.20.3 to 2.20.4 */
394/* ***************************** */
395function upgrade_2203_2204()
396{
397  global $conf;
398
399  // Upgrading options
400  // -----------------
401  $query = '
402SELECT value
403  FROM '.CONFIG_TABLE.'
404WHERE param = "UserAdvManager"
405;';
406
407  $result = pwg_query($query);
408  $conf_UAM = pwg_db_fetch_assoc($result);
409   
410  $Newconf_UAM = unserialize($conf_UAM['value']);
411 
412  $Newconf_UAM[35] = 'false';
413 
414  $update_conf = serialize($Newconf_UAM);
415 
416  conf_update_param('UserAdvManager', pwg_db_real_escape_string($update_conf));
417}
418
419/* upgrade from 2.20.4 to 2.20.7 */
420/* ***************************** */
421function upgrade_2204_2207()
422{
423  global $conf;
424
425  // Upgrading options
426  // -----------------
427  $query = '
428SELECT value
429  FROM '.CONFIG_TABLE.'
430WHERE param = "UserAdvManager"
431;';
432
433  $result = pwg_query($query);
434  $conf_UAM = pwg_db_fetch_assoc($result);
435   
436  $Newconf_UAM = unserialize($conf_UAM['value']);
437 
438  $Newconf_UAM[36] = 'false';
439  $Newconf_UAM[37] = '-1';
440 
441  $update_conf = serialize($Newconf_UAM);
442
443  conf_update_param('UserAdvManager', pwg_db_real_escape_string($update_conf));
444}
445
446/* upgrade from 2.20.7 to 2.20.8 */
447/* ***************************** */
448function upgrade_2207_2208()
449{
450  global $conf;
451
452  // Upgrading options
453  // -----------------
454  $query = '
455SELECT value
456  FROM '.CONFIG_TABLE.'
457WHERE param = "UserAdvManager"
458;';
459
460  $result = pwg_query($query);
461  $conf_UAM = pwg_db_fetch_assoc($result);
462   
463  $Newconf_UAM = unserialize($conf_UAM['value']);
464
465  // Refactoring all configuration options
466  // -------------------------------------
467  $Newconf_UAM[0] = $Newconf_UAM[0];
468  $Newconf_UAM[1] = $Newconf_UAM[1];
469  $Newconf_UAM[2] = $Newconf_UAM[2];
470  $Newconf_UAM[3] = $Newconf_UAM[3];
471  $Newconf_UAM[4] = $Newconf_UAM[4];
472  $Newconf_UAM[5] = $Newconf_UAM[6]; //remove osolete anonymus comments option
473  $Newconf_UAM[6] = $Newconf_UAM[7];
474  $Newconf_UAM[7] = $Newconf_UAM[8];
475  $Newconf_UAM[8] = $Newconf_UAM[9];
476  $Newconf_UAM[9] = $Newconf_UAM[10];
477  $Newconf_UAM[10] = $Newconf_UAM[11];
478  $Newconf_UAM[11] = $Newconf_UAM[12];
479  $Newconf_UAM[12] = $Newconf_UAM[13];
480  $Newconf_UAM[13] = $Newconf_UAM[14];
481  $Newconf_UAM[14] = $Newconf_UAM[15];
482  $Newconf_UAM[15] = $Newconf_UAM[16];
483  $Newconf_UAM[16] = $Newconf_UAM[17];
484  $Newconf_UAM[17] = $Newconf_UAM[18];
485  $Newconf_UAM[18] = $Newconf_UAM[19];
486  $Newconf_UAM[19] = $Newconf_UAM[20];
487  $Newconf_UAM[20] = $Newconf_UAM[21];
488  $Newconf_UAM[21] = $Newconf_UAM[22];
489  $Newconf_UAM[22] = $Newconf_UAM[23];
490  $Newconf_UAM[23] = $Newconf_UAM[24];
491  $Newconf_UAM[24] = $Newconf_UAM[25];
492  $Newconf_UAM[25] = $Newconf_UAM[26];
493  $Newconf_UAM[26] = $Newconf_UAM[27];
494  $Newconf_UAM[27] = $Newconf_UAM[28];
495  $Newconf_UAM[28] = $Newconf_UAM[29];
496  $Newconf_UAM[29] = $Newconf_UAM[30];
497  $Newconf_UAM[30] = $Newconf_UAM[31];
498  $Newconf_UAM[31] = $Newconf_UAM[32];
499  $Newconf_UAM[32] = $Newconf_UAM[33];
500  $Newconf_UAM[33] = $Newconf_UAM[34];
501  $Newconf_UAM[34] = $Newconf_UAM[35];
502 
503  // unset obsolete conf
504  // -------------------
505  unset ($Newconf_UAM[35]);
506  unset ($Newconf_UAM[36]);
507  unset ($Newconf_UAM[37]);
508 
509  $update_conf = serialize($Newconf_UAM);
510
511  conf_update_param('UserAdvManager', pwg_db_real_escape_string($update_conf));
512}
513
514
515/* upgrade from 2.20.8 to 2.30.0 */
516/* ***************************** */
517function upgrade_2208_2300()
518{
519  global $conf;
520
521  // Upgrading options
522  // -----------------
523  $query = '
524SELECT value
525  FROM '.CONFIG_TABLE.'
526WHERE param = "UserAdvManager"
527;';
528
529  $result = pwg_query($query);
530  $conf_UAM = pwg_db_fetch_assoc($result);
531   
532  $Newconf_UAM = unserialize($conf_UAM['value']);
533 
534  $Newconf_UAM[35] = '-1';
535  $Newconf_UAM[36] = '-1';
536  $Newconf_UAM[37] = '-1';
537  $Newconf_UAM[38] = 'false';
538
539  $update_conf = serialize($Newconf_UAM);
540
541  conf_update_param('UserAdvManager', pwg_db_real_escape_string($update_conf));
542
543  // Piwigo's native tables modifications for password reset function - Add pwdreset column
544  // --------------------------------------------------------------------------------------
545  $query = '
546SHOW COLUMNS FROM '.USERS_TABLE.'
547LIKE "UAM_pwdreset"
548;';
549 
550  $result = pwg_query($query);
551
552  if(!pwg_db_fetch_row($result))
553  {
554    $q = '
555ALTER TABLE '.USERS_TABLE.'
556ADD UAM_pwdreset enum("true","false")
557;';
558    pwg_query($q);
559  }
560}
561
562
563/* upgrade from 2.30.x to 2.30.2 */
564/* ***************************** */
565function upgrade_2300_2302()
566{
567  global $conf;
568 
569  load_language('plugin.lang', UAM_PATH);
570
571  // Upgrading options
572  // -----------------
573  $query = '
574SELECT value
575  FROM '.CONFIG_TABLE.'
576WHERE param = "UserAdvManager"
577;';
578
579  $result = pwg_query($query);
580  $conf_UAM = pwg_db_fetch_assoc($result);
581   
582  $Newconf_UAM = unserialize($conf_UAM['value']);
583 
584  $Newconf_UAM[39] = 'false';
585  $Newconf_UAM[40] = l10n('UAM_Default_RejectConnexion_Txt');
586
587  $update_conf = serialize($Newconf_UAM);
588
589  conf_update_param('UserAdvManager', pwg_db_real_escape_string($update_conf));
590}
591
592
593/* upgrade from 2.30.x to 2.40.0 */
594/* ***************************** */
595function upgrade_2300_2400()
596{
597  global $conf;
598 
599  load_language('plugin.lang', UAM_PATH);
600
601  // Upgrading options
602  // -----------------
603  $query = '
604SELECT value
605  FROM '.CONFIG_TABLE.'
606WHERE param = "UserAdvManager"
607;';
608
609  $result = pwg_query($query);
610  $conf_UAM = pwg_db_fetch_assoc($result);
611   
612  $Newconf_UAM = unserialize($conf_UAM['value']);
613
614  $Newconf_UAM[41] = l10n('UAM_Default_ConfirmMail_Subject');        // UAM_CONFIRMMAIL_SUBJECT
615  $Newconf_UAM[42] = l10n('UAM_Default_ConfirmMail_Remail_Subject'); // UAM_CONFIRMMAIL_REMAIL_SUBJECT
616  $Newconf_UAM[43] = l10n('UAM_Default_InfoMail_Subject');           // UAM_INFOMAIL_SUBJECT
617  $Newconf_UAM[44] = l10n('UAM_Default_GTAutoMail_Subject');         // UAM_GTAUTOMAIL_SUBJECT
618  $Newconf_UAM[45] = l10n('UAM_Default_GTReminder_Subject');         // UAM_GTREMINDER_SUBJECT
619  $Newconf_UAM[46] = l10n('UAM_Default_AdminValidationMail_Subject');// UAM_ADMINVALIDATIONMAIL_SUBJECT
620
621  $update_conf = serialize($Newconf_UAM);
622
623  conf_update_param('UserAdvManager', pwg_db_real_escape_string($update_conf));
624}
625?>
Note: See TracBrowser for help on using the repository browser.