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

Last change on this file since 8111 was 8110, checked in by Eric, 14 years ago
  • Improve database cleanup on plugin uninstallation
  • Version 2.16.0 hard coded
  • Property svn:eol-style set to LF
File size: 6.8 KB
Line 
1<?php
2
3if(!defined('UAM_PATH'))
4{
5  define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
6}
7if (!defined('UAM_ROOT'))
8{
9  define('UAM_ROOT', dirname(__FILE__).'/');
10}
11
12include_once (UAM_PATH.'include/constants.php');
13include_once (UAM_PATH.'include/functions.inc.php');
14
15
16function plugin_install()
17{
18        global $conf;
19       
20  $default1 = array('false','false',-1,-1,-1,'false','false','',-1,'','','false','','false',100,'false','false',10,'Hello.
21       
22This 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.
23
24On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
25
26Best regards,
27
28The admin of the gallery.','false','false','false','false','false','Sorry, your account has been deleted due to a too long time passed since your last visit.','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.',-1,-1,'Thank you to have registered the gallery. Your account has been manually validated by admin. You can now visit all the gallery for free !');
29
30  $q = '
31INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
32VALUES ("UserAdvManager","'.addslashes(serialize($default1)).'","UAM parameters")
33  ;';
34  pwg_query($q);
35
36
37  $default2 = array('false',5,'Hello.
38               
39This 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.
40
41Note: After this period, your account will be permanently deleted.','false','Hello.
42
43This 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.
44
45Note: After this period, your account will be permanently deleted.','Thank you to have confirmed your email address and your registration on the gallery. Have fun !','Your activation key is incorrect or expired or you have already validated your account, please contact the webmaster to fix this problem.');
46
47  $q = '
48INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
49VALUES ("UserAdvManager_ConfirmMail","'.addslashes(serialize($default2)).'","UAM ConfirmMail parameters")
50  ;';
51  pwg_query($q);
52 
53  $q = '
54INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
55VALUES ("UserAdvManager_Redir","0","UAM Redirections")
56  ;';
57  pwg_query($q);
58
59
60        $q = "
61CREATE TABLE IF NOT EXISTS ".USER_CONFIRM_MAIL_TABLE." (
62  id varchar(50) NOT NULL default '',
63  user_id smallint(5) NOT NULL default '0',
64  mail_address varchar(255) default NULL,
65  status enum('webmaster','admin','normal','generic','guest') default NULL,
66  date_check datetime default NULL,
67  reminder ENUM('true','false') NULL,
68PRIMARY KEY  (id)
69  )
70;";
71  pwg_query($q);
72
73        $q = "
74CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
75  user_id SMALLINT(5) NOT NULL DEFAULT '0',
76  lastvisit DATETIME NULL DEFAULT NULL,
77  reminder ENUM('true','false') NULL,
78PRIMARY KEY (`user_id`)
79  )
80;";
81  pwg_query($q);
82}
83
84
85function plugin_activate()
86{
87  global $conf;
88
89/* Cleaning obsolete files */
90/* *********************** */
91  clean_obsolete_files();
92 
93  include_once (UAM_PATH.'include/upgradedb.inc.php');
94
95/* Check if old version is < 2.15 */
96/* ****************************** */
97        $query = '
98SELECT param
99  FROM '.CONFIG_TABLE.'
100WHERE param = "nbc_UserAdvManager"
101;';
102  $count1 = pwg_db_num_rows(pwg_query($query));
103 
104  $query = '
105SELECT *
106  FROM '.CONFIG_TABLE.'
107WHERE param = "nbc_UserAdvManager_ConfirmMail"
108;';
109  $count2 = pwg_db_num_rows(pwg_query($query)); 
110
111/* If old params exist an upgrade is needed */
112/* **************************************** */
113  if ($count1 == 1)
114  {
115/* Check for upgrade from 2.10 to 2.11 */
116/* *********************************** */
117    if ($count1 == 1 and $count2 == 0)
118    {
119    /* upgrade from branch 2.10 to 2.11 */
120    /* ******************************** */
121      upgrade_210_211();
122    }
123
124
125/* Check for upgrade from 2.11 to 2.12 */
126/* *********************************** */
127    if (!table_exist(USER_LASTVISIT_TABLE))
128    {
129    /* upgrade from branch 2.11 to 2.12 */
130    /* ******************************** */
131                upgrade_211_212();
132    }
133
134
135/* Check for upgrade from 2.12 to 2.13 */
136/* *********************************** */
137    $fields = mysql_list_fields($conf['db_base'],USER_CONFIRM_MAIL_TABLE);
138    $nb_fields = mysql_num_fields($fields); 
139
140    if ($nb_fields < 6)
141    {
142    /* upgrade from branch 2.12 to 2.13 */
143    /* ******************************** */
144      upgrade_212_213();
145    }
146
147
148/* Serializing conf parameters - Available since 2.14.0 */
149/* **************************************************** */
150    if (unserialize($conf['nbc_UserAdvManager']) === false)
151    {
152    /* upgrade from branch 2.13 to 2.14 */
153    /* ******************************** */
154      upgrade_213_214();
155    }
156   
157
158/* Check for upgrade from 2.14 to 2.15 */
159/* *********************************** */
160    //if ($count1 == 1 or $count2 == 1)
161    //{
162    /* upgrade from branch 2.14 to 2.15 */
163    /* ******************************** */
164      upgrade_214_215();
165    //}
166  }
167
168/* Old version is > 2.15 */
169/* ********************* */
170        $query = '
171SELECT param
172  FROM '.CONFIG_TABLE.'
173WHERE param = "UserAdvManager_Redir"
174;';
175  $count = pwg_db_num_rows(pwg_query($query));
176 
177  if ($count == 0)
178  {
179    upgrade_2153_2154();
180  }
181
182/* Check for upgrade from 2.15 to 2.16 */
183/* *********************************** */
184        $query = '
185SELECT param
186  FROM '.CONFIG_TABLE.'
187WHERE param = "UserAdvManager_Version"
188;';
189  $count = pwg_db_num_rows(pwg_query($query));
190 
191  if ($count == 0)
192  {
193    /* upgrade from branch 2.15 to 2.16 */
194    /* ******************************** */
195    upgrade_215_2160();
196  }
197
198load_conf_from_db('param like \'UserAdvManager\\_%\'');
199}
200
201
202function plugin_uninstall()
203{
204  global $conf;
205
206  if (isset($conf['UserAdvManager']))
207  {
208    $q = '
209DELETE FROM '.CONFIG_TABLE.'
210WHERE param="UserAdvManager"
211;';
212
213    pwg_query($q);
214  }
215
216  if (isset($conf['UserAdvManager_ConfirmMail']))
217  {
218    $q = '
219DELETE FROM '.CONFIG_TABLE.'
220WHERE param="UserAdvManager_ConfirmMail"
221;';
222
223    pwg_query($q);
224  }
225
226  if (isset($conf['UserAdvManager_Redir']))
227  {
228    $q = '
229DELETE FROM '.CONFIG_TABLE.'
230WHERE param="UserAdvManager_Redir"
231;';
232
233    pwg_query($q);
234  }
235
236  if (isset($conf['UserAdvManager_Version']))
237  {
238    $q = '
239DELETE FROM '.CONFIG_TABLE.'
240WHERE param="UserAdvManager_Version"
241;';
242
243    pwg_query($q);
244  }
245
246  $q = 'DROP TABLE '.USER_CONFIRM_MAIL_TABLE.';';
247  pwg_query( $q );
248
249  $q = 'DROP TABLE '.USER_LASTVISIT_TABLE.';';
250  pwg_query( $q );
251}
252?>
Note: See TracBrowser for help on using the repository browser.