source: extensions/UserAdvManager/trunk/maintain.inc.php @ 11530

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

Bug fixed on installation from scratch (unable to save config)

  • Property svn:eol-style set to LF
File size: 9.1 KB
Line 
1<?php
2
3if(!defined('UAM_PATH'))
4{
5  define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
6}
7
8include_once (UAM_PATH.'include/constants.php');
9include_once (UAM_PATH.'include/functions.inc.php');
10
11
12function plugin_install()
13{
14        global $conf;
15       
16  $default1 = array('false','false',-1,-1,-1,'false','',-1,'','','false','','false',100,'false','false',10,'Hello [username].
17       
18This is a reminder because a very long time passed since your last visit on our gallery [mygallery]. 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','false','false','false','Sorry [username], your account has been deleted due to a too long time passed since your last visit at [mygallery].','Sorry [username], your account has been deprecated due to a too long time passed since your last visit at [mygallery]. Please, use the following link to revalidate your account.',-1,-1,'Thank you for registering at [mygallery]. Your account has been manually validated by _admin_. You may now log in at _link_to_site_ and make any appropriate changes to your profile. Welcome to _name_of_site_!','false','You have requested a password reset on our gallery. Please, find below your new connection settings.','false','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.','false','false','false');
25
26        $query = '
27SELECT param
28  FROM '.CONFIG_TABLE.'
29WHERE param = "UserAdvManager"
30;';
31  $count = pwg_db_num_rows(pwg_query($query));
32 
33  if ($count == 0)
34  {
35    $q = '
36INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
37VALUES ("UserAdvManager","'.pwg_db_real_escape_string(serialize($default1)).'","UAM parameters")
38  ;';
39    pwg_query($q);
40  }
41
42
43  $default2 = array('false',5,'Hello [username].
44               
45This is a reminder message because you registered on our gallery [mygallery] 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.
46
47Note: After this period, your account will be permanently deleted.','false','Hello [username].
48
49This is a reminder message because you registered on our gallery [mygallery] 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.
50
51Note: After this period, your account will be permanently deleted.','You have confirmed that you are human and may now use [mygallery]! Welcome [username]!','Your activation key is incorrect or expired or you have already validated your account, please contact the webmaster to fix this problem.');
52
53        $query = '
54SELECT param
55  FROM '.CONFIG_TABLE.'
56WHERE param = "UserAdvManager_ConfirmMail"
57;';
58  $count = pwg_db_num_rows(pwg_query($query));
59 
60  if ($count == 0)
61  {
62    $q = '
63INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
64VALUES ("UserAdvManager_ConfirmMail","'.pwg_db_real_escape_string(serialize($default2)).'","UAM ConfirmMail parameters")
65  ;';
66    pwg_query($q);
67  }
68
69        $query = '
70SELECT param
71  FROM '.CONFIG_TABLE.'
72WHERE param = "UserAdvManager_Redir"
73;';
74  $count = pwg_db_num_rows(pwg_query($query));
75 
76  if ($count == 0)
77  {
78    $q = '
79INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
80VALUES ("UserAdvManager_Redir","0","UAM Redirections")
81  ;';
82    pwg_query($q);
83  }
84
85// Set current plugin version in config table
86  $plugin =  PluginInfos(UAM_PATH);
87  $version = $plugin['version'];
88
89        $query = '
90SELECT param
91  FROM '.CONFIG_TABLE.'
92WHERE param = "UserAdvManager_Version"
93;';
94  $count = pwg_db_num_rows(pwg_query($query));
95 
96  if ($count == 0)
97  {
98    $q = '
99INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
100VALUES ("UserAdvManager_Version","'.$version.'","UAM version check")
101  ;';
102    pwg_query($q);
103  }
104
105
106        $q = "
107CREATE TABLE IF NOT EXISTS ".USER_CONFIRM_MAIL_TABLE." (
108  id varchar(50) NOT NULL default '',
109  user_id smallint(5) NOT NULL default '0',
110  mail_address varchar(255) default NULL,
111  status enum('webmaster','admin','normal','generic','guest') default NULL,
112  date_check datetime default NULL,
113  reminder ENUM('true','false') NULL,
114PRIMARY KEY  (id)
115  )
116ENGINE=MyISAM;";
117  pwg_query($q);
118
119        $q = "
120CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
121  user_id SMALLINT(5) NOT NULL DEFAULT '0',
122  lastvisit DATETIME NULL DEFAULT NULL,
123  reminder ENUM('true','false') NULL,
124PRIMARY KEY (`user_id`)
125  )
126ENGINE=MyISAM;";
127  pwg_query($q);
128}
129
130
131function plugin_activate()
132{
133  global $conf;
134
135/* Cleaning obsolete files */
136/* *********************** */
137  clean_obsolete_files();
138 
139  include_once (UAM_PATH.'include/upgradedb.inc.php');
140
141/* Check if old version is < 2.15 */
142/* ****************************** */
143        $query = '
144SELECT param
145  FROM '.CONFIG_TABLE.'
146WHERE param = "nbc_UserAdvManager"
147;';
148  $count1 = pwg_db_num_rows(pwg_query($query));
149 
150  $query = '
151SELECT *
152  FROM '.CONFIG_TABLE.'
153WHERE param = "nbc_UserAdvManager_ConfirmMail"
154;';
155  $count2 = pwg_db_num_rows(pwg_query($query)); 
156
157/* If old params exist an upgrade is needed */
158/* **************************************** */
159  if ($count1 == 1)
160  {
161/* Check for upgrade from 2.10 to 2.11 */
162/* *********************************** */
163    if ($count1 == 1 and $count2 == 0)
164    {
165    /* upgrade from branch 2.10 to 2.11 */
166    /* ******************************** */
167      upgrade_210_211();
168    }
169
170
171/* Check for upgrade from 2.11 to 2.12 */
172/* *********************************** */
173    if (!table_exist(USER_LASTVISIT_TABLE))
174    {
175    /* upgrade from branch 2.11 to 2.12 */
176    /* ******************************** */
177                upgrade_211_212();
178    }
179
180
181/* Check for upgrade from 2.12 to 2.13 */
182/* *********************************** */
183    $fields = mysql_list_fields($conf['db_base'],USER_CONFIRM_MAIL_TABLE);
184    $nb_fields = mysql_num_fields($fields); 
185
186    if ($nb_fields < 6)
187    {
188    /* upgrade from branch 2.12 to 2.13 */
189    /* ******************************** */
190      upgrade_212_213();
191    }
192
193
194/* Serializing conf parameters - Available since 2.14.0 */
195/* **************************************************** */
196    if (unserialize($conf['nbc_UserAdvManager']) === false)
197    {
198    /* upgrade from branch 2.13 to 2.14 */
199    /* ******************************** */
200      upgrade_213_214();
201    }
202   
203    /* upgrade from branch 2.14 to 2.15 */
204    /* ******************************** */
205      upgrade_214_215();
206  }
207
208/* Old version is > 2.15 */
209/* ********************* */
210        $query = '
211SELECT param
212  FROM '.CONFIG_TABLE.'
213WHERE param = "UserAdvManager_Redir"
214;';
215  $count = pwg_db_num_rows(pwg_query($query));
216 
217  if ($count == 0)
218  {
219    upgrade_2153_2154();
220  }
221
222/* Check for upgrade from 2.15 to 2.16 */
223/* *********************************** */
224        $query = '
225SELECT param
226  FROM '.CONFIG_TABLE.'
227WHERE param = "UserAdvManager_Version"
228;';
229  $count = pwg_db_num_rows(pwg_query($query));
230 
231  if ($count == 0)
232  {
233    /* upgrade from branch 2.15 to 2.16 */
234    /* ******************************** */
235    upgrade_215_2160();
236  }
237
238/* Check database upgrade since version 2.16.0 */
239  if (isset($conf['UserAdvManager_Version']))
240  {
241    if (version_compare($conf['UserAdvManager_Version'], '2.20.0') < 0)
242    {
243    /* upgrade from branch 2.16 to 2.20 */
244    /* ******************************** */
245      upgrade_216_220();
246    }
247   
248    if (version_compare($conf['UserAdvManager_Version'], '2.20.4') < 0)
249    {
250    /* upgrade from version 2.20.3 to 2.20.4 */
251    /* ************************************* */
252      upgrade_2203_2204();
253    }
254   
255    if (version_compare($conf['UserAdvManager_Version'], '2.20.7') < 0)
256    {
257    /* upgrade from version 2.20.4 to 2.20.7 */
258    /* ************************************* */
259      upgrade_2204_2207();
260    }
261
262    if (version_compare($conf['UserAdvManager_Version'], '2.20.8') < 0)
263    {
264    /* upgrade from version 2.20.7 to 2.20.8 */
265    /* ************************************* */
266      upgrade_2207_2208();
267    }
268  }
269
270  // Update plugin version number in #_config table and check consistency of #_plugins table
271  UAM_version_update();
272
273  load_conf_from_db('param like \'UserAdvManager\\_%\'');
274}
275
276
277function plugin_uninstall()
278{
279  global $conf;
280
281  if (isset($conf['UserAdvManager']))
282  {
283    $q = '
284DELETE FROM '.CONFIG_TABLE.'
285WHERE param="UserAdvManager"
286;';
287
288    pwg_query($q);
289  }
290
291  if (isset($conf['UserAdvManager_ConfirmMail']))
292  {
293    $q = '
294DELETE FROM '.CONFIG_TABLE.'
295WHERE param="UserAdvManager_ConfirmMail"
296;';
297
298    pwg_query($q);
299  }
300
301  if (isset($conf['UserAdvManager_Redir']))
302  {
303    $q = '
304DELETE FROM '.CONFIG_TABLE.'
305WHERE param="UserAdvManager_Redir"
306;';
307
308    pwg_query($q);
309  }
310
311  if (isset($conf['UserAdvManager_Version']))
312  {
313    $q = '
314DELETE FROM '.CONFIG_TABLE.'
315WHERE param="UserAdvManager_Version"
316;';
317
318    pwg_query($q);
319  }
320
321  $q = 'DROP TABLE '.USER_CONFIRM_MAIL_TABLE.';';
322  pwg_query( $q );
323
324  $q = 'DROP TABLE '.USER_LASTVISIT_TABLE.';';
325  pwg_query( $q );
326}
327?>
Note: See TracBrowser for help on using the repository browser.