14e3e87e4SAndreas Gohr<?php 24e3e87e4SAndreas Gohr 34e3e87e4SAndreas Gohruse splitbrain\phpcli\Options; 44e3e87e4SAndreas Gohr 54e3e87e4SAndreas Gohrrequire_once __DIR__ . '/vendor/autoload.php'; 64e3e87e4SAndreas Gohr 74e3e87e4SAndreas Gohr/** 84e3e87e4SAndreas Gohr * DokuWiki Plugin upgrade (CLI Component) 94e3e87e4SAndreas Gohr * 104e3e87e4SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 114e3e87e4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 124e3e87e4SAndreas Gohr */ 13fc9fd1daSAndreas Gohrclass cli_plugin_upgrade extends DokuWiki_CLI_Plugin 144e3e87e4SAndreas Gohr{ 154e3e87e4SAndreas Gohr protected $logdefault = 'notice'; 16eb7336c4SAndreas Gohr protected $helper; 17eb7336c4SAndreas Gohr 18eb7336c4SAndreas Gohr /** 19eb7336c4SAndreas Gohr * initialize 20eb7336c4SAndreas Gohr */ 21eb7336c4SAndreas Gohr public function __construct() 22eb7336c4SAndreas Gohr { 23eb7336c4SAndreas Gohr parent::__construct(); 24eb7336c4SAndreas Gohr $this->helper = new helper_plugin_upgrade(); 25eb7336c4SAndreas Gohr $this->helper->setLogger($this); 26eb7336c4SAndreas Gohr } 27eb7336c4SAndreas Gohr 284e3e87e4SAndreas Gohr /** @inheritDoc */ 294e3e87e4SAndreas Gohr protected function setup(Options $options) 304e3e87e4SAndreas Gohr { 31*601d513fSAndreas Gohr $options->setHelp( 32*601d513fSAndreas Gohr 'This tool will upgrade your wiki to the newest release. It will automatically check file permissions '. 33*601d513fSAndreas Gohr 'and download the required tarball. Internet access is required.' 34*601d513fSAndreas Gohr ); 354e3e87e4SAndreas Gohr $options->registerArgument('check|run', 'Either only check if an update can be done or do it', 'true'); 364e3e87e4SAndreas Gohr $options->registerOption('ignoreversions', 'Ignore the version check results and continue anyway', 'i'); 374e3e87e4SAndreas Gohr } 384e3e87e4SAndreas Gohr 394e3e87e4SAndreas Gohr /** @inheritDoc */ 404e3e87e4SAndreas Gohr protected function main(Options $options) 414e3e87e4SAndreas Gohr { 424e3e87e4SAndreas Gohr $arguments = $options->getArgs(); 434e3e87e4SAndreas Gohr if ($arguments[0] === 'check') { 444e3e87e4SAndreas Gohr $dryrun = true; 454e3e87e4SAndreas Gohr } elseif ($arguments[0] === 'run') { 464e3e87e4SAndreas Gohr $dryrun = false; 474e3e87e4SAndreas Gohr } else { 484e3e87e4SAndreas Gohr $this->fatal('Unknown command'); 494e3e87e4SAndreas Gohr } 504e3e87e4SAndreas Gohr 51eb7336c4SAndreas Gohr if (!$this->helper->checkVersions() && !$options->getOpt('ignoreversions')) { 52*601d513fSAndreas Gohr $this->fatal('Upgrade aborted'); 534e3e87e4SAndreas Gohr } 54*601d513fSAndreas Gohr $this->helper->downloadTarball() || $this->fatal('Upgrade aborted'); 55*601d513fSAndreas Gohr $this->helper->extractTarball() || $this->fatal('Upgrade aborted'); 56*601d513fSAndreas Gohr $this->helper->checkPermissions() || $this->fatal('Upgrade aborted'); 574e3e87e4SAndreas Gohr if (!$dryrun) { 58*601d513fSAndreas Gohr $this->helper->copyFiles() || $this->fatal('Upgrade aborted'); 59*601d513fSAndreas Gohr $this->helper->deleteObsoleteFiles() || $this->fatal('Upgrade aborted'); 604e3e87e4SAndreas Gohr } 61eb7336c4SAndreas Gohr $this->helper->cleanUp(); 624e3e87e4SAndreas Gohr } 634e3e87e4SAndreas Gohr 644e3e87e4SAndreas Gohr /** @inheritDoc */ 654e3e87e4SAndreas Gohr public function log($level, $message, array $context = array()) 664e3e87e4SAndreas Gohr { 674e3e87e4SAndreas Gohr // Log messages are HTML formatted, we need to clean them for console 684e3e87e4SAndreas Gohr $message = strip_tags($message); 694e3e87e4SAndreas Gohr $message = htmlspecialchars_decode($message); 704e3e87e4SAndreas Gohr $message = preg_replace('/\s+/', ' ', $message); 714e3e87e4SAndreas Gohr parent::log($level, $message, $context); 724e3e87e4SAndreas Gohr } 734e3e87e4SAndreas Gohr} 744e3e87e4SAndreas Gohr 75eb7336c4SAndreas Gohr// run the script ourselves if called directly 76eb7336c4SAndreas Gohrif(basename($_SERVER['SCRIPT_NAME']) == 'cli.php') { 77eb7336c4SAndreas Gohr $cli = new cli_plugin_upgrade(); 78eb7336c4SAndreas Gohr $cli->run(); 79eb7336c4SAndreas Gohr} 80