<?php
namespace Modules\Utils\Updater\UpdateCurrentVersion; class Controller extends \App\Mvc\Controller\Form\PopupAbstract { protected function initialize() { $this->actionsCfg['index'] = ['authType' => 'none', 'checkSection' => false, 'checkOption' => false,]; $this->actionsCfg['postRedirect'] = ['authType' => 'none', 'checkSection' => false, 'checkOption' => false,]; } protected function getDefaultFormData($R) { return []; } protected function preRenderOperations(\App\Mvc\ViewAbstract $view, array $formData) { if (!$formData[$this->formSubmitButtonName]) { $msgs = new \App\MessagesCollector(); try { $modelObject = new \Modules\Utils\Updater\UpdateCurrentVersion\Model(); $modelObject->validate($msgs); $msgs->addInfo($this->lang['index']['successCheck']); } catch (\App\MessagesException $ex) { $msgs = $ex->getMessagesCollector(); } $view->getMessagesCollector()->appendMessages($msgs); } } protected function processFormData(Array $formData, \App\MessagesCollector $msgs) { try { $modelObject = new \Modules\Utils\Updater\UpdateCurrentVersion\Model(); $modelObject->validate($msgs); $modelObject->execute(); $redirectUrl = APP_URL."../tina/disp.php?module=Utils/Updater/UpdateCurrentVersion&action=postRedirect"; header("Location: ".$redirectUrl); exit(); } catch (\App\MessagesException $ex) { $msgs->appendMessages($ex->getMessagesCollector()); return false; } return true; } protected function actionPostRedirect($R) { $msgs = \App\MessagesCollector::create(); try { $modelObject = new \Modules\Utils\Updater\UpdateCurrentVersion\Model(); $modelObject->markKitAsInstalled(); $msgs->addSuccess($this->lang['postRedirect']['success']); } catch (\App\MessagesException $ex) { $msgs->appendMessages($ex->getMessagesCollector()); } $shouldStartMainCron = false; $main = \App\Cron\Main::getInstance(); if ($main->getStatus()=='should-restart' && $main->isAlreadyRunning()) { \Log::getInstance()->warning(sprintf("[%s] Main cronjob was marked for restart, but it's still running at this moment", __METHOD__)); } if ($main->getStatus()=='should-restart' && !$main->isAlreadyRunning()) { $shouldStartMainCron = true; \Log::getInstance()->info(sprintf("[%s] Main cronjob was marked for restart, restarting now", __METHOD__)); } if ($shouldStartMainCron) { try { $main->start(); } catch (\RuntimeException $ex) { \Log::getInstance()->error(sprintf("[%s] Main cronjob wasn't started. Error: %s", __METHOD__, $ex->getMessage())); } } $view = new View_PostRedirect($this); $view->getMessagesCollector()->appendMessages($msgs); return new \Engine\Mvc\Response\Html($view->render()); } }