source: extensions/HistoryIPExcluder/branches/2.2/include/dbupgrade.inc.php @ 12151

Last change on this file since 12151 was 12151, checked in by Eric, 13 years ago
  • Use data serialization for database storage
  • Use pwg_db_real_escape_string() instead of addslashes()
  • Property svn:eol-style set to LF
File size: 2.0 KB
Line 
1<?php
2
3/* Database upgrading functions */
4
5// This will 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  conf_update_param('HistoryIPConfig', pwg_db_real_escape_string(serialize($Newconf_HIPE)));
29}
30
31
32function upgrade_200()
33{
34  global $conf;
35 
36  $q = '
37UPDATE '.CONFIG_TABLE.'
38SET param = "HistoryIPExcluder"
39WHERE param = "nbc_HistoryIPExcluder"
40;';
41  pwg_query($q);
42
43  $q = '
44UPDATE '.CONFIG_TABLE.'
45SET comment = "History IP Excluder parameters"
46WHERE comment = "Parametres nbc History IP Excluder"
47;';
48  pwg_query($q);
49
50  upgrade_210();
51}
52
53function upgrade_210()
54{
55  global $conf;
56 
57  $default = array (
58    'Blacklist' => "0",
59    'Version'=> "2.1.1",
60  );
61
62  $q = '
63INSERT INTO '.CONFIG_TABLE.' (param,value,comment)
64VALUES ("HistoryIPConfig","'.pwg_db_real_escape_string(serialize($default)).'","History IP Excluder options");
65';
66     
67  pwg_query($q);
68 
69  upgrade_211();
70}
71
72function upgrade_211()
73{
74  global $conf;
75
76  // Create new HIPE entry in plugins table
77  $query = '
78INSERT INTO '.PLUGINS_TABLE.' (id, state, version)
79VALUES ("HistoryIPExcluder","active","2.2.0")
80;';
81 
82  pwg_query($query);
83
84  // Delete old plugin entry in plugins table
85  $query = '
86DELETE FROM '.PLUGINS_TABLE.'
87WHERE id="nbc_HistoryIPExcluder"
88LIMIT 1
89;';
90 
91  pwg_query($query);
92
93  // rename directory
94  if (!rename(PHPWG_PLUGINS_PATH.'nbc_HistoryIPExcluder', PHPWG_PLUGINS_PATH.'HistoryIPExcluder'))
95  {
96    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.');
97  }
98}
99?>
Note: See TracBrowser for help on using the repository browser.