XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
Legacy_Updater.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16require_once XOOPS_LEGACY_PATH . '/admin/class/ModuleUpdater.class.php';
17
18class Legacy_ModuleUpdater extends Legacy_ModulePhasedUpgrader
19{
20 public $_mMilestone = [
21 '106' => 'update106',
22 '200' => 'update200'
23 ];
24
25 public function _processScript()
26 {
27 parent::_processScript();
28 $cVersion = $this->getCurrentVersion();
29 if ($cVersion < 204) {
30 $this->auto_update_session_blob();
31 }
32 }
33
34 public function auto_update_session_blob()
35 {
36 $root = XCube_Root::getSingleton();
37 $db = $root->mController->getDB();
38 $table = $db->prefix('session');
39
40 $sql = 'SHOW COLUMNS FROM `'. $table .'` WHERE Field = \'sess_data\'';
41 if ($res = $db->query($sql)) {
42 $row = $db->fetchArray($res);
43
44 if ('blob' !== strtolower($row['Type'])) {
45 $sql = 'ALTER TABLE `'. $table .'` CHANGE `sess_data` `sess_data` BLOB NOT NULL';
46
47 if ($db->query($sql)) {
48 $this->mLog->addReport('Table `'.$table.'` field `sess_data` changed type to BLOB.');
49 } else {
50 $this->mLog->addError('Type change error of table `'.$table.'` field `sess_data` to BLOB.');
51 }
52 }
53 }
54 }
55
56 public function update200()
57 {
58 $this->mLog->addReport(_AD_LEGACY_MESSAGE_UPDATE_STARTED);
59
60 // Update database table index.
62 if (!$this->_mForceMode && $this->mLog->hasError()) {
63 $this->_processReport();
64 return false;
65 }
66
67 // Normal update process.
69 if (!$this->_mForceMode && $this->mLog->hasError()) {
70 $this->_processReport();
71 return false;
72 }
73
74 $this->_updateBlocks();
75 if (!$this->_mForceMode && $this->mLog->hasError()) {
76 $this->_processReport();
77 return false;
78 }
79
80 $this->_updatePreferences();
81 if (!$this->_mForceMode && $this->mLog->hasError()) {
82 $this->_processReport();
83 return false;
84 }
85
86 $this->saveXoopsModule($this->_mTargetXoopsModule);
87 if (!$this->_mForceMode && $this->mLog->hasError()) {
88 $this->_processReport();
89 return false;
90 }
91
92 $this->_processScript();
93 if (!$this->_mForceMode && $this->mLog->hasError()) {
94 $this->_processReport();
95 return false;
96 }
97
98 $this->_processReport();
99
100 return true;
101 }
102
103 public function update106()
104 {
105 $this->mLog->addReport(_AD_LEGACY_MESSAGE_UPDATE_STARTED);
106
107 // Update database table index.
108 $this->_setUniqueToGroupUserLink();
110 if (!$this->_mForceMode && $this->mLog->hasError()) {
111 $this->_processReport();
112 return false;
113 }
114
115 // Normal update process.
116 $this->_updateModuleTemplates();
117 if (!$this->_mForceMode && $this->mLog->hasError()) {
118 $this->_processReport();
119 return false;
120 }
121
122 $this->_updateBlocks();
123 if (!$this->_mForceMode && $this->mLog->hasError()) {
124 $this->_processReport();
125 return false;
126 }
127
128 $this->_updatePreferences();
129 if (!$this->_mForceMode && $this->mLog->hasError()) {
130 $this->_processReport();
131 return false;
132 }
133
134 $this->saveXoopsModule($this->_mTargetXoopsModule);
135 if (!$this->_mForceMode && $this->mLog->hasError()) {
136 $this->_processReport();
137 return false;
138 }
139
140 $this->_processScript();
141 if (!$this->_mForceMode && $this->mLog->hasError()) {
142 $this->_processReport();
143 return false;
144 }
145
146 $this->_processReport();
147
148 return true;
149 }
150
155 public function _extendConfigTitleSize()
156 {
157 $root =& XCube_Root::getSingleton();
158 $db =& $root->mController->getDB();
159 $table = $db->prefix('config');
160
161 $sql = 'ALTER TABLE `'. $table .'` MODIFY `conf_title` varchar(191) NOT NULL default "", MODIFY `conf_desc` varchar(191) NOT NULL default ""';
162
163 if ($db->query($sql)) {
164 $this->mLog->addReport(XCube_Utils::formatString(_AD_LEGACY_MESSAGE_EXTEND_CONFIG_TITLE_SIZE_SUCCESSFUL, $table));
165 } else {
166 $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_COULD_NOT_EXTEND_CONFIG_TITLE_SIZE, $table));
167 }
168 }
169
170 public function _setUniqueToGroupUserLink()
171 {
172 $root =& XCube_Root::getSingleton();
173 $db =& $root->mController->getDB();
174 $table = $db->prefix('groups_users_link');
175
176 // Delete duplicate data.
177 $sql = 'SELECT `uid`,`groupid`,COUNT(*) AS c FROM `' . $table . '` GROUP BY `uid`,`groupid` HAVING `c` > 1';
178 if ($res = $db->query($sql)) {
179 while ($row = $db->fetchArray($res)) {
180 $sql = sprintf('DELETE FROM `%s` WHERE `uid` = %d AND `groupid` = %d ORDER BY `linkid` DESC', $table, $row['uid'], $row['groupid']);
181 if (!$db->query($sql, $row['c'] - 1)) {
182 $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_COULD_NOT_DELETE_DUPLICATE_DATA, $table));
183 return;
184 }
185 }
186 }
187
188 // Set unique key.
189 $sql = 'ALTER TABLE `' . $table . '` DROP INDEX `groupid_uid`';
190 $db->query($sql); // ignore sql errors
191 $sql = 'ALTER TABLE `' . $table . '` ADD UNIQUE `uid_groupid` (`uid`,`groupid`)';
192 if ($db->query($sql)) {
193 $this->mLog->addReport(XCube_Utils::formatString(_AD_LEGACY_MESSAGE_SET_UNIQUE_KEY_SUCCESSFUL, $table));
194 } else {
195 $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_COULD_NOT_SET_UNIQUE_KEY, $table));
196 }
197 }
198
204 {
205 $root =& XCube_Root::getSingleton();
206 $db =& $root->mController->getDB();
207
208 $permTable = $db->prefix('group_permission');
209 $groupTable = $db->prefix('groups');
210 $sql = sprintf(
211 'SELECT DISTINCT `gperm_groupid` FROM `%s` LEFT JOIN `%s` ON `%s`.`gperm_groupid`=`%s`.`groupid`' . ' WHERE `gperm_modid`=1 AND `groupid` IS NULL',
212 $permTable, $groupTable, $permTable, $groupTable);
213 $result = $db->query($sql);
214 if (!$result) {
215 return false;
216 }
217
218 $gids = [];
219 while ($myrow = $db->fetchArray($result)) {
220 $gids[] = $myrow['gperm_groupid'];
221 }
222
223 $db->freeRecordSet($result);
224
225 // remove all invalid group id entries
226 if (0 != count($gids)) {
227 $sql = sprintf('DELETE FROM `%s` WHERE `gperm_groupid` IN (%s) AND `gperm_modid`=1',
228 $permTable, implode(',', $gids));
229 $result = $db->query($sql);
230 if (!$result) {
231 return false;
232 }
233 }
234
235 return true;
236 }
237}
_extendConfigTitleSize()
match config_title and config_desc size in config table.
_recoverXoopsGroupPermission()
Removes invalid permission instances from DB.
static formatString()
[Static] Formats string with special care for international.