source: extensions/NBC_UserAdvManager/trunk/include/upgradedb.inc.php @ 9253

Last change on this file since 9253 was 9253, checked in by Eric, 14 years ago

Bug 2192 fixed
Bug 2045 improvement

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