source: extensions/HistoryIPExcluder/trunk/include/dbupgrade.inc.php @ 10045

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

Improved update mechanism. When no structural update of database is necessary, it sets the correct version number in plugin's configuration

  • Property svn:eol-style set to LF
File size: 2.1 KB
Line 
1<?php
2
3/* Database upgrading functions */
4
5// This wil update only current plugin version number in database
6function global_version_update()
7{
8  global $conf;
9 
10  // Get current plugin version
11  $plugin =  HIPE_infos(HIPE_PATH);
12  $version = $plugin['version'];
13
14// Update plugin version
15  $query = '
16SELECT value
17  FROM '.CONFIG_TABLE.'
18WHERE param = "HistoryIPConfig"
19;';
20  $result = pwg_query($query);
21 
22  $conf_HIPE = pwg_db_fetch_assoc($result);
23   
24  $Newconf_HIPE = unserialize($conf_HIPE['value']);
25 
26  $Newconf_HIPE['Version'] = $version;
27 
28  $update_conf = serialize($Newconf_HIPE);
29
30  $query = '
31UPDATE '.CONFIG_TABLE.'
32SET value="'.addslashes($update_conf).'"
33WHERE param="HistoryIPConfig"
34LIMIT 1
35;';
36
37        pwg_query($query);
38}
39
40
41function upgrade_200()
42{
43  global $conf;
44 
45  $q = '
46UPDATE '.CONFIG_TABLE.'
47SET param = "HistoryIPExcluder"
48WHERE param = "nbc_HistoryIPExcluder"
49;';
50  pwg_query($q);
51
52  $q = '
53UPDATE '.CONFIG_TABLE.'
54SET comment = "History IP Excluder parameters"
55WHERE comment = "Parametres nbc History IP Excluder"
56;';
57  pwg_query($q);
58
59  upgrade_210();
60}
61
62function upgrade_210()
63{
64  global $conf;
65 
66  $default = array (
67    'Blacklist' => "0",
68    'Version'=> "2.1.1",
69  );
70
71  $q = '
72INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
73VALUES ("HistoryIPConfig","'.addslashes(serialize($default)).'","History IP Excluder options");
74';
75     
76  pwg_query($q);
77 
78  upgrade_211();
79}
80
81function upgrade_211()
82{
83  global $conf;
84
85  // Create new HIPE entry in plugins table
86  $query = '
87INSERT INTO '.PLUGINS_TABLE.' (id, state, version)
88VALUES ("HistoryIPExcluder","active","2.2.0")
89;';
90 
91  pwg_query($query);
92
93  // Delete old plugin entry in plugins table
94  $query = '
95DELETE FROM '.PLUGINS_TABLE.'
96WHERE id="nbc_HistoryIPExcluder"
97LIMIT 1
98;';
99 
100  pwg_query($query);
101
102  // rename directory
103  if (!rename(PHPWG_PLUGINS_PATH.'nbc_HistoryIPExcluder', PHPWG_PLUGINS_PATH.'HistoryIPExcluder'))
104  {
105    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.');
106  }
107}
108?>
Note: See TracBrowser for help on using the repository browser.