-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcli.php
81 lines (71 loc) · 2.59 KB
/
cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
use splitbrain\phpcli\Options;
require_once __DIR__ . '/vendor/autoload.php';
/**
* DokuWiki Plugin upgrade (CLI Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[email protected]>
*/
class cli_plugin_upgrade extends DokuWiki_CLI_Plugin
{
protected $logdefault = 'notice';
protected $helper;
/**
* initialize
*/
public function __construct()
{
parent::__construct();
$this->helper = new helper_plugin_upgrade();
$this->helper->setLogger($this);
}
/** @inheritDoc */
protected function setup(Options $options)
{
$options->setHelp(
'This tool will upgrade your wiki to the newest release. It will automatically check file permissions ' .
'and download the required tarball. Internet access is required.'
);
$options->registerArgument('check|run', 'Either only check if an update can be done or do it', 'true');
$options->registerOption('ignoreversions', 'Ignore the version check results and continue anyway', 'i');
}
/** @inheritDoc */
protected function main(Options $options)
{
$arguments = $options->getArgs();
if ($arguments[0] === 'check') {
$dryrun = true;
} elseif ($arguments[0] === 'run') {
$dryrun = false;
} else {
$this->fatal('Unknown command');
}
if (!$this->helper->checkVersions() && !$options->getOpt('ignoreversions')) {
$this->fatal('Upgrade aborted');
}
$this->helper->downloadTarball() || $this->fatal('Upgrade aborted');
$this->helper->extractTarball() || $this->fatal('Upgrade aborted');
$this->helper->checkPermissions() || $this->fatal('Upgrade aborted');
if (!$dryrun) {
$this->helper->copyFiles() || $this->fatal('Upgrade aborted');
$this->helper->deleteObsoleteFiles() || $this->fatal('Upgrade aborted');
}
$this->helper->cleanUp();
}
/** @inheritDoc */
public function log($level, $message, array $context = array())
{
// Log messages are HTML formatted, we need to clean them for console
$message = strip_tags($message);
$message = htmlspecialchars_decode($message);
$message = preg_replace('/\s+/', ' ', $message);
parent::log($level, $message, $context);
}
}
// run the script ourselves if called directly
if (basename($_SERVER['SCRIPT_NAME']) == 'cli.php') {
$cli = new cli_plugin_upgrade();
$cli->run();
}