source: extensions/Comments_Access_Manager/include/upgradedb.inc.php @ 21119

Last change on this file since 21119 was 21119, checked in by Eric, 7 years ago

Next version is 2.5.2 :
Bug fixed : Installation from scratch did not work (again...)
This version replace 2.5.0 and 2.5.1

  • Property svn:eol-style set to LF
File size: 3.7 KB
Line 
1<?php
2/**
3 * @author Eric@piwigo.org
4 * 
5 * Upgrade processes for old plugin version
6 * Called from maintain.inc.php on plugin activation
7 *
8 */
9
10if(!defined('CM_PATH'))
11{
12  define('CM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
13}
14
15include_once (CM_PATH.'include/functions.inc.php');
16
17// +----------------------------------------------------------+
18// |       Upgrading database from old plugin versions        |
19// +----------------------------------------------------------+
20
21
22/* *************************************** */
23/* Update plugin version in conf table     */
24/* Used everytime a new version is updated */
25/* even if no database upgrade is needed   */
26/* *************************************** */
27function CM_version_update()
28{
29  global $conf;
30 
31  // Get current plugin version
32  $plugin =  CM_Infos(CM_PATH);
33  $version = $plugin['version'];
34
35  // Upgrading options
36  $query = '
37SELECT value
38  FROM '.CONFIG_TABLE.'
39WHERE param = "CommentsManager"
40;';
41
42  $result = pwg_query($query);
43  $conf_CM = pwg_db_fetch_assoc($result);
44   
45  $Newconf_CM = unserialize($conf_CM['value']);
46 
47  $Newconf_CM['CMVersion'] = $version;
48 
49  $update_conf = serialize($Newconf_CM);
50
51  conf_update_param('CommentsManager', pwg_db_real_escape_string($update_conf));
52
53
54// Check #_plugin table consistency
55// Only useful if a previous version upgrade has not worked correctly (rare case)
56  $query = '
57SELECT version
58  FROM '.PLUGINS_TABLE.'
59WHERE id = "CommentsManager"
60;';
61 
62  $data = pwg_db_fetch_assoc(pwg_query($query));
63 
64  if (empty($data['version']) or $data['version'] <> $version)
65  {
66    $query = '
67UPDATE '.PLUGINS_TABLE.'
68SET version="'.$version.'"
69WHERE id = "CommentsManager"
70LIMIT 1
71;';
72
73    pwg_query($query);
74  }
75}
76
77
78/* upgrade from 2.2.0 to 2.2.1 */
79/* *************************** */
80function upgradeCM_220_221()
81{
82  global $conf;
83
84  // Upgrading options
85  $query = '
86SELECT value
87  FROM '.CONFIG_TABLE.'
88WHERE param = "CommentsManager"
89;';
90
91  $result = pwg_query($query);
92  $conf_CM = pwg_db_fetch_assoc($result);
93   
94  $Newconf_CM = unserialize($conf_CM['value']);
95 
96  $Newconf_CM[4] = 'false';
97  $Newconf_CM[5] = '-1';
98 
99  $update_conf = serialize($Newconf_CM);
100
101  conf_update_param('CommentsManager', pwg_db_real_escape_string($update_conf));
102}
103
104
105/* upgrade from 2.2.1 to 2.2.2 */
106/* *************************** */
107function upgradeCM_221_222()
108{
109  global $conf;
110
111  // Upgrading options
112  $query = '
113SELECT value
114  FROM '.CONFIG_TABLE.'
115WHERE param = "CommentsManager"
116;';
117
118  $result = pwg_query($query);
119  $conf_CM = pwg_db_fetch_assoc($result);
120   
121  $Newconf_CM = unserialize($conf_CM['value']);
122 
123  $Newconf_CM[6] = 'false';
124  $Newconf_CM[7] = '-1';
125 
126  $update_conf = serialize($Newconf_CM);
127
128  conf_update_param('CommentsManager', pwg_db_real_escape_string($update_conf));
129}
130
131
132/* upgrade from 2.4 to 2.5 */
133/* *********************** */
134function upgradeCM_240_250()
135{
136  global $conf;
137
138  // Upgrading options - Changing config variables to assoc array
139  // ------------------------------------------------------------
140 
141  // Upgrade $conf_CM options
142  $conf_CM = unserialize($conf['CommentsManager']);
143
144  $Newconf_CM = array(
145    'CMVersion'               => $conf_CM[0],
146    'CM_No_Comment_Anonymous' => $conf_CM[1],
147    'CM_GROUPCOMM'            => $conf_CM[2],
148    'CM_ALLOWCOMM_GROUP'      => $conf_CM[3],
149    'CM_GROUPVALID1'          => $conf_CM[4],
150    'CM_VALIDCOMM1_GROUP'     => $conf_CM[5],
151    'CM_GROUPVALID2'          => $conf_CM[6],
152    'CM_VALIDCOMM2_GROUP'     => $conf_CM[7]
153  );
154
155  // unset obsolete conf
156  // -------------------
157  for ($i = 0; $i <= 7; $i++)
158  {
159    unset ($conf_CM[$i]);
160  }
161
162  $update_conf = serialize($Newconf_CM);
163
164  conf_update_param('CommentsManager', pwg_db_real_escape_string($update_conf));
165}
166?>
Note: See TracBrowser for help on using the repository browser.