*/
require_once __DIR__ . '/vendor/autoload.php';
class admin_plugin_upgrade extends DokuWiki_Admin_Plugin
{
protected $haderrors = false;
/** @var helper_plugin_upgrade */
protected $helper;
/**
* initialize helper
*/
public function __construct()
{
$this->helper = plugin_load('helper', 'upgrade');
$this->helper->setLogger($this);
}
/** @inheritDoc */
public function getMenuSort()
{
return 555;
}
/** @inheritDoc */
public function handle()
{
if (!empty($_REQUEST['step']) && !checkSecurityToken()) {
unset($_REQUEST['step']);
}
}
public function html()
{
$abrt = false;
$next = false;
$ok = true;
echo '
';
// enable auto scroll
?>
nextStep($abrt, $next, $ok);
// disable auto scroll
?>
';
$careful = '';
if (!$ok) {
echo '
' . $this->getLang('careful') . '
';
$careful = 'careful';
}
$action = script();
echo '
';
$this->displayProgressBar($next);
}
/**
* Display a progress bar of all steps
*
* @param string $next the next step
*/
private function displayProgressBar($next)
{
$steps = ['version', 'download', 'unpack', 'check', 'upgrade'];
$active = true;
$count = 0;
echo '
';
foreach ($steps as $step) {
$count++;
if ($step == $next) $active = false;
if ($active) {
echo '- ';
echo '✔';
} else {
echo '
- ';
echo '' . $count . '';
}
echo '' . $this->getLang('step_' . $step) . '';
echo '
';
}
echo '
';
}
/**
* Decides the current step and executes it
*
* @param bool $abrt
* @param bool $next
* @param bool $ok
*/
private function nextStep(&$abrt, &$next, &$ok)
{
if (isset($_REQUEST['step']) && is_array($_REQUEST['step'])) {
$keys = array_keys($_REQUEST['step']);
$step = array_shift($keys);
} else {
$step = '';
}
if ($step == 'cancel' || $step == 'done') {
$ok = $this->helper->cleanup();
if ($step == 'cancel') $step = '';
}
if ($step) {
$abrt = true;
$next = false;
if ($step == 'version') {
$ok = $this->helper->checkVersions();
$next = 'download';
} elseif ($step == 'done') {
echo $this->locale_xhtml('final');
$next = '';
$abrt = '';
} elseif (!file_exists($this->helper->tgzfile)) {
if ($ok = $this->helper->downloadTarball()) $next = 'unpack';
} elseif (!is_dir($this->helper->tgzdir)) {
if ($ok = $this->helper->extractTarball()) $next = 'check';
} elseif ($step != 'upgrade') {
if ($ok = $this->helper->checkPermissions()) $next = 'upgrade';
} elseif ($step == 'upgrade') {
if ($ok = $this->helper->copyFiles()) {
$ok = $this->helper->deleteObsoleteFiles();
$this->helper->cleanup();
$next = 'done';
$abrt = '';
}
} else {
echo 'uhm. what happened? where am I? This should not happen';
}
} else {
# first time run, show intro
echo $this->locale_xhtml('step0');
$this->helper->cleanup(); // make sure we start clean
$abrt = false;
$next = 'version';
}
}
/**
* Print the given message and flush buffers
*
* @param string $level
* @param string $message
*/
public function log($level, $message) {
echo '
' . $message . '
';
flush();
ob_flush();
}
}