1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Upgrader from 2.2.* to 2.3.0 |
5
|
|
|
* |
6
|
|
|
* You may not change or alter any portion of this comment or credits |
7
|
|
|
* of supporting developers from this source code or any supporting source code |
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
* This program is distributed in the hope that it will be useful, |
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
12
|
|
|
* |
13
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
14
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html) |
15
|
|
|
* @package upgrader |
16
|
|
|
* @since 2.3.0 |
17
|
|
|
* @author Taiwen Jiang <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Upgrade_220 extends XoopsUpgrade |
20
|
|
|
{ |
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
parent::__construct(basename(__DIR__)); |
24
|
|
|
$this->tasks = array('config', 'profile', 'block'/*, 'pm', 'module'*/); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Check if config category already removed |
29
|
|
|
* |
30
|
|
|
*/ |
31
|
|
|
public function check_config() |
32
|
|
|
{ |
33
|
|
|
$sql = 'SHOW COLUMNS FROM `' . $GLOBALS['xoopsDB']->prefix('configcategory') . "` LIKE 'confcat_modid'"; |
34
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
35
|
|
|
if (!$result) { |
36
|
|
|
return true; |
37
|
|
|
} |
38
|
|
|
return !($GLOBALS['xoopsDB']->getRowsNum($result) > 0); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Check if user profile table already converted |
43
|
|
|
* |
44
|
|
|
*/ |
45
|
|
|
public function check_profile() |
46
|
|
|
{ |
47
|
|
|
/* @var $module_handler XoopsModuleHandler */ |
48
|
|
|
$module_handler = xoops_getHandler('module'); |
49
|
|
|
if (!$profile_module = $module_handler->getByDirname('profile')) { |
|
|
|
|
50
|
|
|
return true; |
51
|
|
|
} |
52
|
|
|
$sql = 'SHOW COLUMNS FROM ' . $GLOBALS['xoopsDB']->prefix('users') . " LIKE 'posts'"; |
53
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
54
|
|
|
if (!$result) { |
55
|
|
|
return false; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return !($GLOBALS['xoopsDB']->getRowsNum($result) == 0); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Check if block table already converted |
63
|
|
|
* |
64
|
|
|
*/ |
65
|
|
|
public function check_block() |
66
|
|
|
{ |
67
|
|
|
$sql = "SHOW TABLES LIKE '" . $GLOBALS['xoopsDB']->prefix('block_instance') . "'"; |
68
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($sql); |
69
|
|
|
if (!$result) { |
70
|
|
|
return true; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return !($GLOBALS['xoopsDB']->getRowsNum($result) > 0); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
|
|
public function apply() |
80
|
|
|
{ |
81
|
|
|
if (empty($_GET['upd220'])) { |
82
|
|
|
$this->logs[] = _CONFIRM_UPGRADE_220; |
83
|
|
|
$res = false; |
84
|
|
|
} else { |
85
|
|
|
$res = parent::apply(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $res; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
|
|
public function apply_config() |
95
|
|
|
{ |
96
|
|
|
global $xoopsDB; |
97
|
|
|
|
98
|
|
|
$result = true; |
99
|
|
|
|
100
|
|
|
//Set core configuration back to zero for system module |
101
|
|
|
$xoopsDB->queryF('UPDATE `' . $xoopsDB->prefix('config') . '` SET conf_modid = 0 WHERE conf_modid = 1'); |
102
|
|
|
|
103
|
|
|
//Change debug modes so there can only be one active at any one time |
104
|
|
|
$xoopsDB->queryF('UPDATE `' . $xoopsDB->prefix('config') . "` SET conf_formtype = 'select', conf_valuetype = 'int' WHERE conf_name = 'debug_mode'"); |
105
|
|
|
|
106
|
|
|
//Reset category ID for non-system configs |
107
|
|
|
$xoopsDB->queryF('UPDATE `' . $xoopsDB->prefix('config') . '` SET conf_catid = 0 WHERE conf_modid > 1 AND conf_catid > 0'); |
108
|
|
|
|
109
|
|
|
// remove admin theme configuration item |
110
|
|
|
$xoopsDB->queryF('DELETE FROM `' . $xoopsDB->prefix('config') . "` WHERE conf_name='theme_set_admin'"); |
111
|
|
|
|
112
|
|
|
//Drop non-System config categories |
113
|
|
|
$xoopsDB->queryF('DELETE FROM `' . $xoopsDB->prefix('configcategory') . '` WHERE confcat_modid > 1'); |
114
|
|
|
|
115
|
|
|
//Drop category information fields added in 2.2 |
116
|
|
|
$xoopsDB->queryF('ALTER TABLE `' . $xoopsDB->prefix('configcategory') . '` DROP `confcat_nameid`, DROP `confcat_description`, DROP `confcat_modid`'); |
117
|
|
|
|
118
|
|
|
// Re-add user configuration category |
119
|
|
|
$xoopsDB->queryF('INSERT INTO `' . $xoopsDB->prefix('configcategory') . "` (confcat_id, confcat_name, confcat_order) VALUES (2, '_MD_AM_USERSETTINGS', 2)"); |
120
|
|
|
|
121
|
|
|
//Rebuild user configuration items |
122
|
|
|
//Get values from Profile module |
123
|
|
|
$profile_config_arr = array(); |
124
|
|
|
$profile_config_arr['minpass'] = 5; |
125
|
|
|
$profile_config_arr['minuname'] = 3; |
126
|
|
|
$profile_config_arr['new_user_notify'] = 1; |
127
|
|
|
$profile_config_arr['new_user_notify_group'] = XOOPS_GROUP_ADMIN; |
128
|
|
|
$profile_config_arr['activation_type'] = 0; |
129
|
|
|
$profile_config_arr['activation_group'] = XOOPS_GROUP_ADMIN; |
130
|
|
|
$profile_config_arr['uname_test_level'] = 0; |
131
|
|
|
$profile_config_arr['avatar_allow_upload'] = 0; |
132
|
|
|
$profile_config_arr['avatar_width'] = 80; |
133
|
|
|
$profile_config_arr['avatar_height'] = 80; |
134
|
|
|
$profile_config_arr['avatar_maxsize'] = 35000; |
135
|
|
|
$profile_config_arr['self_delete'] = 0; |
136
|
|
|
$profile_config_arr['bad_unames'] = serialize(array('webmaster', '^xoops', '^admin')); |
137
|
|
|
$profile_config_arr['bad_emails'] = serialize(array('xoops.org$')); |
138
|
|
|
$profile_config_arr['maxuname'] = 10; |
139
|
|
|
$profile_config_arr['avatar_minposts'] = 0; |
140
|
|
|
$profile_config_arr['allow_chgmail'] = 0; |
141
|
|
|
$profile_config_arr['reg_dispdsclmr'] = 0; |
142
|
|
|
$profile_config_arr['reg_disclaimer'] = ''; |
143
|
|
|
$profile_config_arr['allow_register'] = 1; |
144
|
|
|
|
145
|
|
|
/* @var $module_handler XoopsModuleHandler */ |
146
|
|
|
$module_handler = xoops_getHandler('module'); |
147
|
|
|
/* @var $config_handler XoopsConfigHandler */ |
148
|
|
|
$config_handler = xoops_getHandler('config'); |
149
|
|
|
$profile_module = $module_handler->getByDirname('profile'); |
150
|
|
|
if (is_object($profile_module)) { |
151
|
|
|
$profile_config = $config_handler->getConfigs(new Criteria('conf_modid', $profile_module->getVar('mid'))); |
|
|
|
|
152
|
|
|
foreach (array_keys($profile_config) as $i) { |
153
|
|
|
$profile_config_arr[$profile_config[$i]->getVar('conf_name')] = $profile_config[$i]->getVar('conf_value', 'n'); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$xoopsDB->queryF('INSERT INTO `' . $xoopsDB->prefix('config') . '` (conf_modid, conf_catid, conf_name, conf_title, conf_value, conf_desc, conf_formtype, conf_valuetype, conf_order) VALUES ' . " (0, 2, 'minpass', '_MD_AM_MINPASS', " . $xoopsDB->quote($profile_config_arr['minpass']) . ", '_MD_AM_MINPASSDSC', 'textbox', 'int', 1)," . " (0, 2, 'minuname', '_MD_AM_MINUNAME', " . $xoopsDB->quote($profile_config_arr['minuname']) . ", '_MD_AM_MINUNAMEDSC', 'textbox', 'int', 2)," . " (0, 2, 'new_user_notify', '_MD_AM_NEWUNOTIFY', " . $xoopsDB->quote($profile_config_arr['new_user_notify']) . ", '_MD_AM_NEWUNOTIFYDSC', 'yesno', 'int', 4)," . " (0, 2, 'new_user_notify_group', '_MD_AM_NOTIFYTO', " . $xoopsDB->quote($profile_config_arr['new_user_notify_group']) . ", '_MD_AM_NOTIFYTODSC', 'group', 'int', 6)," . " (0, 2, 'activation_type', '_MD_AM_ACTVTYPE', " . $xoopsDB->quote($profile_config_arr['activation_type']) . ", '_MD_AM_ACTVTYPEDSC', 'select', 'int', 8)," . " (0, 2, 'activation_group', '_MD_AM_ACTVGROUP', " . $xoopsDB->quote($profile_config_arr['activation_group']) . ", '_MD_AM_ACTVGROUPDSC', 'group', 'int', 10)," . " (0, 2, 'uname_test_level', '_MD_AM_UNAMELVL', " . $xoopsDB->quote($profile_config_arr['uname_test_level']) . ", '_MD_AM_UNAMELVLDSC', 'select', 'int', 12)," . " (0, 2, 'avatar_allow_upload', '_MD_AM_AVATARALLOW', " . $xoopsDB->quote($profile_config_arr['avatar_allow_upload']) . ", '_MD_AM_AVATARALWDSC', 'yesno', 'int', 14)," . " (0, 2, 'avatar_width', '_MD_AM_AVATARW', " . $xoopsDB->quote($profile_config_arr['avatar_width']) . ", '_MD_AM_AVATARWDSC', 'textbox', 'int', 16)," . " (0, 2, 'avatar_height', '_MD_AM_AVATARH', " . $xoopsDB->quote($profile_config_arr['avatar_height']) . ", '_MD_AM_AVATARHDSC', 'textbox', 'int', 18)," . " (0, 2, 'avatar_maxsize', '_MD_AM_AVATARMAX', " . $xoopsDB->quote($profile_config_arr['avatar_maxsize']) . ", '_MD_AM_AVATARMAXDSC', 'textbox', 'int', 20)," . " (0, 2, 'self_delete', '_MD_AM_SELFDELETE', " . $xoopsDB->quote($profile_config_arr['self_delete']) . ", '_MD_AM_SELFDELETEDSC', 'yesno', 'int', 22)," . " (0, 2, 'bad_unames', '_MD_AM_BADUNAMES', " . $xoopsDB->quote($profile_config_arr['bad_unames']) . ", '_MD_AM_BADUNAMESDSC', 'textarea', 'array', 24)," . " (0, 2, 'bad_emails', '_MD_AM_BADEMAILS', " . $xoopsDB->quote($profile_config_arr['bad_emails']) . ", '_MD_AM_BADEMAILSDSC', 'textarea', 'array', 26)," . " (0, 2, 'maxuname', '_MD_AM_MAXUNAME', " . $xoopsDB->quote($profile_config_arr['maxuname']) . ", '_MD_AM_MAXUNAMEDSC', 'textbox', 'int', 3)," . " (0, 2, 'avatar_minposts', '_MD_AM_AVATARMP', " . $xoopsDB->quote($profile_config_arr['avatar_minposts']) . ", '_MD_AM_AVATARMPDSC', 'textbox', 'int', 15)," . " (0, 2, 'allow_chgmail', '_MD_AM_ALLWCHGMAIL', " . $xoopsDB->quote($profile_config_arr['allow_chgmail']) . ", '_MD_AM_ALLWCHGMAILDSC', 'yesno', 'int', 3)," . " (0, 2, 'reg_dispdsclmr', '_MD_AM_DSPDSCLMR', " . $xoopsDB->quote($profile_config_arr['reg_dispdsclmr']) . ", '_MD_AM_DSPDSCLMRDSC', 'yesno', 'int', 30)," . " (0, 2, 'reg_disclaimer', '_MD_AM_REGDSCLMR', " . $xoopsDB->quote($profile_config_arr['reg_disclaimer']) . ", '_MD_AM_REGDSCLMRDSC', 'textarea', 'text', 32)," . " (0, 2, 'allow_register', '_MD_AM_ALLOWREG', " . $xoopsDB->quote($profile_config_arr['allow_register']) . ", '_MD_AM_ALLOWREGDSC', 'yesno', 'int', 0)"); |
158
|
|
|
|
159
|
|
|
//Rebuild user configuration options |
160
|
|
|
$criteria = new CriteriaCompo(new Criteria('conf_name', "('activation_type', 'uname_test_level')", 'IN')); |
161
|
|
|
$criteria->add(new Criteria('conf_modid', 0)); |
162
|
|
|
$criteria->setSort('conf_name'); |
163
|
|
|
$criteria->setOrder('ASC'); |
164
|
|
|
$configs = $config_handler->getConfigs($criteria); |
165
|
|
|
$id_activation_type = $configs[0]->getVar('conf_id'); |
166
|
|
|
$id_uname_test_level = $configs[1]->getVar('conf_id'); |
167
|
|
|
$xoopsDB->queryF('INSERT INTO `' . $xoopsDB->prefix('configoption') . '` (confop_name, confop_value, conf_id) VALUES ' . " ('_MD_AM_USERACTV', '0', {$id_activation_type})," . " ('_MD_AM_AUTOACTV', '1', {$id_activation_type})," . " ('_MD_AM_ADMINACTV', '2', {$id_activation_type})," . " ('_MD_AM_STRICT', '0', {$id_uname_test_level})," . " ('_MD_AM_MEDIUM', '1', {$id_uname_test_level})," . " ('_MD_AM_LIGHT', '2', {$id_uname_test_level})"); |
168
|
|
|
|
169
|
|
|
return $result; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return bool |
174
|
|
|
*/ |
175
|
|
|
public function apply_profile() |
176
|
|
|
{ |
177
|
|
|
global $xoopsDB; |
178
|
|
|
// Restore users table |
179
|
|
|
$xoopsDB->queryF('ALTER TABLE `' . $xoopsDB->prefix('users') . "` |
180
|
|
|
ADD url varchar(100) NOT NULL default '', |
181
|
|
|
ADD user_regdate int(10) unsigned NOT NULL default '0', |
182
|
|
|
ADD user_icq varchar(15) NOT NULL default '', |
183
|
|
|
ADD user_from varchar(100) NOT NULL default '', |
184
|
|
|
ADD user_sig tinytext, |
185
|
|
|
ADD user_viewemail tinyint(1) unsigned NOT NULL default '0', |
186
|
|
|
ADD actkey varchar(8) NOT NULL default '', |
187
|
|
|
ADD user_aim varchar(18) NOT NULL default '', |
188
|
|
|
ADD user_yim varchar(25) NOT NULL default '', |
189
|
|
|
ADD user_msnm varchar(100) NOT NULL default '', |
190
|
|
|
ADD posts mediumint(8) unsigned NOT NULL default '0', |
191
|
|
|
ADD attachsig tinyint(1) unsigned NOT NULL default '0', |
192
|
|
|
ADD theme varchar(100) NOT NULL default '', |
193
|
|
|
ADD timezone_offset float(3,1) NOT NULL default '0.0', |
194
|
|
|
ADD last_login int(10) unsigned NOT NULL default '0', |
195
|
|
|
ADD umode varchar(10) NOT NULL default '', |
196
|
|
|
ADD uorder tinyint(1) unsigned NOT NULL default '0', |
197
|
|
|
ADD notify_method tinyint(1) NOT NULL default '1', |
198
|
|
|
ADD notify_mode tinyint(1) NOT NULL default '0', |
199
|
|
|
ADD user_occ varchar(100) NOT NULL default '', |
200
|
|
|
ADD bio tinytext, |
201
|
|
|
ADD user_intrest varchar(150) NOT NULL default '', |
202
|
|
|
ADD user_mailok tinyint(1) unsigned NOT NULL default '1' |
203
|
|
|
"); |
204
|
|
|
|
205
|
|
|
// Copy data from profile table |
206
|
|
|
$profile_fields = array( |
207
|
|
|
'url', |
208
|
|
|
'user_regdate', |
209
|
|
|
'user_icq', |
210
|
|
|
'user_from', |
211
|
|
|
'user_sig', |
212
|
|
|
'user_viewemail', |
213
|
|
|
'actkey', |
214
|
|
|
'user_aim', |
215
|
|
|
'user_yim', |
216
|
|
|
'user_msnm', |
217
|
|
|
'posts', |
218
|
|
|
'attachsig', |
219
|
|
|
'theme', |
220
|
|
|
'timezone_offset', |
221
|
|
|
'last_login', |
222
|
|
|
'umode', |
223
|
|
|
'uorder', |
224
|
|
|
'notify_method', |
225
|
|
|
'notify_mode', |
226
|
|
|
'user_occ', |
227
|
|
|
'bio', |
228
|
|
|
'user_intrest', |
229
|
|
|
'user_mailok'); |
230
|
|
|
foreach ($profile_fields as $field) { |
231
|
|
|
$xoopsDB->queryF('UPDATE `' . $xoopsDB->prefix('users') . '` u, `' . $xoopsDB->prefix('user_profile') . "` p SET u.{$field} = p.{$field} WHERE u.uid=p.profileid"); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
//Set display name as real name |
235
|
|
|
$xoopsDB->queryF('UPDATE `' . $xoopsDB->prefix('users') . "` SET name=uname WHERE name=''"); |
236
|
|
|
//Set loginname as uname |
237
|
|
|
$xoopsDB->queryF('UPDATE `' . $xoopsDB->prefix('users') . '` SET uname=loginname'); |
238
|
|
|
//Drop loginname |
239
|
|
|
$xoopsDB->queryF('ALTER TABLE `' . $xoopsDB->prefix('users') . '` DROP loginname'); |
240
|
|
|
|
241
|
|
|
return true; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @param $block |
246
|
|
|
* @param $blocks |
247
|
|
|
* |
248
|
|
|
* @return int|null|string |
249
|
|
|
*/ |
250
|
|
|
public function _block_lookup($block, $blocks) |
251
|
|
|
{ |
252
|
|
|
if ($block['show_func'] === 'b_system_custom_show') { |
253
|
|
|
return 0; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
foreach ($blocks as $key => $bk) { |
257
|
|
|
if ($block['show_func'] == $bk['show_func'] && $block['edit_func'] == $bk['edit_func'] && $block['template'] == $bk['template']) { |
258
|
|
|
return $key; |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
return null; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @return bool |
267
|
|
|
*/ |
268
|
|
|
public function apply_block() |
269
|
|
|
{ |
270
|
|
|
global $xoopsDB; |
271
|
|
|
$xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('block_module_link') . ' SET module_id = -1, pageid = 0 WHERE module_id < 2 AND pageid = 1'); |
272
|
|
|
|
273
|
|
|
//Change block module link to remove pages |
274
|
|
|
//Remove page links for module subpages |
275
|
|
|
$xoopsDB->queryF('DELETE FROM ' . $xoopsDB->prefix('block_module_link') . ' WHERE pageid > 0'); |
276
|
|
|
|
277
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('block_module_link') . '` DROP PRIMARY KEY'; |
278
|
|
|
$xoopsDB->queryF($sql); |
279
|
|
|
$sql = 'ALTER TABLE `' . $xoopsDB->prefix('block_module_link') . '` DROP pageid'; |
280
|
|
|
$xoopsDB->queryF($sql); |
281
|
|
|
$sql = 'ALTER IGNORE TABLE `' . $xoopsDB->prefix('block_module_link') . '` ADD PRIMARY KEY (`block_id` , `module_id`)'; |
282
|
|
|
$xoopsDB->queryF($sql); |
283
|
|
|
|
284
|
|
|
$xoopsDB->queryF('RENAME TABLE `' . $xoopsDB->prefix('newblocks') . '` TO `' . $xoopsDB->prefix('newblocks_bak') . '`'); |
285
|
|
|
|
286
|
|
|
// Create new block table |
287
|
|
|
$sql = 'CREATE TABLE ' . $xoopsDB->prefix('newblocks') . " ( |
288
|
|
|
bid mediumint(8) unsigned NOT NULL auto_increment, |
289
|
|
|
mid smallint(5) unsigned NOT NULL default '0', |
290
|
|
|
func_num tinyint(3) unsigned NOT NULL default '0', |
291
|
|
|
options varchar(255) NOT NULL default '', |
292
|
|
|
name varchar(150) NOT NULL default '', |
293
|
|
|
title varchar(255) NOT NULL default '', |
294
|
|
|
content text, |
295
|
|
|
side tinyint(1) unsigned NOT NULL default '0', |
296
|
|
|
weight smallint(5) unsigned NOT NULL default '0', |
297
|
|
|
visible tinyint(1) unsigned NOT NULL default '0', |
298
|
|
|
block_type char(1) NOT NULL default '', |
299
|
|
|
c_type char(1) NOT NULL default '', |
300
|
|
|
isactive tinyint(1) unsigned NOT NULL default '0', |
301
|
|
|
dirname varchar(50) NOT NULL default '', |
302
|
|
|
func_file varchar(50) NOT NULL default '', |
303
|
|
|
show_func varchar(50) NOT NULL default '', |
304
|
|
|
edit_func varchar(50) NOT NULL default '', |
305
|
|
|
template varchar(50) NOT NULL default '', |
306
|
|
|
bcachetime int(10) unsigned NOT NULL default '0', |
307
|
|
|
last_modified int(10) unsigned NOT NULL default '0', |
308
|
|
|
PRIMARY KEY (bid), |
309
|
|
|
KEY mid (mid), |
310
|
|
|
KEY visible (visible), |
311
|
|
|
KEY isactive_visible_mid (isactive,visible,mid), |
312
|
|
|
KEY mid_funcnum (mid,func_num) |
313
|
|
|
) TYPE=MyISAM; |
314
|
|
|
"; |
315
|
|
|
$xoopsDB->queryF($sql); |
316
|
|
|
|
317
|
|
|
$sql = ' SELECT MAX(instanceid) FROM ' . $xoopsDB->prefix('block_instance'); |
318
|
|
|
$result = $xoopsDB->query($sql); |
319
|
|
|
list($MaxInstanceId) = $xoopsDB->fetchRow($result); |
320
|
|
|
|
321
|
|
|
// Change custom block mid from 1 to 0 |
322
|
|
|
$sql = 'UPDATE `' . $xoopsDB->prefix('newblocks_bak') . "` SET mid = 0 WHERE show_func = 'b_system_custom_show'"; |
323
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
324
|
|
|
|
325
|
|
|
$sql = ' SELECT b.*, i.instanceid ' . ' FROM ' . $xoopsDB->prefix('block_instance') . ' AS i LEFT JOIN ' . $xoopsDB->prefix('newblocks_bak') . ' AS b ON b.bid = i.bid ' . ' GROUP BY b.dirname, b.bid, i.instanceid'; |
326
|
|
|
$result = $xoopsDB->query($sql); |
327
|
|
|
$dirname = ''; |
328
|
|
|
$bid = 0; |
329
|
|
|
$block_key = null; |
330
|
|
|
while (false !== ($row = $xoopsDB->fetchArray($result))) { |
331
|
|
|
if ($row['dirname'] != $dirname) { |
332
|
|
|
$dirname = $row['dirname']; |
333
|
|
|
$modversion = array(); |
334
|
|
|
if (!@include XOOPS_ROOT_PATH . '/modules/' . $dirname . '/xoops_version.php') { |
335
|
|
|
continue; |
336
|
|
|
} |
337
|
|
|
} |
338
|
|
|
if (empty($modversion['blocks']) && $dirname !== 'system') { |
339
|
|
|
continue; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
$isClone = true; |
343
|
|
|
if ($row['bid'] != $bid) { |
344
|
|
|
$bid = $row['bid']; |
345
|
|
|
$isClone = false; |
346
|
|
|
$block_key = null; |
|
|
|
|
347
|
|
|
$block_key = @$this->_block_lookup($row, $modversion['blocks']); |
|
|
|
|
348
|
|
|
} |
349
|
|
|
if ($block_key === null) { |
350
|
|
|
continue; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
// Copy data from block instance table and blocks table |
354
|
|
|
$sql = ' INSERT INTO ' . $xoopsDB->prefix('newblocks') . ' (bid, mid, options, name, title, side, weight, visible, ' . ' func_num, ' . ' block_type, ' . ' c_type, ' . ' isactive, dirname, func_file,' . ' show_func, edit_func, template, bcachetime, last_modified)' . ' SELECT ' . ' i.instanceid, c.mid, i.options, c.name, i.title, i.side, i.weight, i.visible, ' . " {$block_key}, " . ($isClone ? " CASE WHEN c.show_func='b_system_custom_show' THEN 'C' ELSE 'D' END," : " CASE WHEN c.show_func='b_system_custom_show' THEN 'C' WHEN c.mid = 1 THEN 'S' ELSE 'M' END,") . " CASE WHEN c.c_type='' THEN 'H' ELSE c.c_type END," . ' c.isactive, c.dirname, c.func_file,' . ' c.show_func, c.edit_func, c.template, i.bcachetime, c.last_modified' . ' FROM ' . $xoopsDB->prefix('block_instance') . ' AS i,' . ' ' . $xoopsDB->prefix('newblocks_bak') . ' AS c' . ' WHERE i.bid = c.bid' . ' AND i.instanceid = ' . $row['instanceid']; |
355
|
|
|
$xoopsDB->queryF($sql); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
$sql = ' SELECT b.* ' . ' FROM ' . $xoopsDB->prefix('newblocks_bak') . ' AS b LEFT JOIN ' . $xoopsDB->prefix('block_instance') . ' AS i ON b.bid = i.bid ' . ' WHERE i.instanceid IS NULL'; |
359
|
|
|
' GROUP BY b.dirname, b.bid'; |
360
|
|
|
$result = $xoopsDB->query($sql); |
361
|
|
|
$dirname = ''; |
362
|
|
|
$bid = 0; |
363
|
|
|
$block_key = null; |
364
|
|
|
while (false !== ($row = $xoopsDB->fetchArray($result))) { |
365
|
|
|
if ($row['dirname'] != $dirname) { |
366
|
|
|
$dirname = $row['dirname']; |
367
|
|
|
$modversion = array(); |
368
|
|
|
if (!@include XOOPS_ROOT_PATH . '/modules/' . $dirname . '/xoops_version.php') { |
369
|
|
|
continue; |
370
|
|
|
} |
371
|
|
|
} |
372
|
|
|
if (empty($modversion['blocks']) && $dirname !== 'system') { |
373
|
|
|
continue; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
if ($row['bid'] != $bid) { |
377
|
|
|
$bid = $row['bid']; |
378
|
|
|
$block_key = null; |
379
|
|
|
$block_key = @$this->_block_lookup($row, $modversion['blocks']); |
380
|
|
|
} |
381
|
|
|
if ($block_key === null) { |
382
|
|
|
continue; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
// Copy data from blocks table |
386
|
|
|
$sql = ' INSERT INTO ' . $xoopsDB->prefix('newblocks') . ' (bid, mid, options, name, title, side, weight, visible, ' . ' func_num, ' . ' block_type, ' . ' c_type, ' . ' isactive, dirname, func_file,' . ' show_func, edit_func, template, bcachetime, last_modified)' . ' SELECT ' . " bid + {$MaxInstanceId}, mid, options, name, name, 0, 0, 0, " . " {$block_key}, " . " CASE WHEN show_func='b_system_custom_show' THEN 'C' WHEN mid = 1 THEN 'S' ELSE 'M' END," . " CASE WHEN c_type='' THEN 'H' ELSE c_type END," . ' isactive, dirname, func_file,' . ' show_func, edit_func, template, 0, last_modified' . ' FROM ' . $xoopsDB->prefix('newblocks_bak') . ' WHERE bid = ' . $row['bid']; |
387
|
|
|
$xoopsDB->queryF($sql); |
388
|
|
|
|
389
|
|
|
// Build block-module link |
390
|
|
|
$sql = ' INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id)' . ' SELECT ' . " bid + {$MaxInstanceId}, -1" . ' FROM ' . $xoopsDB->prefix('newblocks_bak') . ' WHERE bid = ' . $row['bid']; |
391
|
|
|
$xoopsDB->queryF($sql); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
// Dealing with tables |
395
|
|
|
$xoopsDB->queryF('DROP TABLE `' . $xoopsDB->prefix('block_instance') . '`;'); |
396
|
|
|
$xoopsDB->queryF('DROP TABLE `' . $xoopsDB->prefix('newblocks_bak') . '`;'); |
397
|
|
|
|
398
|
|
|
// Deal with custom blocks, convert options to type and content |
399
|
|
|
$sql = 'SELECT bid, options FROM `' . $xoopsDB->prefix('newblocks') . "` WHERE show_func='b_system_custom_show'"; |
400
|
|
|
$result = $xoopsDB->query($sql); |
401
|
|
|
while (false !== (list($bid, $options) = $xoopsDB->fetchRow($result))) { |
402
|
|
|
$_options = unserialize($options); |
403
|
|
|
$content = $_options[0]; |
404
|
|
|
$type = $_options[1]; |
405
|
|
|
$xoopsDB->queryF('UPDATE `' . $xoopsDB->prefix('newblocks') . "` SET c_type = '{$type}', options = '', content = " . $xoopsDB->quote($content) . " WHERE bid = {$bid}"); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
// Deal with block options, convert array values to "," and "|" delimited |
409
|
|
|
$sql = 'UPDATE `' . $xoopsDB->prefix('newblocks') . "` SET options = '' WHERE show_func <> 'b_system_custom_show' AND ( options = 'a:1:{i:0;s:0:\"\";}' OR options = 'a:0:{}' )"; |
410
|
|
|
$result = $xoopsDB->queryF($sql); |
411
|
|
|
$sql = 'SELECT bid, options FROM `' . $xoopsDB->prefix('newblocks') . "` WHERE show_func <> 'b_system_custom_show' AND options <> ''"; |
412
|
|
|
$result = $xoopsDB->query($sql); |
413
|
|
|
while (false !== (list($bid, $_options) = $xoopsDB->fetchRow($result))) { |
414
|
|
|
$options = unserialize($_options); |
415
|
|
|
if (empty($options) || !is_array($options)) { |
416
|
|
|
$options = array(); |
417
|
|
|
} |
418
|
|
|
$count = count($options); |
419
|
|
|
//Convert array values to comma-separated |
420
|
|
|
for ($i = 0; $i < $count; ++$i) { |
421
|
|
|
if (is_array($options[$i])) { |
422
|
|
|
$options[$i] = implode(',', $options[$i]); |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
$options = implode('|', $options); |
426
|
|
|
$sql = 'UPDATE `' . $xoopsDB->prefix('newblocks') . '` SET options = ' . $xoopsDB->quote($options) . " WHERE bid = {$bid}"; |
427
|
|
|
$xoopsDB->queryF($sql); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
return true; |
431
|
|
|
} |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
$upg = new Upgrade_220(); |
435
|
|
|
return $upg; |
436
|
|
|
|