From 919f44aaa49d6a72b0dc3297169e0d35a26aafe8 Mon Sep 17 00:00:00 2001 From: morgan Date: Mon, 20 Jan 2025 10:59:33 +0100 Subject: [PATCH] Remove logs tags --- classes/ErrorHandler.php | 2 +- classes/Task/Update/UpdateDatabase.php | 2 +- classes/Task/Update/UpdateModules.php | 2 +- classes/UpgradePage.php | 4 ++-- classes/UpgradeTools/CacheCleaner.php | 4 ++-- classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php | 2 +- classes/UpgradeTools/Module/ModuleAdapter.php | 2 +- classes/UpgradeTools/Module/ModuleMigration.php | 10 +++++----- tests/unit/ErrorHandlerTest.php | 8 ++++---- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/classes/ErrorHandler.php b/classes/ErrorHandler.php index c1f184676..202f75dc1 100644 --- a/classes/ErrorHandler.php +++ b/classes/ErrorHandler.php @@ -140,7 +140,7 @@ protected function report(string $file, int $line, int $type, string $message, ? if ($type >= Logger::CRITICAL) { http_response_code(500); } - $log = "[INTERNAL] $file line $line - $message"; + $log = "$file line $line - $message"; if (!empty($trace)) { $log .= PHP_EOL . $trace; } diff --git a/classes/Task/Update/UpdateDatabase.php b/classes/Task/Update/UpdateDatabase.php index eac2855bd..f43562837 100644 --- a/classes/Task/Update/UpdateDatabase.php +++ b/classes/Task/Update/UpdateDatabase.php @@ -170,7 +170,7 @@ protected function checkVersionIsNewer(): void $versionCompare = version_compare($destinationVersion, $currentVersion); if ($versionCompare === -1) { - throw new UpgradeException($this->container->getTranslator()->trans('[ERROR] Version to install is too old.') . ' ' . $this->container->getTranslator()->trans('Current version: %oldversion%. Version to install: %newversion%.', ['%oldversion%' => $currentVersion, '%newversion%' => $destinationVersion])); + throw new UpgradeException($this->container->getTranslator()->trans('Version to install is too old. Current version: %oldversion%. Version to install: %newversion%.', ['%oldversion%' => $currentVersion, '%newversion%' => $destinationVersion])); } elseif ($versionCompare === 0) { throw new UpgradeException($this->container->getTranslator()->trans('You already have the %s version.', [$destinationVersion])); } diff --git a/classes/Task/Update/UpdateModules.php b/classes/Task/Update/UpdateModules.php index 8a5cdcee8..a1a6312e5 100644 --- a/classes/Task/Update/UpdateModules.php +++ b/classes/Task/Update/UpdateModules.php @@ -92,7 +92,7 @@ public function run(): int $module = \Module::getInstanceByName($moduleInfos['name']); if (!($module instanceof \Module)) { - throw (new UpgradeException($this->translator->trans('[WARNING] Error when trying to retrieve module %s instance.', [$moduleInfos['name']])))->setSeverity(UpgradeException::SEVERITY_WARNING); + throw (new UpgradeException($this->translator->trans('Error when trying to retrieve module %s instance.', [$moduleInfos['name']])))->setSeverity(UpgradeException::SEVERITY_WARNING); } $moduleMigrationContext = new ModuleMigrationContext($module, $dbVersion); diff --git a/classes/UpgradePage.php b/classes/UpgradePage.php index 47882397f..0fb63b77c 100644 --- a/classes/UpgradePage.php +++ b/classes/UpgradePage.php @@ -246,7 +246,7 @@ private function getErrorMessage(): array if (!file_exists($this->autoupgradePath . DIRECTORY_SEPARATOR . 'ajax-upgradetab.php')) { return [ 'message' => $translator->trans( - '[TECHNICAL ERROR] ajax-upgradetab.php is missing. Please reinstall or reset the module.' + 'ajax-upgradetab.php is missing. Please reinstall or reset the module.' ), ]; } @@ -296,7 +296,7 @@ private function getJsParams(string $ajaxResult): array 'processCancelledCheckForRestore' => $translator->trans('Operation canceled. Checking for restoration...'), 'confirmRestoreBackup' => $translator->trans('Do you want to restore %s?', [$this->backupName]), 'processCancelledWithError' => $translator->trans('Operation canceled. An error happened.'), - 'missingAjaxUpgradeTab' => $translator->trans('[TECHNICAL ERROR] ajax-upgradetab.php is missing. Please reinstall the module.'), + 'missingAjaxUpgradeTab' => $translator->trans('ajax-upgradetab.php is missing. Please reinstall the module.'), 'clickToRefreshAndUseNewConfiguration' => $translator->trans('Click to refresh the page and use the new configuration'), 'errorDetectedDuring' => $translator->trans('Error detected during'), 'downloadTimeout' => $translator->trans('The request exceeded the max_time_limit. Please change your server configuration.'), diff --git a/classes/UpgradeTools/CacheCleaner.php b/classes/UpgradeTools/CacheCleaner.php index f2d35cb73..5154f6053 100644 --- a/classes/UpgradeTools/CacheCleaner.php +++ b/classes/UpgradeTools/CacheCleaner.php @@ -74,7 +74,7 @@ public function cleanFolders(): void foreach ($dirsToClean as $dir) { if (!file_exists($dir)) { - $this->logger->debug($this->container->getTranslator()->trans('[SKIP] directory "%s" does not exist and cannot be emptied.', [str_replace($this->container->getProperty(UpgradeContainer::PS_ROOT_PATH), '', $dir)])); + $this->logger->debug($this->container->getTranslator()->trans('Directory "%s" does not exist and cannot be emptied.', [str_replace($this->container->getProperty(UpgradeContainer::PS_ROOT_PATH), '', $dir)])); continue; } foreach (scandir($dir) as $file) { @@ -87,7 +87,7 @@ public function cleanFolders(): void } elseif (is_dir($dir . $file . DIRECTORY_SEPARATOR)) { FilesystemAdapter::deleteDirectory($dir . $file . DIRECTORY_SEPARATOR); } - $this->logger->debug($this->container->getTranslator()->trans('[CLEANING CACHE] File %s removed', [$file])); + $this->logger->debug($this->container->getTranslator()->trans('File %s removed', [$file])); } } } diff --git a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php index 2c9130e6c..92b6b5a4e 100644 --- a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php +++ b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php @@ -489,7 +489,7 @@ protected function runSqlQuery(string $upgrade_file, string $query): void if (!empty($matches[1])) { $drop = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . $matches[1] . '`;'; if ($this->db->execute($drop, false)) { - $this->logger->debug($this->container->getTranslator()->trans('[DROP] SQL %s table has been dropped.', ['`' . _DB_PREFIX_ . $matches[1] . '`'])); + $this->logger->debug($this->container->getTranslator()->trans('SQL %s table has been dropped.', ['`' . _DB_PREFIX_ . $matches[1] . '`'])); } } } diff --git a/classes/UpgradeTools/Module/ModuleAdapter.php b/classes/UpgradeTools/Module/ModuleAdapter.php index 149880281..449422ee0 100644 --- a/classes/UpgradeTools/Module/ModuleAdapter.php +++ b/classes/UpgradeTools/Module/ModuleAdapter.php @@ -139,7 +139,7 @@ public function listModulesPresentInFolderAndInstalled(): array $dir = $this->modulesPath; if (!is_dir($dir)) { - throw (new UpgradeException($this->translator->trans('[ERROR] %dir% does not exist or is not a directory.', ['%dir%' => $dir])))->addQuickInfo($this->translator->trans('[ERROR] %s does not exist or is not a directory.', [$dir]))->setSeverity(UpgradeException::SEVERITY_ERROR); + throw (new UpgradeException($this->translator->trans('%dir% does not exist or is not a directory.', ['%dir%' => $dir])))->addQuickInfo($this->translator->trans('%s does not exist or is not a directory.', [$dir]))->setSeverity(UpgradeException::SEVERITY_ERROR); } foreach ($this->getInstalledVersionOfModules() as $moduleInstalled) { diff --git a/classes/UpgradeTools/Module/ModuleMigration.php b/classes/UpgradeTools/Module/ModuleMigration.php index 26c6220ce..88fb7ba59 100644 --- a/classes/UpgradeTools/Module/ModuleMigration.php +++ b/classes/UpgradeTools/Module/ModuleMigration.php @@ -111,14 +111,14 @@ public function runMigration(ModuleMigrationContext $moduleMigrationContext): vo try { if (!$this->loadAndCallFunction($migrationFilePath, $methodName, $moduleMigrationContext)) { - throw (new UpgradeException($this->translator->trans('[WARNING] Migration failed while running the file %s. Module %s disabled.', [basename($migrationFilePath), $moduleMigrationContext->getModuleName()])))->setSeverity(UpgradeException::SEVERITY_WARNING); + throw (new UpgradeException($this->translator->trans('Migration failed while running the file %s. Module %s disabled.', [basename($migrationFilePath), $moduleMigrationContext->getModuleName()])))->setSeverity(UpgradeException::SEVERITY_WARNING); } } catch (UpgradeException $e) { $moduleMigrationContext->getModuleInstance()->disable(); throw $e; } catch (Throwable $t) { $moduleMigrationContext->getModuleInstance()->disable(); - throw (new UpgradeException($this->translator->trans('[WARNING] Unexpected error when trying to upgrade module %s. Module %s disabled.', [$moduleMigrationContext->getModuleName(), $moduleMigrationContext->getModuleName()]), 0, $t))->setSeverity(UpgradeException::SEVERITY_WARNING); + throw (new UpgradeException($this->translator->trans('Unexpected error when trying to upgrade module %s. Module %s disabled.', [$moduleMigrationContext->getModuleName(), $moduleMigrationContext->getModuleName()]), 0, $t))->setSeverity(UpgradeException::SEVERITY_WARNING); } } } @@ -129,7 +129,7 @@ public function runMigration(ModuleMigrationContext $moduleMigrationContext): vo public function saveVersionInDb(ModuleMigrationContext $moduleMigrationContext): void { if (!\Module::upgradeModuleVersion($moduleMigrationContext->getModuleName(), $moduleMigrationContext->getLocalVersion())) { - throw (new UpgradeException($this->translator->trans('[WARNING] Module %s version could not be updated. Database might be unavailable.', [$moduleMigrationContext->getModuleName()]), 0))->setSeverity(UpgradeException::SEVERITY_WARNING); + throw (new UpgradeException($this->translator->trans('Module %s version could not be updated. Database might be unavailable.', [$moduleMigrationContext->getModuleName()]), 0))->setSeverity(UpgradeException::SEVERITY_WARNING); } } @@ -157,12 +157,12 @@ private function loadAndCallFunction(string $filePath, string $methodName, Modul $pushedFileContents = file_put_contents($sandboxedFilePath, str_replace($methodName, $uniqueMethodName, file_get_contents($filePath))); if ($pushedFileContents === false) { - throw (new UpgradeException($this->translator->trans('[WARNING] Could not write temporary file %s.', [$sandboxedFilePath])))->setSeverity(UpgradeException::SEVERITY_WARNING); + throw (new UpgradeException($this->translator->trans('Could not write temporary file %s.', [$sandboxedFilePath])))->setSeverity(UpgradeException::SEVERITY_WARNING); } require_once $sandboxedFilePath; if (!function_exists($uniqueMethodName)) { - throw (new UpgradeException($this->translator->trans('[WARNING] Method %s does not exist. Module %s disabled.', [$uniqueMethodName, $moduleMigrationContext->getModuleName()])))->setSeverity(UpgradeException::SEVERITY_WARNING); + throw (new UpgradeException($this->translator->trans('Method %s does not exist. Module %s disabled.', [$uniqueMethodName, $moduleMigrationContext->getModuleName()])))->setSeverity(UpgradeException::SEVERITY_WARNING); } return call_user_func($uniqueMethodName, $moduleMigrationContext->getModuleInstance()); diff --git a/tests/unit/ErrorHandlerTest.php b/tests/unit/ErrorHandlerTest.php index b08fd3091..f32164cab 100644 --- a/tests/unit/ErrorHandlerTest.php +++ b/tests/unit/ErrorHandlerTest.php @@ -60,7 +60,7 @@ public function testCheckExceptionAndContent() $errors = $this->logger->getErrors(); $this->assertCount(1, $errors); - $this->assertContains('[INTERNAL] ' . __FILE__ . ' line ' . $line . ' - Exception: ERMAGHERD', end($errors)); + $this->assertContains( __FILE__ . ' line ' . $line . ' - Exception: ERMAGHERD', end($errors)); } public function testWarningInErrorHandler() @@ -70,7 +70,7 @@ public function testWarningInErrorHandler() $msgs = $this->logger->getInfos(); $this->assertCount(0, $this->logger->getErrors()); $this->assertCount(1, $msgs); - $this->assertSame(end($msgs), 'WARNING - [INTERNAL] ' . __FILE__ . ' line ' . $line . ' - Trololo'); + $this->assertSame(end($msgs), 'WARNING - ' . __FILE__ . ' line ' . $line . ' - Trololo'); } /** @@ -84,8 +84,8 @@ public function testGeneratedJsonLog($log) public function logProvider() { return [ - ["[INTERNAL] /var/www/html/modules/autoupgrade/classes/Task/Upgrade/BackupFiles.php line 55 - Class 'PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeContainer' not found"], - ["[INTERNAL] /var/www/html/modules/autoupgrade/classes/Task/Upgrade/BackupDb.php line 105 - Can't use method return value in write context"], + ["/var/www/html/modules/autoupgrade/classes/Task/Upgrade/BackupFiles.php line 55 - Class 'PrestaShop\Module\AutoUpgrade\Task\Upgrade\UpgradeContainer' not found"], + ["/var/www/html/modules/autoupgrade/classes/Task/Upgrade/BackupDb.php line 105 - Can't use method return value in write context"], ]; } }