Skip to content

Commit

Permalink
Merge pull request #785 from PrestaShopCorp/fix-mbo-ui-tests
Browse files Browse the repository at this point in the history
Remove custom cache clearer
  • Loading branch information
jolelievre authored Nov 20, 2024
2 parents 2c907d4 + 317fa5f commit 023d336
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 124 deletions.
4 changes: 2 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MBO_CDC_URL="https://assets.prestashop3.com/dst/mbo/v1/mbo-cdc.umd.js"
DISTRIBUTION_API_URL="https://mbo-api.prestashop.com"
SENTRY_CREDENTIALS=""
SENTRY_ENVIRONMENT=""
SENTRY_CREDENTIALS="https://[email protected]/6520457"
SENTRY_ENVIRONMENT="production"
ADDONS_API_URL="https://api-addons.prestashop.com"

# For testing purpose only
Expand Down
8 changes: 0 additions & 8 deletions config/services/overrides.yml

This file was deleted.

22 changes: 0 additions & 22 deletions src/Addons/Subscriber/ModuleManagementEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use PrestaShop\Module\Mbo\Module\Repository;
use PrestaShop\Module\Mbo\Service\View\ContextBuilder;
use PrestaShop\Module\Mbo\Tab\TabCollectionProviderInterface;
use PrestaShop\PrestaShop\Core\Cache\Clearer\CacheClearerInterface;
use PrestaShop\PrestaShop\Core\Module\ModuleInterface;
use PrestaShopBundle\Event\ModuleManagementEvent;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -72,14 +71,6 @@ class ModuleManagementEventSubscriber implements EventSubscriberInterface
*/
private $versionChangeApplyConfigCommandHandler;

/**
* @var CacheClearerInterface
*/
private $cacheClearer;

/** @var bool */
private $cleared = false;

public function __construct(
LoggerInterface $logger,
Repository $moduleRepository,
Expand All @@ -88,7 +79,6 @@ public function __construct(
Client $distributionClient,
AdminAuthenticationProvider $adminAuthenticationProvider,
VersionChangeApplyConfigCommandHandler $versionChangeApplyConfigCommandHandler,
CacheClearerInterface $cacheClearer,
) {
$this->logger = $logger;
$this->moduleRepository = $moduleRepository;
Expand All @@ -97,7 +87,6 @@ public function __construct(
$this->distributionClient = $distributionClient;
$this->adminAuthenticationProvider = $adminAuthenticationProvider;
$this->versionChangeApplyConfigCommandHandler = $versionChangeApplyConfigCommandHandler;
$this->cacheClearer = $cacheClearer;
}

public static function getSubscribedEvents(): array
Expand All @@ -116,12 +105,10 @@ public static function getSubscribedEvents(): array
['onUninstall'],
],
ModuleManagementEvent::ENABLE => [
['clearSfCache'],
['clearCatalogCache'],
['onEnable'],
],
ModuleManagementEvent::DISABLE => [
['clearSfCache'],
['clearCatalogCache'],
['onDisable'],
],
Expand All @@ -130,7 +117,6 @@ public static function getSubscribedEvents(): array
['onUpgrade'],
],
ModuleManagementEvent::RESET => [
['clearSfCache'],
['clearCatalogCache'],
['onReset'],
],
Expand All @@ -144,14 +130,6 @@ public function clearCatalogCache(): void
$this->contextBuilder->clearCache();
}

public function clearSfCache(ModuleManagementEvent $event): void
{
if (!$this->cleared) {
$this->cacheClearer->clear();
$this->cleared = true;
}
}

public function onInstall(ModuleManagementEvent $event): void
{
$this->logEvent(ModuleManagementEvent::INSTALL, $event);
Expand Down
5 changes: 3 additions & 2 deletions src/Api/Service/ModuleTransitionExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use PrestaShop\Module\Mbo\Module\Exception\UnknownModuleTransitionCommandException;
use PrestaShop\Module\Mbo\Module\Module;
use PrestaShop\Module\Mbo\Module\ValueObject\ModuleTransitionCommand;
use PrestaShop\PrestaShop\Adapter\Cache\Clearer\SymfonyCacheClearer;
use PrestaShop\PrestaShop\Core\Cache\Clearer\CacheClearerInterface;
use Symfony\Component\HttpFoundation\Session\Session;

Expand Down Expand Up @@ -114,8 +115,8 @@ public function execute(...$parameters): array
if (ModuleTransitionCommand::MODULE_COMMAND_DOWNLOAD === $transition) {
// Clear the cache after download to force reload module services
try {
/** @var CacheClearerInterface $cacheClearer */
$cacheClearer = $psMbo->get('mbo.symfony_cache_clearer');
/** @var CacheClearerInterface|false $cacheClearer */
$cacheClearer = $psMbo->get(SymfonyCacheClearer::class);
} catch (\Exception $e) {
ErrorHelper::reportError($e);
$cacheClearer = false;
Expand Down
85 changes: 0 additions & 85 deletions src/Service/MboSymfonyCacheClearer.php

This file was deleted.

11 changes: 7 additions & 4 deletions src/Traits/HaveConfigurationPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
namespace PrestaShop\Module\Mbo\Traits;

use Configuration;
use PrestaShop\Module\Mbo\Service\MboSymfonyCacheClearer;
use PrestaShop\PrestaShop\Adapter\Cache\Clearer\SymfonyCacheClearer;
use PrestaShop\PrestaShop\Core\Cache\Clearer\CacheClearerInterface;
use Symfony\Component\Dotenv\Dotenv;

trait HaveConfigurationPage
Expand Down Expand Up @@ -147,9 +148,11 @@ private function saveNewDotenvData(string $envFilePath): string
$dotEnv = new Dotenv();
$dotEnv->overload($envFilePath);

/** @var MboSymfonyCacheClearer $cacheClearer */
$cacheClearer = $this->get(MboSymfonyCacheClearer::class);
$cacheClearer->clear();
/** @var CacheClearerInterface|null $cacheClearer */
$cacheClearer = $this->get(SymfonyCacheClearer::class);
if ($cacheClearer) {
$cacheClearer->clear();
}

$message = '<div style="padding-bottom: 15px;">Configuration updated to :
<ul><li>MBO : ' . ucfirst($newMboValue) . '</li>
Expand Down
3 changes: 2 additions & 1 deletion src/Traits/Hooks/UseActionBeforeUpgradeModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use PrestaShop\Module\Mbo\Helpers\ErrorHelper;
use PrestaShop\Module\Mbo\Module\ActionsManager;
use PrestaShop\Module\Mbo\Service\HookExceptionHolder;
use PrestaShop\PrestaShop\Adapter\Cache\Clearer\SymfonyCacheClearer;
use PrestaShop\PrestaShop\Core\Cache\Clearer\CacheClearerInterface;
use PrestaShop\PrestaShop\Core\File\Exception\FileNotFoundException;
use PrestaShop\PrestaShop\Core\Module\SourceHandler\SourceHandlerNotFoundException;
Expand Down Expand Up @@ -104,7 +105,7 @@ private function purgeCache(): void
{
try {
/** @var CacheClearerInterface|null $cacheClearer */
$cacheClearer = $this->get(CacheClearerInterface::class);
$cacheClearer = $this->get(SymfonyCacheClearer::class);
if (null === $cacheClearer) {
throw new ExpectedServiceNotFoundException('Unable to get MboCacheClearer service');
}
Expand Down

0 comments on commit 023d336

Please sign in to comment.