upgrade_220::apply_block()   F
last analyzed

Complexity

Conditions 22
Paths 2688

Size

Total Lines 220
Code Lines 146

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 146
nc 2688
nop 0
dl 0
loc 220
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Upgrader from 2.2.* to 2.3.0
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 *
11
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
12
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
13
 * @package         upgrader
14
 * @since           2.3.0
15
 * @author          Taiwen Jiang <[email protected]>
16
 * @version         $Id$
17
 */
18
19
class upgrade_220 extends xoopsUpgrade
20
{
21
    var $tasks = array('config', 'profile', 'block' /*, 'pm', 'module'*/);
22
23
    function upgrade_220()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
24
    {
25
        $this->xoopsUpgrade(basename(dirname(__FILE__)));
26
    }
27
28
    /**
29
     * Check if config category already removed
30
31
     */
32
    function check_config()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33
    {
34
        $xoops = Xoops::getInstance();
35
        $sql = "SHOW COLUMNS FROM `" . $xoops->db()->prefix('configcategory') . "` LIKE 'confcat_modid'";
36
        $result = $xoops->db()->queryF($sql);
0 ignored issues
show
Bug introduced by
The method queryF() does not exist on Xoops\Core\Database\Connection. Did you maybe mean queryFromFile()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        $result = $xoops->db()->/** @scrutinizer ignore-call */ queryF($sql);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
        if (!$result) {
38
            return true;
39
        }
40
        if ($xoops->db()->getRowsNum($result) > 0) {
0 ignored issues
show
Bug introduced by
The method getRowsNum() does not exist on Xoops\Core\Database\Connection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        if ($xoops->db()->/** @scrutinizer ignore-call */ getRowsNum($result) > 0) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
            return false;
42
        }
43
        return true;
44
    }
45
46
    /**
47
     * Check if user profile table already converted
48
49
     */
50
    function check_profile()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
51
    {
52
        $xoops = Xoops::getInstance();
53
        $module_handler = $xoops->getHandlerModule();
54
        if (!$profile_module = $module_handler->getByDirname('profile')) {
0 ignored issues
show
Unused Code introduced by
The assignment to $profile_module is dead and can be removed.
Loading history...
55
            return true;
56
        }
57
        $sql = "SHOW COLUMNS FROM " . $xoops->db()->prefix("users") . " LIKE 'posts'";
58
        $result = $xoops->db()->queryF($sql);
59
        if (!$result) {
60
            return false;
61
        }
62
        if ($xoops->db()->getRowsNum($result) == 0) {
63
            return false;
64
        }
65
        return true;
66
    }
67
68
    /**
69
     * Check if block table already converted
70
71
     */
72
    function check_block()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
73
    {
74
        $xoops = Xoops::getInstance();
75
        $sql = "SHOW TABLES LIKE '" . $xoops->db()->prefix("block_instance") . "'";
76
        $result = $xoops->db()->queryF($sql);
77
        if (!$result) {
78
            return true;
79
        }
80
        if ($xoops->db()->getRowsNum($result) > 0) {
81
            return false;
82
        }
83
        return true;
84
    }
85
86
    function apply()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
87
    {
88
        if (empty($_GET['upd220'])) {
89
            $this->logs[] = _CONFIRM_UPGRADE_220;
90
            $res = false;
91
        } else {
92
            $res = parent::apply();
93
        }
94
        return $res;
95
    }
96
97
    function apply_config()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
98
    {
99
        $xoops = Xoops::getInstance();
100
101
        $result = true;
102
103
        //Set core configuration back to zero for system module
104
        $xoops->db()->queryF("UPDATE `" . $xoops->db()->prefix('config') . "` SET conf_modid = 0 WHERE conf_modid = 1");
105
106
        //Change debug modes so there can only be one active at any one time
107
        $xoops->db()->queryF("UPDATE `" . $xoops->db()->prefix('config') . "` SET conf_formtype = 'select', conf_valuetype = 'int' WHERE conf_name = 'debug_mode'");
108
109
        //Reset category ID for non-system configs
110
        $xoops->db()->queryF("UPDATE `" . $xoops->db()->prefix('config') . "` SET conf_catid = 0 WHERE conf_modid > 1 AND conf_catid > 0");
111
112
        // remove admin theme configuration item
113
        $xoops->db()->queryF("DELETE FROM `" . $xoops->db()->prefix('config') . "` WHERE conf_name='theme_set_admin'");
114
115
        //Drop non-System config categories
116
        $xoops->db()->queryF("DELETE FROM `" . $xoops->db()->prefix('configcategory') . "` WHERE confcat_modid > 1");
117
118
        //Drop category information fields added in 2.2
119
        $xoops->db()->queryF("ALTER TABLE `" . $xoops->db()->prefix("configcategory") . "` DROP `confcat_nameid`, DROP `confcat_description`, DROP `confcat_modid`");
120
121
        // Re-add user configuration category
122
        $xoops->db()->queryF("INSERT INTO `" . $xoops->db()->prefix("configcategory") . "` (confcat_id, confcat_name, confcat_order) VALUES (2, '_MD_AM_USERSETTINGS', 2)");
123
124
        //Rebuild user configuration items
125
        //Get values from Profile module
126
        $profile_config_arr = array();
127
        $profile_config_arr['minpass'] = 5;
128
        $profile_config_arr['minuname'] = 3;
129
        $profile_config_arr['new_user_notify'] = 1;
130
        $profile_config_arr['new_user_notify_group'] = XOOPS_GROUP_ADMIN;
131
        $profile_config_arr['activation_type'] = 0;
132
        $profile_config_arr['activation_group'] = XOOPS_GROUP_ADMIN;
133
        $profile_config_arr['uname_test_level'] = 0;
134
        $profile_config_arr['avatar_allow_upload'] = 0;
135
        $profile_config_arr['avatar_width'] = 80;
136
        $profile_config_arr['avatar_height'] = 80;
137
        $profile_config_arr['avatar_maxsize'] = 35000;
138
        $profile_config_arr['self_delete'] = 0;
139
        $profile_config_arr['bad_unames'] = serialize(array('webmaster', '^xoops', '^admin'));
140
        $profile_config_arr['bad_emails'] = serialize(array('xoops.org$'));
141
        $profile_config_arr['maxuname'] = 10;
142
        $profile_config_arr['avatar_minposts'] = 0;
143
        $profile_config_arr['allow_chgmail'] = 0;
144
        $profile_config_arr['reg_dispdsclmr'] = 0;
145
        $profile_config_arr['reg_disclaimer'] = "";
146
        $profile_config_arr['allow_register'] = 1;
147
148
        $module_handler = $xoops->getHandlerModule();
149
        $config_handler = $xoops->getHandlerConfig();
150
        $profile_module = $module_handler->getByDirname('profile');
151
        if (is_object($profile_module)) {
152
            $profile_config = $config_handler->getConfigs(new Criteria('conf_modid', $profile_module->getVar('mid')));
0 ignored issues
show
Bug introduced by
It seems like $profile_module->getVar('mid') can also be of type string[]; however, parameter $value of Criteria::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

152
            $profile_config = $config_handler->getConfigs(new Criteria('conf_modid', /** @scrutinizer ignore-type */ $profile_module->getVar('mid')));
Loading history...
153
            foreach (array_keys($profile_config) as $i) {
154
                $profile_config_arr[$profile_config[$i]->getVar('conf_name')] = $profile_config[$i]->getVar('conf_value', 'n');
155
            }
156
        }
157
158
        $xoops->db()->queryF("INSERT INTO `" .
159
                $xoops->db()->prefix("config") .
160
                "` (conf_modid, conf_catid, conf_name, conf_title, conf_value, conf_desc, conf_formtype, conf_valuetype, conf_order) VALUES " .
161
                " (0, 2, 'minpass', '_MD_AM_MINPASS', " .
162
                $xoops->db()->quote($profile_config_arr['minpass']) . ", '_MD_AM_MINPASSDSC', 'textbox', 'int', 1)," .
163
                " (0, 2, 'minuname', '_MD_AM_MINUNAME', " .
164
                $xoops->db()->quote($profile_config_arr['minuname']) . ", '_MD_AM_MINUNAMEDSC', 'textbox', 'int', 2)," . " (0, 2, 'new_user_notify', '_MD_AM_NEWUNOTIFY', " .
165
                $xoops->db()->quote($profile_config_arr['new_user_notify']) . ", '_MD_AM_NEWUNOTIFYDSC', 'yesno', 'int', 4)," . " (0, 2, 'new_user_notify_group', '_MD_AM_NOTIFYTO', " .
166
                $xoops->db()->quote($profile_config_arr['new_user_notify_group']) . ", '_MD_AM_NOTIFYTODSC', 'group', 'int', 6)," . " (0, 2, 'activation_type', '_MD_AM_ACTVTYPE', " .
167
                $xoops->db()->quote($profile_config_arr['activation_type']) . ", '_MD_AM_ACTVTYPEDSC', 'select', 'int', 8)," . " (0, 2, 'activation_group', '_MD_AM_ACTVGROUP', ".
168
                $xoops->db()->quote($profile_config_arr['activation_group']) . ", '_MD_AM_ACTVGROUPDSC', 'group', 'int', 10)," . " (0, 2, 'uname_test_level', '_MD_AM_UNAMELVL', " .
169
                $xoops->db()->quote($profile_config_arr['uname_test_level']) . ", '_MD_AM_UNAMELVLDSC', 'select', 'int', 12)," . " (0, 2, 'avatar_allow_upload', '_MD_AM_AVATARALLOW', " .
170
                $xoops->db()->quote($profile_config_arr['avatar_allow_upload']) . ", '_MD_AM_AVATARALWDSC', 'yesno', 'int', 14)," . " (0, 2, 'avatar_width', '_MD_AM_AVATARW', " .
171
                $xoops->db()->quote($profile_config_arr['avatar_width']) . ", '_MD_AM_AVATARWDSC', 'textbox', 'int', 16)," . " (0, 2, 'avatar_height', '_MD_AM_AVATARH', " .
172
                $xoops->db()->quote($profile_config_arr['avatar_height']) . ", '_MD_AM_AVATARHDSC', 'textbox', 'int', 18)," . " (0, 2, 'avatar_maxsize', '_MD_AM_AVATARMAX', " .
173
                $xoops->db()->quote($profile_config_arr['avatar_maxsize']) . ", '_MD_AM_AVATARMAXDSC', 'textbox', 'int', 20)," . " (0, 2, 'self_delete', '_MD_AM_SELFDELETE', " .
174
                $xoops->db()->quote($profile_config_arr['self_delete']) . ", '_MD_AM_SELFDELETEDSC', 'yesno', 'int', 22)," . " (0, 2, 'bad_unames', '_MD_AM_BADUNAMES', " .
175
                $xoops->db()->quote($profile_config_arr['bad_unames']) . ", '_MD_AM_BADUNAMESDSC', 'textarea', 'array', 24)," . " (0, 2, 'bad_emails', '_MD_AM_BADEMAILS', " .
176
                $xoops->db()->quote($profile_config_arr['bad_emails']) . ", '_MD_AM_BADEMAILSDSC', 'textarea', 'array', 26)," . " (0, 2, 'maxuname', '_MD_AM_MAXUNAME', " .
177
                $xoops->db()->quote($profile_config_arr['maxuname']) . ", '_MD_AM_MAXUNAMEDSC', 'textbox', 'int', 3)," . " (0, 2, 'avatar_minposts', '_MD_AM_AVATARMP', " .
178
                $xoops->db()->quote($profile_config_arr['avatar_minposts']) . ", '_MD_AM_AVATARMPDSC', 'textbox', 'int', 15)," . " (0, 2, 'allow_chgmail', '_MD_AM_ALLWCHGMAIL', " .
179
                $xoops->db()->quote($profile_config_arr['allow_chgmail']) . ", '_MD_AM_ALLWCHGMAILDSC', 'yesno', 'int', 3)," . " (0, 2, 'reg_dispdsclmr', '_MD_AM_DSPDSCLMR', " .
180
                $xoops->db()->quote($profile_config_arr['reg_dispdsclmr']) . ", '_MD_AM_DSPDSCLMRDSC', 'yesno', 'int', 30)," . " (0, 2, 'reg_disclaimer', '_MD_AM_REGDSCLMR', " .
181
                $xoops->db()->quote($profile_config_arr['reg_disclaimer']) . ", '_MD_AM_REGDSCLMRDSC', 'textarea', 'text', 32)," . " (0, 2, 'allow_register', '_MD_AM_ALLOWREG', " .
182
                $xoops->db()->quote($profile_config_arr['allow_register']) . ", '_MD_AM_ALLOWREGDSC', 'yesno', 'int', 0)");
183
184
        //Rebuild user configuration options
185
        $criteria = new CriteriaCompo(new Criteria('conf_name', "('activation_type', 'uname_test_level')", "IN"));
186
        $criteria->add(new Criteria('conf_modid', 0));
187
        $criteria->setSort('conf_name');
188
        $criteria->setOrder('ASC');
189
        $configs = $config_handler->getConfigs($criteria);
190
        $id_activation_type = $configs[0]->getVar("conf_id");
191
        $id_uname_test_level = $configs[1]->getVar("conf_id");
192
        $xoops->db()->queryF("INSERT INTO `" .
193
                $xoops->db()->prefix("configoption") .
194
                "` (confop_name, confop_value, conf_id) VALUES " .
195
                " ('_MD_AM_USERACTV', '0', {$id_activation_type})," .
196
                " ('_MD_AM_AUTOACTV', '1', {$id_activation_type})," .
197
                " ('_MD_AM_ADMINACTV', '2', {$id_activation_type})," .
198
                " ('_MD_AM_STRICT', '0', {$id_uname_test_level})," .
199
                " ('_MD_AM_MEDIUM', '1', {$id_uname_test_level})," .
200
                " ('_MD_AM_LIGHT', '2', {$id_uname_test_level})");
201
202
        return $result;
203
    }
204
205
    function apply_profile()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
206
    {
207
        $xoops = Xoops::getInstance();
208
        $xoops->db();
209
        // Restore users table
210
        $xoops->db()->queryF("ALTER TABLE `" . $xoops->db()->prefix("users") . "`
211
              ADD url varchar(100) NOT NULL default '',
212
              ADD user_regdate int(10) unsigned NOT NULL default '0',
213
              ADD user_icq varchar(15) NOT NULL default '',
214
              ADD user_from varchar(100) NOT NULL default '',
215
              ADD user_sig tinytext,
216
              ADD user_viewemail tinyint(1) unsigned NOT NULL default '0',
217
              ADD actkey varchar(8) NOT NULL default '',
218
              ADD user_aim varchar(18) NOT NULL default '',
219
              ADD user_yim varchar(25) NOT NULL default '',
220
              ADD user_msnm varchar(100) NOT NULL default '',
221
              ADD posts mediumint(8) unsigned NOT NULL default '0',
222
              ADD attachsig tinyint(1) unsigned NOT NULL default '0',
223
              ADD theme varchar(100) NOT NULL default '',
224
              ADD timezone_offset float(3,1) NOT NULL default '0.0',
225
              ADD last_login int(10) unsigned NOT NULL default '0',
226
              ADD umode varchar(10) NOT NULL default '',
227
              ADD uorder tinyint(1) unsigned NOT NULL default '0',
228
              ADD notify_method tinyint(1) NOT NULL default '1',
229
              ADD notify_mode tinyint(1) NOT NULL default '0',
230
              ADD user_occ varchar(100) NOT NULL default '',
231
              ADD bio tinytext,
232
              ADD user_intrest varchar(150) NOT NULL default '',
233
              ADD user_mailok tinyint(1) unsigned NOT NULL default '1'
234
              ");
235
236
        // Copy data from profile table
237
        $profile_fields = array(
238
            "url", "user_regdate", "user_icq", "user_from", "user_sig", "user_viewemail", "actkey", "user_aim",
239
            "user_yim", "user_msnm", "posts", "attachsig", "theme", "timezone_offset", "last_login", "umode", "uorder",
240
            "notify_method", "notify_mode", "user_occ", "bio", "user_intrest", "user_mailok"
241
        );
242
        foreach ($profile_fields as $field) {
243
            $xoops->db()->queryF("UPDATE `" .
244
                    $xoops->db()->prefix("users") . "` u, `" .
245
                    $xoops->db()->prefix("user_profile") .
246
                    "` p SET u.{$field} = p.{$field} WHERE u.uid=p.profileid");
247
        }
248
249
        //Set display name as real name
250
        $xoops->db()->queryF("UPDATE `" . $xoops->db()->prefix("users") . "` SET name=uname WHERE name=''");
251
        //Set loginname as uname
252
        $xoops->db()->queryF("UPDATE `" . $xoops->db()->prefix("users") . "` SET uname=loginname");
253
        //Drop loginname
254
        $xoops->db()->queryF("ALTER TABLE `" . $xoops->db()->prefix("users") . "` DROP loginname");
255
256
        return true;
257
    }
258
259
    function _block_lookup($block, $blocks)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
260
    {
261
        if ($block['show_func'] == 'b_system_custom_show') {
262
            return 0;
263
        }
264
265
        foreach ($blocks as $key => $bk) {
266
            if ($block['show_func'] == $bk['show_func'] && $block['edit_func'] == $bk['edit_func'] && $block['template'] == $bk['template']
267
            ) {
268
                return $key;
269
            }
270
        }
271
        return null;
272
    }
273
274
    function apply_block()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
275
    {
276
        $xoops = Xoops::getInstance();
277
        $xoops->db()->queryF("UPDATE " .
278
                $xoops->db()->prefix("block_module_link") .
279
                " SET module_id = -1, pageid = 0 WHERE module_id < 2 AND pageid = 1");
280
281
        //Change block module link to remove pages
282
        //Remove page links for module subpages
283
        $xoops->db()->queryF("DELETE FROM " .
284
                $xoops->db()->prefix("block_module_link") .
285
                " WHERE pageid > 0");
286
287
        $sql = "ALTER TABLE `" .
288
                $xoops->db()->prefix("block_module_link") .
289
                "` DROP PRIMARY KEY";
290
        $xoops->db()->queryF($sql);
291
        $sql = "ALTER TABLE `" .
292
                $xoops->db()->prefix("block_module_link") .
293
                "` DROP pageid";
294
        $xoops->db()->queryF($sql);
295
        $sql = "ALTER IGNORE TABLE `" .
296
                $xoops->db()->prefix("block_module_link") .
297
                "` ADD PRIMARY KEY (`block_id` , `module_id`)";
298
        $xoops->db()->queryF($sql);
299
300
        $xoops->db()->queryF("RENAME TABLE `" .
301
                $xoops->db()->prefix("newblocks") .
302
                "` TO `" .
303
                $xoops->db()->prefix("newblocks_bak") .
304
                "`");
305
306
        // Create new block table
307
        $sql = "CREATE TABLE " . $xoops->db()->prefix("newblocks") . " (
308
              bid mediumint(8) unsigned NOT NULL auto_increment,
309
              mid smallint(5) unsigned NOT NULL default '0',
310
              func_num tinyint(3) unsigned NOT NULL default '0',
311
              options varchar(255) NOT NULL default '',
312
              name varchar(150) NOT NULL default '',
313
              title varchar(255) NOT NULL default '',
314
              content text,
315
              side tinyint(1) unsigned NOT NULL default '0',
316
              weight smallint(5) unsigned NOT NULL default '0',
317
              visible tinyint(1) unsigned NOT NULL default '0',
318
              block_type char(1) NOT NULL default '',
319
              c_type char(1) NOT NULL default '',
320
              isactive tinyint(1) unsigned NOT NULL default '0',
321
              dirname varchar(50) NOT NULL default '',
322
              func_file varchar(50) NOT NULL default '',
323
              show_func varchar(50) NOT NULL default '',
324
              edit_func varchar(50) NOT NULL default '',
325
              template varchar(50) NOT NULL default '',
326
              bcachetime int(10) unsigned NOT NULL default '0',
327
              last_modified int(10) unsigned NOT NULL default '0',
328
              PRIMARY KEY  (bid),
329
              KEY mid (mid),
330
              KEY visible (visible),
331
              KEY isactive_visible_mid (isactive,visible,mid),
332
              KEY mid_funcnum (mid,func_num)
333
            ) TYPE=MyISAM;
334
            ";
335
        $xoops->db()->queryF($sql);
336
337
        $sql = "SELECT MAX(instanceid) FROM " .
338
                $xoops->db()->prefix('block_instance');
339
        $result = $xoops->db()->query($sql);
340
        list($MaxInstanceId) = $xoops->db()->fetchRow($result);
0 ignored issues
show
Bug introduced by
The method fetchRow() does not exist on Xoops\Core\Database\Connection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

340
        list($MaxInstanceId) = $xoops->db()->/** @scrutinizer ignore-call */ fetchRow($result);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
341
342
        // Change custom block mid from 1 to 0
343
        $sql = "UPDATE `" .
344
                $xoops->db()->prefix("newblocks_bak") .
345
                "` SET mid = 0 WHERE show_func = 'b_system_custom_show'";
346
        $result = $xoops->db()->queryF($sql);
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
347
348
        $sql = "SELECT b.*, i.instanceid " . "   FROM " .
349
                $xoops->db()->prefix('block_instance') . " AS i LEFT JOIN " . $xoops->db()->prefix("newblocks_bak") .
350
                " AS b ON b.bid = i.bid " . "   GROUP BY b.dirname, b.bid, i.instanceid";
351
        $result = $xoops->db()->query($sql);
352
        $dirname = '';
353
        $bid = 0;
354
        $block_key = null;
355
        while (false !== ($row = $xoops->db()->fetchArray($result))) {
356
            if ($row['dirname'] != $dirname) {
357
                $dirname = $row['dirname'];
358
                $modversion = array();
359
                if (!@include XOOPS_ROOT_PATH . '/modules/' . $dirname . '/xoops_version.php') {
360
                    continue;
361
                }
362
            }
363
            if (empty($modversion['blocks']) && $dirname != 'system') {
364
                continue;
365
            }
366
367
            $isClone = true;
368
            if ($row['bid'] != $bid) {
369
                $bid = $row['bid'];
370
                $isClone = false;
371
                $block_key = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $block_key is dead and can be removed.
Loading history...
372
                $block_key = @$this->_block_lookup($row, $modversion['blocks']);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $modversion does not seem to be defined for all execution paths leading up to this point.
Loading history...
373
            }
374
            if ($block_key === null) {
375
                continue;
376
            }
377
378
            // Copy data from block instance table and blocks table
379
            $sql = "INSERT INTO " .
380
                    $xoops->db()->prefix("newblocks") .
381
                    " (bid, mid, options, name, title, side, weight, visible, " .
382
                    " func_num, " .
383
                    " block_type, " .
384
                    " c_type, " .
385
                    " isactive, dirname, func_file," .
386
                    " show_func, edit_func, template, bcachetime, last_modified)" .
387
                    " SELECT " .
388
                    " i.instanceid, c.mid, i.options, c.name, i.title, i.side, i.weight, i.visible, " .
389
                    " {$block_key}, " .
390
                    ($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,") .
391
                    " CASE WHEN c.c_type='' THEN 'H' ELSE c.c_type END," .
392
                    " c.isactive, c.dirname, c.func_file," .
393
                    " c.show_func, c.edit_func, c.template, i.bcachetime, c.last_modified" .
394
                    " FROM " . $xoops->db()->prefix("block_instance") .
395
                    " AS i," .
396
                    " " .
397
                    $xoops->db()->prefix("newblocks_bak") .
398
                    " AS c" .
399
                    " WHERE i.bid = c.bid" .
400
                    " AND i.instanceid = " .
401
                    $row['instanceid'];
402
            $xoops->db()->queryF($sql);
403
        }
404
405
        $sql = "SELECT b.* " .
406
                "FROM " .
407
                $xoops->db()->prefix("newblocks_bak") .
408
                " AS b LEFT JOIN " .
409
                $xoops->db()->prefix('block_instance') .
410
                " AS i ON b.bid = i.bid " .
411
                " WHERE i.instanceid IS NULL" .
412
                " GROUP BY b.dirname, b.bid";
413
        $result = $xoops->db()->query($sql);
414
        $dirname = '';
415
        $bid = 0;
416
        $block_key = null;
417
        while (false !== ($row = $xoops->db()->fetchArray($result))) {
418
            if ($row['dirname'] != $dirname) {
419
                $dirname = $row['dirname'];
420
                $modversion = array();
421
                if (!@include XOOPS_ROOT_PATH . '/modules/' . $dirname . '/xoops_version.php') {
422
                    continue;
423
                }
424
            }
425
            if (empty($modversion['blocks']) && $dirname != 'system') {
426
                continue;
427
            }
428
429
            if ($row['bid'] != $bid) {
430
                $bid = $row['bid'];
431
                $block_key = null;
432
                $block_key = @$this->_block_lookup($row, $modversion['blocks']);
433
            }
434
            if ($block_key === null) {
435
                continue;
436
            }
437
438
            // Copy data from blocks table
439
            $sql = "    INSERT INTO " . $xoops->db()
440
                    ->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 " . $xoops
441
                    ->db()->prefix("newblocks_bak") . " WHERE bid = " . $row['bid'];
442
            $xoops->db()->queryF($sql);
443
444
            // Build block-module link
445
            $sql = "    INSERT INTO " . $xoops->db()
446
                    ->prefix("block_module_link") . "       (block_id, module_id)" . "  SELECT " . "        bid + {$MaxInstanceId}, -1" . " FROM " . $xoops
447
                    ->db()->prefix("newblocks_bak") . " WHERE bid = " . $row['bid'];
448
            $xoops->db()->queryF($sql);
449
        }
450
451
        // Dealing with tables
452
        $xoops->db()->queryF("DROP TABLE `" . $xoops->db()->prefix("block_instance") . "`;");
453
        $xoops->db()->queryF("DROP TABLE `" . $xoops->db()->prefix("newblocks_bak") . "`;");
454
455
        // Deal with custom blocks, convert options to type and content
456
        $sql = "SELECT bid, options FROM `" . $xoops->db()
457
                ->prefix("newblocks") . "` WHERE show_func='b_system_custom_show'";
458
        $result = $xoops->db()->query($sql);
459
        while (false !== (list($bid, $options) = $xoops->db()->fetchRow($result))) {
460
            $_options = unserialize($options);
461
            $content = $_options[0];
462
            $type = $_options[1];
463
            $xoops->db()->queryF("UPDATE `" . $xoops->db()
464
                    ->prefix("newblocks") . "` SET c_type = '{$type}', options = '', content = " . $xoops->db()
465
                    ->quote($content) . " WHERE bid = {$bid}");
466
        }
467
468
        // Deal with block options, convert array values to "," and "|" delimited
469
        $sql = "UPDATE `" . $xoops->db()
470
                ->prefix("newblocks") . "` SET options = '' WHERE show_func <> 'b_system_custom_show' AND ( options = 'a:1:{i:0;s:0:\"\";}' OR options = 'a:0:{}' )";
471
        $result = $xoops->db()->queryF($sql);
472
        $sql = "SELECT bid, options FROM `" . $xoops->db()
473
                ->prefix("newblocks") . "` WHERE show_func <> 'b_system_custom_show' AND options <> ''";
474
        $result = $xoops->db()->query($sql);
475
        while (false !== (list($bid, $_options) = $xoops->db()->fetchRow($result))) {
476
            $options = unserialize($_options);
477
            if (empty($options) || !is_array($options)) {
478
                $options = array();
479
            }
480
            $count = count($options);
481
            //Convert array values to comma-separated
482
            for ($i = 0; $i < $count; $i++) {
483
                if (is_array($options[$i])) {
484
                    $options[$i] = implode(',', $options[$i]);
485
                }
486
            }
487
            $options = implode('|', $options);
488
            $sql = "UPDATE `" . $xoops->db()->prefix("newblocks") . "` SET options = " . $xoops->db()
489
                    ->quote($options) . " WHERE bid = {$bid}";
490
            $xoops->db()->queryF($sql);
491
        }
492
493
        return true;
494
    }
495
}
496
497
$upg = new upgrade_220();
498
return $upg;
499
500
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
501