Completed
Pull Request — master (#568)
by Michael
06:11
created

upgrade_231::check_field()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 18
nc 6
nop 0
dl 0
loc 26
rs 8.439
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
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
12
/**
13
 * Upgrader from 2.3.0 to 2.3.1
14
 * See the enclosed file license.txt for licensing information.
15
 * If you did not receive this file, get it at http://www.fsf.org/copyleft/gpl.html
16
 *
17
 * @copyright   The XOOPS project http://www.xoops.org/
18
 * @license     http://www.fsf.org/copyleft/gpl.html GNU General Public License (GPL)
19
 * @package     upgrader
20
 * @since       2.3.0
21
 * @author      Taiwen Jiang <[email protected]>
22
 * @version     $Id$
23
 */
24
25
class upgrade_231 extends xoopsUpgrade
26
{
27
    public $tasks = array('field');
28
29
    public function __construct()
30
    {
31
        xoopsUpgrade::__construct(basename(__DIR__));
0 ignored issues
show
Bug Best Practice introduced by
The method xoopsUpgrade::__construct() is not static, but was called statically. ( Ignorable by Annotation )

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

31
        xoopsUpgrade::/** @scrutinizer ignore-call */ 
32
                      __construct(basename(__DIR__));
Loading history...
32
    }
33
34
    /**
35
     * Check if field type already fixed for mysql strict mode
36
37
     */
38
    public function check_field()
39
    {
40
        $xoops = Xoops::getInstance();
41
        $db = $xoops->db();
42
        $fields = array(
43
            "cache_data"     => "cache_model", "htmlcode" => "banner", "extrainfo" => "bannerclient",
44
            "com_text"       => "xoopscomments", "conf_value" => "config", "description" => "groups",
45
            "imgsetimg_body" => "imgsetimg", "content" => "newblocks", "msg_text" => "priv_msgs",
46
            "sess_data"      => "session", "tplset_credits" => "tplset", "tpl_source" => "tplsource",
47
            "user_sig"       => "users", "bio" => "users",
48
        );
49
        foreach ($fields as $field => $table) {
50
            $sql = "SHOW COLUMNS FROM `" . $db->prefix($table) . "` LIKE '{$field}'";
51
            if (!$result = $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

51
            if (!$result = $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...
52
                return false;
53
            }
54
            while ($row = $db->fetchArray($result)) {
55
                if ($row['Field'] != $field) {
56
                    continue;
57
                }
58
                if (strtoupper($row['Null']) != "YES") {
59
                    return false;
60
                }
61
            }
62
        }
63
        return true;
64
    }
65
66
    public function apply_field()
67
    {
68
        $xoops = Xoops::getInstance();
69
        $db = $xoops->db();
70
        $allowWebChanges = $db->allowWebChanges;
0 ignored issues
show
Bug introduced by
The property allowWebChanges does not seem to exist on Xoops\Core\Database\Connection.
Loading history...
71
        $db->allowWebChanges = true;
72
        $result = $db->queryFromFile(__DIR__ . "/mysql.structure.sql");
73
        $db->allowWebChanges = $allowWebChanges;
74
        return $result;
75
    }
76
}
77
78
$upg = new upgrade_231();
79
return $upg;
80