source: extensions/UserAdvManager/branches/2.20/include/upgradedb.inc.php @ 9909

Last change on this file since 9909 was 9909, checked in by Eric, 13 years ago

r9908 merged from trunk to branch 2.20

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