From f6aa24d5c170ca61b97a4d614bce0697ab4682c7 Mon Sep 17 00:00:00 2001 From: nuxsmin Date: Mon, 30 Jul 2018 12:06:53 +0200 Subject: [PATCH] * [FIX] Fixed wrong behaviour when updating custom fields data module * [FIX] Delete non-existant users in notifications table * [MOD] Improved error logging --- app/modules/api/Init.php | 2 +- .../web/Controllers/IndexController.php | 4 +- .../web/Controllers/StatusController.php | 4 +- .../web/Controllers/Traits/ItemTrait.php | 2 +- app/modules/web/Init.php | 8 +- lib/Base.php | 8 +- lib/BaseFunctions.php | 92 ++++++++++++++----- lib/SP/Bootstrap.php | 24 ++--- lib/SP/Config/Config.php | 4 +- lib/SP/Config/ConfigCache.php | 4 +- lib/SP/Core/Acl/Actions.php | 6 +- lib/SP/Core/Context/SessionContext.php | 4 +- lib/SP/Core/Crypt/Crypt.php | 8 +- lib/SP/Core/Crypt/CryptSessionHandler.php | 8 +- lib/SP/Core/Crypt/Hash.php | 2 +- lib/SP/Core/Crypt/SecureKeyCookie.php | 10 +- lib/SP/Core/Crypt/Session.php | 2 +- lib/SP/Core/Events/EventDispatcherBase.php | 2 +- lib/SP/Core/Language.php | 4 +- lib/SP/Core/UI/Theme.php | 4 +- lib/SP/DataModel/CustomFieldData.php | 4 +- lib/SP/DataModel/TrackData.php | 2 +- lib/SP/Html/DataGrid/DataGridBase.php | 4 +- lib/SP/Html/Minify.php | 6 +- lib/SP/Http/Request.php | 2 +- lib/SP/Http/Response.php | 34 ------- lib/SP/Mvc/View/Template.php | 8 +- lib/SP/Plugin/PluginManager.php | 2 +- lib/SP/Providers/Log/FileLogHandler.php | 4 +- lib/SP/Providers/Mail/MailProvider.php | 2 +- lib/SP/Repositories/Track/TrackRequest.php | 2 +- lib/SP/Services/Account/AccountAclService.php | 10 +- .../Services/Account/AccountCryptService.php | 4 +- .../Services/Account/AccountSearchService.php | 4 +- lib/SP/Services/Account/AccountService.php | 2 +- .../Services/Crypt/SecureSessionService.php | 4 +- lib/SP/Services/Export/XmlVerifyService.php | 2 +- lib/SP/Services/Import/FileImport.php | 2 +- lib/SP/Services/Import/XmlFileImport.php | 2 +- lib/SP/Services/Install/MySQL.php | 6 +- lib/SP/Services/Service.php | 8 +- lib/SP/Services/Task/Task.php | 4 +- lib/SP/Services/Task/TaskService.php | 10 +- lib/SP/Services/Track/TrackService.php | 2 +- lib/SP/Services/Upgrade/UpgradeAppService.php | 2 +- .../Upgrade/UpgradeCustomFieldData.php | 7 +- .../Upgrade/UpgradeDatabaseService.php | 6 +- lib/SP/Storage/Database/Database.php | 5 +- .../Database/DatabaseConnectionData.php | 2 +- lib/SP/Storage/Database/DatabaseUtil.php | 2 +- lib/SP/Storage/Database/MySQLHandler.php | 21 ++--- lib/SP/Util/ImageUtil.php | 4 +- lib/SP/Util/Util.php | 2 +- schemas/30018072302.sql | 2 + 54 files changed, 196 insertions(+), 189 deletions(-) diff --git a/app/modules/api/Init.php b/app/modules/api/Init.php index 475f6f0b..e191af76 100644 --- a/app/modules/api/Init.php +++ b/app/modules/api/Init.php @@ -81,7 +81,7 @@ final class Init extends ModuleBase */ public function initialize($controller) { - debugLog(__FUNCTION__); + logger(__FUNCTION__); // Initialize context $this->context->initialize(); diff --git a/app/modules/web/Controllers/IndexController.php b/app/modules/web/Controllers/IndexController.php index 45989d20..535def46 100644 --- a/app/modules/web/Controllers/IndexController.php +++ b/app/modules/web/Controllers/IndexController.php @@ -24,7 +24,6 @@ namespace SP\Modules\Web\Controllers; -use SP\Http\Response; use SP\Modules\Web\Controllers\Helpers\LayoutHelper; /** @@ -43,7 +42,8 @@ final class IndexController extends ControllerBase public function indexAction() { if (!$this->session->isLoggedIn()) { - Response::redirect('index.php?r=login'); + $this->router->response() + ->redirect('index.php?r=login'); } else { $this->dic->get(LayoutHelper::class)->getFullLayout('main', $this->acl); diff --git a/app/modules/web/Controllers/StatusController.php b/app/modules/web/Controllers/StatusController.php index 25b99970..fae7a18d 100644 --- a/app/modules/web/Controllers/StatusController.php +++ b/app/modules/web/Controllers/StatusController.php @@ -79,7 +79,7 @@ final class StatusController extends SimpleControllerBase } } - debugLog($requestData->message); + logger($requestData->message); } $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Versión no disponible')); @@ -114,7 +114,7 @@ final class StatusController extends SimpleControllerBase $this->returnJsonResponseData($notices); } - debugLog($requestData->message); + logger($requestData->message); } $this->returnJsonResponse(JsonResponse::JSON_ERROR, __u('Notificaciones no disponibles')); diff --git a/app/modules/web/Controllers/Traits/ItemTrait.php b/app/modules/web/Controllers/Traits/ItemTrait.php index 0b3e00ea..e69f4398 100644 --- a/app/modules/web/Controllers/Traits/ItemTrait.php +++ b/app/modules/web/Controllers/Traits/ItemTrait.php @@ -83,7 +83,7 @@ trait ItemTrait $customFields[] = $customField; } catch (CryptoException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); } } diff --git a/app/modules/web/Init.php b/app/modules/web/Init.php index f1c09b7c..c0bc53c6 100644 --- a/app/modules/web/Init.php +++ b/app/modules/web/Init.php @@ -111,7 +111,7 @@ final class Init extends ModuleBase */ public function initialize($controller) { - debugLog(__METHOD__); + logger(__METHOD__); // Iniciar la sesión de PHP $this->initSession($this->configData->isEncryptSession()); @@ -127,7 +127,7 @@ final class Init extends ModuleBase // Initialize theme $this->theme->initialize(); } else { - debugLog('Browser reload'); + logger('Browser reload'); $this->context->setAppStatus(SessionContext::APP_STATUS_RELOADED); @@ -185,7 +185,7 @@ final class Init extends ModuleBase $this->pluginManager->loadPlugins(); if ($this->context->isLoggedIn() && $this->context->getAppStatus() === SessionContext::APP_STATUS_RELOADED) { - debugLog('Reload user profile'); + logger('Reload user profile'); // Recargar los permisos del perfil de usuario $this->context->setUserProfile($this->container->get(UserProfileService::class)->getById($this->context->getUserData()->getUserProfileId())->getProfile()); } @@ -282,7 +282,7 @@ final class Init extends ModuleBase // Recargar los permisos del perfil de usuario // $this->session->setUserProfile(Profile::getItem()->getById($this->session->getUserData()->getUserProfileId())); } catch (CryptoException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); SessionContext::restart(); return; diff --git a/lib/Base.php b/lib/Base.php index 3dd48885..158c716e 100644 --- a/lib/Base.php +++ b/lib/Base.php @@ -73,13 +73,13 @@ try { Bootstrap::run($builder->build()); } catch (\Exception $e) { - debugLog($e->getMessage()); - debugLog($e->getTraceAsString()); + logger($e->getMessage()); + logger($e->getTraceAsString()); die($e->getMessage()); } catch (\Psr\Container\ContainerExceptionInterface $e) { - debugLog($e->getMessage()); - debugLog($e->getTraceAsString()); + logger($e->getMessage()); + logger($e->getTraceAsString()); die($e->getMessage()); } \ No newline at end of file diff --git a/lib/BaseFunctions.php b/lib/BaseFunctions.php index 6699f61e..f67be42a 100644 --- a/lib/BaseFunctions.php +++ b/lib/BaseFunctions.php @@ -23,46 +23,94 @@ */ /** - * Función para enviar mensajes al log de errores + * [type] [caller] data + */ +define('LOG_FORMAT', "[%s] [%s] %s"); +/** + * [timestamp] [type] [caller] data + */ +define('LOG_FORMAT_OWN', "%s [%s] [%s] %s\n"); + +/** + * Basic logger to handle some debugging and exception messages. + * + * It will log messages into syspass.log or PHP error log file. + * + * In order to log debugging messages, DEBUG constant must be set to true. + * + * A more advanced event logging should be handled through EventDispatcher * * @param mixed $data - * @param bool $printLastCaller + * @param string $type */ -function debugLog($data, $printLastCaller = false) +function logger($data, $type = 'DEBUG') { - $line = date('Y-m-d H:i:s') . ' - ' . print_r($data, true) . PHP_EOL; + if (!DEBUG && $type === 'DEBUG') { + return; + } + + $date = date('Y-m-d H:i:s'); + $caller = getLastCaller(); + + if (is_scalar($data)) { + $line = sprintf(LOG_FORMAT_OWN, $date, $type, $caller, $data); + } else { + $line = sprintf(LOG_FORMAT_OWN, $date, $type, $caller, print_r($data, true)); + } + $useOwn = (!defined('LOG_FILE') || !error_log($line, 3, LOG_FILE) ); if ($useOwn === false) { - error_log(print_r($data, true)); - } - - if ($printLastCaller === true) { - if ($useOwn === true) { - error_log(formatTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)), 3, LOG_FILE); + if (is_scalar($data)) { + $line = sprintf(LOG_FORMAT, $type, $caller, $data); } else { - error_log(formatTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))); + $line = sprintf(LOG_FORMAT, $type, $caller, print_r($data, true)); } + + error_log($line); } } /** - * Procesar una excepción y registrarla en el log + * Print last callers from backtrace + */ +function printLastCallers() +{ + logger(formatTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))); +} + +/** + * Print last caller from backtrace + * + * @return string + */ +function getLastCaller() +{ + $callers = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); + + if (isset($callers[2]) + && isset($callers[2]['class']) + && isset($callers[2]['function']) + ) { + return $callers[2]['class'] . '::' . $callers[2]['function']; + } + + return 'N/A'; +} + +/** + * Process an exception and log into the error log * * @param \Exception $exception */ function processException(\Exception $exception) { - debugLog(__($exception->getMessage())); - debugLog($exception->getTraceAsString()); + logger(sprintf("%s\n%s", __($exception->getMessage()), $exception->getTraceAsString()), 'EXCEPTION'); - $previous = $exception->getPrevious(); - - if ($previous !== null) { - debugLog(__($previous->getMessage())); - debugLog($previous->getTraceAsString()); + if (($previous = $exception->getPrevious()) !== null) { + logger(sprintf("(P) %s\n%s", __($previous->getMessage()), $previous->getTraceAsString()), 'EXCEPTION'); } } @@ -92,7 +140,7 @@ function formatTrace($trace) * Alias gettext function * * @param string $message - * @param bool $translate Si es necesario traducir + * @param bool $translate Si es necesario traducir * * @return string */ @@ -118,7 +166,7 @@ function __u($message) * * @param string $domain * @param string $message - * @param bool $translate + * @param bool $translate * * @return string */ @@ -186,7 +234,7 @@ function initModule($module) function nDirname($dir, $levels) { if (version_compare(PHP_VERSION, '7.0') === -1) { - debugLog(realpath(dirname($dir) . str_repeat('../', $levels))); + logger(realpath(dirname($dir) . str_repeat('../', $levels))); return realpath(dirname($dir) . str_repeat('../', $levels)); } diff --git a/lib/SP/Bootstrap.php b/lib/SP/Bootstrap.php index 3b209631..338b7c16 100644 --- a/lib/SP/Bootstrap.php +++ b/lib/SP/Bootstrap.php @@ -130,10 +130,10 @@ final class Bootstrap $oops = "Oops, it looks like this content doesn't exist..."; $this->router->onError(function ($router, $err_msg, $type, $err) { - debugLog('Routing error: ' . $err_msg); + logger('Routing error: ' . $err_msg); /** @var Exception|\Throwable $err */ - debugLog('Routing error: ' . $err->getTraceAsString()); + logger('Routing error: ' . $err->getTraceAsString()); /** @var Klein $router */ $router->response()->body($err_msg); @@ -152,7 +152,7 @@ final class Bootstrap $method = $action . 'Action'; if (!method_exists($controllerClass, $method)) { - debugLog($controllerClass . '::' . $method); + logger($controllerClass . '::' . $method); throw new RuntimeException($oops); } @@ -162,7 +162,7 @@ final class Bootstrap self::$container->get(InitApi::class) ->initialize($controller); - debugLog('Routing call: ' . $controllerClass . '::' . $method); + logger('Routing call: ' . $controllerClass . '::' . $method); return call_user_func([new $controllerClass(self::$container, $method, $apiRequest), $method]); } catch (\Exception $e) { @@ -195,7 +195,7 @@ final class Bootstrap $controllerClass = 'SP\\Modules\\' . ucfirst(APP_MODULE) . '\\Controllers\\' . ucfirst($controller) . 'Controller'; if (!method_exists($controllerClass, $method)) { - debugLog($controllerClass . '::' . $method); + logger($controllerClass . '::' . $method); throw new RuntimeException($oops); } @@ -209,7 +209,7 @@ final class Bootstrap break; } - debugLog('Routing call: ' . $controllerClass . '::' . $method . '::' . print_r($params, true)); + logger('Routing call: ' . $controllerClass . '::' . $method . '::' . print_r($params, true)); return call_user_func_array([new $controllerClass(self::$container, $method), $method], $params); } catch (\Exception $e) { @@ -236,7 +236,7 @@ final class Bootstrap */ protected function initializeCommon() { - debugLog(__FUNCTION__); + logger(__FUNCTION__); self::$checkPhpVersion = Checks::checkPhpVersion(); @@ -314,7 +314,7 @@ final class Bootstrap && touch(LOG_FILE) && chmod(LOG_FILE, 0600) ) { - debugLog('Setup log file: ' . LOG_FILE); + logger('Setup log file: ' . LOG_FILE); } if (date_default_timezone_get() === 'UTC') { @@ -420,14 +420,14 @@ final class Bootstrap switch ($module) { case 'web': - debugLog('------------'); - debugLog('Boostrap:web'); + logger('------------'); + logger('Boostrap:web'); $bs->router->dispatch($bs->request->getRequest()); break; case 'api': - debugLog('------------'); - debugLog('Boostrap:api'); + logger('------------'); + logger('Boostrap:api'); $bs->router->dispatch($bs->request->getRequest()); break; diff --git a/lib/SP/Config/Config.php b/lib/SP/Config/Config.php index 4dabd0c3..15154165 100644 --- a/lib/SP/Config/Config.php +++ b/lib/SP/Config/Config.php @@ -107,7 +107,7 @@ final class Config self::$timeUpdated = $this->configData->getConfigDate(); $this->configLoaded = true; - debugLog('Config loaded'); + logger('Config loaded'); } } @@ -250,7 +250,7 @@ final class Config public function generateUpgradeKey() { if (empty($this->configData->getUpgradeKey())) { - debugLog('Generating upgrade key'); + logger('Generating upgrade key'); return $this->saveConfig($this->configData->setUpgradeKey(Util::generateRandomBytes(16)), false); } diff --git a/lib/SP/Config/ConfigCache.php b/lib/SP/Config/ConfigCache.php index f78a5561..fbb6a7bb 100644 --- a/lib/SP/Config/ConfigCache.php +++ b/lib/SP/Config/ConfigCache.php @@ -64,7 +64,7 @@ final class ConfigCache try { $this->fileCache->save(self::CONFIG_CACHE_FILE, $configData); - debugLog('Saved config cache'); + logger('Saved config cache'); } catch (FileException $e) { processException($e); } @@ -81,7 +81,7 @@ final class ConfigCache $configData = $this->fileCache->load(self::CONFIG_CACHE_FILE); if ($configData instanceof ConfigData) { - debugLog('Loaded config cache'); + logger('Loaded config cache'); return $configData; } diff --git a/lib/SP/Core/Acl/Actions.php b/lib/SP/Core/Acl/Actions.php index f502530b..4b6c1f32 100644 --- a/lib/SP/Core/Acl/Actions.php +++ b/lib/SP/Core/Acl/Actions.php @@ -91,7 +91,7 @@ final class Actions try { $this->actions = $this->fileStorage->load(self::ACTIONS_CACHE_FILE); - debugLog('Loaded actions cache'); + logger('Loaded actions cache'); } catch (FileException $e) { processException($e); @@ -105,7 +105,7 @@ final class Actions */ protected function mapAndSave() { - debugLog('ACTION CACHE MISS'); + logger('ACTION CACHE MISS'); $this->map(); $this->saveCache(); @@ -154,7 +154,7 @@ final class Actions try { $this->fileStorage->save(self::ACTIONS_CACHE_FILE, $this->actions); - debugLog('Saved actions cache'); + logger('Saved actions cache'); } catch (FileException $e) { processException($e); } diff --git a/lib/SP/Core/Context/SessionContext.php b/lib/SP/Core/Context/SessionContext.php index 00e4a494..e85d3318 100644 --- a/lib/SP/Core/Context/SessionContext.php +++ b/lib/SP/Core/Context/SessionContext.php @@ -54,7 +54,7 @@ final class SessionContext extends ContextBase */ public static function close() { - debugLog('Session closed'); + logger('Session closed'); session_write_close(); @@ -124,7 +124,7 @@ final class SessionContext extends ContextBase { try { if (self::$isLocked) { - debugLog('Session locked; key=' . $key); + logger('Session locked; key=' . $key); } else { parent::setContextKey($key, $value); } diff --git a/lib/SP/Core/Crypt/Crypt.php b/lib/SP/Core/Crypt/Crypt.php index 4b269f78..31cedaf1 100644 --- a/lib/SP/Core/Crypt/Crypt.php +++ b/lib/SP/Core/Crypt/Crypt.php @@ -59,7 +59,7 @@ final class Crypt return Crypto::encrypt((string)$data, $key); } catch (CryptoException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); throw $e; } @@ -82,7 +82,7 @@ final class Crypt return KeyProtectedByPassword::loadFromAsciiSafeString($key)->unlockKey($password); } catch (CryptoException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); throw $e; } @@ -113,7 +113,7 @@ final class Crypt return Crypto::decrypt($data, Key::loadFromAsciiSafeString($securedKey)); } catch (CryptoException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); throw $e; } @@ -138,7 +138,7 @@ final class Crypt return KeyProtectedByPassword::createRandomPasswordProtectedKey($password); } catch (CryptoException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); throw $e; } diff --git a/lib/SP/Core/Crypt/CryptSessionHandler.php b/lib/SP/Core/Crypt/CryptSessionHandler.php index 171652e3..7f64c9a1 100644 --- a/lib/SP/Core/Crypt/CryptSessionHandler.php +++ b/lib/SP/Core/Crypt/CryptSessionHandler.php @@ -81,8 +81,8 @@ final class CryptSessionHandler extends \SessionHandler } catch (CryptoException $e) { self::$isSecured = false; - debugLog($e->getMessage()); - debugLog('Session data not encrypted.'); + logger($e->getMessage()); + logger('Session data not encrypted.'); return $data; } @@ -118,8 +118,8 @@ final class CryptSessionHandler extends \SessionHandler } catch (CryptoException $e) { self::$isSecured = false; - debugLog('Could not encrypt session data.'); - debugLog($e->getMessage()); + logger('Could not encrypt session data.'); + logger($e->getMessage()); } return parent::write($id, $data); diff --git a/lib/SP/Core/Crypt/Hash.php b/lib/SP/Core/Crypt/Hash.php index 59e5b617..11bb9132 100644 --- a/lib/SP/Core/Crypt/Hash.php +++ b/lib/SP/Core/Crypt/Hash.php @@ -63,7 +63,7 @@ final class Hash $key = hash('sha256', $key); if ($isCheck === false) { - debugLog('[INFO] Password string shortened using SHA256 and then BCRYPT'); + logger('[INFO] Password string shortened using SHA256 and then BCRYPT'); } } diff --git a/lib/SP/Core/Crypt/SecureKeyCookie.php b/lib/SP/Core/Crypt/SecureKeyCookie.php index fbff805b..274bcb0a 100644 --- a/lib/SP/Core/Crypt/SecureKeyCookie.php +++ b/lib/SP/Core/Crypt/SecureKeyCookie.php @@ -69,7 +69,7 @@ final class SecureKeyCookie extends Cookie $data = $this->getCookieData($cookie, $key); if ($data === false) { - debugLog('Cookie verification error.'); + logger('Cookie verification error.'); return $this->saveKey($key); } @@ -83,7 +83,7 @@ final class SecureKeyCookie extends Cookie try { return Key::loadFromAsciiSafeString($vault->getData($key)); } catch (CryptoException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); return false; } @@ -127,16 +127,16 @@ final class SecureKeyCookie extends Cookie $vault->saveData($this->securedKey->saveToAsciiSafeString(), $key); if ($this->setCookie($this->sign(serialize($vault), $key))) { - debugLog('Generating a new session key.'); + logger('Generating a new session key.'); return $this->securedKey; } else { - debugLog('Could not generate session key cookie.'); + logger('Could not generate session key cookie.'); unset($this->securedKey); } } catch (CryptoException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); } return false; diff --git a/lib/SP/Core/Crypt/Session.php b/lib/SP/Core/Crypt/Session.php index 03235005..fb97da8e 100644 --- a/lib/SP/Core/Crypt/Session.php +++ b/lib/SP/Core/Crypt/Session.php @@ -78,7 +78,7 @@ final class Session */ public static function reKey(SessionContext $sessionContext) { - debugLog(__METHOD__); + logger(__METHOD__); $oldSeed = session_id() . $sessionContext->getSidStartTime(); diff --git a/lib/SP/Core/Events/EventDispatcherBase.php b/lib/SP/Core/Events/EventDispatcherBase.php index f63412e5..771a733f 100644 --- a/lib/SP/Core/Events/EventDispatcherBase.php +++ b/lib/SP/Core/Events/EventDispatcherBase.php @@ -60,7 +60,7 @@ abstract class EventDispatcherBase implements EventDispatcherInterface // throw new InvalidClassException(sprintf(__('Observador ya inicializado "%s"'), $observerClass)); } - debugLog('Attach: ' . $observerClass); + logger('Attach: ' . $observerClass); $this->observers[$observerClass] = $observer; } diff --git a/lib/SP/Core/Language.php b/lib/SP/Core/Language.php index 90a95a07..bb9ddb69 100644 --- a/lib/SP/Core/Language.php +++ b/lib/SP/Core/Language.php @@ -213,8 +213,8 @@ final class Language putenv('LANGUAGE=' . $lang); if (!($result = setlocale(LC_ALL, $locales))) { - debugLog('Could not set locales'); - debugLog('Domain path: ' . LOCALES_PATH); + logger('Could not set locales'); + logger('Domain path: ' . LOCALES_PATH); } bindtextdomain('messages', LOCALES_PATH); diff --git a/lib/SP/Core/UI/Theme.php b/lib/SP/Core/UI/Theme.php index 60e10bac..d9e146e3 100644 --- a/lib/SP/Core/UI/Theme.php +++ b/lib/SP/Core/UI/Theme.php @@ -165,7 +165,7 @@ final class Theme implements ThemeInterface try { $this->icons = $this->fileCache->load(self::ICONS_CACHE_FILE); - debugLog('Loaded icons cache'); + logger('Loaded icons cache'); return $this->icons; } catch (FileException $e) { @@ -183,7 +183,7 @@ final class Theme implements ThemeInterface try { $this->fileCache->save(self::ICONS_CACHE_FILE, $this->icons); - debugLog('Saved icons cache'); + logger('Saved icons cache'); } catch (FileException $e) { processException($e); } diff --git a/lib/SP/DataModel/CustomFieldData.php b/lib/SP/DataModel/CustomFieldData.php index 4e597b97..9ae61a1d 100644 --- a/lib/SP/DataModel/CustomFieldData.php +++ b/lib/SP/DataModel/CustomFieldData.php @@ -63,7 +63,7 @@ class CustomFieldData */ public function getId() { - return $this->id; + return (int)$this->id; } /** @@ -71,7 +71,7 @@ class CustomFieldData */ public function setId($id) { - $this->id = $id; + $this->id = (int)$id; } /** diff --git a/lib/SP/DataModel/TrackData.php b/lib/SP/DataModel/TrackData.php index 3d22c0a0..69b13f5c 100644 --- a/lib/SP/DataModel/TrackData.php +++ b/lib/SP/DataModel/TrackData.php @@ -152,7 +152,7 @@ class TrackData extends DataModelBase } elseif (strlen($ip) > 4) { $this->ipv6 = $ip; } elseif ($ip === false) { - debugLog(sprintf('%s : %s', __('IP inválida'), $track_ip)); + logger(sprintf('%s : %s', __('IP inválida'), $track_ip)); throw new InvalidArgumentException(__u('IP inválida'), InvalidArgumentException::ERROR, $track_ip); } diff --git a/lib/SP/Html/DataGrid/DataGridBase.php b/lib/SP/Html/DataGrid/DataGridBase.php index d499ab30..ba3b920f 100644 --- a/lib/SP/Html/DataGrid/DataGridBase.php +++ b/lib/SP/Html/DataGrid/DataGridBase.php @@ -331,7 +331,7 @@ abstract class DataGridBase implements DataGridInterface try { $this->_actionsTemplate = $this->checkTemplate($template); } catch (FileNotFoundException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); } return $this; @@ -360,7 +360,7 @@ abstract class DataGridBase implements DataGridInterface try { $this->_pagerTemplate = $this->checkTemplate($template, $base); } catch (FileNotFoundException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); } return $this; diff --git a/lib/SP/Html/Minify.php b/lib/SP/Html/Minify.php index f4ca0a5b..d2bc9bee 100644 --- a/lib/SP/Html/Minify.php +++ b/lib/SP/Html/Minify.php @@ -123,7 +123,7 @@ final class Minify try { $data .= '/* URL: ' . $file['name'] . ' */' . PHP_EOL . Util::getDataFromUrl($file['name']); } catch (SPException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); } } else { @@ -259,7 +259,7 @@ final class Minify 'md5' => md5_file($filePath) ); } else { - debugLog('File not found: ' . $filePath); + logger('File not found: ' . $filePath); } } @@ -310,7 +310,7 @@ final class Minify 'md5' => md5_file($filePath) ); } else { - debugLog('File not found: ' . $filePath); + logger('File not found: ' . $filePath); } } diff --git a/lib/SP/Http/Request.php b/lib/SP/Http/Request.php index b05309d9..3421341a 100644 --- a/lib/SP/Http/Request.php +++ b/lib/SP/Http/Request.php @@ -236,7 +236,7 @@ final class Request // Desencriptar con la clave RSA if ($clearData === false) { - debugLog('No RSA encrypted data from request'); + logger('No RSA encrypted data from request'); return $encryptedData; } diff --git a/lib/SP/Http/Response.php b/lib/SP/Http/Response.php index 723d9ac9..fe833f98 100644 --- a/lib/SP/Http/Response.php +++ b/lib/SP/Http/Response.php @@ -24,7 +24,6 @@ namespace SP\Http; -use SP\Bootstrap; use SP\Core\Exceptions\SPException; use SP\Util\Json; @@ -100,37 +99,4 @@ final class Response exit(json_encode($data)); } } - - /** - * Devuelve una respuesta de error en formato HTML. - * - * @param $data - */ - public static function printHtmlError($data) - { - $error = '
' . htmlentities($data) . '
'; - - exit($error); - } - - /** - * Internal URL redirection - * - * @param $url - */ - public static function redirectInternal($url) - { - self::redirect(Bootstrap::$WEBURI . '/' . $url); - } - - /** - * URL redirection - * - * @param $url - */ - public static function redirect($url) - { - header('Location: ' . $url); - die(); - } } \ No newline at end of file diff --git a/lib/SP/Mvc/View/Template.php b/lib/SP/Mvc/View/Template.php index 22ecbf94..e12218d5 100644 --- a/lib/SP/Mvc/View/Template.php +++ b/lib/SP/Mvc/View/Template.php @@ -121,7 +121,7 @@ final class Template if (!is_readable($templateFile)) { $msg = sprintf(__('No es posible obtener la plantilla "%s" : %s'), $templateFile, $template); - debugLog($msg); + logger($msg); throw new FileNotFoundException($msg); } @@ -271,7 +271,7 @@ final class Template public function __get($name) { if (!array_key_exists($name, $this->vars)) { - debugLog(sprintf(__('No es posible obtener la variable "%s"'), $name)); + logger(sprintf(__('No es posible obtener la variable "%s"'), $name)); throw new InvalidArgumentException(sprintf(__('No es posible obtener la variable "%s"'), $name)); } @@ -319,7 +319,7 @@ final class Template public function __unset($name) { if (!array_key_exists($name, $this->vars)) { - debugLog(sprintf(__('No es posible destruir la variable "%s"'), $name)); + logger(sprintf(__('No es posible destruir la variable "%s"'), $name)); throw new InvalidArgumentException(sprintf(__('No es posible destruir la variable "%s"'), $name)); } @@ -431,7 +431,7 @@ final class Template */ public function dumpVars() { - debugLog($this->vars); + logger($this->vars); } /** diff --git a/lib/SP/Plugin/PluginManager.php b/lib/SP/Plugin/PluginManager.php index 07c0942b..b79347e2 100644 --- a/lib/SP/Plugin/PluginManager.php +++ b/lib/SP/Plugin/PluginManager.php @@ -163,7 +163,7 @@ class PluginManager foreach ($this->getPlugins() as $name) { if (($plugin = $this->loadPlugin($name)) !== null) { - debugLog('Plugin loaded: ' . $name); + logger('Plugin loaded: ' . $name); $this->eventDispatcher->attach($plugin); } diff --git a/lib/SP/Providers/Log/FileLogHandler.php b/lib/SP/Providers/Log/FileLogHandler.php index 770a5735..b4e5840e 100644 --- a/lib/SP/Providers/Log/FileLogHandler.php +++ b/lib/SP/Providers/Log/FileLogHandler.php @@ -76,9 +76,9 @@ final class FileLogHandler extends Provider implements EventReceiver $this->language->setAppLocales(); if (($e = $event->getSource()) instanceof \Exception) { - debugLog(sprintf(self::MESSAGE_FORMAT, $eventType, __($e->getMessage()))); + logger(sprintf(self::MESSAGE_FORMAT, $eventType, __($e->getMessage()))); } elseif (($eventMessage = $event->getEventMessage()) !== null) { - debugLog(sprintf(self::MESSAGE_FORMAT, $eventType, $eventMessage->composeText(';'))); + logger(sprintf(self::MESSAGE_FORMAT, $eventType, $eventMessage->composeText(';'))); } $this->language->unsetAppLocales(); diff --git a/lib/SP/Providers/Mail/MailProvider.php b/lib/SP/Providers/Mail/MailProvider.php index 3bca5213..d100683d 100644 --- a/lib/SP/Providers/Mail/MailProvider.php +++ b/lib/SP/Providers/Mail/MailProvider.php @@ -75,7 +75,7 @@ final class MailProvider extends Provider if ($this->debug) { $this->mailer->SMTPDebug = 2; $this->mailer->Debugoutput = function ($str, $level) { - debugLog($str); + logger($str); }; } diff --git a/lib/SP/Repositories/Track/TrackRequest.php b/lib/SP/Repositories/Track/TrackRequest.php index c87fea17..ed4558ce 100644 --- a/lib/SP/Repositories/Track/TrackRequest.php +++ b/lib/SP/Repositories/Track/TrackRequest.php @@ -53,7 +53,7 @@ final class TrackRequest } elseif (strlen($ip) > 4) { $this->ipv6 = $ip; } elseif ($ip === false) { - debugLog(sprintf('%s : %s', __('IP inválida'), $address)); + logger(sprintf('%s : %s', __('IP inválida'), $address)); throw new InvalidArgumentException(__u('IP inválida'), InvalidArgumentException::ERROR, $address); } diff --git a/lib/SP/Services/Account/AccountAclService.php b/lib/SP/Services/Account/AccountAclService.php index 3d847ccc..194051d1 100644 --- a/lib/SP/Services/Account/AccountAclService.php +++ b/lib/SP/Services/Account/AccountAclService.php @@ -78,11 +78,11 @@ final class AccountAclService extends Service */ public static function clearAcl($userId) { - debugLog(__FUNCTION__); + logger(__FUNCTION__); try { if (FileUtil::rmdir_recursive(self::ACL_PATH . $userId) === false) { - debugLog(sprintf('Unable to delete %s directory', self::ACL_PATH . $userId)); + logger(sprintf('Unable to delete %s directory', self::ACL_PATH . $userId)); return false; } @@ -121,13 +121,13 @@ final class AccountAclService extends Service || $this->userData->getLastUpdate() > $accountAcl->getTime())); if (!$this->accountAcl->isModified()) { - debugLog('Account ACL HIT'); + logger('Account ACL HIT'); return $accountAcl; } } - debugLog('Account ACL MISS'); + logger('Account ACL MISS'); $this->accountAcl->setAccountId($accountAclDto->getAccountId()); @@ -169,7 +169,7 @@ final class AccountAclService extends Service return $acl; } } catch (FileException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); } return null; diff --git a/lib/SP/Services/Account/AccountCryptService.php b/lib/SP/Services/Account/AccountCryptService.php index a883f321..dba63b8a 100644 --- a/lib/SP/Services/Account/AccountCryptService.php +++ b/lib/SP/Services/Account/AccountCryptService.php @@ -142,9 +142,9 @@ final class AccountCryptService extends Service TaskFactory::update($taskId, $taskMessage); - debugLog($taskMessage->composeText()); + logger($taskMessage->composeText()); } else { - debugLog( + logger( sprintf(__('Cuentas actualizadas: %d / %d - %d%% - ETA: %ds (%.2f/s)'), $counter, $numAccounts, diff --git a/lib/SP/Services/Account/AccountSearchService.php b/lib/SP/Services/Account/AccountSearchService.php index 7c5c27f7..eab2bdcd 100644 --- a/lib/SP/Services/Account/AccountSearchService.php +++ b/lib/SP/Services/Account/AccountSearchService.php @@ -376,7 +376,7 @@ final class AccountSearchService extends Service try { $this->fileCache->save(self::COLORS_CACHE_FILE, $this->accountColor); - debugLog('Saved accounts color cache'); + logger('Saved accounts color cache'); return $this->accountColor[$id]; } catch (FileException $e) { @@ -412,7 +412,7 @@ final class AccountSearchService extends Service try { $this->accountColor = $this->fileCache->load(self::COLORS_CACHE_FILE); - debugLog('Loaded accounts color cache'); + logger('Loaded accounts color cache'); } catch (FileException $e) { processException($e); } diff --git a/lib/SP/Services/Account/AccountService.php b/lib/SP/Services/Account/AccountService.php index c9a3f0cc..dc64c551 100644 --- a/lib/SP/Services/Account/AccountService.php +++ b/lib/SP/Services/Account/AccountService.php @@ -267,7 +267,7 @@ final class AccountService extends Service implements AccountServiceInterface $this->accountToTagRepository->add($accountRequest); } } catch (SPException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); } } diff --git a/lib/SP/Services/Crypt/SecureSessionService.php b/lib/SP/Services/Crypt/SecureSessionService.php index f7f203c9..8df0c05f 100644 --- a/lib/SP/Services/Crypt/SecureSessionService.php +++ b/lib/SP/Services/Crypt/SecureSessionService.php @@ -77,7 +77,7 @@ final class SecureSessionService extends Service try { if ($this->fileCache->isExpired($this->getFileNameFromCookie(), self::CACHE_EXPIRE_TIME)) { - debugLog('Session key expired or does not exist.'); + logger('Session key expired or does not exist.'); return $this->saveKey(); } @@ -126,7 +126,7 @@ final class SecureSessionService extends Service $securedKey = Key::createNewRandomKey(); $this->fileCache->save($this->getFileNameFromCookie(), (new Vault())->saveData($securedKey->saveToAsciiSafeString(), $this->getCypher())); - debugLog('Saved session key.'); + logger('Saved session key.'); return $securedKey; } catch (\Exception $e) { diff --git a/lib/SP/Services/Export/XmlVerifyService.php b/lib/SP/Services/Export/XmlVerifyService.php index cdbbe3a1..28960dab 100644 --- a/lib/SP/Services/Export/XmlVerifyService.php +++ b/lib/SP/Services/Export/XmlVerifyService.php @@ -101,7 +101,7 @@ final class XmlVerifyService extends Service if ($this->xml->loadXML((new FileHandler($this->xmlFile))->read()) === false) { foreach (libxml_get_errors() as $error) { - debugLog(__METHOD__ . ' - ' . $error->message); + logger(__METHOD__ . ' - ' . $error->message); } throw new ServiceException( diff --git a/lib/SP/Services/Import/FileImport.php b/lib/SP/Services/Import/FileImport.php index 47643ab8..474b3669 100644 --- a/lib/SP/Services/Import/FileImport.php +++ b/lib/SP/Services/Import/FileImport.php @@ -110,7 +110,7 @@ final class FileImport if (!file_exists($fileData['tmp_name']) || !is_readable($fileData['tmp_name'])) { // Registramos el máximo tamaño permitido por PHP - debugLog('Max. upload size: ' . Util::getMaxUpload()); + logger('Max. upload size: ' . Util::getMaxUpload()); throw new FileException( __u('Error interno al leer el archivo'), diff --git a/lib/SP/Services/Import/XmlFileImport.php b/lib/SP/Services/Import/XmlFileImport.php index c88f4be9..9a34b0f8 100644 --- a/lib/SP/Services/Import/XmlFileImport.php +++ b/lib/SP/Services/Import/XmlFileImport.php @@ -72,7 +72,7 @@ final class XmlFileImport if ($this->xmlDOM->loadXML($this->fileImport->readFileToString()) === false) { foreach (libxml_get_errors() as $error) { - debugLog(__METHOD__ . ' - ' . $error->message); + logger(__METHOD__ . ' - ' . $error->message); } throw new ImportException( diff --git a/lib/SP/Services/Install/MySQL.php b/lib/SP/Services/Install/MySQL.php index 88e1c7ac..16e6a51a 100644 --- a/lib/SP/Services/Install/MySQL.php +++ b/lib/SP/Services/Install/MySQL.php @@ -158,7 +158,7 @@ final class MySQL implements DatabaseSetupInterface return; } - debugLog('Creating DB user'); + logger('Creating DB user'); try { $query = 'CREATE USER %s@`%s` IDENTIFIED BY %s'; @@ -289,7 +289,7 @@ final class MySQL implements DatabaseSetupInterface } } - debugLog('Rollback'); + logger('Rollback'); } /** @@ -330,7 +330,7 @@ final class MySQL implements DatabaseSetupInterface } catch (PDOException $e) { processException($e); - debugLog('Query: ' . $query); + logger('Query: ' . $query); $this->rollback(); diff --git a/lib/SP/Services/Service.php b/lib/SP/Services/Service.php index f1427c02..0c469b6c 100644 --- a/lib/SP/Services/Service.php +++ b/lib/SP/Services/Service.php @@ -106,7 +106,7 @@ abstract class Service } catch (\Exception $e) { $database->rollbackTransaction(); - debugLog('Transaction:Rollback'); + logger('Transaction:Rollback'); $this->eventDispatcher->notifyEvent('database.rollback', new Event($this, EventMessage::factory() @@ -139,7 +139,7 @@ abstract class Service return $key; } catch (CryptoException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); throw new ServiceException(__u('Error ol obtener la clave maestra del contexto')); } @@ -159,11 +159,11 @@ abstract class Service $this->context->setTrasientKey('_masterpass', $masterPass); } } catch (ContextException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); throw new ServiceException(__u('Error ol establecer la clave maestra en el contexto')); } catch (CryptoException $e) { - debugLog($e->getMessage()); + logger($e->getMessage()); throw new ServiceException(__u('Error ol establecer la clave maestra en el contexto')); } diff --git a/lib/SP/Services/Task/Task.php b/lib/SP/Services/Task/Task.php index 16800862..bcf7b6e1 100644 --- a/lib/SP/Services/Task/Task.php +++ b/lib/SP/Services/Task/Task.php @@ -232,7 +232,7 @@ final class Task */ public function deregister() { - debugLog('Deregister Task: ' . $this->name); + logger('Deregister Task: ' . $this->name); return unlink($this->fileTask); } @@ -298,7 +298,7 @@ final class Task */ public function register($lockSession = true) { - debugLog('Register Task: ' . $this->name); + logger('Register Task: ' . $this->name); file_put_contents($this->fileTask, serialize($this)); diff --git a/lib/SP/Services/Task/TaskService.php b/lib/SP/Services/Task/TaskService.php index dbefc8d6..200dc8be 100644 --- a/lib/SP/Services/Task/TaskService.php +++ b/lib/SP/Services/Task/TaskService.php @@ -87,11 +87,11 @@ final class TaskService extends Service while (!$this->checkTaskRegistered() || !$this->checkTaskFile()) { if ($count >= self::STARTUP_WAIT_COUNT || !file_exists($this->lockFile)) { - debugLog('Aborting ...'); + logger('Aborting ...'); die(1); } else { - debugLog(sprintf('Waiting for task "%s" (%ds) ...', $taskId, (self::STARTUP_WAIT_COUNT - $count) * self::STARTUP_WAIT_TIME)); + logger(sprintf('Waiting for task "%s" (%ds) ...', $taskId, (self::STARTUP_WAIT_COUNT - $count) * self::STARTUP_WAIT_TIME)); $count++; sleep(self::STARTUP_WAIT_TIME); @@ -143,7 +143,7 @@ final class TaskService extends Service protected function checkTaskRegistered() { if (is_object($this->task)) { - debugLog('Task detected: ' . $this->task->getTaskId()); + logger('Task detected: ' . $this->task->getTaskId()); return true; } @@ -174,7 +174,7 @@ final class TaskService extends Service */ protected function readTaskStatus() { - debugLog('Tracking task: ' . $this->task->getTaskId()); + logger('Tracking task: ' . $this->task->getTaskId()); $id = 0; $failCount = 0; @@ -190,7 +190,7 @@ final class TaskService extends Service $this->sendMessage($id, $content); $id++; } else { - debugLog($taskMessage->composeJson()); + logger($taskMessage->composeJson()); $this->sendMessage($id, $taskMessage->composeJson()); $failCount++; diff --git a/lib/SP/Services/Track/TrackService.php b/lib/SP/Services/Track/TrackService.php index 2fcbfc13..ff496e8f 100644 --- a/lib/SP/Services/Track/TrackService.php +++ b/lib/SP/Services/Track/TrackService.php @@ -135,7 +135,7 @@ final class TrackService extends Service ->addDetail(__u('Segundos'), self::TIME_SLEEP * $attempts)) ); - debugLog('Tracking delay: ' . self::TIME_SLEEP * $attempts . 's'); + logger('Tracking delay: ' . self::TIME_SLEEP * $attempts . 's'); sleep(self::TIME_SLEEP * $attempts); diff --git a/lib/SP/Services/Upgrade/UpgradeAppService.php b/lib/SP/Services/Upgrade/UpgradeAppService.php index 0f9da9f0..6fdc43b2 100644 --- a/lib/SP/Services/Upgrade/UpgradeAppService.php +++ b/lib/SP/Services/Upgrade/UpgradeAppService.php @@ -72,7 +72,7 @@ final class UpgradeAppService extends Service implements UpgradeInterface ); } - debugLog('APP Upgrade: ' . $appVersion); + logger('APP Upgrade: ' . $appVersion); $configData->setConfigVersion($appVersion); diff --git a/lib/SP/Services/Upgrade/UpgradeCustomFieldData.php b/lib/SP/Services/Upgrade/UpgradeCustomFieldData.php index 091bde58..76a5dbf2 100644 --- a/lib/SP/Services/Upgrade/UpgradeCustomFieldData.php +++ b/lib/SP/Services/Upgrade/UpgradeCustomFieldData.php @@ -28,7 +28,6 @@ namespace SP\Services\Upgrade; use SP\Core\Acl\ActionsInterface; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; -use SP\Core\Exceptions\SPException; use SP\Services\CustomField\CustomFieldService; use SP\Services\Service; use SP\Storage\Database\Database; @@ -66,11 +65,9 @@ class UpgradeCustomFieldData extends Service foreach ($customFieldService->getAll() as $item) { $queryData = new QueryData(); $queryData->setQuery('UPDATE CustomFieldData SET moduleId = ? WHERE id = ? LIMIT 1'); - $queryData->setParams([$this->moduleMapper($item->getModuleId())]); + $queryData->setParams([$this->moduleMapper($item->getModuleId()), $item->getId()]); - if ($this->db->doQuery($queryData)->getNumRows() === 0) { - throw new SPException(__u('Error al actualizar los datos del campo personalizado')); - } + $this->db->doQuery($queryData); $this->eventDispatcher->notifyEvent('upgrade.customField.process', new Event($this, EventMessage::factory() diff --git a/lib/SP/Services/Upgrade/UpgradeDatabaseService.php b/lib/SP/Services/Upgrade/UpgradeDatabaseService.php index 5f335479..b8cbe215 100644 --- a/lib/SP/Services/Upgrade/UpgradeDatabaseService.php +++ b/lib/SP/Services/Upgrade/UpgradeDatabaseService.php @@ -98,7 +98,7 @@ final class UpgradeDatabaseService extends Service implements UpgradeInterface ); } - debugLog('DB Upgrade: ' . $upgradeVersion); + logger('DB Upgrade: ' . $upgradeVersion); $configData->setDatabaseVersion($upgradeVersion); @@ -152,7 +152,7 @@ final class UpgradeDatabaseService extends Service implements UpgradeInterface $queries = $this->getQueriesFromFile($version); if (count($queries) === 0) { - debugLog(__('No es necesario actualizar la Base de Datos.')); + logger(__('No es necesario actualizar la Base de Datos.')); $this->eventDispatcher->notifyEvent('upgrade.db.process', new Event($this, EventMessage::factory() @@ -175,7 +175,7 @@ final class UpgradeDatabaseService extends Service implements UpgradeInterface $this->db->doQuery($queryData); } catch (\Exception $e) { processException($e); - debugLog('SQL: ' . $query); + logger('SQL: ' . $query); $this->eventDispatcher->notifyEvent('exception', new Event($this, EventMessage::factory() diff --git a/lib/SP/Storage/Database/Database.php b/lib/SP/Storage/Database/Database.php index 934bf90c..893639a1 100644 --- a/lib/SP/Storage/Database/Database.php +++ b/lib/SP/Storage/Database/Database.php @@ -172,9 +172,6 @@ final class Database implements DatabaseInterface */ public function doQuery(QueryData $queryData, $getRawData = false) { - // Limpiar valores de caché -// $this->lastResult = []; - /** @var PDOStatement $stmt */ $stmt = $this->prepareQueryData($queryData); @@ -334,7 +331,7 @@ final class Database implements DatabaseInterface return $result; } else { - debugLog('beginTransaction: already in transaction'); + logger('beginTransaction: already in transaction'); return true; } diff --git a/lib/SP/Storage/Database/DatabaseConnectionData.php b/lib/SP/Storage/Database/DatabaseConnectionData.php index b6a4116f..29b0cb46 100644 --- a/lib/SP/Storage/Database/DatabaseConnectionData.php +++ b/lib/SP/Storage/Database/DatabaseConnectionData.php @@ -81,7 +81,7 @@ final class DatabaseConnectionData */ public function refreshFromConfig(ConfigData $configData) { - debugLog('Refresh DB connection data'); + logger('Refresh DB connection data'); return $this->setDbHost($configData->getDbHost()) ->setDbName($configData->getDbName()) diff --git a/lib/SP/Storage/Database/DatabaseUtil.php b/lib/SP/Storage/Database/DatabaseUtil.php index 2e3b3147..eaf96a78 100644 --- a/lib/SP/Storage/Database/DatabaseUtil.php +++ b/lib/SP/Storage/Database/DatabaseUtil.php @@ -111,7 +111,7 @@ final class DatabaseUtil } catch (\Exception $e) { processException($e); - debugLog($e->getMessage()); + logger($e->getMessage()); } return $dbinfo; diff --git a/lib/SP/Storage/Database/MySQLHandler.php b/lib/SP/Storage/Database/MySQLHandler.php index 73e0d273..851f7f01 100644 --- a/lib/SP/Storage/Database/MySQLHandler.php +++ b/lib/SP/Storage/Database/MySQLHandler.php @@ -67,6 +67,7 @@ final class MySQLHandler implements DBStorageInterface /** * Devuelve el estado de conexión a la BBDD + * * OK -> 0 * KO -> 1 * @@ -130,27 +131,23 @@ final class MySQLHandler implements DBStorageInterface */ public function getConnectionUri() { + $dsn = ['charset=utf8']; + if (empty($this->connectionData->getDbSocket())) { - $dsn = 'mysql:host=' . $this->connectionData->getDbHost(); + $dsn[] = 'host=' . $this->connectionData->getDbHost(); if (null !== $this->connectionData->getDbPort()) { - $dsn .= ';port=' . $this->connectionData->getDbPort(); + $dsn[] = 'port=' . $this->connectionData->getDbPort(); } - - if (null !== $this->connectionData->getDbName()) { - $dsn .= ';dbname=' . $this->connectionData->getDbName(); - } - - return $dsn . ';charset=utf8'; + } else { + $dsn[] = 'unix_socket=' . $this->connectionData->getDbSocket(); } - $dsn = 'mysql:unix_socket=' . $this->connectionData->getDbSocket(); - if (!empty($this->connectionData->getDbName())) { - $dsn .= ';dbname=' . $this->connectionData->getDbName(); + $dsn[] = 'dbname=' . $this->connectionData->getDbName(); } - return $dsn . ';charset=utf8'; + return 'mysql:' . implode(';', $dsn); } /** diff --git a/lib/SP/Util/ImageUtil.php b/lib/SP/Util/ImageUtil.php index bec25fea..5a6b89ed 100644 --- a/lib/SP/Util/ImageUtil.php +++ b/lib/SP/Util/ImageUtil.php @@ -45,7 +45,7 @@ final class ImageUtil public static function convertText($text) { if (!Checks::gdIsAvailable()) { - debugLog(sprintf(__('Extensión \'%s\' no cargada'), 'GD')); + logger(sprintf(__('Extensión \'%s\' no cargada'), 'GD')); return false; } @@ -96,7 +96,7 @@ final class ImageUtil public static function createThumbnail($image) { if (!Checks::gdIsAvailable()) { - debugLog(sprintf(__('Extensión \'%s\' no cargada'), 'GD')); + logger(sprintf(__('Extensión \'%s\' no cargada'), 'GD')); return false; } diff --git a/lib/SP/Util/Util.php b/lib/SP/Util/Util.php index 33421cb1..55f33c5b 100644 --- a/lib/SP/Util/Util.php +++ b/lib/SP/Util/Util.php @@ -177,7 +177,7 @@ final class Util $ConfigData = Bootstrap::getContainer()->get(ConfigData::class); if (!Checks::curlIsAvailable()) { - debugLog(sprintf(__('Extensión \'%s\' no cargada'), 'CURL')); + logger(sprintf(__('Extensión \'%s\' no cargada'), 'CURL')); throw new SPException(sprintf(__('Extensión \'%s\' no cargada'), 'CURL')); } diff --git a/schemas/30018072302.sql b/schemas/30018072302.sql index fe1efa06..86d26c10 100644 --- a/schemas/30018072302.sql +++ b/schemas/30018072302.sql @@ -35,6 +35,8 @@ ALTER TABLE User ALTER TABLE UserPassRecover MODIFY hash varbinary(255) NOT NULL $$ +DELETE FROM Notification WHERE userId NOT IN (SELECT id FROM User) $$ + ALTER TABLE Notification ADD CONSTRAINT fk_Notificationt_userId FOREIGN KEY (userId) REFERENCES User (id) ON DELETE CASCADE ON UPDATE CASCADE $$ \ No newline at end of file