Completed
Push — master ( 72206a...a05009 )
by Michael
11:12
created

index.php ➔ getDbValue()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 6
nop 4
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * Upgrader index file
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             upgrader
15
 * @since               2.3.0
16
 * @author              Skalpa Keo <[email protected]>
17
 * @author              Taiwen Jiang <[email protected]>
18
 */
19
/* @var  $xoopsUser XoopsUser */
20
21
//Before xoops 2.5.8 the table 'sess_ip' was of type varchar (15). This is a problem for IPv6 addresses because it is longer. The upgrade process would change the column to VARCHAR(45) but it requires login, which is failing. If the user has an IPv6 address, it is converted to short IP during the upgrade. At the end of the upgrade IPV6 works
22
//save current IP
23
$ip = $_SERVER['REMOTE_ADDR'];
24
if (strlen($_SERVER['REMOTE_ADDR']) > 15) {
25
    //new IP for upgrade
26
    $_SERVER['REMOTE_ADDR'] = '::1';
27
}
28
29
include_once '../mainfile.php';
30
defined('XOOPS_ROOT_PATH') or die('Bad installation: please add this folder to the XOOPS install you want to upgrade');
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
31
32
$reporting = -1; // 0;
33
if (isset($_GET['debug'])) {
34
    $reporting = -1;
35
}
36
error_reporting($reporting);
37
$xoopsLogger->activated = true;
38
$xoopsLogger->enableRendering();
39
xoops_loadLanguage('logger');
40
41
require './class/abstract.php';
42
require './class/patchstatus.php';
43
require './class/control.php';
44
45
$GLOBALS['error'] = false;
46
$upgradeControl = new UpgradeControl();
47
48
$upgradeControl->determineLanguage();
49
$upgradeControl->buildUpgradeQueue();
50
51
ob_start();
52
global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
53
if (!$xoopsUser || !$xoopsUser->isAdmin()) {
54
    include_once 'login.php';
55
} else {
56
    $op = Xmf\Request::getCmd('action', '');
57
    if (!$upgradeControl->needUpgrade) {
58
        $op = '';
59
    }
60
    if (empty($op)) {
61
        $upgradeControl->loadLanguage('welcome');
62
        echo _XOOPS_UPGRADE_WELCOME;
63
    } else {
64
        if (!empty($upgradeControl->needWriteFiles)) {
65
            echo '<div class="panel panel-danger">'
66
                . '<div class="panel-heading">' . _SET_FILES_WRITABLE . '</div>'
67
                . '<div class="panel-body"><ul class="fa-ul">';
68
            foreach ($upgradeControl->needWriteFiles as $file) {
69
                echo '<li><i class="fa-li fa fa-ban text-danger"></i>' . $file . '</li>';
70
                $GLOBALS['error'] = true;
71
            }
72
            echo '</ul></div></div>';
73
        } else {
74
            $next = $upgradeControl->getNextPatch();
75
            printf('<h2>' . _PERFORMING_UPGRADE . '</h2>', $next);
76
            /** @var $upgrader XoopsUpgrade */
77
            $upgradeClass = $upgradeControl->upgradeQueue[$next]->patchClass;
78
            $upgrader = new $upgradeClass();
79
            $res = $upgrader->apply();
80
            if ($message = $upgrader->message()) {
81
                echo '<div class="well">' . $message . '</div>';
82
            }
83
84
            if ($res) {
85
                $upgradeControl->upgradeQueue[$next]->applied = true;
86
            }
87
        }
88
    }
89
    if (0 === $upgradeControl->countUpgradeQueue()) {
90
            echo $upgradeControl->oneButtonContinueForm(
91
                XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin&amp;op=update&amp;module=system',
92
                array()
93
            );
94
    } else {
95
        echo $upgradeControl->oneButtonContinueForm();
96
    }
97
}
98
$content = ob_get_contents();
99
ob_end_clean();
100
101
include_once 'upgrade_tpl.php';
102