Files
kupshop/bundles/External/ZNZBundle/EventSubscriber/CronSubscriber.php
2025-08-02 16:30:27 +02:00

65 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace External\ZNZBundle\EventSubscriber;
use External\ZNZBundle\Util\Product\ZNZVisibilityUpdater;
use External\ZNZBundle\Util\ZNZLogger;
use External\ZNZBundle\Util\ZNZPriceLevelsGenerator;
use External\ZNZBundle\Util\ZNZTranslationsUtil;
use External\ZNZBundle\Util\ZNZUtil;
use KupShop\KupShopBundle\Event\CronEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CronSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly ZNZUtil $znzUtil,
private readonly ZNZPriceLevelsGenerator $priceLevelsGenerator,
private readonly ZNZTranslationsUtil $znzTranslationsUtil,
private readonly ZNZVisibilityUpdater $visibilityUpdater,
private readonly ZNZLogger $znzLogger,
) {
}
public static function getSubscribedEvents(): array
{
return [
CronEvent::RUN_NORMAL => [
['sortParametersAndVariationsValues', 200],
['updateEmptyTranslations', 200],
],
CronEvent::RUN_EXPENSIVE => [
['handleExpensive', 200],
],
];
}
/** Seradime hodnoty jmenovek variant a hodnoty parametru tak, jak potrebujeme */
public function sortParametersAndVariationsValues(): void
{
$this->znzUtil->sortColorLabelValues();
$this->znzUtil->sortParameterAlphabet(
$this->znzUtil->getParameterByKey('objemsJednotkou')
);
$this->znzUtil->sortParameterAlphabet(
$this->znzUtil->getParameterByKey('SpecifikaBaleni')
);
}
public function updateEmptyTranslations(): void
{
$this->znzTranslationsUtil->updateAll();
$this->visibilityUpdater->updateVisibility();
}
public function handleExpensive(): void
{
$this->znzLogger->activityProcessLog('Aktualizace filtr parametrů u nových výrobců', fn () => $this->znzUtil->updateParametersProducers());
$this->znzLogger->activityProcessLog('Generování souvisejících produktů', fn () => $this->znzUtil->generateProductsRelated());
$this->znzLogger->activityProcessLog('Aktualizace cenových hladin uživatelů', fn () => $this->priceLevelsGenerator->generate());
$this->znzLogger->activityProcessLog('Promazání MOVED_x produktů a variant', fn () => $this->znzUtil->cleanMovedProducts());
}
}