* [MOD] Code refactoring

This commit is contained in:
nuxsmin
2018-03-15 18:40:12 +01:00
committed by Rubén D
parent 74ceb8dc8c
commit fddbf24138
4 changed files with 5 additions and 191 deletions

View File

@@ -26,6 +26,7 @@ namespace SP\Modules\Web\Controllers;
use Klein\Klein;
use SP\Bootstrap;
use SP\Core\Install\Installer;
use SP\Mvc\View\Template;
use SP\Util\Util;
@@ -36,8 +37,6 @@ use SP\Util\Util;
*/
class ErrorController
{
use SP\Core\Dic\InjectableTrait;
/**
* @var Template
*/
@@ -49,19 +48,10 @@ class ErrorController
/**
* ErrorController constructor.
*
* @throws \SP\Core\Dic\ContainerException
*/
public function __construct()
{
$this->injectDependencies();
}
/**
* @param Template $view
* @param Klein $router
* @param Klein $router
*/
public function inject(Template $view, Klein $router)
public function __construct(Template $view, Klein $router)
{
$this->view = $view;
$this->router = $router;
@@ -75,7 +65,7 @@ class ErrorController
$this->view->assign('startTime', microtime());
$this->view->assign('appInfo', Util::getAppInfo());
$this->view->assign('appVersion', Util::getVersionString());
$this->view->assign('appVersion', Installer::VERSION_TEXT);
$this->view->assign('logoIcon', Bootstrap::$WEBURI . '/public/images/logo_icon.png');
$this->view->assign('logoNoText', Bootstrap::$WEBURI . '/public/images/logo_icon.svg');
$this->view->assign('logo', Bootstrap::$WEBURI . '/public/images/logo_full_bg.png');

View File

@@ -28,7 +28,6 @@ defined('APP_ROOT') || die();
use SP\Account\AccountUtil;
use SP\Core\DiFactory;
use SP\Core\Exceptions\SPException;
use SP\Core\Upgrade\Check;
use SP\Http\Request;
use SP\Services\Task\Task;
@@ -42,7 +41,6 @@ use SP\Util\Util;
*/
class MainController
{
/**
* Obtener los datos para el interface de actualización de componentes
*
@@ -87,72 +85,4 @@ class MainController
$this->view();
exit();
}
/**
* Obtener los datos para el interface de comprobación de actualizaciones
*
* @throws \Psr\Container\ContainerExceptionInterface
*/
public function getCheckUpdates()
{
$this->view->addTemplate('update');
$this->view->assign('hasUpdates', false);
$this->view->assign('updateStatus', null);
if ($this->configData->isCheckUpdates()) {
$updates = Util::checkUpdates();
if (is_array($updates)) {
$description = nl2br($updates['description']);
$version = $updates['version'];
$this->view->assign('hasUpdates', true);
$this->view->assign('title', $updates['title']);
$this->view->assign('url', $updates['url']);
$this->view->assign('description', sprintf('%s - %s <br><br>%s', __('Descargar nueva versión'), $version, $description));
} else {
$this->view->assign('updateStatus', $updates);
}
}
if ($this->configData->isChecknotices()) {
$notices = Util::checkNotices();
$numNotices = count($notices);
$noticesTitle = '';
if ($notices !== false && $numNotices > 0) {
$noticesTitle = __('Avisos de sysPass') . '<br>';
foreach ($notices as $notice) {
$noticesTitle .= '<br>' . $notice[0];
}
}
$this->view->assign('numNotices', $numNotices);
$this->view->assign('noticesTitle', $noticesTitle);
}
}
/**
* Realizar las acciones del controlador
*
* @param mixed $type Tipo de acción
*/
public function doAction($type = null)
{
$this->setPage($type);
try {
switch ($type) {
case 'prelogin.passreset':
$this->getPassReset();
break;
}
DiFactory::getEventDispatcher()->notifyEvent('main.' . $type, $this);
} catch (SPException $e) {
$this->showError(self::ERR_EXCEPTION);
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -155,64 +155,6 @@ class Util
return '2.2-dev';
}
/**
* Comprobar si hay actualizaciones de sysPass disponibles desde internet (github.com)
* Esta función hace una petición a GitHub y parsea el JSON devuelto para verificar
* si la aplicación está actualizada
*
* @return array|bool
*/
public static function checkUpdates()
{
try {
$data = self::getDataFromUrl(self::getAppInfo('appupdates'));
} catch (SPException $e) {
return false;
}
$updateInfo = json_decode($data);
if (!isset($updateInfo->message)) {
// $updateInfo[0]->tag_name
// $updateInfo[0]->name
// $updateInfo[0]->body
// $updateInfo[0]->tarball_url
// $updateInfo[0]->zipball_url
// $updateInfo[0]->published_at
// $updateInfo[0]->html_url
$version = $updateInfo->tag_name;
$url = $updateInfo->html_url;
$title = $updateInfo->name;
$description = $updateInfo->body;
$date = $updateInfo->published_at;
preg_match('/v?(\d+)\.(\d+)\.(\d+)\.(\d+)(\-[a-z0-9.]+)?$/', $version, $remoteVersion);
// preg_match('/v?(\d+)\.(\d+)\.(\d+)(\-[a-z0-9.]+)?$/', $version, $realVer);
if (is_array($remoteVersion)) {
$appVersion = self::getVersionStringNormalized();
$pubVersion = $remoteVersion[1] . $remoteVersion[2] . $remoteVersion[3] . '.' . $remoteVersion[4];
// $pubVersion = $realVer[1] . $realVer[2] . $realVer[3];
if (self::checkVersion($appVersion, $pubVersion)) {
return [
'version' => $version,
'url' => $url,
'title' => $title,
'description' => $description,
'date' => $date];
}
return true;
}
return false;
}
return false;
}
/**
* Obtener datos desde una URL usando CURL
*
@@ -468,54 +410,6 @@ class Util
return [implode('', Installer::VERSION), Installer::BUILD];
}
/**
* Comprobar si hay notificaciones de sysPass disponibles desde internet (github.com)
* Esta función hace una petición a GitHub y parsea el JSON devuelto
*
* @return array|bool
* @throws \Psr\Container\ContainerExceptionInterface
*/
public static function checkNotices()
{
/** @var ConfigData $ConfigData */
$ConfigData = Bootstrap::getContainer()->get(ConfigData::class);
if (!$ConfigData->isChecknotices()) {
return false;
}
try {
$data = self::getDataFromUrl(self::getAppInfo('appnotices'));
} catch (SPException $e) {
return false;
}
$noticesData = json_decode($data);
if (!isset($noticesData->message)) {
$notices = [];
// $noticesData[0]->title
// $noticesData[0]->body
// $noticesData[0]->created_at
foreach ($noticesData as $notice) {
$notices[] = [
$notice->title,
// $notice->body,
$notice->created_at
];
}
return $notices;
}
debugLog($noticesData->message);
return false;
}
/**
* Realiza el proceso de logout.
*/