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

xoopsUpgrade::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
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
 * Upgrade interface class
14
 *
15
 * See the enclosed file license.txt for licensing information.
16
 * If you did not receive this file, get it at http://www.fsf.org/copyleft/gpl.html
17
 *
18
 * @copyright   The XOOPS project http://www.xoops.org/
19
 * @license     http://www.fsf.org/copyleft/gpl.html GNU General Public License (GPL)
20
 * @package     upgrader
21
 * @since       2.3.0
22
 * @author      Taiwen Jiang <[email protected]>
23
 * @version     $Id$
24
 */
25
26
27
class xoopsUpgrade
28
{
29
    public $usedFiles = array( );
30
    public $tasks = array( );
31
    public $languageFolder = null;
32
    public $logs = array();
33
34
    public function __construct($dirname = null)
35
    {
36
        if ($dirname) {
37
            $this->loadLanguage($dirname);
38
        }
39
    }
40
41
    public function isApplied()
42
    {
43
        $step = get_class($this);
44
        if (!isset($_SESSION['xoops_upgrade'][$step]) || !is_array($_SESSION['xoops_upgrade'][$step])) {
45
            $_SESSION['xoops_upgrade'][$step] = array();
46
        }
47
        foreach ($this->tasks as $task) {
48
            if (!in_array($task, $_SESSION['xoops_upgrade'][$step])) {
49
                if (!$res = $this->{"check_{$task}"}()) {
0 ignored issues
show
Unused Code introduced by
The assignment to $res is dead and can be removed.
Loading history...
50
                    $_SESSION['xoops_upgrade'][$step][] = $task;
51
                }
52
            }
53
        }
54
        return empty($_SESSION['xoops_upgrade'][$step]) ? true : false;
55
    }
56
57
    public function apply()
58
    {
59
        $step = get_class($this);
60
        $tasks = $_SESSION['xoops_upgrade'][$step];
61
        foreach ($tasks as $task) {
62
            $res = $this->{"apply_{$task}"}();
63
            if (!$res) {
64
                return false;
65
            }
66
            array_shift($_SESSION['xoops_upgrade'][$step]);
67
        }
68
        return true;
69
    }
70
71
    public function loadLanguage($dirname)
72
    {
73
        global $upgrade_language;
74
75
        if (file_exists("./{$dirname}/language/{$upgrade_language}.php")) {
76
            include_once "./{$dirname}/language/{$upgrade_language}.php";
77
        } elseif (file_exists("./{$dirname}/language/english.php")) {
78
            include_once "./{$dirname}/language/english.php";
79
        }
80
    }
81
82
    public function message()
83
    {
84
        return empty($this->logs) ? "" : implode("<br>", $this->logs);
85
    }
86
}
87