Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LOG] Update some error logs to warning #1138

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion classes/DbWrapper.php → classes/Database/DbWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\AutoUpgrade;
namespace PrestaShop\Module\AutoUpgrade\Database;

use Db;
use mysqli_result;
Expand Down
13 changes: 13 additions & 0 deletions classes/Database/MysqlErrorCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace PrestaShop\Module\AutoUpgrade\Database;

class MysqlErrorCode
{
public const TABLE_ALREADY_EXISTS = '1050';
public const UNKNOWN_COLUMN_IN_FIELD_LIST = '1054';
public const DUPLICATE_COLUMN_NAME = '1060';
public const DUPLICATE_KEY = '1061';
public const DUPLICATE_ENTRY = '1062';
public const CANNOT_DROP_KEY = '1091';
}
18 changes: 5 additions & 13 deletions classes/State/UpdateState.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ class UpdateState extends AbstractState

/**
* @var bool Determining if all steps went totally successfully
*
* @deprecated To remove with the old UI
*/
protected $warning_exists = false;
protected $warningDetected = false;

protected function getFileNameForPersistentStorage(): string
{
Expand Down Expand Up @@ -115,20 +113,14 @@ public function setInstalledLanguagesIso(array $installedLanguagesIso): self
return $this;
}

/**
* @deprecated Unused on the UIs from v7
*/
public function getWarningExists(): bool
public function isWarningDetected(): bool
{
return $this->warning_exists;
return $this->warningDetected;
}

/**
* @deprecated Unused on the UIs from v7
*/
public function setWarningExists(bool $warning_exists): self
public function setWarningDetected(bool $warningDetected): self
{
$this->warning_exists = $warning_exists;
$this->warningDetected = $warningDetected;
$this->save();

return $this;
Expand Down
2 changes: 1 addition & 1 deletion classes/Task/Update/UpdateComplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function run(): int

$destinationVersion = $state->getDestinationVersion();

$this->logger->info($state->getWarningExists() ?
$this->logger->info($state->isWarningDetected() ?
$this->translator->trans('Shop updated to %s, but some warnings have been found.', [$destinationVersion]) :
$this->translator->trans('Shop updated to %s. Congratulations! You can now reactivate your shop.', [$destinationVersion])
);
Expand Down
1 change: 1 addition & 0 deletions classes/Task/Update/UpdateModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ private function handleException(UpgradeException $e): void
}
if ($e->getSeverity() === UpgradeException::SEVERITY_WARNING) {
$this->logger->warning($e->getMessage());
$this->container->getUpdateState()->setWarningDetected(true);
}

foreach ($e->getQuickInfos() as $log) {
Expand Down
39 changes: 24 additions & 15 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use InvalidArgumentException;
use Language;
use ParseError;
use PrestaShop\Module\AutoUpgrade\Database\MysqlErrorCode;
use PrestaShop\Module\AutoUpgrade\Exceptions\UpdateDatabaseException;
use PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException;
use PrestaShop\Module\AutoUpgrade\Log\LoggerInterface;
Expand Down Expand Up @@ -140,7 +141,7 @@ public function finalizeCoreUpdate(): void

$this->runCoreCacheClean();

if ($this->container->getUpdateState()->getWarningExists()) {
if ($this->container->getUpdateState()->isWarningDetected()) {
$this->logger->warning($this->container->getTranslator()->trans('Warning detected during update.'));
} else {
$this->logger->info($this->container->getTranslator()->trans('Database update completed'));
Expand Down Expand Up @@ -456,20 +457,20 @@ private function hasPhpError($phpRes): bool

private function logPhpError(string $upgrade_file, string $query, string $message): void
{
$this->logger->error('PHP ' . $upgrade_file . ' ' . $query . ": \n" . $message);
$this->container->getUpdateState()->setWarningExists(true);
$this->logger->warning('PHP ' . $upgrade_file . ' ' . $query . ": \n" . $message);
Quetzacoalt91 marked this conversation as resolved.
Show resolved Hide resolved
$this->container->getUpdateState()->setWarningDetected(true);
}

private function logMissingFileError(string $path, string $func_name, string $query): void
{
$this->logger->error($path . strtolower($func_name) . ' PHP - missing file ' . $query);
$this->container->getUpdateState()->setWarningExists(true);
$this->logger->warning($this->container->getTranslator()->trans('%s PHP - missing file %s', [$path . strtolower($func_name), $query]));
$this->container->getUpdateState()->setWarningDetected(true);
}

private function logForbiddenObjectMethodError(string $phpString, string $upgrade_file): void
{
$this->logger->error($upgrade_file . ' PHP - Object Method call is forbidden (' . $phpString . ')');
$this->container->getUpdateState()->setWarningExists(true);
$this->logger->warning($this->container->getTranslator()->trans('%s PHP - Object Method call is forbidden (%s)', [$upgrade_file, $phpString]));
$this->container->getUpdateState()->setWarningDetected(true);
}

protected function runSqlQuery(string $upgrade_file, string $query): void
Expand All @@ -494,13 +495,21 @@ protected function runSqlQuery(string $upgrade_file, string $query): void
$error = $this->db->getMsgError();
$error_number = $this->db->getNumberError();

$this->logger->warning($this->container->getTranslator()->trans('The execution of the query failed: %s, %s', [$error_number, $error]));
$this->logger->warning($this->container->getTranslator()->trans('Migration file: %s, Query: %s', [$upgrade_file, $query]));

$duplicates = ['1050', '1054', '1060', '1061', '1062', '1091'];
$duplicates = [
MysqlErrorCode::TABLE_ALREADY_EXISTS,
MysqlErrorCode::UNKNOWN_COLUMN_IN_FIELD_LIST,
MysqlErrorCode::DUPLICATE_COLUMN_NAME,
MysqlErrorCode::DUPLICATE_KEY,
MysqlErrorCode::DUPLICATE_ENTRY,
MysqlErrorCode::CANNOT_DROP_KEY,
];
if (!in_array($error_number, $duplicates)) {
$this->logger->error('SQL ' . $upgrade_file . ' ' . $error_number . ' in ' . $query . ': ' . $error);
$this->container->getUpdateState()->setWarningExists(true);
$this->logger->warning($this->container->getTranslator()->trans('The execution of the query failed: %s, %s', [$error_number, $error]));
$this->logger->warning($this->container->getTranslator()->trans('Migration file: %s, Query: %s', [$upgrade_file, $query]));
$this->container->getUpdateState()->setWarningDetected(true);
} else {
$this->logger->debug($this->container->getTranslator()->trans('The execution of the query failed: %s, %s. This error code can be safely ignored.', [$error_number, $error]));
$this->logger->debug($this->container->getTranslator()->trans('Migration file: %s, Query: %s', [$upgrade_file, $query]));
}
}

Expand Down Expand Up @@ -808,12 +817,12 @@ protected function updateRTLFiles(): void
try {
$commandBus->handle($adaptThemeToTRLLanguages);
} catch (CoreException $e) {
$this->logger->error('
$this->logger->warning('
PHP Impossible to generate RTL files for theme' . $theme['name'] . "\n" .
$e->getMessage()
);

$this->container->getUpdateState()->setWarningExists(true);
$this->container->getUpdateState()->setWarningDetected(true);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion classes/UpgradeTools/Module/ModuleDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public function downloadModule(ModuleDownloaderContext $moduleDownloaderContext)
}

if (!$downloadSuccessful) {
throw (new UpgradeException('All download attempts have failed. Check your environment and try again.'))->setSeverity(UpgradeException::SEVERITY_ERROR);
$message = $this->translator->trans('All download attempts have failed. The module %s has been disabled. You can try to update it manually afterwards.', [$moduleDownloaderContext->getModuleName()]);
throw (new UpgradeException($message))->setSeverity(UpgradeException::SEVERITY_WARNING);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/State/UpdateStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testExportOfData(): void
'currentVersion' => '1.7.8.6',
'destinationVersion' => '9.0.0',
'installedLanguagesIso' => [],
'warning_exists' => false,
'warningDetected' => false,

'progressPercentage' => 20,
];
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/UpgradeTools/Module/ModuleDownloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function testModuleDownloaderFails()
PHP_VERSION_ID >= 80000 ? ['RecursiveDirectoryIterator::__construct(/non-existing-folder): Failed to open directory: No such file or directory']
: ['RecursiveDirectoryIterator::__construct(/non-existing-folder): failed to open dir: No such file or directory'], ['Download of source #0 has failed.']
);
$this->expectExceptionMessage('All download attempts have failed. Check your environment and try again.');
$this->expectExceptionMessage('All download attempts have failed. The module mymodule has been disabled. You can try to update it manually afterwards.');

$this->moduleDownloader->downloadModule($moduleContext);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ public function testDetectionOfXmlFileInDownloadedContents()
['Invalid contents from provider (Got an XML file).'],
['Download of source #0 has failed.']
);
$this->expectExceptionMessage('All download attempts have failed. Check your environment and try again.');
$this->expectExceptionMessage('All download attempts have failed. The module mymodule has been disabled. You can try to update it manually afterwards.');

$this->downloadService
->method('downloadWithRetry')
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/add_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/add_hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/add_new_status_stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/add_new_tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;
use PrestaShopBundle\Security\Voter\PageVoter;

/**
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/copy_tab_rights.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;
use PrestaShopBundle\Security\Voter\PageVoter;

/**
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/deactivate_custom_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/drop_column_if_exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/execute_sql_if_table_exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/ps_1740_update_module_tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* File copied from ps_update_tabs.php and modified for only adding modules related tabs
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/ps_1750_update_module_tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* File copied from ps_update_tabs.php and modified for only adding modules related tabs
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/ps_1751_update_module_sf_tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* File copied from ps_update_tabs.php and modified for only adding modules related tabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Localization\CLDR\LocaleRepository;

Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/ps_1760_update_tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* File copied from ps_1750_update_module_tabs.php and modified to add new roles
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/ps_1761_update_currencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Localization\CLDR\LocaleRepository;

Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/ps_1763_update_tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* File copied from ps_1750_update_module_tabs.php and modified to add new roles
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/ps_1770_preset_tab_enabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Preset enabled new column in tabs to true for all (except for disabled modules)
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/ps_1770_update_charset.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/ps_1770_update_order_status_colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;
use PrestaShop\PrestaShop\Core\Domain\Order\Status\OrderStatusColor;

/**
Expand Down
2 changes: 1 addition & 1 deletion upgrade/php/ps_1771_update_customer_note.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\AutoUpgrade\DbWrapper;
use PrestaShop\Module\AutoUpgrade\Database\DbWrapper;

/**
* Copyright since 2007 PrestaShop SA and Contributors
Expand Down
Loading
Loading