diff --git a/src/Command/CronCommand.php b/src/Command/CronCommand.php index ed9b6ec83a..36ed87bc27 100644 --- a/src/Command/CronCommand.php +++ b/src/Command/CronCommand.php @@ -12,7 +12,6 @@ use Shopsys\FrameworkBundle\Component\Cron\Config\CronModuleConfig; use Shopsys\FrameworkBundle\Component\Cron\CronFacade; use Shopsys\FrameworkBundle\Component\Cron\MutexFactory; -use Shopsys\FrameworkBundle\Component\Deprecations\DeprecationHelper; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -192,22 +191,11 @@ private function runCron( } /** - * @phpstan-ignore-next-line * @param int $runEveryMin * @return \DateTimeImmutable */ - private function getCurrentRoundedTime(/* int $runEveryMin */) + private function getCurrentRoundedTime(int $runEveryMin) { - $runEveryMin = DeprecationHelper::triggerNewArgumentInMethod( - __METHOD__, - '$runEveryMin', - 'int', - func_get_args(), - 0, - CronModuleConfig::RUN_EVERY_MIN_DEFAULT, - true, - ); - $time = new DateTime('now', $this->getCronTimeZone()); $time->modify('-' . $time->format('s') . ' sec'); $time->modify('-' . ($time->format('i') % $runEveryMin) . ' min'); diff --git a/src/Component/Cron/Config/CronConfig.php b/src/Component/Cron/Config/CronConfig.php index 60098c3198..f489e24cd4 100644 --- a/src/Component/Cron/Config/CronConfig.php +++ b/src/Component/Cron/Config/CronConfig.php @@ -8,7 +8,6 @@ use Shopsys\FrameworkBundle\Component\Cron\Config\Exception\CronModuleConfigNotFoundException; use Shopsys\FrameworkBundle\Component\Cron\CronTimeResolver; use Shopsys\FrameworkBundle\Component\Cron\Exception\InvalidCronModuleException; -use Shopsys\FrameworkBundle\Component\Deprecations\DeprecationHelper; use Shopsys\Plugin\Cron\IteratedCronModuleInterface; use Shopsys\Plugin\Cron\SimpleCronModuleInterface; @@ -34,9 +33,7 @@ public function __construct(protected readonly CronTimeResolver $cronTimeResolve * @param string $timeMinutes * @param string $instanceName * @param string|null $readableName - * @phpstan-ignore-next-line * @param int $runEveryMin - * @phpstan-ignore-next-line * @param int $timeoutIteratedCronSec */ public function registerCronModuleInstance( @@ -46,35 +43,12 @@ public function registerCronModuleInstance( string $timeMinutes, string $instanceName, ?string $readableName = null, - /* - int $runEveryMin, - int $timeoutIteratedCronSec, - */ + int $runEveryMin = CronModuleConfig::RUN_EVERY_MIN_DEFAULT, + int $timeoutIteratedCronSec = CronModuleConfig::TIMEOUT_ITERATED_CRON_SEC_DEFAULT, ): void { if (!$service instanceof SimpleCronModuleInterface && !$service instanceof IteratedCronModuleInterface) { throw new InvalidCronModuleException($serviceId); } - - $runEveryMin = DeprecationHelper::triggerNewArgumentInMethod( - __METHOD__, - '$runEveryMin', - 'int', - func_get_args(), - 6, - CronModuleConfig::RUN_EVERY_MIN_DEFAULT, - true, - ); - - $timeoutIteratedCronSec = DeprecationHelper::triggerNewArgumentInMethod( - __METHOD__, - '$timeoutIteratedCronSec', - 'int', - func_get_args(), - 7, - CronModuleConfig::TIMEOUT_ITERATED_CRON_SEC_DEFAULT, - true, - ); - $this->cronTimeResolver->validateTimeString($timeHours, 23, 1); $this->cronTimeResolver->validateTimeString($timeMinutes, 55, 5); diff --git a/src/Component/Cron/CronModuleExecutor.php b/src/Component/Cron/CronModuleExecutor.php index fbfbc141ae..3df42391ee 100644 --- a/src/Component/Cron/CronModuleExecutor.php +++ b/src/Component/Cron/CronModuleExecutor.php @@ -8,48 +8,26 @@ use DateTimeImmutable; use Shopsys\FrameworkBundle\Component\Cron\Config\CronConfig; use Shopsys\FrameworkBundle\Component\Cron\Config\CronModuleConfig; -use Shopsys\FrameworkBundle\Component\Deprecations\DeprecationHelper; -use Shopsys\FrameworkBundle\DependencyInjection\SetterInjectionTrait; use Shopsys\Plugin\Cron\IteratedCronModuleInterface; use Shopsys\Plugin\Cron\SimpleCronModuleInterface; class CronModuleExecutor { - use SetterInjectionTrait; - public const RUN_STATUS_OK = 'ok'; public const RUN_STATUS_TIMEOUT = 'timeout'; public const RUN_STATUS_SUSPENDED = 'suspended'; - /** - * @deprecated This will be removed in next major version - */ - protected ?DateTimeImmutable $canRunTo = null; - protected DateTimeImmutable $startedAt; /** - * @param int $secondsTimeout - * @param \Shopsys\FrameworkBundle\Component\Cron\Config\CronConfig|null $cronConfig + * @param \Shopsys\FrameworkBundle\Component\Cron\Config\CronConfig $cronConfig */ public function __construct( - int $secondsTimeout, - protected ?CronConfig $cronConfig = null, + protected readonly CronConfig $cronConfig, ) { - $this->canRunTo = new DateTimeImmutable('+' . $secondsTimeout . ' sec'); $this->startedAt = new DateTimeImmutable('now'); } - /** - * @required - * @param \Shopsys\FrameworkBundle\Component\Cron\Config\CronConfig $cronConfig - * @internal This function will be replaced by constructor injection in next major - */ - public function setCronConfig(CronConfig $cronConfig): void - { - $this->setDependency($cronConfig, 'cronConfig'); - } - /** * @param \Shopsys\Plugin\Cron\SimpleCronModuleInterface|\Shopsys\Plugin\Cron\IteratedCronModuleInterface $cronModuleService * @param bool $suspended @@ -93,31 +71,15 @@ public function runModule($cronModuleService, $suspended) /** * @phpstan-impure - * @phpstan-ignore-next-line * @param \Shopsys\FrameworkBundle\Component\Cron\Config\CronModuleConfig $cronConfig * @return bool */ - public function canRun(/* CronModuleConfig $cronConfig */): bool + public function canRun(CronModuleConfig $cronConfig): bool { - $triggerNewArgumentInMethod = DeprecationHelper::triggerNewArgumentInMethod( - __METHOD__, - '$cronConfig', - 'CronModuleConfig', - func_get_args(), - 0, - null, - true, + $canRunUntil = $this->startedAt->add( + DateInterval::createFromDateString($cronConfig->getTimeoutIteratedCronSec() . ' seconds'), ); - $cronConfig = $triggerNewArgumentInMethod; - - if ($cronConfig !== null) { - $canRunUntil = $this->startedAt->add( - DateInterval::createFromDateString($cronConfig->getTimeoutIteratedCronSec() . ' seconds'), - ); - - return $canRunUntil > new DateTimeImmutable('now'); - } - return $this->canRunTo > new DateTimeImmutable(); + return $canRunUntil > new DateTimeImmutable('now'); } } diff --git a/src/Component/Cron/CronModuleFacade.php b/src/Component/Cron/CronModuleFacade.php index 01515bb895..2f8d0241fe 100644 --- a/src/Component/Cron/CronModuleFacade.php +++ b/src/Component/Cron/CronModuleFacade.php @@ -8,36 +8,23 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\QueryBuilder; use Shopsys\FrameworkBundle\Component\Cron\Config\CronModuleConfig; -use Shopsys\FrameworkBundle\DependencyInjection\SetterInjectionTrait; class CronModuleFacade { - use SetterInjectionTrait; - /** * @param \Doctrine\ORM\EntityManagerInterface $em * @param \Shopsys\FrameworkBundle\Component\Cron\CronModuleRepository $cronModuleRepository * @param \Shopsys\FrameworkBundle\Component\Cron\CronFilter $cronFilter - * @param \Shopsys\FrameworkBundle\Component\Cron\CronModuleRunFactory|null $cronModuleRunFactory + * @param \Shopsys\FrameworkBundle\Component\Cron\CronModuleRunFactory $cronModuleRunFactory */ public function __construct( protected readonly EntityManagerInterface $em, protected readonly CronModuleRepository $cronModuleRepository, protected readonly CronFilter $cronFilter, - protected ?CronModuleRunFactory $cronModuleRunFactory = null, + protected readonly CronModuleRunFactory $cronModuleRunFactory, ) { } - /** - * @required - * @param \Shopsys\FrameworkBundle\Component\Cron\CronModuleRunFactory $cronModuleRunFactory - * @internal This function will be replaced by constructor injection in next major - */ - public function setCronModuleRunFactory(CronModuleRunFactory $cronModuleRunFactory): void - { - $this->setDependency($cronModuleRunFactory, 'cronModuleRunFactory'); - } - /** * @param \Shopsys\FrameworkBundle\Component\Cron\Config\CronModuleConfig[] $cronModuleConfigs */ diff --git a/src/Controller/Admin/DefaultController.php b/src/Controller/Admin/DefaultController.php index b94be803a2..8d3256ab8b 100644 --- a/src/Controller/Admin/DefaultController.php +++ b/src/Controller/Admin/DefaultController.php @@ -12,7 +12,6 @@ use Shopsys\FrameworkBundle\Component\Grid\GridView; use Shopsys\FrameworkBundle\Component\Grid\QueryBuilderDataSource; use Shopsys\FrameworkBundle\Component\Setting\Setting; -use Shopsys\FrameworkBundle\DependencyInjection\SetterInjectionTrait; use Shopsys\FrameworkBundle\Form\Admin\QuickSearch\QuickSearchFormData; use Shopsys\FrameworkBundle\Form\Admin\QuickSearch\QuickSearchFormType; use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider; @@ -28,13 +27,7 @@ class DefaultController extends AdminBaseController { - use SetterInjectionTrait; - protected const PREVIOUS_DAYS_TO_LOAD_STATISTICS_FOR = 7; - /** - * @deprecated This will be removed in next major - */ - protected const HOUR_IN_SECONDS = 60 * 60; /** * @param \Shopsys\FrameworkBundle\Model\Statistics\StatisticsFacade $statisticsFacade @@ -47,8 +40,8 @@ class DefaultController extends AdminBaseController * @param \Shopsys\FrameworkBundle\Component\Grid\GridFactory $gridFactory * @param \Shopsys\FrameworkBundle\Component\Cron\Config\CronConfig $cronConfig * @param \Shopsys\FrameworkBundle\Component\Cron\CronFacade $cronFacade - * @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider|null $breadcrumbOverrider - * @param \Shopsys\FrameworkBundle\Twig\DateTimeFormatterExtension|null $dateTimeFormatterExtension + * @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider + * @param \Shopsys\FrameworkBundle\Twig\DateTimeFormatterExtension $dateTimeFormatterExtension */ public function __construct( protected readonly StatisticsFacade $statisticsFacade, @@ -61,31 +54,11 @@ public function __construct( protected readonly GridFactory $gridFactory, protected readonly CronConfig $cronConfig, protected readonly CronFacade $cronFacade, - protected ?BreadcrumbOverrider $breadcrumbOverrider = null, - protected ?DateTimeFormatterExtension $dateTimeFormatterExtension = null, + protected readonly BreadcrumbOverrider $breadcrumbOverrider, + protected readonly DateTimeFormatterExtension $dateTimeFormatterExtension, ) { } - /** - * @required - * @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider - * @internal This function will be replaced by constructor injection in next major - */ - public function setBreadcrumbOverrider(BreadcrumbOverrider $breadcrumbOverrider): void - { - $this->setDependency($breadcrumbOverrider, 'breadcrumbOverrider'); - } - - /** - * @required - * @param \Shopsys\FrameworkBundle\Twig\DateTimeFormatterExtension $dateTimeFormatterExtension - * @internal This function will be replaced by constructor injection in next major - */ - public function setDateTimeFormatterExtension(DateTimeFormatterExtension $dateTimeFormatterExtension): void - { - $this->setDependency($dateTimeFormatterExtension, 'dateTimeFormatterExtension'); - } - /** * @Route("/dashboard/") * @return \Symfony\Component\HttpFoundation\Response @@ -367,16 +340,6 @@ public function cronEnableAction(string $serviceId): Response return $this->redirectToRoute('admin_default_dashboard'); } - /** - * @deprecated This method will be removed in the next major release. Use DateTimeFormatterExtension::formatDurationInSeconds() instead. - * @param int|null $durationInSeconds - * @return string - */ - protected function getFormattedDuration(?int $durationInSeconds): string - { - return $this->dateTimeFormatterExtension->formatDurationInSeconds($durationInSeconds); - } - /** * @Route("/cron/detail/{serviceId}") * @param string $serviceId diff --git a/src/Controller/Admin/SuperadminController.php b/src/Controller/Admin/SuperadminController.php index 4b50d795e7..576d58baab 100644 --- a/src/Controller/Admin/SuperadminController.php +++ b/src/Controller/Admin/SuperadminController.php @@ -8,7 +8,6 @@ use Shopsys\FrameworkBundle\Component\Grid\ArrayDataSource; use Shopsys\FrameworkBundle\Component\Grid\GridFactory; use Shopsys\FrameworkBundle\Component\Router\LocalizedRouterFactory; -use Shopsys\FrameworkBundle\DependencyInjection\SetterInjectionTrait; use Shopsys\FrameworkBundle\Form\Admin\Module\ModulesFormType; use Shopsys\FrameworkBundle\Form\Admin\Superadmin\InputPriceTypeFormType; use Shopsys\FrameworkBundle\Form\Admin\Superadmin\MailWhitelistFormType; @@ -26,8 +25,6 @@ class SuperadminController extends AdminBaseController { - use SetterInjectionTrait; - /** * @param \Shopsys\FrameworkBundle\Model\Module\ModuleList $moduleList * @param \Shopsys\FrameworkBundle\Model\Module\ModuleFacade $moduleFacade @@ -36,9 +33,9 @@ class SuperadminController extends AdminBaseController * @param \Shopsys\FrameworkBundle\Component\Grid\GridFactory $gridFactory * @param \Shopsys\FrameworkBundle\Model\Localization\Localization $localization * @param \Shopsys\FrameworkBundle\Component\Router\LocalizedRouterFactory $localizedRouterFactory - * @param \Shopsys\FrameworkBundle\Model\Mail\Setting\MailSettingFacade|null $mailSettingFacade - * @param \Shopsys\FrameworkBundle\Model\Mail\MailerSettingProvider|null $mailerSettingProvider - * @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainTabsFacade|null $adminDomainTabsFacade + * @param \Shopsys\FrameworkBundle\Model\Mail\Setting\MailSettingFacade $mailSettingFacade + * @param \Shopsys\FrameworkBundle\Model\Mail\MailerSettingProvider $mailerSettingProvider + * @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainTabsFacade $adminDomainTabsFacade */ public function __construct( protected readonly ModuleList $moduleList, @@ -48,42 +45,12 @@ public function __construct( protected readonly GridFactory $gridFactory, protected readonly Localization $localization, protected readonly LocalizedRouterFactory $localizedRouterFactory, - protected /* readonly */ ?MailSettingFacade $mailSettingFacade = null, - protected /* readonly */ ?MailerSettingProvider $mailerSettingProvider = null, - protected /* readonly */ ?AdminDomainTabsFacade $adminDomainTabsFacade = null, + protected readonly MailSettingFacade $mailSettingFacade, + protected readonly MailerSettingProvider $mailerSettingProvider, + protected readonly AdminDomainTabsFacade $adminDomainTabsFacade, ) { } - /** - * @required - * @param \Shopsys\FrameworkBundle\Model\Mail\Setting\MailSettingFacade $mailSettingFacade - * @internal This function will be replaced by constructor injection in next major - */ - public function setMailSettingFacade(MailSettingFacade $mailSettingFacade): void - { - $this->setDependency($mailSettingFacade, 'mailSettingFacade'); - } - - /** - * @required - * @param \Shopsys\FrameworkBundle\Model\Mail\MailerSettingProvider $mailerSettingProvider - * @internal This function will be replaced by constructor injection in next major - */ - public function setMailerSettingProvider(MailerSettingProvider $mailerSettingProvider): void - { - $this->setDependency($mailerSettingProvider, 'mailerSettingProvider'); - } - - /** - * @required - * @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainTabsFacade $adminDomainTabsFacade - * @internal This function will be replaced by constructor injection in next major - */ - public function setAdminDomainTabsFacade(AdminDomainTabsFacade $adminDomainTabsFacade): void - { - $this->setDependency($adminDomainTabsFacade, 'adminDomainTabsFacade'); - } - /** * @Route("/superadmin/errors/") * @return \Symfony\Component\HttpFoundation\Response @@ -241,7 +208,6 @@ public function mailWhitelistAction(Request $request): Response return $this->render('@ShopsysFramework/Admin/Content/Superadmin/mailWhitelist.html.twig', [ 'form' => $form->createView(), - 'isOverridden' => $this->mailerSettingProvider->isMailerWhitelistExpressionsSet(), 'isWhitelistForced' => $this->mailerSettingProvider->isWhitelistForced(), ]); } diff --git a/src/Model/Advert/AdvertRepository.php b/src/Model/Advert/AdvertRepository.php index 500f7ebc0f..b9841f6975 100644 --- a/src/Model/Advert/AdvertRepository.php +++ b/src/Model/Advert/AdvertRepository.php @@ -6,7 +6,7 @@ use DateTimeImmutable; use Doctrine\ORM\EntityManagerInterface; -use Shopsys\FrameworkBundle\Component\Deprecations\DeprecationHelper; +use LogicException; use Shopsys\FrameworkBundle\Model\Advert\Exception\AdvertNotFoundException; class AdvertRepository @@ -44,7 +44,7 @@ public function findById($advertId) protected function getAdvertByPositionQueryBuilder($positionName, $domainId, $category = null) { if (AdvertPositionRegistry::isCategoryPosition($positionName) && $category === null) { - DeprecationHelper::trigger('Retrieving advert on product list page without setting category is deprecated and will be disabled in next major.'); + throw new LogicException('Cannot retrieve advert on product list page without setting category.'); } $dateToday = (new DateTimeImmutable())->format('Y-m-d 00:00:00'); diff --git a/src/Model/Mail/EventListener/EnvelopeListener.php b/src/Model/Mail/EventListener/EnvelopeListener.php index 93295ff56c..9624cc1d9e 100644 --- a/src/Model/Mail/EventListener/EnvelopeListener.php +++ b/src/Model/Mail/EventListener/EnvelopeListener.php @@ -4,7 +4,7 @@ namespace Shopsys\FrameworkBundle\Model\Mail\EventListener; -use Shopsys\FrameworkBundle\Component\Deprecations\DeprecationHelper; +use InvalidArgumentException; use Shopsys\FrameworkBundle\Model\Mail\Email; use Shopsys\FrameworkBundle\Model\Mail\MailerSettingProvider; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -18,8 +18,9 @@ class EnvelopeListener implements EventSubscriberInterface /** * @param \Shopsys\FrameworkBundle\Model\Mail\MailerSettingProvider $mailerSettingProvider */ - public function __construct(protected readonly MailerSettingProvider $mailerSettingProvider) - { + public function __construct( + protected readonly MailerSettingProvider $mailerSettingProvider, + ) { } /** @@ -29,8 +30,8 @@ public function onMessage(MessageEvent $event): void { $message = $event->getMessage(); - if (!($message instanceof Message)) { - return; + if (!($message instanceof Email)) { + throw new InvalidArgumentException(sprintf('Message must be instance of %s.', Email::class)); } $originalRecipients = [ @@ -39,17 +40,10 @@ public function onMessage(MessageEvent $event): void ...$this->getAddressesFromMessageHeader($message, 'Bcc'), ]; - if ($message instanceof Email && $message->getDomainId() !== 0) { - $allowedRecipients = $this->getAllowedRecipientsOnDomain($originalRecipients, $message->getDomainId()); - $isWhitelistEnabled = $this->mailerSettingProvider->isWhitelistEnabled($message->getDomainId()); - } else { - DeprecationHelper::trigger('Email is not instance of ' . Email::class . ' this will throw exception in next major version.'); - - $allowedRecipients = $this->getAllowedRecipients($originalRecipients); - $isWhitelistEnabled = false; - } + $allowedRecipients = $this->getAllowedRecipientsOnDomain($originalRecipients, $message->getDomainId()); + $isWhitelistEnabled = $this->mailerSettingProvider->isWhitelistEnabled($message->getDomainId()); - if (!$isWhitelistEnabled && !$this->mailerSettingProvider->isMailerMasterEmailSet()) { + if (!$isWhitelistEnabled) { return; } @@ -77,32 +71,6 @@ protected function getAddressesFromMessageHeader(Message $message, string $heade return []; } - /** - * @param \Symfony\Component\Mime\Address[] $originalRecipients - * @return \Symfony\Component\Mime\Address[] - * @deprecated use getAllowedRecipientsOnDomain() instead - */ - protected function getAllowedRecipients(array $originalRecipients): array - { - DeprecationHelper::triggerMethod(__METHOD__, 'getAllowedRecipientsOnDomain()'); - - $allowedRecipients = []; - - if ($this->mailerSettingProvider->isMailerMasterEmailSet()) { - $allowedRecipients = [new Address($this->mailerSettingProvider->getMailerMasterEmailAddress())]; - } - - foreach ($originalRecipients as $originalRecipient) { - foreach ($this->mailerSettingProvider->getMailerWhitelistExpressions() as $whitelistedPattern) { - if (preg_match($whitelistedPattern, $originalRecipient->getAddress())) { - $allowedRecipients[] = $originalRecipient; - } - } - } - - return $allowedRecipients; - } - /** * @param \Symfony\Component\Mime\Address[] $originalRecipients * @param int $domainId diff --git a/src/Model/Mail/Exception/MasterMailNotSetException.php b/src/Model/Mail/Exception/MasterMailNotSetException.php deleted file mode 100644 index 14a2bd50fe..0000000000 --- a/src/Model/Mail/Exception/MasterMailNotSetException.php +++ /dev/null @@ -1,15 +0,0 @@ -getMessageWithReplacedVariables($messageData); - - try { - $this->symfonyMailer->send($message); - } catch (TransportExceptionInterface $exception) { - $this->logger->error('There was a failure while sending emails', [ - 'exception' => $exception, - ]); - } - } - /** * @param \Shopsys\FrameworkBundle\Model\Mail\MessageData $messageData * @param int $domainId @@ -66,14 +45,13 @@ public function sendForDomain(MessageData $messageData, int $domainId): void /** * @param \Shopsys\FrameworkBundle\Model\Mail\MessageData $messageData - * @phpstan-ignore-next-line * @param int $domainId * @return \Shopsys\FrameworkBundle\Model\Mail\Email */ protected function getMessageWithReplacedVariables( MessageData $messageData, - /* int $domainId */ - ): BaseEmail { + int $domainId, + ): Email { $body = $this->replaceVariables( $messageData->body, $messageData->variablesReplacementsForBody, @@ -83,16 +61,6 @@ protected function getMessageWithReplacedVariables( $messageData->variablesReplacementsForSubject, ); - $domainId = DeprecationHelper::triggerNewArgumentInMethod( - __METHOD__, - '$domainId', - 'int', - func_get_args(), - 1, - 0, - true, - ); - $email = new Email($domainId); $email ->subject($subject) diff --git a/src/Model/Mail/MailerSettingProvider.php b/src/Model/Mail/MailerSettingProvider.php index 77cc451786..f5049d7e40 100644 --- a/src/Model/Mail/MailerSettingProvider.php +++ b/src/Model/Mail/MailerSettingProvider.php @@ -5,96 +5,31 @@ namespace Shopsys\FrameworkBundle\Model\Mail; use Nette\Utils\Json; -use Shopsys\FrameworkBundle\Component\Deprecations\DeprecationHelper; -use Shopsys\FrameworkBundle\DependencyInjection\SetterInjectionTrait; -use Shopsys\FrameworkBundle\Model\Mail\Exception\MasterMailNotSetException; use Shopsys\FrameworkBundle\Model\Mail\Setting\MailSettingFacade; class MailerSettingProvider { - use SetterInjectionTrait; - - /** - * @deprecated This will be removed in next major version - * @var string[] - */ - protected array $mailerWhitelistExpressions; - - /** - * @deprecated This will be removed in next major version - */ - protected ?string $mailerMasterEmailAddress; - protected bool $deliveryDisabled; /** - * @param string $mailerWhitelist - * @param string $mailerMasterEmailAddress * @param string $mailerDsn - * @param bool|null $whitelistForced - * @param \Shopsys\FrameworkBundle\Model\Mail\Setting\MailSettingFacade|null $mailSettingFacade + * @param bool $whitelistForced + * @param \Shopsys\FrameworkBundle\Model\Mail\Setting\MailSettingFacade $mailSettingFacade */ public function __construct( - string $mailerWhitelist, - string $mailerMasterEmailAddress, string $mailerDsn, - protected readonly ?bool $whitelistForced = null, - protected /* readonly */ ?MailSettingFacade $mailSettingFacade = null, + protected readonly bool $whitelistForced, + protected readonly MailSettingFacade $mailSettingFacade, ) { - if ($mailerWhitelist !== '') { - DeprecationHelper::trigger('Property "$mailerWhitelist" is deprecated and should not be passed to "%s"', __METHOD__); - } - - if ($mailerMasterEmailAddress !== '') { - DeprecationHelper::trigger('Property "$mailerMasterEmailAddress" is deprecated and should not be passed to "%s"', __METHOD__); - } - - $this->mailerWhitelistExpressions = $mailerWhitelist !== '' ? explode(',', $mailerWhitelist) : []; - $this->mailerMasterEmailAddress = $mailerMasterEmailAddress !== '' ? $mailerMasterEmailAddress : null; $this->deliveryDisabled = $mailerDsn === Mailer::DISABLED_MAILER_DSN; } - /** - * @required - * @param \Shopsys\FrameworkBundle\Model\Mail\Setting\MailSettingFacade $mailSettingFacade - * @internal This function will be replaced by constructor injection in next major - */ - public function setMailSettingFacade(MailSettingFacade $mailSettingFacade): void - { - $this->setDependency($mailSettingFacade, 'mailSettingFacade'); - } - - /** - * @return string[] - * @deprecated This method will be removed in next major version - */ - public function getMailerWhitelistExpressions(): array - { - DeprecationHelper::triggerMethod(__METHOD__); - - return $this->mailerWhitelistExpressions; - } - - /** - * @return bool - */ - public function isMailerWhitelistExpressionsSet(): bool - { - return $this->mailerWhitelistExpressions !== []; - } - /** * @param int $domainId * @return string[] */ public function getWhitelistPatternsAsArray(int $domainId): array { - $mailerWhitelistExpressions = $this->getMailerWhitelistExpressions(); - - if ($mailerWhitelistExpressions !== []) { - return $mailerWhitelistExpressions; - } - $mailWhitelist = $this->mailSettingFacade->getMailWhitelist($domainId); return $mailWhitelist !== null ? Json::decode($mailWhitelist, Json::FORCE_ARRAY) : []; @@ -114,24 +49,7 @@ public function isWhitelistForced(): bool */ public function isWhitelistEnabled(int $domainId): bool { - return $this->isMailerWhitelistExpressionsSet() - || $this->isWhitelistForced() - || $this->mailSettingFacade->isWhitelistEnabled($domainId); - } - - /** - * @return string - * @deprecated This method will be removed in next major version - */ - public function getMailerMasterEmailAddress(): string - { - DeprecationHelper::triggerMethod(__METHOD__); - - if ($this->isMailerMasterEmailSet() === false) { - throw new MasterMailNotSetException(); - } - - return $this->mailerMasterEmailAddress; + return $this->isWhitelistForced() || $this->mailSettingFacade->isWhitelistEnabled($domainId); } /** @@ -141,15 +59,4 @@ public function isDeliveryDisabled(): bool { return $this->deliveryDisabled; } - - /** - * @return bool - * @deprecated This method will be removed in next major version - */ - public function isMailerMasterEmailSet(): bool - { - DeprecationHelper::triggerMethod(__METHOD__); - - return $this->mailerMasterEmailAddress !== null && $this->mailerMasterEmailAddress !== ''; - } } diff --git a/src/Model/Product/Search/AggregationResultToProductFilterCountDataTransformer.php b/src/Model/Product/Search/AggregationResultToProductFilterCountDataTransformer.php index 25f9c17f47..cf8f3ea04d 100644 --- a/src/Model/Product/Search/AggregationResultToProductFilterCountDataTransformer.php +++ b/src/Model/Product/Search/AggregationResultToProductFilterCountDataTransformer.php @@ -4,7 +4,6 @@ namespace Shopsys\FrameworkBundle\Model\Product\Search; -use Shopsys\FrameworkBundle\Component\Deprecations\DeprecationHelper; use Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterCountData; class AggregationResultToProductFilterCountDataTransformer @@ -24,11 +23,10 @@ public function translateAbsoluteNumbers(array $aggregationResult): ProductFilte } /** - * @deprecated This method visibility will be changed to public in next major version * @param array $aggregationResult * @return int[] */ - protected function getFlagCount(array $aggregationResult): array + public function getFlagCount(array $aggregationResult): array { $result = []; @@ -44,11 +42,10 @@ protected function getFlagCount(array $aggregationResult): array } /** - * @deprecated This method visibility will be changed to public in next major version * @param array $aggregationResult * @return int[] */ - protected function getBrandCount(array $aggregationResult): array + public function getBrandCount(array $aggregationResult): array { $result = []; @@ -63,28 +60,6 @@ protected function getBrandCount(array $aggregationResult): array return $result; } - /** - * @deprecated This method will be replaced by getFlagCount() in next major version - * @param array $aggregationResult - * @return int[] - */ - public function translateFlagsPlusNumbers(array $aggregationResult): array - { - return $this->getFlagCount($aggregationResult); - } - - /** - * @deprecated This method will be replaced by getBrandCount() in next major version - * @param array $aggregationResult - * @return int[] - */ - public function translateBrandsPlusNumbers(array $aggregationResult): array - { - DeprecationHelper::triggerMethod(__METHOD__, 'getBrandCount'); - - return $this->getBrandCount($aggregationResult); - } - /** * @param array $aggregationResult * @return int diff --git a/src/Model/Product/Search/ProductFilterCountDataElasticsearchRepository.php b/src/Model/Product/Search/ProductFilterCountDataElasticsearchRepository.php index 06d0989fed..69a51d5e9b 100644 --- a/src/Model/Product/Search/ProductFilterCountDataElasticsearchRepository.php +++ b/src/Model/Product/Search/ProductFilterCountDataElasticsearchRepository.php @@ -148,27 +148,26 @@ protected function calculateFlagsPlusNumbers( } $flagsPlusNumberResult = $this->client->search($plusFlagsQuery->getFlagsPlusNumbersQuery($flagIds)); - return $this->aggregationResultToCountDataTransformer->translateFlagsPlusNumbers($flagsPlusNumberResult); + return $this->aggregationResultToCountDataTransformer->getFlagCount($flagsPlusNumberResult); } /** - * @deprecated Parameter $plusFlagsQuery will be renamed to $plusBrandsQuery in next major * @param \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterData $productFilterData - * @param \Shopsys\FrameworkBundle\Model\Product\Search\FilterQuery $plusFlagsQuery + * @param \Shopsys\FrameworkBundle\Model\Product\Search\FilterQuery $plusBrandsQuery * @return int[] */ protected function calculateBrandsPlusNumbers( ProductFilterData $productFilterData, - FilterQuery $plusFlagsQuery, + FilterQuery $plusBrandsQuery, ): array { $brandsIds = []; foreach ($productFilterData->brands as $brand) { $brandsIds[] = $brand->getId(); } - $brandsPlusNumberResult = $this->client->search($plusFlagsQuery->getBrandsPlusNumbersQuery($brandsIds)); + $brandsPlusNumberResult = $this->client->search($plusBrandsQuery->getBrandsPlusNumbersQuery($brandsIds)); - return $this->aggregationResultToCountDataTransformer->translateBrandsPlusNumbers($brandsPlusNumberResult); + return $this->aggregationResultToCountDataTransformer->getBrandCount($brandsPlusNumberResult); } /** diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index e7adb46253..8706bd7f88 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -9,12 +9,6 @@ parameters: # Use Shopsys Translatable listener for prezent/doctrine-translatable to allow set fallback language on postPersist event prezent_doctrine_translatable.listener.class: Shopsys\FrameworkBundle\Model\Localization\TranslatableListener - # @deprecated This parameter is added here to prevent BC-break and will be removed in the next major release - cron_instances: - default: - run_every_min: 5 - timeout_iterated_cron_sec: 240 - services: _defaults: autowire: true @@ -160,9 +154,7 @@ services: Shopsys\FrameworkBundle\Component\Cron\Config\CronConfig: ~ - Shopsys\FrameworkBundle\Component\Cron\CronModuleExecutor: - arguments: - $secondsTimeout: 240 + Shopsys\FrameworkBundle\Component\Cron\CronModuleExecutor: ~ Shopsys\FrameworkBundle\Component\Environment\EnvironmentFileSetting: arguments: @@ -1003,8 +995,6 @@ services: Shopsys\FrameworkBundle\Model\Mail\MailerSettingProvider: arguments: - - '%env(MAILER_DELIVERY_WHITELIST)%' - - '%env(MAILER_MASTER_EMAIL_ADDRESS)%' - '%env(MAILER_DSN)%' - '%env(bool:MAILER_FORCE_WHITELIST)%' diff --git a/src/Resources/translations/messages.cs.po b/src/Resources/translations/messages.cs.po index cb84dea6f3..55eb5c5fc6 100644 --- a/src/Resources/translations/messages.cs.po +++ b/src/Resources/translations/messages.cs.po @@ -595,9 +595,6 @@ msgstr "Měna {{ name }} byla smazána" msgid "Currency settings modified" msgstr "Nastavení měn bylo upraveno" -msgid "Currently the ENV variable MAILER_DELIVERY_WHITELIST is set and overrides this setting." -msgstr "Nyní je nastavena environment proměnná MAILER_DELIVERY_WHITELIST, která přepisuje toto nastavení." - msgid "Customer" msgstr "Zákazník" diff --git a/src/Resources/translations/messages.en.po b/src/Resources/translations/messages.en.po index df9fc250ab..375991f74c 100644 --- a/src/Resources/translations/messages.en.po +++ b/src/Resources/translations/messages.en.po @@ -595,9 +595,6 @@ msgstr "" msgid "Currency settings modified" msgstr "" -msgid "Currently the ENV variable MAILER_DELIVERY_WHITELIST is set and overrides this setting." -msgstr "" - msgid "Customer" msgstr "" diff --git a/src/Resources/views/Admin/Content/Superadmin/mailWhitelist.html.twig b/src/Resources/views/Admin/Content/Superadmin/mailWhitelist.html.twig index fdd52d3d6b..8ea750f0bf 100644 --- a/src/Resources/views/Admin/Content/Superadmin/mailWhitelist.html.twig +++ b/src/Resources/views/Admin/Content/Superadmin/mailWhitelist.html.twig @@ -16,12 +16,6 @@ {% endif %} - {% if isOverridden %} -
- {{ 'Currently the ENV variable MAILER_DELIVERY_WHITELIST is set and overrides this setting.'|trans }} -
- {% endif %} - {{ form_start(form) }} {% embed '@ShopsysFramework/Admin/Inline/FixedBar/fixedBar.html.twig' %} {% block fixed_bar_content %} diff --git a/src/Twig/MailerSettingExtension.php b/src/Twig/MailerSettingExtension.php index a8d45cb661..5bf76a3534 100644 --- a/src/Twig/MailerSettingExtension.php +++ b/src/Twig/MailerSettingExtension.php @@ -41,7 +41,6 @@ public function getFunctions() public function isMailerSettingUnusual() { return $this->mailerSettingProvider->isDeliveryDisabled() - || $this->mailerSettingProvider->isMailerMasterEmailSet() || $this->mailerSettingProvider->isWhitelistEnabled($this->domain->getId()); } @@ -52,7 +51,6 @@ public function getMailerSettingInfo() { return $this->twigEnvironment->render('@ShopsysFramework/Common/Mailer/settingInfo.html.twig', [ 'isDeliveryDisabled' => $this->mailerSettingProvider->isDeliveryDisabled(), - 'mailerMasterEmailAddress' => $this->mailerSettingProvider->isMailerMasterEmailSet() ? $this->mailerSettingProvider->getMailerMasterEmailAddress() : null, 'isWhitelistEnabled' => $this->mailerSettingProvider->isWhitelistEnabled($this->domain->getId()), 'mailerWhitelistExpressions' => $this->mailerSettingProvider->getWhitelistPatternsAsArray($this->domain->getId()), ]); diff --git a/tests/Unit/Component/Cron/CronFacadeTest.php b/tests/Unit/Component/Cron/CronFacadeTest.php index b8dc3cb056..b1c1d4df7c 100644 --- a/tests/Unit/Component/Cron/CronFacadeTest.php +++ b/tests/Unit/Component/Cron/CronFacadeTest.php @@ -120,7 +120,7 @@ private function createCronFacade(CronConfig $cronConfig, CronModuleFacade $cron /** @var \Symfony\Bridge\Monolog\Logger $loggerMock */ $loggerMock = $this->createMock(Logger::class); - $cronModuleExecutor = new CronModuleExecutor(240, $cronConfig); + $cronModuleExecutor = new CronModuleExecutor($cronConfig); return new CronFacade($loggerMock, $cronConfig, $cronModuleFacade, $cronModuleExecutor); } diff --git a/tests/Unit/Component/Cron/CronModuleExecutorTest.php b/tests/Unit/Component/Cron/CronModuleExecutorTest.php index dcee698069..ba8fb86300 100644 --- a/tests/Unit/Component/Cron/CronModuleExecutorTest.php +++ b/tests/Unit/Component/Cron/CronModuleExecutorTest.php @@ -100,6 +100,6 @@ private function getCronModuleExecutor(array $servicesIndexedById): CronModuleEx ); } - return new CronModuleExecutor(1, $cronConfig); + return new CronModuleExecutor($cronConfig); } } diff --git a/tests/Unit/Model/Mail/EnvelopeListenerTest.php b/tests/Unit/Model/Mail/EnvelopeListenerTest.php index e247202fdc..583e624e34 100644 --- a/tests/Unit/Model/Mail/EnvelopeListenerTest.php +++ b/tests/Unit/Model/Mail/EnvelopeListenerTest.php @@ -5,38 +5,48 @@ namespace Tests\FrameworkBundle\Unit\Model\Mail; use PHPUnit\Framework\TestCase; +use Shopsys\FrameworkBundle\Model\Mail\Email; use Shopsys\FrameworkBundle\Model\Mail\EventListener\EnvelopeListener; use Shopsys\FrameworkBundle\Model\Mail\MailerSettingProvider; +use Shopsys\FrameworkBundle\Model\Mail\Setting\MailSettingFacade; use Symfony\Component\Mailer\Envelope; use Symfony\Component\Mailer\Event\MessageEvent; use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Header\Headers; use Symfony\Component\Mime\Header\MailboxListHeader; -use Symfony\Component\Mime\Message; class EnvelopeListenerTest extends TestCase { /** * @dataProvider onMessageDataProvider - * @param \Symfony\Component\Mime\Address|null $masterMail - * @param string $deliveryWhitelist + * @param string|null $deliveryWhitelist + * @param bool $isWhitelistEnabled + * @param bool $isWhitelistForced * @param \Symfony\Component\Mime\Address[] $mailsTo * @param \Symfony\Component\Mime\Address|null $mailCc * @param \Symfony\Component\Mime\Address|null $mailBcc * @param array $expectedRecipients */ public function testOnMessage( - ?Address $masterMail, - string $deliveryWhitelist, + ?string $deliveryWhitelist, + bool $isWhitelistEnabled, + bool $isWhitelistForced, array $mailsTo, ?Address $mailCc, ?Address $mailBcc, array $expectedRecipients, ): void { + $mailSettingFacadeMock = $this->getMockBuilder(MailSettingFacade::class) + ->disableOriginalConstructor() + ->getMock(); + + $mailSettingFacadeMock->method('getMailWhitelist')->willReturn($deliveryWhitelist); + $mailSettingFacadeMock->method('isWhitelistEnabled')->willReturn($isWhitelistEnabled); + $mailerSettingProvider = new MailerSettingProvider( - $deliveryWhitelist, - $masterMail !== null ? $masterMail->getAddress() : '', 'dsn', + $isWhitelistForced, + $mailSettingFacadeMock, ); $envelopeListener = new EnvelopeListener($mailerSettingProvider); $messageEvent = $this->getMessageEvent($mailsTo, $mailCc, $mailBcc); @@ -71,7 +81,7 @@ protected function getMessageEvent( } $envelope = new Envelope($sender, $recipients); - return new MessageEvent(new Message($headers), $envelope, 'transport'); + return new MessageEvent(new Email(1, $headers), $envelope, 'transport'); } /** @@ -79,16 +89,17 @@ protected function getMessageEvent( */ public function onMessageDataProvider(): iterable { - $shopsysMasterMail = new Address('no-reply-mastermail@shopsys.com'); $netdeveloNoReplyMail = new Address('no-reply@netdevelo.cz'); $shopsysNoReplyMail1 = new Address('no-reply@shopsys.com'); $shopsysNoReplyMail2 = new Address('no-reply2@shopsys.com'); $shopsysNoReplyMail3 = new Address('no-reply3@shopsys.com'); + $nonExistingMail = new Address('no-reply@domain.tld'); - // when no master mail is set, whitelist is ignored + // when whitelist is set but not enabled, all mails are delivered to the required addresses without restrictions yield [ - 'masterMail' => null, - 'deliveryWhitelist' => '/@shopsys\.com$/', + 'deliveryWhitelist' => json_encode(['/@shopsys\.com$/'], JSON_THROW_ON_ERROR), + 'isWhitelistEnabled' => false, + 'isWhitelistForced' => false, 'mailsTo' => [$netdeveloNoReplyMail], 'mailCc' => null, 'mailBcc' => null, @@ -96,55 +107,60 @@ public function onMessageDataProvider(): iterable $netdeveloNoReplyMail, ], ]; - // when master mail is set without whitelist, all mails are delivered to the master mail only + + // when whitelist is enabled but empty, all mails are sent to the non-existing address yield [ - 'masterMail' => $shopsysMasterMail, - 'deliveryWhitelist' => '', + 'deliveryWhitelist' => null, + 'isWhitelistEnabled' => true, + 'isWhitelistForced' => false, 'mailsTo' => [$shopsysNoReplyMail1], 'mailCc' => $shopsysNoReplyMail2, 'mailBcc' => $shopsysNoReplyMail3, 'expectedRecipients' => [ - $shopsysMasterMail, + $nonExistingMail, ], ]; - // when master mail is set with whitelist, all mails are delivered to the master mail and to the recipients that match the whitelisted patterns only + + // when whitelist is set and enabled, all mails are delivered to the recipients that match the whitelisted patterns only yield [ - 'masterMail' => $shopsysMasterMail, - 'deliveryWhitelist' => '/@shopsys\.com$/', + 'deliveryWhitelist' => json_encode(['/@shopsys\.com$/'], JSON_THROW_ON_ERROR), + 'isWhitelistEnabled' => true, + 'isWhitelistForced' => false, 'mailsTo' => [$netdeveloNoReplyMail], 'mailCc' => $shopsysNoReplyMail1, 'mailBcc' => $shopsysNoReplyMail2, 'expectedRecipients' => [ - $shopsysMasterMail, $shopsysNoReplyMail1, $shopsysNoReplyMail2, ], ]; - // when there are multiple patterns in the whitelist, mails are delivered to the addresses that match at least one of the patterns + + // when whitelist is set disabled but forced, all mails are still delivered to the recipients that match the whitelisted patterns only yield [ - 'masterMail' => $shopsysMasterMail, - 'deliveryWhitelist' => '/@shopsys\.com$/,/@netdevelo\.cz$/', - 'mailsTo' => [$shopsysNoReplyMail1], - 'mailCc' => $shopsysNoReplyMail2, - 'mailBcc' => $netdeveloNoReplyMail, + 'deliveryWhitelist' => json_encode(['/@shopsys\.com$/'], JSON_THROW_ON_ERROR), + 'isWhitelistEnabled' => false, + 'isWhitelistForced' => true, + 'mailsTo' => [$netdeveloNoReplyMail], + 'mailCc' => $shopsysNoReplyMail1, + 'mailBcc' => $shopsysNoReplyMail2, 'expectedRecipients' => [ - $shopsysMasterMail, $shopsysNoReplyMail1, $shopsysNoReplyMail2, - $netdeveloNoReplyMail, ], ]; - // when there is no master mail nor whitelist, all mails are delivered to the required addresses without restrictions + + // when there are multiple patterns in the whitelist, mails are delivered to the addresses that match at least one of the patterns yield [ - 'masterMail' => null, - 'deliveryWhitelist' => '', - 'mailsTo' => [$netdeveloNoReplyMail], + 'deliveryWhitelist' => json_encode(['/@shopsys\.com$/', '/@netdevelo\.cz$/'], JSON_THROW_ON_ERROR), + 'isWhitelistEnabled' => true, + 'isWhitelistForced' => false, + 'mailsTo' => [$shopsysNoReplyMail1], 'mailCc' => $shopsysNoReplyMail2, - 'mailBcc' => $shopsysNoReplyMail3, + 'mailBcc' => $netdeveloNoReplyMail, 'expectedRecipients' => [ - $netdeveloNoReplyMail, + $shopsysNoReplyMail1, $shopsysNoReplyMail2, - $shopsysNoReplyMail3, + $netdeveloNoReplyMail, ], ]; }