source: extensions/HistoryIPExcluder/trunk/maintain.inc.php @ 9881

Last change on this file since 9881 was 9881, checked in by Eric, 10 years ago

Bug fixed on plugin upgrade_211()

  • Property svn:eol-style set to LF
File size: 4.1 KB
Line 
1<?php
2
3if (!defined('HIPE_PATH')) define('HIPE_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
4
5include_once (HIPE_PATH.'include/functions.inc.php');
6
7function plugin_install()
8{
9  global $conf;
10 
11// Set plugin parameters
12  $default= array();
13
14        $query = '
15SELECT param
16  FROM '.CONFIG_TABLE.'
17WHERE param = "HistoryIPExcluder"
18;';
19  $count = pwg_db_num_rows(pwg_query($query));
20 
21  if ($count == 0)
22  {
23    $q = '
24INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
25VALUES ("HistoryIPExcluder","","History IP Excluder parameters");
26';
27     
28    pwg_query($q);
29  }
30
31// Set plugin config
32  $plugin =  HIPE_infos(HIPE_PATH);
33  $version = $plugin['version'];
34
35  $default = array (
36    'Blacklist' => "0",
37    'Version'=> $version,
38  );
39
40        $query = '
41SELECT param
42  FROM '.CONFIG_TABLE.'
43WHERE param = "HistoryIPConfig"
44;';
45  $count = pwg_db_num_rows(pwg_query($query));
46 
47  if ($count == 0)
48  {
49    $q = '
50INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
51VALUES ("HistoryIPConfig","'.addslashes(serialize($default)).'","History IP Excluder options");
52';
53    pwg_query($q);
54  }
55}
56
57
58function plugin_activate()
59{
60  global $conf;
61 
62/* Check for upgrade from 2.0.0 to 2.0.1 */
63/* *************************************** */
64        $query = '
65SELECT param
66  FROM '.CONFIG_TABLE.'
67WHERE param = "nbc_HistoryIPExcluder"
68;';
69  $count = pwg_db_num_rows(pwg_query($query));
70 
71        if ($count == 1)
72        {
73  /* upgrade from version 2.0.0 to 2.0.1  */
74  /* ************************************ */
75                upgrade_200();
76        }
77
78        $query = '
79SELECT param
80  FROM '.CONFIG_TABLE.'
81WHERE param = "HistoryIPConfig"
82;';
83  $count = pwg_db_num_rows(pwg_query($query));
84
85        if ($count == 0)
86        {
87  /* upgrade from version 2.1.0 to 2.1.1  */
88  /* ************************************ */
89                upgrade_210();
90        }
91
92  /* upgrade from version 2.1.1 to 2.2.0 */
93  /* *********************************** */
94  $HIPE_Config = unserialize($conf['HistoryIPConfig']);
95  if ($HIPE_Config['Version'] != '2.2.0')
96  {
97    upgrade_211();
98  }
99}
100
101
102function plugin_uninstall()
103{
104  global $conf;
105
106  if (isset($conf['HistoryIPExcluder']))
107  {
108    $q = '
109DELETE FROM '.CONFIG_TABLE.'
110WHERE param="HistoryIPExcluder" LIMIT 1;
111';
112
113    pwg_query($q);
114  }
115  if (isset($conf['HistoryIPConfig']))
116  {
117    $q = '
118DELETE FROM '.CONFIG_TABLE.'
119WHERE param="HistoryIPConfig" LIMIT 1;
120';
121
122    pwg_query($q);
123  } 
124}
125
126
127function upgrade_200()
128{
129  global $conf;
130 
131  $q = '
132UPDATE '.CONFIG_TABLE.'
133SET param = "HistoryIPExcluder"
134WHERE param = "nbc_HistoryIPExcluder"
135;';
136  pwg_query($q);
137
138  $q = '
139UPDATE '.CONFIG_TABLE.'
140SET comment = "History IP Excluder parameters"
141WHERE comment = "Parametres nbc History IP Excluder"
142;';
143  pwg_query($q);
144
145  upgrade_210();
146}
147
148function upgrade_210()
149{
150  global $conf;
151 
152  $default = array (
153    'Blacklist' => "0",
154    'Version'=> "2.1.1",
155  );
156
157  $q = '
158INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
159VALUES ("HistoryIPConfig","'.addslashes(serialize($default)).'","History IP Excluder options");
160';
161     
162  pwg_query($q);
163}
164
165function upgrade_211()
166{
167  global $conf;
168
169// Update plugin version
170  $query = '
171SELECT value
172  FROM '.CONFIG_TABLE.'
173WHERE param = "HistoryIPConfig"
174;';
175  $result = pwg_query($query);
176 
177  $conf_HIPE = pwg_db_fetch_assoc($result);
178   
179  $Newconf_HIPE = unserialize($conf_HIPE['value']);
180 
181  $Newconf_HIPE['Version'] = '2.2.0';
182 
183  $update_conf = serialize($Newconf_HIPE);
184
185  $query = '
186UPDATE '.CONFIG_TABLE.'
187SET value="'.addslashes($update_conf).'"
188WHERE param="HistoryIPConfig"
189LIMIT 1
190;';
191
192        pwg_query($query); 
193
194  // Create new HIPE entry in plugins table
195  $query = '
196INSERT INTO '.PLUGINS_TABLE.' (id, state, version)
197VALUES ("HistoryIPExcluder","active","2.2.0")
198;';
199 
200  pwg_query($query);
201
202  // Delete old plugin entry in plugins table
203  $query = '
204DELETE FROM '.PLUGINS_TABLE.'
205WHERE id="nbc_HistoryIPExcluder"
206LIMIT 1
207;';
208 
209  pwg_query($query);
210
211  // rename directory
212  if (!rename(PHPWG_PLUGINS_PATH.'nbc_HistoryIPExcluder', PHPWG_PLUGINS_PATH.'HistoryIPExcluder'))
213  {
214    die('Fatal error on plugin upgrade process : Unable to rename directory ! Please, rename manualy the plugin directory name from ../plugins/nbc_HistoryIPExcluder to ../plugins/HistoryIPExcluder.');
215  }
216}
217?>
Note: See TracBrowser for help on using the repository browser.