source: extensions/UserAdvManager/branches/2.30/maintain.inc.php @ 12248

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

Merge r12247 from trunk to branch 2.30

  • Property svn:eol-style set to LF
File size: 11.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/* ****************************************************************** */
17/* **************** BEGIN - Data preparation in vars **************** */
18/* ****************************************************************** */
19
20  // Default global parameters for UserAdvManager conf
21  $default1 = array('false','false',-1,-1,-1,'false','',-1,'','','false','','false',100,'false','false',10,'Hello [username].
22       
23This 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.
24
25On receipt of this message and no new visit within 15 days, we would be obliged to automatically delete your account.
26
27Best regards,
28
29The 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',-1,-1,-1,'false');
30
31  // Default specific parameters for UserAdvManager ConfirmMail conf
32  $default2 = array('false',5,'Hello [username].
33               
34This 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.
35
36Note: After this period, your account will be permanently deleted.','false','Hello [username].
37
38This 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.
39
40Note: 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.');
41
42  // Set current plugin version in config table
43  $plugin =  PluginInfos(UAM_PATH);
44  $version = $plugin['version'];
45
46/* **************************************************************** */
47/* **************** END - Data preparation in vars **************** */
48/* **************************************************************** */
49
50
51/* ***************************************************************************** */
52/* **************** BEGIN - Database actions and initialization **************** */
53/* ***************************************************************************** */
54
55  // Create UserAdvManager conf if not already exists
56        $query = '
57SELECT param
58  FROM '.CONFIG_TABLE.'
59WHERE param = "UserAdvManager"
60;';
61  $count = pwg_db_num_rows(pwg_query($query));
62 
63  if ($count == 0)
64  {
65    $q = '
66INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
67VALUES ("UserAdvManager","'.pwg_db_real_escape_string(serialize($default1)).'","UAM parameters")
68  ;';
69    pwg_query($q);
70  }
71
72  // Create UserAdvManager_ConfirmMail conf if not already exists
73        $query = '
74SELECT param
75  FROM '.CONFIG_TABLE.'
76WHERE param = "UserAdvManager_ConfirmMail"
77;';
78  $count = pwg_db_num_rows(pwg_query($query));
79 
80  if ($count == 0)
81  {
82    $q = '
83INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
84VALUES ("UserAdvManager_ConfirmMail","'.pwg_db_real_escape_string(serialize($default2)).'","UAM ConfirmMail parameters")
85  ;';
86    pwg_query($q);
87  }
88
89  // Create UserAdvManager_Redir conf if not already exists
90        $query = '
91SELECT param
92  FROM '.CONFIG_TABLE.'
93WHERE param = "UserAdvManager_Redir"
94;';
95  $count = pwg_db_num_rows(pwg_query($query));
96 
97  if ($count == 0)
98  {
99    $q = '
100INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
101VALUES ("UserAdvManager_Redir","0","UAM Redirections")
102  ;';
103    pwg_query($q);
104  }
105
106  // Create UserAdvManager_Version conf if not already exists
107        $query = '
108SELECT param
109  FROM '.CONFIG_TABLE.'
110WHERE param = "UserAdvManager_Version"
111;';
112  $count = pwg_db_num_rows(pwg_query($query));
113 
114  if ($count == 0)
115  {
116    $q = '
117INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
118VALUES ("UserAdvManager_Version","'.$version.'","UAM version check")
119  ;';
120    pwg_query($q);
121  }
122
123  // Create USER_CONFIRM_MAIL_TABLE
124        $q = "
125CREATE TABLE IF NOT EXISTS ".USER_CONFIRM_MAIL_TABLE." (
126  id varchar(50) NOT NULL default '',
127  user_id smallint(5) NOT NULL default '0',
128  mail_address varchar(255) default NULL,
129  status enum('webmaster','admin','normal','generic','guest') default NULL,
130  date_check datetime default NULL,
131  reminder ENUM('true','false') NULL,
132PRIMARY KEY  (id)
133  )
134ENGINE=MyISAM;";
135  pwg_query($q);
136
137  // Create USER_LASTVISIT_TABLE
138        $q = "
139CREATE TABLE IF NOT EXISTS ".USER_LASTVISIT_TABLE." (
140  user_id SMALLINT(5) NOT NULL DEFAULT '0',
141  lastvisit DATETIME NULL DEFAULT NULL,
142  reminder ENUM('true','false') NULL,
143PRIMARY KEY (`user_id`)
144  )
145ENGINE=MyISAM;";
146  pwg_query($q);
147
148  // Piwigo's native tables modifications for password reset function - Add pwdreset column if not already exists
149  $query = '
150SHOW COLUMNS FROM '.USERS_TABLE.'
151LIKE "UAM_pwdreset"
152;';
153 
154  $result = pwg_query($query);
155
156  if(!pwg_db_fetch_row($result))
157  {
158    $q = '
159ALTER TABLE '.USERS_TABLE.'
160ADD UAM_pwdreset enum("true","false")
161;';
162    pwg_query($q);
163  }
164
165/* *************************************************************************** */
166/* **************** END - Database actions and initialization **************** */
167/* *************************************************************************** */
168}
169
170
171function plugin_activate()
172{
173  global $conf;
174
175/* Cleaning obsolete files */
176/* *********************** */
177  clean_obsolete_files();
178 
179  include_once (UAM_PATH.'include/upgradedb.inc.php');
180
181/* Check if old version is < 2.15 */
182/* ****************************** */
183        $query = '
184SELECT param
185  FROM '.CONFIG_TABLE.'
186WHERE param = "nbc_UserAdvManager"
187;';
188  $count1 = pwg_db_num_rows(pwg_query($query));
189 
190  $query = '
191SELECT *
192  FROM '.CONFIG_TABLE.'
193WHERE param = "nbc_UserAdvManager_ConfirmMail"
194;';
195  $count2 = pwg_db_num_rows(pwg_query($query)); 
196
197/* If old params exist an upgrade is needed */
198/* **************************************** */
199  if ($count1 == 1)
200  {
201/* Check for upgrade from 2.10 to 2.11 */
202/* *********************************** */
203    if ($count1 == 1 and $count2 == 0)
204    {
205    /* upgrade from branch 2.10 to 2.11 */
206    /* ******************************** */
207      upgrade_210_211();
208    }
209
210
211/* Check for upgrade from 2.11 to 2.12 */
212/* *********************************** */
213    if (!table_exist(USER_LASTVISIT_TABLE))
214    {
215    /* upgrade from branch 2.11 to 2.12 */
216    /* ******************************** */
217                upgrade_211_212();
218    }
219
220
221/* Check for upgrade from 2.12 to 2.13 */
222/* *********************************** */
223    $fields = mysql_list_fields($conf['db_base'],USER_CONFIRM_MAIL_TABLE);
224    $nb_fields = mysql_num_fields($fields); 
225
226    if ($nb_fields < 6)
227    {
228    /* upgrade from branch 2.12 to 2.13 */
229    /* ******************************** */
230      upgrade_212_213();
231    }
232
233
234/* Serializing conf parameters - Available since 2.14.0 */
235/* **************************************************** */
236    if (unserialize($conf['nbc_UserAdvManager']) === false)
237    {
238    /* upgrade from branch 2.13 to 2.14 */
239    /* ******************************** */
240      upgrade_213_214();
241    }
242   
243    /* upgrade from branch 2.14 to 2.15 */
244    /* ******************************** */
245      upgrade_214_215();
246  }
247
248/* Old version is > 2.15 */
249/* ********************* */
250        $query = '
251SELECT param
252  FROM '.CONFIG_TABLE.'
253WHERE param = "UserAdvManager_Redir"
254;';
255  $count = pwg_db_num_rows(pwg_query($query));
256 
257  if ($count == 0)
258  {
259    upgrade_2153_2154();
260  }
261
262/* Check for upgrade from 2.15 to 2.16 */
263/* *********************************** */
264        $query = '
265SELECT param
266  FROM '.CONFIG_TABLE.'
267WHERE param = "UserAdvManager_Version"
268;';
269  $count = pwg_db_num_rows(pwg_query($query));
270 
271  if ($count == 0)
272  {
273    /* upgrade from branch 2.15 to 2.16 */
274    /* ******************************** */
275    upgrade_215_2160();
276  }
277
278/* Check database upgrade since version 2.16.0 */
279  if (isset($conf['UserAdvManager_Version']))
280  {
281    if (version_compare($conf['UserAdvManager_Version'], '2.20.0') < 0)
282    {
283    /* upgrade from branch 2.16 to 2.20 */
284    /* ******************************** */
285      upgrade_216_220();
286    }
287   
288    if (version_compare($conf['UserAdvManager_Version'], '2.20.4') < 0)
289    {
290    /* upgrade from version 2.20.3 to 2.20.4 */
291    /* ************************************* */
292      upgrade_2203_2204();
293    }
294   
295    if (version_compare($conf['UserAdvManager_Version'], '2.20.7') < 0)
296    {
297    /* upgrade from version 2.20.4 to 2.20.7 */
298    /* ************************************* */
299      upgrade_2204_2207();
300    }
301
302    if (version_compare($conf['UserAdvManager_Version'], '2.20.8') < 0)
303    {
304    /* upgrade from version 2.20.7 to 2.20.8 */
305    /* ************************************* */
306      upgrade_2207_2208();
307    }
308
309    if (version_compare($conf['UserAdvManager_Version'], '2.30.0') < 0)
310    {
311    /* upgrade from version 2.20.8 to 2.30.0 */
312    /* ************************************* */
313      upgrade_2208_2300();
314    }
315  }
316
317  // Update plugin version number in #_config table and check consistency of #_plugins table
318  UAM_version_update();
319
320  load_conf_from_db('param like \'UserAdvManager\\_%\'');
321}
322
323
324function plugin_uninstall()
325{
326  global $conf;
327
328  if (isset($conf['UserAdvManager']))
329  {
330    $q = '
331DELETE FROM '.CONFIG_TABLE.'
332WHERE param="UserAdvManager"
333;';
334
335    pwg_query($q);
336  }
337
338  if (isset($conf['UserAdvManager_ConfirmMail']))
339  {
340    $q = '
341DELETE FROM '.CONFIG_TABLE.'
342WHERE param="UserAdvManager_ConfirmMail"
343;';
344
345    pwg_query($q);
346  }
347
348  if (isset($conf['UserAdvManager_Redir']))
349  {
350    $q = '
351DELETE FROM '.CONFIG_TABLE.'
352WHERE param="UserAdvManager_Redir"
353;';
354
355    pwg_query($q);
356  }
357
358  if (isset($conf['UserAdvManager_Version']))
359  {
360    $q = '
361DELETE FROM '.CONFIG_TABLE.'
362WHERE param="UserAdvManager_Version"
363;';
364
365    pwg_query($q);
366  }
367
368  $q = '
369DROP TABLE '.USER_CONFIRM_MAIL_TABLE.'
370;';
371  pwg_query( $q );
372
373  $q = '
374DROP TABLE '.USER_LASTVISIT_TABLE.'
375;';
376  pwg_query( $q );
377
378  $q = '
379ALTER TABLE '.USERS_TABLE.'
380DROP UAM_pwdreset
381;';
382  pwg_query($q);
383}
384?>
Note: See TracBrowser for help on using the repository browser.