WebInstallerUpgrade::isSlow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
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. See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License along
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 * http://www.gnu.org/copyleft/gpl.html
17
 *
18
 * @file
19
 * @ingroup Deployment
20
 */
21
22
class WebInstallerUpgrade extends WebInstallerPage {
23
24
	/**
25
	 * @return bool Always true.
26
	 */
27
	public function isSlow() {
28
		return true;
29
	}
30
31
	/**
32
	 * @return string|null
33
	 */
34
	public function execute() {
0 ignored issues
show
Coding Style introduced by
execute uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
35
		if ( $this->getVar( '_UpgradeDone' ) ) {
36
			// Allow regeneration of LocalSettings.php, unless we are working
37
			// from a pre-existing LocalSettings.php file and we want to avoid
38
			// leaking its contents
39
			if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
40
				// Done message acknowledged
41
				return 'continue';
42
			} else {
43
				// Back button click
44
				// Show the done message again
45
				// Make them click back again if they want to do the upgrade again
46
				$this->showDoneMessage();
47
48
				return 'output';
49
			}
50
		}
51
52
		// wgDBtype is generally valid here because otherwise the previous page
53
		// (connect) wouldn't have declared its happiness
54
		$type = $this->getVar( 'wgDBtype' );
55
		$installer = $this->parent->getDBInstaller( $type );
56
57
		if ( !$installer->needsUpgrade() ) {
58
			return 'skip';
59
		}
60
61
		if ( $this->parent->request->wasPosted() ) {
62
			$installer->preUpgrade();
63
64
			$this->startLiveBox();
65
			$result = $installer->doUpgrade();
66
			$this->endLiveBox();
67
68
			if ( $result ) {
69
				// If they're going to possibly regenerate LocalSettings, we
70
				// need to create the upgrade/secret keys. Bug 26481
71
				if ( !$this->getVar( '_ExistingDBSettings' ) ) {
72
					$this->parent->generateKeys();
73
				}
74
				$this->setVar( '_UpgradeDone', true );
75
				$this->showDoneMessage();
76
77
				return 'output';
78
			}
79
		}
80
81
		$this->startForm();
82
		$this->addHTML( $this->parent->getInfoBox(
83
			wfMessage( 'config-can-upgrade', $GLOBALS['wgVersion'] )->plain() ) );
84
		$this->endForm();
85
86
		return null;
87
	}
88
89
	public function showDoneMessage() {
90
		$this->startForm();
91
		$regenerate = !$this->getVar( '_ExistingDBSettings' );
92
		if ( $regenerate ) {
93
			$msg = 'config-upgrade-done';
94
		} else {
95
			$msg = 'config-upgrade-done-no-regenerate';
96
		}
97
		$this->parent->disableLinkPopups();
98
		$this->addHTML(
99
			$this->parent->getInfoBox(
100
				wfMessage( $msg,
101
					$this->getVar( 'wgServer' ) .
102
					$this->getVar( 'wgScriptPath' ) . '/index.php'
103
				)->plain(), 'tick-32.png'
104
			)
105
		);
106
		$this->parent->restoreLinkPopups();
107
		$this->endForm( $regenerate ? 'regenerate' : false, false );
108
	}
109
110
}
111