Your IP : 216.73.217.13


Current Path : /var/www/www.indacotrentino.com/www/app/code/Amasty/CronScheduleList/Model/
Upload File :
Current File : /var/www/www.indacotrentino.com/www/app/code/Amasty/CronScheduleList/Model/ScheduleCollection.php

<?php
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Cron Schedule List for Magento 2 (System) 
 */

namespace Amasty\CronScheduleList\Model;

use Magento\Cron\Model\Schedule;

class ScheduleCollection extends \Magento\Cron\Model\ResourceModel\Schedule\Collection
{
    public function getLastActivity()
    {
        $this->addFieldToFilter('job_code', 'amasty_cron_activity')
            ->getSelect()->where('finished_at IS NOT NULL')->order('finished_at');

        return $this->getLastItem();
    }

    public function removeActivitySchedule()
    {
        $this->getSelect()->where('job_code != "amasty_cron_activity"');

        return $this;
    }

    public function getFailedScheduleByJobCode($jobCode)
    {
        return $this->addFieldToFilter('job_code', $jobCode)
            ->addFieldToFilter('status', Schedule::STATUS_ERROR)
            ->getLastItem();
    }

    public function getLastFailedJobs()
    {
        $lastFailedJobs = [];
        $items = $this->addFieldToFilter('status', Schedule::STATUS_ERROR)->getItems();

        foreach ($items as $item) {
            $lastFailedJobs[$item->getJobCode()] = $item;
        }

        return $lastFailedJobs;
    }
}