Skip to content

Commit

Permalink
[shopsys] removed deprecations before release 12.0 (#2768)
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmannmartin authored Sep 5, 2023
1 parent 9540169 commit a679d39
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 466 deletions.
14 changes: 1 addition & 13 deletions src/Command/CronCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
30 changes: 2 additions & 28 deletions src/Component/Cron/Config/CronConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(
Expand All @@ -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);

Expand Down
50 changes: 6 additions & 44 deletions src/Component/Cron/CronModuleExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
}
17 changes: 2 additions & 15 deletions src/Component/Cron/CronModuleFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
45 changes: 4 additions & 41 deletions src/Controller/Admin/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
46 changes: 6 additions & 40 deletions src/Controller/Admin/SuperadminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,8 +25,6 @@

class SuperadminController extends AdminBaseController
{
use SetterInjectionTrait;

/**
* @param \Shopsys\FrameworkBundle\Model\Module\ModuleList $moduleList
* @param \Shopsys\FrameworkBundle\Model\Module\ModuleFacade $moduleFacade
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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(),
]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Advert/AdvertRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down
Loading

0 comments on commit a679d39

Please sign in to comment.