1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_LEGACY_PATH . '/admin/class/ModuleUpdater.class.php';
14:
15: class Legacy_ModuleUpdater extends Legacy_ModulePhasedUpgrader
16: {
17: var $_mMilestone = array(
18: '106' => 'update106',
19: '200' => 'update200'
20: );
21:
22: function update200()
23: {
24: $this->mLog->addReport(_AD_LEGACY_MESSAGE_UPDATE_STARTED);
25:
26:
27: $this->_extendConfigTitleSize();
28: if (!$this->_mForceMode && $this->mLog->hasError())
29: {
30: $this->_processReport();
31: return false;
32: }
33:
34:
35: $this->_updateModuleTemplates();
36: if (!$this->_mForceMode && $this->mLog->hasError())
37: {
38: $this->_processReport();
39: return false;
40: }
41:
42: $this->_updateBlocks();
43: if (!$this->_mForceMode && $this->mLog->hasError())
44: {
45: $this->_processReport();
46: return false;
47: }
48:
49: $this->_updatePreferences();
50: if (!$this->_mForceMode && $this->mLog->hasError())
51: {
52: $this->_processReport();
53: return false;
54: }
55:
56: $this->saveXoopsModule($this->_mTargetXoopsModule);
57: if (!$this->_mForceMode && $this->mLog->hasError())
58: {
59: $this->_processReport();
60: return false;
61: }
62:
63: $this->_processScript();
64: if (!$this->_mForceMode && $this->mLog->hasError())
65: {
66: $this->_processReport();
67: return false;
68: }
69:
70: $this->_processReport();
71:
72: return true;
73: }
74:
75: function update106()
76: {
77: $this->mLog->addReport(_AD_LEGACY_MESSAGE_UPDATE_STARTED);
78:
79:
80: $this->_setUniqueToGroupUserLink();
81: $this->_recoverXoopsGroupPermission();
82: if (!$this->_mForceMode && $this->mLog->hasError())
83: {
84: $this->_processReport();
85: return false;
86: }
87:
88:
89: $this->_updateModuleTemplates();
90: if (!$this->_mForceMode && $this->mLog->hasError())
91: {
92: $this->_processReport();
93: return false;
94: }
95:
96: $this->_updateBlocks();
97: if (!$this->_mForceMode && $this->mLog->hasError())
98: {
99: $this->_processReport();
100: return false;
101: }
102:
103: $this->_updatePreferences();
104: if (!$this->_mForceMode && $this->mLog->hasError())
105: {
106: $this->_processReport();
107: return false;
108: }
109:
110: $this->saveXoopsModule($this->_mTargetXoopsModule);
111: if (!$this->_mForceMode && $this->mLog->hasError())
112: {
113: $this->_processReport();
114: return false;
115: }
116:
117: $this->_processScript();
118: if (!$this->_mForceMode && $this->mLog->hasError())
119: {
120: $this->_processReport();
121: return false;
122: }
123:
124: $this->_processReport();
125:
126: return true;
127: }
128:
129: 130: 131: 132:
133: function _extendConfigTitleSize()
134: {
135: $root =& XCube_Root::getSingleton();
136: $db =& $root->mController->getDB();
137: $table = $db->prefix('config');
138:
139: $sql = 'ALTER TABLE `'. $table .'` MODIFY `conf_title` varchar(255) NOT NULL default "", MODIFY `conf_desc` varchar(255) NOT NULL default ""';
140:
141: if ($db->query($sql))
142: {
143: $this->mLog->addReport(XCube_Utils::formatString(_AD_LEGACY_MESSAGE_EXTEND_CONFIG_TITLE_SIZE_SUCCESSFUL, $table));
144: }
145: else
146: {
147: $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_COULD_NOT_EXTEND_CONFIG_TITLE_SIZE, $table));
148: }
149: }
150:
151: function _setUniqueToGroupUserLink()
152: {
153: $root =& XCube_Root::getSingleton();
154: $db =& $root->mController->getDB();
155: $table = $db->prefix('groups_users_link');
156:
157:
158: $sql = 'SELECT `uid`,`groupid`,COUNT(*) AS c FROM `' . $table . '` GROUP BY `uid`,`groupid` HAVING `c` > 1';
159: if ($res = $db->query($sql))
160: {
161: while ($row = $db->fetchArray($res))
162: {
163: $sql = sprintf('DELETE FROM `%s` WHERE `uid` = %d AND `groupid` = %d ORDER BY `linkid` DESC', $table, $row['uid'], $row['groupid']);
164: if (!$db->query($sql, $row['c'] - 1))
165: {
166: $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_COULD_NOT_DELETE_DUPLICATE_DATA, $table));
167: return;
168: }
169: }
170: }
171:
172:
173: $sql = 'ALTER TABLE `' . $table . '` DROP INDEX `groupid_uid`';
174: $db->query($sql);
175: $sql = 'ALTER TABLE `' . $table . '` ADD UNIQUE `uid_groupid` (`uid`,`groupid`)';
176: if ($db->query($sql))
177: {
178: $this->mLog->addReport(XCube_Utils::formatString(_AD_LEGACY_MESSAGE_SET_UNIQUE_KEY_SUCCESSFUL, $table));
179: }
180: else
181: {
182: $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_COULD_NOT_SET_UNIQUE_KEY, $table));
183: }
184: }
185:
186: 187: 188: 189:
190: function _recoverXoopsGroupPermission()
191: {
192: $root =& XCube_Root::getSingleton();
193: $db =& $root->mController->getDB();
194:
195: $permTable = $db->prefix('group_permission');
196: $groupTable = $db->prefix('groups');
197: $sql = sprintf("SELECT DISTINCT `gperm_groupid` FROM `%s` LEFT JOIN `%s` ON `%s`.`gperm_groupid`=`%s`.`groupid`" .
198: " WHERE `gperm_modid`=1 AND `groupid` IS NULL",
199: $permTable, $groupTable, $permTable, $groupTable);
200: $result = $db->query($sql);
201: if (!$result) {
202: return false;
203: }
204:
205: $gids = array();
206: while ($myrow = $db->fetchArray($result)) {
207: $gids[] = $myrow['gperm_groupid'];
208: }
209:
210: $db->freeRecordSet( $result );
211:
212:
213: if (count( $gids ) != 0) {
214: $sql = sprintf('DELETE FROM `%s` WHERE `gperm_groupid` IN (%s) AND `gperm_modid`=1',
215: $permTable, implode(',', $gids));
216: $result = $xoopsDB->query($sql);
217: if (!$result) {
218: return false;
219: }
220: }
221:
222: return true;
223: }
224: }
225:
226: ?>
227: