Skip to content

Commit

Permalink
Remove logs tags
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rgan01 committed Jan 20, 2025
1 parent 7a342a1 commit eb6e585
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion classes/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Update/UpdateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Update/UpdateModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions classes/UpgradePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
),
];
}
Expand Down Expand Up @@ -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.'),
Expand Down
4 changes: 2 additions & 2 deletions classes/UpgradeTools/CacheCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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] . '`']));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion classes/UpgradeTools/Module/ModuleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions classes/UpgradeTools/Module/ModuleMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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');
}

/**
Expand All @@ -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"],
];
}
}
8 changes: 4 additions & 4 deletions tests/unit/UpgradeTools/Module/ModuleMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function testRunMigrationWithBadUpgradeMethodName()
$this->moduleMigration->needMigration($moduleMigrationContext);

$this->expectException(\PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException::class);
$this->expectExceptionMessage('[WARNING] Method mymodule_upgrade_module_1_2_0 does not exist. Module mymodule disabled.');
$this->expectExceptionMessage('Method mymodule_upgrade_module_1_2_0 does not exist. Module mymodule disabled.');

$this->moduleMigration->runMigration($moduleMigrationContext);
}
Expand All @@ -220,7 +220,7 @@ public function testRunMigrationWithUpgradeMethodReturnFalse()
$this->moduleMigration->needMigration($moduleMigrationContext);

$this->expectException(\PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException::class);
$this->expectExceptionMessage('[WARNING] Migration failed while running the file upgrade-1.2.1.php. Module mymodule disabled.');
$this->expectExceptionMessage('Migration failed while running the file upgrade-1.2.1.php. Module mymodule disabled.');

$this->moduleMigration->runMigration($moduleMigrationContext);
}
Expand All @@ -236,7 +236,7 @@ public function testRunMigrationWithUpgradeMethodThrowError()
$this->moduleMigration->needMigration($moduleMigrationContext);

$this->expectException(\PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException::class);
$this->expectExceptionMessage('[WARNING] Unexpected error when trying to upgrade module mymodule. Module mymodule disabled.');
$this->expectExceptionMessage('Unexpected error when trying to upgrade module mymodule. Module mymodule disabled.');

$this->moduleMigration->runMigration($moduleMigrationContext);
}
Expand All @@ -262,7 +262,7 @@ public function testSaveVersionInDbThrowErrorThenFail()
$moduleMigrationContext = new ModuleMigrationContext($mymodule, $dbVersion);

$this->expectException(\PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException::class);
$this->expectExceptionMessage('[WARNING] Module mymodule version could not be updated. Database might be unavailable.');
$this->expectExceptionMessage('Module mymodule version could not be updated. Database might be unavailable.');

$this->assertNull($this->moduleMigration->saveVersionInDb($moduleMigrationContext));
}
Expand Down

0 comments on commit eb6e585

Please sign in to comment.