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

Last change on this file since 12239 was 12239, checked in by Eric, 13 years ago
  • Bug 2437 fixed - New feature : Request password renewal for selected users in Piwigo's users management panel.
  • Language files updates.
  • obsolete.list file creation to clean old help directories in languages.
  • Perform database upgrade.
  • Property svn:eol-style set to LF
File size: 9.7 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',-1,-1,-1,'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  // Piwigo's native tables modifications for password reset function - Add pwdreset column
130  $query = '
131SHOW COLUMNS FROM '.USERS_TABLE.'
132LIKE "UAM_pwdreset"
133;';
134 
135  $result = pwg_query($query);
136
137  if(!pwg_db_fetch_row($result))
138  {
139    $q = '
140ALTER TABLE '.USERS_TABLE.'
141ADD UAM_pwdreset enum("true","false")
142;';
143    pwg_query($q);
144  }
145}
146
147
148function plugin_activate()
149{
150  global $conf;
151
152/* Cleaning obsolete files */
153/* *********************** */
154  clean_obsolete_files();
155 
156  include_once (UAM_PATH.'include/upgradedb.inc.php');
157
158/* Check if old version is < 2.15 */
159/* ****************************** */
160        $query = '
161SELECT param
162  FROM '.CONFIG_TABLE.'
163WHERE param = "nbc_UserAdvManager"
164;';
165  $count1 = pwg_db_num_rows(pwg_query($query));
166 
167  $query = '
168SELECT *
169  FROM '.CONFIG_TABLE.'
170WHERE param = "nbc_UserAdvManager_ConfirmMail"
171;';
172  $count2 = pwg_db_num_rows(pwg_query($query)); 
173
174/* If old params exist an upgrade is needed */
175/* **************************************** */
176  if ($count1 == 1)
177  {
178/* Check for upgrade from 2.10 to 2.11 */
179/* *********************************** */
180    if ($count1 == 1 and $count2 == 0)
181    {
182    /* upgrade from branch 2.10 to 2.11 */
183    /* ******************************** */
184      upgrade_210_211();
185    }
186
187
188/* Check for upgrade from 2.11 to 2.12 */
189/* *********************************** */
190    if (!table_exist(USER_LASTVISIT_TABLE))
191    {
192    /* upgrade from branch 2.11 to 2.12 */
193    /* ******************************** */
194                upgrade_211_212();
195    }
196
197
198/* Check for upgrade from 2.12 to 2.13 */
199/* *********************************** */
200    $fields = mysql_list_fields($conf['db_base'],USER_CONFIRM_MAIL_TABLE);
201    $nb_fields = mysql_num_fields($fields); 
202
203    if ($nb_fields < 6)
204    {
205    /* upgrade from branch 2.12 to 2.13 */
206    /* ******************************** */
207      upgrade_212_213();
208    }
209
210
211/* Serializing conf parameters - Available since 2.14.0 */
212/* **************************************************** */
213    if (unserialize($conf['nbc_UserAdvManager']) === false)
214    {
215    /* upgrade from branch 2.13 to 2.14 */
216    /* ******************************** */
217      upgrade_213_214();
218    }
219   
220    /* upgrade from branch 2.14 to 2.15 */
221    /* ******************************** */
222      upgrade_214_215();
223  }
224
225/* Old version is > 2.15 */
226/* ********************* */
227        $query = '
228SELECT param
229  FROM '.CONFIG_TABLE.'
230WHERE param = "UserAdvManager_Redir"
231;';
232  $count = pwg_db_num_rows(pwg_query($query));
233 
234  if ($count == 0)
235  {
236    upgrade_2153_2154();
237  }
238
239/* Check for upgrade from 2.15 to 2.16 */
240/* *********************************** */
241        $query = '
242SELECT param
243  FROM '.CONFIG_TABLE.'
244WHERE param = "UserAdvManager_Version"
245;';
246  $count = pwg_db_num_rows(pwg_query($query));
247 
248  if ($count == 0)
249  {
250    /* upgrade from branch 2.15 to 2.16 */
251    /* ******************************** */
252    upgrade_215_2160();
253  }
254
255/* Check database upgrade since version 2.16.0 */
256  if (isset($conf['UserAdvManager_Version']))
257  {
258    if (version_compare($conf['UserAdvManager_Version'], '2.20.0') < 0)
259    {
260    /* upgrade from branch 2.16 to 2.20 */
261    /* ******************************** */
262      upgrade_216_220();
263    }
264   
265    if (version_compare($conf['UserAdvManager_Version'], '2.20.4') < 0)
266    {
267    /* upgrade from version 2.20.3 to 2.20.4 */
268    /* ************************************* */
269      upgrade_2203_2204();
270    }
271   
272    if (version_compare($conf['UserAdvManager_Version'], '2.20.7') < 0)
273    {
274    /* upgrade from version 2.20.4 to 2.20.7 */
275    /* ************************************* */
276      upgrade_2204_2207();
277    }
278
279    if (version_compare($conf['UserAdvManager_Version'], '2.20.8') < 0)
280    {
281    /* upgrade from version 2.20.7 to 2.20.8 */
282    /* ************************************* */
283      upgrade_2207_2208();
284    }
285
286    if (version_compare($conf['UserAdvManager_Version'], '2.30.0') < 0)
287    {
288    /* upgrade from version 2.20.8 to 2.30.0 */
289    /* ************************************* */
290      upgrade_2208_2300();
291    }
292  }
293
294  // Update plugin version number in #_config table and check consistency of #_plugins table
295  UAM_version_update();
296
297  load_conf_from_db('param like \'UserAdvManager\\_%\'');
298}
299
300
301function plugin_uninstall()
302{
303  global $conf;
304
305  if (isset($conf['UserAdvManager']))
306  {
307    $q = '
308DELETE FROM '.CONFIG_TABLE.'
309WHERE param="UserAdvManager"
310;';
311
312    pwg_query($q);
313  }
314
315  if (isset($conf['UserAdvManager_ConfirmMail']))
316  {
317    $q = '
318DELETE FROM '.CONFIG_TABLE.'
319WHERE param="UserAdvManager_ConfirmMail"
320;';
321
322    pwg_query($q);
323  }
324
325  if (isset($conf['UserAdvManager_Redir']))
326  {
327    $q = '
328DELETE FROM '.CONFIG_TABLE.'
329WHERE param="UserAdvManager_Redir"
330;';
331
332    pwg_query($q);
333  }
334
335  if (isset($conf['UserAdvManager_Version']))
336  {
337    $q = '
338DELETE FROM '.CONFIG_TABLE.'
339WHERE param="UserAdvManager_Version"
340;';
341
342    pwg_query($q);
343  }
344
345  $q = '
346DROP TABLE '.USER_CONFIRM_MAIL_TABLE.'
347;';
348  pwg_query( $q );
349
350  $q = '
351DROP TABLE '.USER_LASTVISIT_TABLE.'
352;';
353  pwg_query( $q );
354
355  $q = '
356ALTER TABLE '.USERS_TABLE.'
357DROP UAM_pwdreset
358;';
359  pwg_query($q);
360}
361?>
Note: See TracBrowser for help on using the repository browser.