source: extensions/NBC_UserAdvManager/trunk/maintain.inc.php @ 5086

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

[NBC_UserAdvManager] Pre-2.14.0

  • Small remaining upgrade bug fixed
  • Property svn:eol-style set to LF
File size: 9.0 KB
Line 
1<?php
2
3if(!defined("NBC_UAM_PATH")) define('NBC_UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
4if (!defined('NBC_UAM_ROOT')) {
5  define('NBC_UAM_ROOT',     dirname(__FILE__).'/');
6}
7
8include_once (NBC_UAM_PATH.'include/constants.php');
9include_once (NBC_UAM_PATH.'include/functions.inc.php');
10
11
12function plugin_install()
13{
14        global $conf;
15       
16  $default1 = array('false','false','false',-1,-1,-1,'false','false','',-1,'','','false','','false',100,'false','false',10,'Hello.
17       
18This 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.
19
20On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
21
22Best regards,
23
24The admin of the gallery.','false','false');
25
26  $q = '
27INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
28VALUES ("nbc_UserAdvManager","'.addslashes(serialize($default1)).'","NBC_UAM parameters")
29  ;';
30  pwg_query($q);
31
32
33  $default2 = array('false',5,'Hello.
34               
35This 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.
36
37Note: After this period, your account will be permanently deleted.','false','Hello.
38
39This 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.
40
41Note: After this period, your account will be permanently deleted.');
42
43  $q = '
44INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
45VALUES ("nbc_UserAdvManager_ConfirmMail","'.addslashes(serialize($default2)).'","NBC_UAM ConfirmMail parameters")
46  ;';
47  pwg_query($q);
48
49
50        $q = "
51CREATE TABLE IF NOT EXISTS ".USER_CONFIRM_MAIL_TABLE." (
52  id varchar(50) NOT NULL default '',
53  user_id smallint(5) NOT NULL default '0',
54  mail_address varchar(255) default NULL,
55  status enum('webmaster','admin','normal','generic','guest') default NULL,
56  date_check datetime default NULL,
57  reminder ENUM('true','false') NULL,
58PRIMARY KEY  (id)
59  )
60;";
61  pwg_query($q);
62
63        $q = "
64CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
65  user_id SMALLINT(5) NOT NULL DEFAULT '0',
66  lastvisit DATETIME NULL DEFAULT NULL,
67  reminder ENUM('true','false') NULL,
68PRIMARY KEY (`user_id`)
69  )
70;";
71  pwg_query($q);
72}
73
74
75function plugin_activate()
76{
77  global $conf;
78
79/* Cleaning obsolete files */
80/* *********************** */
81  clean_obsolete_files();
82
83
84/* Check for upgrade from 2.10 to 2.11 */
85/* *********************************** */
86        $query = '
87SELECT *
88  FROM '.CONFIG_TABLE.'
89WHERE param = "nbc_UserAdvManager_ConfirmMail"
90;';
91  $count = mysql_num_rows(pwg_query($query)); 
92 
93        if ($count == 0)
94        {
95  /* upgrade from branch 2.10 to 2.11 */
96  /* ******************************** */
97                upgrade_210();
98        }
99
100
101/* Check for upgrade from 2.11 to 2.12 */
102/* *********************************** */
103  if (!table_exist(USER_LASTVISIT_TABLE))
104  {
105  /* upgrade from branch 2.11 to 2.12 */
106  /* ******************************** */
107                upgrade_211();
108  }
109
110
111/* Check for upgrade from 2.12 to 2.13 */
112/* *********************************** */
113  $query = '
114SELECT *
115FROM '.USER_CONFIRM_MAIL_TABLE.'
116;';
117
118  $result = pwg_query($query);
119       
120        $numfields = mysql_num_fields($result);
121
122  if ($numfields < 6)
123  {
124  /* upgrade from branch 2.12 to 2.13 */
125  /* ******************************** */
126    upgrade_212();
127  }
128
129
130/* Serializing conf parameters - Available since 2.14.0 */
131/* **************************************************** */
132  if (unserialize($conf['nbc_UserAdvManager']) === false)
133  {
134  /* upgrade from branch 2.13 to 2.14 */
135  /* ******************************** */
136    upgrade_213();
137  }
138}
139
140
141function plugin_uninstall()
142{
143  global $conf;
144
145  if (isset($conf['nbc_UserAdvManager']))
146  {
147    $q = '
148DELETE FROM '.CONFIG_TABLE.'
149WHERE param="nbc_UserAdvManager"
150;';
151
152    pwg_query($q);
153  }
154
155  if (isset($conf['nbc_UserAdvManager_ConfirmMail']))
156  {
157    $q = '
158DELETE FROM '.CONFIG_TABLE.'
159WHERE param="nbc_UserAdvManager_ConfirmMail"
160;';
161
162    pwg_query($q);
163  }
164
165  $q = 'DROP TABLE '.USER_CONFIRM_MAIL_TABLE.';';
166  pwg_query( $q );
167
168  $q = 'DROP TABLE '.USER_LASTVISIT_TABLE.';';
169  pwg_query( $q );
170}
171
172
173// +----------------------------------------------------------+
174// |       Upgrading database from old plugin versions        |
175// +----------------------------------------------------------+
176
177/* upgrade from branch 2.10 to 2.11 */
178/* ******************************** */
179function upgrade_210()
180{
181        global $conf;
182         
183  $q = '
184INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
185VALUES ("nbc_UserAdvManager_ConfirmMail","false;5;Hello.
186               
187This 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.
188
189Note: After this period, your account will be permanently deleted.;false;Hello.
190
191This 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.
192
193Note: After this period, your account will be permanently deleted.","Parametres nbc_UserAdvManager - ConfirmMail")
194  ;';
195  pwg_query($q);
196
197  upgrade_211();
198}
199
200
201/* upgrade from branch 2.11 to 2.12 */
202/* ******************************** */
203function upgrade_211()
204{
205        global $conf;
206
207  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
208
209  if ((!isset($conf_UAM[14]) and !isset($conf_UAM[15])) and !isset($conf_UAM[16]) and !isset($conf_UAM[17]))
210  {
211    $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.
212       
213This 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.
214
215On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
216
217Best regards,
218
219The admin of the gallery.';
220               
221                $query = '
222UPDATE '.CONFIG_TABLE.'
223SET value="'.$upgrade_UAM.'"
224WHERE param="nbc_UserAdvManager"
225LIMIT 1
226;';
227                pwg_query($query);
228  }
229 
230        $q = "
231CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
232  user_id SMALLINT(5) NOT NULL DEFAULT '0',
233  lastvisit DATETIME NULL DEFAULT NULL,
234  reminder ENUM('true','false') NULL,
235PRIMARY KEY (`user_id`)
236  )
237;";
238  pwg_query($q);
239
240  upgrade_212();
241}
242
243
244/* upgrade from branch 2.12 to 2.13 */
245/* ******************************** */
246function upgrade_212()
247{
248/* Create missing table */
249  $query = "
250ALTER TABLE ".USER_CONFIRM_MAIL_TABLE."
251ADD reminder ENUM('true', 'false') NULL DEFAULT NULL
252;";
253 
254  pwg_query($query);
255
256/* Upgrade plugin configuration */
257        global $conf;
258
259  $conf_UAM = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
260
261  if ((!isset($conf_UAM[20])))
262  {
263    $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';
264               
265                $query = '
266UPDATE '.CONFIG_TABLE.'
267SET value="'.$upgrade_UAM.'"
268WHERE param="nbc_UserAdvManager"
269LIMIT 1
270;';
271                pwg_query($query);
272   
273    upgrade_213();
274  }
275}
276
277
278/* upgrade from branch 2.13 to 2.14 */
279/* ******************************** */
280function upgrade_213()
281{
282        global $conf;
283 
284  $conf_UAM = explode(';', $conf['nbc_UserAdvManager']);
285
286  $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');
287
288  $query = '
289UPDATE '.CONFIG_TABLE.'
290  SET value = "'.addslashes(serialize($upgrade_UAM)).'"
291  WHERE param = "nbc_UserAdvManager"
292;';
293  pwg_query($query);
294 
295  if (unserialize($conf['nbc_UserAdvManager_ConfirmMail']) === false)
296  {
297    $data = explode(';', $conf['nbc_UserAdvManager_ConfirmMail']);
298
299    $query = '
300UPDATE '.CONFIG_TABLE.'
301  SET value = "'.addslashes(serialize($data)).'"
302  WHERE param = "nbc_UserAdvManager_ConfirmMail"
303;';
304    pwg_query($query);
305  }
306}
307?>
Note: See TracBrowser for help on using the repository browser.