Completed
Push — master ( 72393c...40c653 )
by Michael
13s
created

Upgrade_2510   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 104
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B check_metarobots() 0 24 4
A apply_metarobots() 0 9 1
A check_protectordata() 0 5 1
C apply_protectordata() 0 27 7
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 17 and the first side effect is on line 122.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use Xmf\Database\Tables;
4
5
/**
6
 * Upgrade from 2.5.8 to 2.5.9
7
 *
8
 * See the enclosed file license.txt for licensing information.
9
 * If you did not receive this file, get it at http://www.gnu.org/licenses/gpl-2.0.html
10
 *
11
 * @copyright    (c) 2000-2016 XOOPS Project (www.xoops.org)
12
 * @license          GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
13
 * @package          Upgrade
14
 * @since            2.5.9
15
 * @author           XOOPS Team
16
 */
17
class Upgrade_2510 extends XoopsUpgrade
18
{
19
    /**
20
     * __construct
21
     */
22
    public function __construct()
23
    {
24
        parent::__construct(basename(__DIR__));
25
        $this->tasks = array('metarobots', 'protectordata');
26
        $this->usedFiles = array();
27
    }
28
29
    /**
30
     * Make meta_robots a textbox instead of a select
31
     *
32
     * @return bool
33
     */
34
    public function check_metarobots()
35
    {
36
        /* @var $db XoopsMySQLDatabase */
37
        $db = XoopsDatabaseFactory::getDatabaseConnection();
38
39
        $table = $db->prefix('config');
40
41
        $sql = sprintf(
42
            'SELECT count(*) FROM `%s` '
43
            . "WHERE `conf_formtype` = 'select' AND `conf_name` = 'meta_robots' AND `conf_modid` = 0",
44
            $db->escape($table)
45
        );
46
47
        /** @var mysqli_result $result */
48
        $result = $db->query($sql);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $db->query($sql) (which targets XoopsMySQLDatabase::query()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
49
        if ($result) {
50
            $row = $db->fetchRow($result);
51
            if ($row) {
52
                $count = $row[0];
53
                return (0 === (int) $count) ? true : false;
54
            }
55
        }
56
        return false;
57
    }
58
59
    /**
60
     * Make meta_robots a textbox instead of a select
61
     *
62
     * This will allow webmasters to utilize current robots meta tag standards
63
     * @link https://developers.google.com/search/reference/robots_meta_tag
64
     *
65
     * @return bool
66
     */
67
    public function apply_metarobots()
68
    {
69
        // UPDATE `x569_config` SET `conf_formtype` = 'textbox' WHERE `conf_name` = 'meta_robots' and `conf_modid` = 0
70
71
        $migrate = new Tables();
72
        $migrate->useTable('config');
73
        $migrate->update('config', array('conf_formtype' => 'textbox'), "WHERE `conf_name` = 'meta_robots' AND `conf_modid` = 0");
74
        return $migrate->executeQueue(true);
75
    }
76
77
    /**
78
     * Do we need to move protector writable data?
79
     *
80
     * @return bool
81
     */
82
    public function check_protectordata()
83
    {
84
        $destinationPath = XOOPS_VAR_PATH . '/protector/';
85
        return file_exists($destinationPath);
86
    }
87
88
    /**
89
     * Move protector configs to xoops_data to segregate writable data for containerization
90
     *
91
     * @return bool
92
     */
93
    public function apply_protectordata()
94
    {
95
        $returnResult = false;
96
        $sourcePath = XOOPS_PATH . '/modules/protector/configs/';
97
        $destinationPath = XOOPS_VAR_PATH . '/protector/';
98
99
        if (!file_exists($destinationPath)) {
100
            mkdir($destinationPath);
101
        }
102
        $directory = dir($sourcePath);
103
        if (false !== $directory) {
104
            $returnResult = true;
105
            while (false !== ($entry = $directory->read())) {
106
                if ('.' !== $entry && '..' !== $entry) {
107
                    $src = $sourcePath . $entry;
108
                    $dest = $destinationPath . $entry;
109
                    $result = copy($src, $dest);
110
                    if (false === $result) {
111
                        $returnResult = false;
112
                        $this->logs[] = sprintf('Protector file copy %s failed', $entry);
113
                    }
114
                }
115
            }
116
            $directory->close();
117
        }
118
        return $returnResult;
119
    }
120
}
121
122
$upg = new Upgrade_2510();
123
return $upg;
124