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

Last change on this file since 22112 was 21519, checked in by Eric, 12 years ago

Next version is 2.50.2 :
Bug 2866 fixed - Fatal error message (Fatal error: Call to undefined function switch_lang_to()) when using validation link

  • Property svn:eol-style set to LF
File size: 13.7 KB
RevLine 
[3742]1<?php
2
[6255]3if(!defined('UAM_PATH'))
4{
5  define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
6}
[3742]7
[5181]8include_once (UAM_PATH.'include/constants.php');
9include_once (UAM_PATH.'include/functions.inc.php');
[3742]10
[12271]11load_language('plugin.lang', UAM_PATH);
[5064]12
[12271]13
[3742]14function plugin_install()
15{
[3872]16        global $conf;
[12247]17
18/* ****************************************************************** */
19/* **************** BEGIN - Data preparation in vars **************** */
20/* ****************************************************************** */
21
22  // Default global parameters for UserAdvManager conf
[12271]23  // -------------------------------------------------
[21075]24  $defaultUAM = array(
25    'MAIL_INFO'                   => 'false',
26    'CONFIRM_MAIL'                => 'false',
27    'NO_CONFIRM_GROUP'            => '-1',
28    'VALIDATED_GROUP'             => '-1',
29    'VALIDATED_STATUS'            => '-1',
30    'USERNAME_CHAR'               => 'false',
31    'USERNAME_CHAR_LIST'          => '',
32    'NO_CONFIRM_STATUS'           => '-1',
33    'MAILINFO_TEXT'               => l10n('UAM_Default_InfoMail_Txt'),
34    'CONFIRMMAIL_TEXT'            => l10n('UAM_Default_ConfirmMail_Txt'),
35    'MAILEXCLUSION'               => 'false',
36    'MAILEXCLUSION_LIST'          => '',
37    'PASSWORDENF'                 => 'false',
38    'PASSWORD_SCORE'              => '100',
39    'ADMINPASSWENF'               => 'false',
40    'GHOSTRACKER'                 => 'false',
41    'GHOSTRACKER_DAYLIMIT'        => '10',
42    'GHOSTRACKER_REMINDERTEXT'    => l10n('UAM_Default_GhstReminder_Txt'),
43    'ADDLASTVISIT'                => 'false',
44    'ADMINCONFMAIL'               => 'false',
45    'REDIRTOPROFILE'              => 'false',
46    'GTAUTO'                      => 'false',
47    'GTAUTOMAIL'                  => 'false',
48    'GTAUTODEL'                   => l10n('UAM_Default_GhstDeletion_Txt'),
49    'GTAUTOMAILTEXT'              => l10n('UAM_Default_GhstDemotion_Txt'),
50    'DOWNGRADE_GROUP'             => '-1',
51    'DOWNGRADE_STATUS'            => '-1',
52    'ADMINVALIDATIONMAIL'         => l10n('UAM_Default_AdminValidation_Txt'),
53    'CUSTOMPASSWRETR'             => 'false',
54    'CUSTOMPASSWRETR_TEXT'        => l10n('UAM_Default_PwdRequest_Txt'),
55    'USRAUTO'                     => 'false',
56    'USRAUTODEL'                  => l10n('UAM_Default_ValidationTimeout_Txt'),
57    'USRAUTOMAIL'                 => 'false',
58    'STUFFS'                      => 'false',
59    'HIDEPASSW'                   => 'false',
60    'NO_VALID_LEVEL'              => '-1',
61    'VALID_LEVEL'                 => '-1',
62    'DOWNGRADE_LEVEL'             => '-1',
63    'PWDRESET'                    => 'false',
64    'REJECTCONNECT'               => 'false',
65    'REJECTCONNECT_TEXT'          => l10n('UAM_Default_RejectConnexion_Txt'),
66    'CONFIRMMAIL_SUBJECT'         => l10n('UAM_Default_ConfirmMail_Subject'),
67    'CONFIRMMAIL_REMAIL_SUBJECT'  => l10n('UAM_Default_ConfirmMail_Remail_Subject'),
68    'INFOMAIL_SUBJECT'            => l10n('UAM_Default_InfoMail_Subject'),
69    'GTAUTOMAIL_SUBJECT'          => l10n('UAM_Default_GTAutoMail_Subject'),
70    'GTREMINDER_SUBJECT'          => l10n('UAM_Default_GTReminder_Subject'),
71    'ADMINVALIDATIONMAIL_SUBJECT' => l10n('UAM_Default_AdminValidationMail_Subject')
72  );
[12271]73 
[12247]74  // Default specific parameters for UserAdvManager ConfirmMail conf
[12271]75  // ---------------------------------------------------------------
[21075]76  $defaultConfirmMail = array(
77    'CONFIRMMAIL_TIMEOUT'     => 'false',
78    'CONFIRMMAIL_DELAY'       => '5',
79    'CONFIRMMAIL_REMAIL_TXT1' => l10n('UAM_Default_CfmMail_Remail_Txt1'),
80    'CONFIRMMAIL_REMAIL'      => 'false',
81    'CONFIRMMAIL_REMAIL_TXT2' => l10n('UAM_Default_CfmMail_Remail_Txt2'),
82    'CONFIRMMAIL_CUSTOM_TXT1' => l10n('UAM_Default_CfmMail_Custom_Txt1'),
83    'CONFIRMMAIL_CUSTOM_TXT2' => l10n('UAM_Default_CfmMail_Custom_Txt2')
84  );
[12271]85 
[12247]86  // Set current plugin version in config table
[12271]87  // ------------------------------------------
[12247]88  $plugin =  PluginInfos(UAM_PATH);
89  $version = $plugin['version'];
90
91/* **************************************************************** */
92/* **************** END - Data preparation in vars **************** */
93/* **************************************************************** */
94
95
96/* ***************************************************************************** */
97/* **************** BEGIN - Database actions and initialization **************** */
98/* ***************************************************************************** */
99
100  // Create UserAdvManager conf if not already exists
[12271]101  // ------------------------------------------------
[9853]102        $query = '
103SELECT param
104  FROM '.CONFIG_TABLE.'
105WHERE param = "UserAdvManager"
106;';
107  $count = pwg_db_num_rows(pwg_query($query));
108 
109  if ($count == 0)
110  {
111    $q = '
[4143]112INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
[12271]113VALUES ("UserAdvManager","'.pwg_db_real_escape_string(serialize($defaultUAM)).'","UAM parameters")
[5056]114  ;';
[9853]115    pwg_query($q);
116  }
[4143]117
[12247]118  // Create UserAdvManager_ConfirmMail conf if not already exists
[12271]119  // ------------------------------------------------------------
[9853]120        $query = '
121SELECT param
122  FROM '.CONFIG_TABLE.'
123WHERE param = "UserAdvManager_ConfirmMail"
124;';
125  $count = pwg_db_num_rows(pwg_query($query));
126 
127  if ($count == 0)
128  {
129    $q = '
[4143]130INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
[12271]131VALUES ("UserAdvManager_ConfirmMail","'.pwg_db_real_escape_string(serialize($defaultConfirmMail)).'","UAM ConfirmMail parameters")
[5056]132  ;';
[9853]133    pwg_query($q);
134  }
135
[12247]136  // Create UserAdvManager_Redir conf if not already exists
[12271]137  // ------------------------------------------------------
[9853]138        $query = '
139SELECT param
140  FROM '.CONFIG_TABLE.'
141WHERE param = "UserAdvManager_Redir"
142;';
143  $count = pwg_db_num_rows(pwg_query($query));
[6775]144 
[9853]145  if ($count == 0)
146  {
147    $q = '
[6775]148INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
149VALUES ("UserAdvManager_Redir","0","UAM Redirections")
150  ;';
[9853]151    pwg_query($q);
152  }
[5056]153
[12247]154  // Create UserAdvManager_Version conf if not already exists
[12271]155  // --------------------------------------------------------
[9853]156        $query = '
157SELECT param
158  FROM '.CONFIG_TABLE.'
[11095]159WHERE param = "UserAdvManager_Version"
[9853]160;';
161  $count = pwg_db_num_rows(pwg_query($query));
162 
163  if ($count == 0)
164  {
165    $q = '
[9846]166INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
167VALUES ("UserAdvManager_Version","'.$version.'","UAM version check")
168  ;';
[9853]169    pwg_query($q);
170  }
[5056]171
[12247]172  // Create USER_CONFIRM_MAIL_TABLE
[12271]173  // ------------------------------
[21519]174        $q = '
175CREATE TABLE IF NOT EXISTS '.USER_CONFIRM_MAIL_TABLE.' (
176  id varchar(50) NOT NULL default "",
177  user_id smallint(5) NOT NULL default "0",
[4143]178  mail_address varchar(255) default NULL,
[21519]179  status enum("webmaster","admin","normal","generic","guest") default NULL,
[4143]180  date_check datetime default NULL,
[21519]181  reminder ENUM("true","false") NULL,
[4143]182PRIMARY KEY  (id)
183  )
[21519]184ENGINE=MyISAM;';
[3742]185  pwg_query($q);
[4135]186
[12247]187  // Create USER_LASTVISIT_TABLE
[12271]188  // ---------------------------
[21519]189        $q = '
190CREATE TABLE IF NOT EXISTS '.USER_LASTVISIT_TABLE.' (
191  user_id SMALLINT(5) NOT NULL DEFAULT "0",
[4143]192  lastvisit DATETIME NULL DEFAULT NULL,
[21519]193  reminder ENUM("true","false") NULL,
[4143]194PRIMARY KEY (`user_id`)
195  )
[21519]196ENGINE=MyISAM;';
[4135]197  pwg_query($q);
[12239]198
[12247]199  // Piwigo's native tables modifications for password reset function - Add pwdreset column if not already exists
[12271]200  // ------------------------------------------------------------------------------------------------------------
[12239]201  $query = '
202SHOW COLUMNS FROM '.USERS_TABLE.'
203LIKE "UAM_pwdreset"
204;';
205 
206  $result = pwg_query($query);
207
208  if(!pwg_db_fetch_row($result))
209  {
210    $q = '
211ALTER TABLE '.USERS_TABLE.'
212ADD UAM_pwdreset enum("true","false")
213;';
214    pwg_query($q);
215  }
[12247]216
[17887]217  // Piwigo's native tables modifications for validation status
218  // ----------------------------------------------------------
219  $query = '
220SHOW COLUMNS FROM '.USERS_TABLE.'
221LIKE "UAM_validated"
222;';
223 
224  $result = pwg_query($query);
225
226  if(!pwg_db_fetch_row($result))
227  {
228    $q = '
229ALTER TABLE '.USERS_TABLE.'
230ADD UAM_validated enum("true","false")
231;';
232    pwg_query($q);
233  }
234
[12247]235/* *************************************************************************** */
236/* **************** END - Database actions and initialization **************** */
237/* *************************************************************************** */
[3742]238}
239
[5064]240
[3872]241function plugin_activate()
242{
[5064]243  global $conf;
[5056]244
[4952]245/* Cleaning obsolete files */
[5064]246/* *********************** */
247  clean_obsolete_files();
[5762]248 
249  include_once (UAM_PATH.'include/upgradedb.inc.php');
[5056]250
[5762]251/* Check if old version is < 2.15 */
252/* ****************************** */
[5593]253        $query = '
254SELECT param
255  FROM '.CONFIG_TABLE.'
[5762]256WHERE param = "nbc_UserAdvManager"
[5593]257;';
[6251]258  $count1 = pwg_db_num_rows(pwg_query($query));
259 
260  $query = '
261SELECT *
262  FROM '.CONFIG_TABLE.'
263WHERE param = "nbc_UserAdvManager_ConfirmMail"
264;';
265  $count2 = pwg_db_num_rows(pwg_query($query)); 
[5056]266
[5593]267/* If old params exist an upgrade is needed */
268/* **************************************** */
[6251]269  if ($count1 == 1)
[5593]270  {
[4380]271/* Check for upgrade from 2.10 to 2.11 */
[5064]272/* *********************************** */
[6251]273    if ($count1 == 1 and $count2 == 0)
[5593]274    {
275    /* upgrade from branch 2.10 to 2.11 */
276    /* ******************************** */
[5762]277      upgrade_210_211();
[5593]278    }
[4135]279
[4380]280
281/* Check for upgrade from 2.11 to 2.12 */
[5064]282/* *********************************** */
[5593]283    if (!table_exist(USER_LASTVISIT_TABLE))
284    {
285    /* upgrade from branch 2.11 to 2.12 */
286    /* ******************************** */
[5762]287                upgrade_211_212();
[5593]288    }
[4380]289
290
291/* Check for upgrade from 2.12 to 2.13 */
[5064]292/* *********************************** */
[21075]293    $fields = pwg_query('SHOW COLUMNS FROM '.USER_CONFIRM_MAIL_TABLE.';');
294    $nb_fields = pwg_db_num_rows($fields);
[4380]295
[5593]296    if ($nb_fields < 6)
297    {
298    /* upgrade from branch 2.12 to 2.13 */
299    /* ******************************** */
[5762]300      upgrade_212_213();
[5593]301    }
[5056]302
303
[5064]304/* Serializing conf parameters - Available since 2.14.0 */
305/* **************************************************** */
[5593]306    if (unserialize($conf['nbc_UserAdvManager']) === false)
307    {
308    /* upgrade from branch 2.13 to 2.14 */
309    /* ******************************** */
[5762]310      upgrade_213_214();
[5593]311    }
[5762]312   
[6251]313    /* upgrade from branch 2.14 to 2.15 */
314    /* ******************************** */
315      upgrade_214_215();
316  }
317
[6775]318/* Old version is > 2.15 */
319/* ********************* */
320        $query = '
[5181]321SELECT param
322  FROM '.CONFIG_TABLE.'
[6775]323WHERE param = "UserAdvManager_Redir"
[5181]324;';
[6251]325  $count = pwg_db_num_rows(pwg_query($query));
[5181]326 
[6775]327  if ($count == 0)
[6251]328  {
[6775]329    upgrade_2153_2154();
[5593]330  }
[6354]331
[8065]332/* Check for upgrade from 2.15 to 2.16 */
333/* *********************************** */
[7955]334        $query = '
335SELECT param
336  FROM '.CONFIG_TABLE.'
337WHERE param = "UserAdvManager_Version"
338;';
339  $count = pwg_db_num_rows(pwg_query($query));
340 
341  if ($count == 0)
342  {
[8065]343    /* upgrade from branch 2.15 to 2.16 */
344    /* ******************************** */
345    upgrade_215_2160();
[7955]346  }
347
[10957]348/* Check database upgrade since version 2.16.0 */
[12271]349/* ******************************************* */
[10957]350  if (isset($conf['UserAdvManager_Version']))
[9135]351  {
[10957]352    if (version_compare($conf['UserAdvManager_Version'], '2.20.0') < 0)
353    {
[9135]354    /* upgrade from branch 2.16 to 2.20 */
355    /* ******************************** */
[10957]356      upgrade_216_220();
357    }
358   
359    if (version_compare($conf['UserAdvManager_Version'], '2.20.4') < 0)
360    {
361    /* upgrade from version 2.20.3 to 2.20.4 */
362    /* ************************************* */
363      upgrade_2203_2204();
364    }
365   
366    if (version_compare($conf['UserAdvManager_Version'], '2.20.7') < 0)
367    {
368    /* upgrade from version 2.20.4 to 2.20.7 */
369    /* ************************************* */
370      upgrade_2204_2207();
371    }
[11018]372
373    if (version_compare($conf['UserAdvManager_Version'], '2.20.8') < 0)
374    {
375    /* upgrade from version 2.20.7 to 2.20.8 */
376    /* ************************************* */
377      upgrade_2207_2208();
378    }
[12189]379
380    if (version_compare($conf['UserAdvManager_Version'], '2.30.0') < 0)
381    {
382    /* upgrade from version 2.20.8 to 2.30.0 */
383    /* ************************************* */
384      upgrade_2208_2300();
385    }
[12661]386
387    if (version_compare($conf['UserAdvManager_Version'], '2.30.2') < 0)
388    {
389    /* upgrade from version 2.30.x to 2.30.2 */
390    /* ************************************* */
391      upgrade_2300_2302();
392    }
[14729]393
394    if (version_compare($conf['UserAdvManager_Version'], '2.40.0') < 0)
395    {
396    /* upgrade from version 2.30.x to 2.40.0 */
397    /* ************************************* */
398      upgrade_2300_2400();
399    }
[17887]400
[18479]401    if (version_compare($conf['UserAdvManager_Version'], '2.41.0') < 0)
[17887]402    {
[18479]403    /* upgrade from version 2.40.x to 2.41.0 */
[17887]404    /* ************************************* */
[18479]405      upgrade_2400_2410();
[17887]406    }
[21075]407
408    if (version_compare($conf['UserAdvManager_Version'], '2.50.0') < 0)
409    {
410    /* upgrade from version 2.41.x to 2.50.0 */
411    /* ************************************* */
412      upgrade_2410_2500();
413    }
[9135]414  }
415
[10706]416  // Update plugin version number in #_config table and check consistency of #_plugins table
[12271]417  // ---------------------------------------------------------------------------------------
[10144]418  UAM_version_update();
419
420  load_conf_from_db('param like \'UserAdvManager\\_%\'');
[3872]421}
[3742]422
[4135]423
[3742]424function plugin_uninstall()
425{
426  global $conf;
427
[5181]428  if (isset($conf['UserAdvManager']))
[3742]429  {
430    $q = '
[4143]431DELETE FROM '.CONFIG_TABLE.'
[5181]432WHERE param="UserAdvManager"
[4143]433;';
[3742]434
435    pwg_query($q);
436  }
437
[5181]438  if (isset($conf['UserAdvManager_ConfirmMail']))
[3881]439  {
440    $q = '
[4143]441DELETE FROM '.CONFIG_TABLE.'
[5181]442WHERE param="UserAdvManager_ConfirmMail"
[4143]443;';
[3742]444
[3881]445    pwg_query($q);
446  }
447
[6822]448  if (isset($conf['UserAdvManager_Redir']))
449  {
450    $q = '
451DELETE FROM '.CONFIG_TABLE.'
452WHERE param="UserAdvManager_Redir"
453;';
454
455    pwg_query($q);
456  }
457
[8110]458  if (isset($conf['UserAdvManager_Version']))
459  {
460    $q = '
461DELETE FROM '.CONFIG_TABLE.'
462WHERE param="UserAdvManager_Version"
463;';
464
465    pwg_query($q);
466  }
467
[12239]468  $q = '
469DROP TABLE '.USER_CONFIRM_MAIL_TABLE.'
470;';
[3742]471  pwg_query( $q );
[4135]472
[12239]473  $q = '
474DROP TABLE '.USER_LASTVISIT_TABLE.'
475;';
[4135]476  pwg_query( $q );
[12239]477
478  $q = '
479ALTER TABLE '.USERS_TABLE.'
480DROP UAM_pwdreset
481;';
482  pwg_query($q);
[17887]483
484  $q = '
485ALTER TABLE '.USERS_TABLE.'
486DROP UAM_validated
487;';
488  pwg_query($q);
[3742]489}
490?>
Note: See TracBrowser for help on using the repository browser.