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

Last change on this file since 10706 was 10706, checked in by Eric, 13 years ago
  • Bug 2289 fixed - "Password in clear text in the information email" works now in the logical way
  • Plugin update improvement
  • New version 2.20.6 hard coded for publication
  • Property svn:eol-style set to LF
File size: 12.2 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  $plugin =  PluginInfos(UAM_PATH);
32  $version = $plugin['version'];
33
34  // Update plugin version in #_config table
35  $query = '
36UPDATE '.CONFIG_TABLE.'
37SET value="'.$version.'"
38WHERE param="UserAdvManager_Version"
39LIMIT 1
40;';
41
42  pwg_query($query);
43
44
45// Check #_plugin table consistency
46// Only useful if a previous version upgrade has not worked correctly (rare case)
47  $query = '
48SELECT version
49  FROM '.PLUGINS_TABLE.'
50WHERE id = "UserAdvManager"
51;';
52 
53  $data = pwg_db_fetch_assoc(pwg_query($query));
54 
55  if (empty($data['version']) or $data['version'] <> $version)
56  {
57    $query = '
58UPDATE '.PLUGINS_TABLE.'
59SET version="'.$version.'"
60WHERE id = "UserAdvManager"
61LIMIT 1
62;';
63
64    pwg_query($query);
65  }
66}
67
68
69/* upgrade from branch 2.10 to 2.11 */
70/* ******************************** */
71function upgrade_210_211()
72{
73        global $conf;
74         
75  $q = '
76INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
77VALUES ("nbc_UserAdvManager_ConfirmMail","false;5;Hello.
78               
79This 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.
80
81Note: After this period, your account will be permanently deleted.;false;Hello.
82
83This 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.
84
85Note: After this period, your account will be permanently deleted.","Parametres nbc_UserAdvManager - ConfirmMail")
86  ;';
87  pwg_query($q);
88
89  upgrade_211_212();
90}
91
92
93/* upgrade from branch 2.11 to 2.12 */
94/* ******************************** */
95function upgrade_211_212()
96{
97        global $conf;
98
99  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
100
101  if ((!isset($conf_UAM[14]) and !isset($conf_UAM[15])) and !isset($conf_UAM[16]) and !isset($conf_UAM[17]))
102  {
103    $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.
104       
105This 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.
106
107On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
108
109Best regards,
110
111The admin of the gallery.';
112               
113                $query = '
114UPDATE '.CONFIG_TABLE.'
115SET value="'.$upgrade_UAM.'"
116WHERE param="nbc_UserAdvManager"
117LIMIT 1
118;';
119                pwg_query($query);
120  }
121 
122        $q = "
123CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
124  user_id SMALLINT(5) NOT NULL DEFAULT '0',
125  lastvisit DATETIME NULL DEFAULT NULL,
126  reminder ENUM('true','false') NULL,
127PRIMARY KEY (`user_id`)
128  )
129;";
130  pwg_query($q);
131
132  upgrade_212_213();
133}
134
135
136/* upgrade from branch 2.12 to 2.13 */
137/* ******************************** */
138function upgrade_212_213()
139{
140  // Create missing table
141  $query = "
142ALTER TABLE ".USER_CONFIRM_MAIL_TABLE."
143ADD reminder ENUM('true', 'false') NULL DEFAULT NULL
144;";
145 
146  pwg_query($query);
147
148  // Upgrade plugin configuration
149        global $conf;
150
151  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
152
153  if ((!isset($conf_UAM[20])))
154  {
155    $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';
156               
157                $query = '
158UPDATE '.CONFIG_TABLE.'
159SET value="'.$upgrade_UAM.'"
160WHERE param="nbc_UserAdvManager"
161LIMIT 1
162;';
163                pwg_query($query);
164   
165    upgrade_213_214();
166  }
167}
168
169
170/* upgrade from branch 2.13 to 2.14 */
171/* ******************************** */
172function upgrade_213_214()
173{
174        global $conf;
175 
176  $conf_UAM = explode(';', $conf['nbc_UserAdvManager']);
177
178  $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');
179
180  $query = '
181UPDATE '.CONFIG_TABLE.'
182  SET value = "'.addslashes(serialize($upgrade_UAM)).'"
183  WHERE param = "nbc_UserAdvManager"
184;';
185  pwg_query($query);
186 
187  if (unserialize($conf['nbc_UserAdvManager_ConfirmMail']) === false)
188  {
189    $data = explode(';', $conf['nbc_UserAdvManager_ConfirmMail']);
190
191    $query = '
192UPDATE '.CONFIG_TABLE.'
193  SET value = "'.addslashes(serialize($data)).'"
194  WHERE param = "nbc_UserAdvManager_ConfirmMail"
195;';
196    pwg_query($query);
197   
198    upgrade_214_215();
199  }
200}
201
202
203/* upgrade from branch 2.14 to 2.15 */
204/* ******************************** */
205function upgrade_214_215()
206{
207  global $conf;
208
209  // Changing parameter name
210  $q = '
211UPDATE '.CONFIG_TABLE.'
212SET param = "UserAdvManager"
213WHERE param = "nbc_UserAdvManager"
214;';
215  pwg_query($q);
216 
217  $q = '
218UPDATE '.CONFIG_TABLE.'
219SET param = "UserAdvManager_ConfirmMail"
220WHERE param = "nbc_UserAdvManager_ConfirmMail"
221;';
222  pwg_query($q);
223
224  // Upgrading ConfirmMail options
225  $query = '
226SELECT value
227  FROM '.CONFIG_TABLE.'
228WHERE param = "UserAdvManager_ConfirmMail"
229;';
230
231  $result = pwg_query($query);
232  $conf_UAM_ConfirmMail = pwg_db_fetch_assoc($result);
233   
234  $conf_ConfirmMail = unserialize($conf_UAM_ConfirmMail['value']);
235 
236  $conf_ConfirmMail[5] ='Thank you to have confirmed your email address and your registration on the gallery. Have fun !';
237  $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.';
238 
239  $update_conf = serialize($conf_ConfirmMail);
240   
241  $query = '
242      UPDATE '.CONFIG_TABLE.'
243                        SET value="'.addslashes($update_conf).'"
244                        WHERE param="UserAdvManager_ConfirmMail"
245                        LIMIT 1
246                ;';
247
248                pwg_query($query);
249   
250    upgrade_2153_2154();
251}
252
253
254/* upgrade from 2.15.3 to 2.15.4 */
255/* ***************************** */
256function upgrade_2153_2154()
257{
258  global $conf;
259
260  // Upgrading options
261  $query = '
262SELECT value
263  FROM '.CONFIG_TABLE.'
264WHERE param = "UserAdvManager"
265;';
266
267  $result = pwg_query($query);
268  $conf_UAM = pwg_db_fetch_assoc($result);
269   
270  $Newconf_UAM = unserialize($conf_UAM['value']);
271 
272  $Newconf_UAM[0] = $Newconf_UAM[0];
273  $Newconf_UAM[1] = $Newconf_UAM[2];
274  $Newconf_UAM[2] = $Newconf_UAM[3];
275  $Newconf_UAM[3] = $Newconf_UAM[4];
276  $Newconf_UAM[4] = $Newconf_UAM[5];
277  $Newconf_UAM[5] = $Newconf_UAM[6];
278  $Newconf_UAM[6] = $Newconf_UAM[7];
279  $Newconf_UAM[7] = $Newconf_UAM[8];
280  $Newconf_UAM[8] = $Newconf_UAM[9];
281  $Newconf_UAM[9] = $Newconf_UAM[10];
282  $Newconf_UAM[10] = $Newconf_UAM[11];
283  $Newconf_UAM[11] = $Newconf_UAM[12];
284  $Newconf_UAM[12] = $Newconf_UAM[13];
285  $Newconf_UAM[13] = $Newconf_UAM[14];
286  $Newconf_UAM[14] = $Newconf_UAM[15];
287  $Newconf_UAM[15] = $Newconf_UAM[16];
288  $Newconf_UAM[16] = $Newconf_UAM[17];
289  $Newconf_UAM[17] = $Newconf_UAM[18];
290  $Newconf_UAM[18] = $Newconf_UAM[19];
291  $Newconf_UAM[19] = $Newconf_UAM[20];
292  $Newconf_UAM[20] = $Newconf_UAM[21];
293  $Newconf_UAM[21] = 'false';
294 
295  $update_conf = serialize($Newconf_UAM);
296   
297  $query = '
298      UPDATE '.CONFIG_TABLE.'
299                        SET value="'.addslashes($update_conf).'"
300                        WHERE param="UserAdvManager"
301                        LIMIT 1
302                ;';
303
304        pwg_query($query);
305
306  $query = '
307INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
308VALUES ("UserAdvManager_Redir","0","UAM Redirections")
309  ;';
310 
311  pwg_query($query);
312}
313
314
315/* upgrade from 2.15.x to 2.16.0 */
316/* ***************************** */
317function upgrade_215_2160()
318{
319  global $conf;
320
321  // Upgrading options
322  $query = '
323SELECT value
324  FROM '.CONFIG_TABLE.'
325WHERE param = "UserAdvManager"
326;';
327
328  $result = pwg_query($query);
329  $conf_UAM = pwg_db_fetch_assoc($result);
330   
331  $Newconf_UAM = unserialize($conf_UAM['value']);
332 
333  $Newconf_UAM[22] = 'false';
334  $Newconf_UAM[23] = 'false';
335  $Newconf_UAM[24] = 'Sorry, your account has been deleted due to a too long time passed since your last visit.';
336  $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.';
337  $Newconf_UAM[26] = '-1';
338  $Newconf_UAM[27] = '-1';
339  $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 !';
340 
341  $update_conf = serialize($Newconf_UAM);
342   
343  $query = '
344      UPDATE '.CONFIG_TABLE.'
345                        SET value="'.addslashes($update_conf).'"
346                        WHERE param="UserAdvManager"
347                        LIMIT 1
348                ;';
349
350        pwg_query($query);
351
352  // Insert a new config entry for futur plugin's version check
353  $query = '
354INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
355VALUES ("UserAdvManager_Version","2.16.0","UAM version check")
356  ;';
357 
358  pwg_query($query);
359}
360
361
362/* upgrade from 2.16.x to 2.20.0 */
363/* ***************************** */
364function upgrade_216_220()
365{
366  global $conf;
367
368  // Upgrading options
369  $query = '
370SELECT value
371  FROM '.CONFIG_TABLE.'
372WHERE param = "UserAdvManager"
373;';
374
375  $result = pwg_query($query);
376  $conf_UAM = pwg_db_fetch_assoc($result);
377   
378  $Newconf_UAM = unserialize($conf_UAM['value']);
379 
380  $Newconf_UAM[29] = 'false';
381  $Newconf_UAM[30] = 'You have requested a password reset on our gallery. Please, find below your new connection settings.';
382  $Newconf_UAM[31] = 'false';
383  $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.';
384  $Newconf_UAM[33] = 'false';
385  $Newconf_UAM[34] = 'false';
386 
387  $update_conf = serialize($Newconf_UAM);
388   
389  $query = '
390UPDATE '.CONFIG_TABLE.'
391SET value="'.addslashes($update_conf).'"
392WHERE param="UserAdvManager"
393LIMIT 1
394;';
395
396        pwg_query($query);
397
398  // Create new UAM entry in plugins table
399  $uam_new_version = "2.20.0";
400
401  $query = '
402INSERT INTO '.PLUGINS_TABLE.' (id, state, version)
403VALUES ("UserAdvManager","active","'.$uam_new_version.'")
404;';
405 
406  pwg_query($query);
407
408  // Delete old plugin entry in plugins table
409  $query = '
410DELETE FROM '.PLUGINS_TABLE.'
411WHERE id="NBC_UserAdvManager"
412LIMIT 1
413;';
414 
415  pwg_query($query);
416
417  // rename directory
418  if (!rename(PHPWG_PLUGINS_PATH.'NBC_UserAdvManager', PHPWG_PLUGINS_PATH.'UserAdvManager'))
419  {
420    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.');
421  }
422}
423
424/* upgrade from 2.20.3 to 2.20.4 */
425/* ***************************** */
426function upgrade_2203_2204()
427{
428  global $conf;
429
430  // Upgrading options
431  $query = '
432SELECT value
433  FROM '.CONFIG_TABLE.'
434WHERE param = "UserAdvManager"
435;';
436
437  $result = pwg_query($query);
438  $conf_UAM = pwg_db_fetch_assoc($result);
439   
440  $Newconf_UAM = unserialize($conf_UAM['value']);
441 
442  $Newconf_UAM[35] = 'false';
443 
444  $update_conf = serialize($Newconf_UAM);
445   
446  $query = '
447UPDATE '.CONFIG_TABLE.'
448SET value="'.addslashes($update_conf).'"
449WHERE param="UserAdvManager"
450LIMIT 1
451;';
452
453        pwg_query($query);
454}
455?>
Note: See TracBrowser for help on using the repository browser.