refactoring

This commit is contained in:
Yuri Kuznetsov
2021-06-15 11:59:44 +03:00
parent dc5ac7b3a3
commit f2ee9afa88
5 changed files with 69 additions and 18 deletions
+1 -3
View File
@@ -29,8 +29,6 @@
namespace Espo\Core\Job;
use Espo\Entities\ScheduledJob;
use DateTimeImmutable;
/**
@@ -41,5 +39,5 @@ interface JobPreperable extends Job
/**
* Create multiple job records for a scheduled job.
*/
public function prepare(ScheduledJob $scheduledJob, DateTimeImmutable $executeTime): void;
public function prepare(ScheduledJobData $data, DateTimeImmutable $executeTime): void;
}
@@ -152,10 +152,12 @@ class ScheduleProcessor
if ($this->jobFactory->isPreparable($jobName)) {
$jobObj = $this->jobFactory->create($jobName);
$data = new ScheduledJobData($scheduledJob->getId(), $scheduledJob->getName());
$executeAtDt = DateTimeImmutable
::createFromFormat(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT, $executeTime);
$jobObj->prepare($scheduledJob, $executeAtDt);
$jobObj->prepare($data, $executeAtDt);
return;
}
@@ -0,0 +1,53 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2021 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Job;
class ScheduledJobData
{
private $id;
private $name;
public function __construct(string $id, string $name)
{
$this->id = $id;
$this->name = $name;
}
public function getId(): string
{
return $this->id;
}
public function getName(): string
{
return $this->name;
}
}
+6 -7
View File
@@ -35,13 +35,12 @@ use Espo\Core\{
Job\JobStatus,
Job\JobPreperable,
Job\Data,
Job\ScheduledJobData,
ServiceFactory,
ORM\EntityManager,
Utils\DateTime,
};
use Espo\Entities\ScheduledJob;
use Throwable;
use DateTimeImmutable;
@@ -87,7 +86,7 @@ class CheckEmailAccounts implements JobPreperable
}
}
public function prepare(ScheduledJob $scheduledJob, DateTimeImmutable $executeTime): void
public function prepare(ScheduledJobData $data, DateTimeImmutable $executeTime): void
{
$collection = $this->entityManager
->getRDBRepository('EmailAccount')
@@ -103,7 +102,7 @@ class CheckEmailAccounts implements JobPreperable
$running = $this->entityManager
->getRDBRepository('Job')
->where([
'scheduledJobId' => $scheduledJob->getId(),
'scheduledJobId' => $data->getId(),
'status' => [
JobStatus::RUNNING,
JobStatus::READY,
@@ -120,7 +119,7 @@ class CheckEmailAccounts implements JobPreperable
$countPending = $this->entityManager
->getRDBRepository('Job')
->where([
'scheduledJobId' => $scheduledJob->getId(),
'scheduledJobId' => $data->getId(),
'status' => JobStatus::PENDING,
'targetType' => 'EmailAccount',
'targetId' => $entity->getId(),
@@ -134,8 +133,8 @@ class CheckEmailAccounts implements JobPreperable
$jobEntity = $this->entityManager->getEntity('Job');
$jobEntity->set([
'name' => $scheduledJob->getName(),
'scheduledJobId' => $scheduledJob->getId(),
'name' => $data->getName(),
'scheduledJobId' => $data->getId(),
'executeTime' => $executeTime->format(DateTime::SYSTEM_DATE_TIME_FORMAT),
'targetType' => 'EmailAccount',
'targetId' => $entity->getId(),
+6 -7
View File
@@ -35,13 +35,12 @@ use Espo\Core\{
Job\JobStatus,
Job\JobPreperable,
Job\Data,
Job\ScheduledJobData,
ServiceFactory,
ORM\EntityManager,
Utils\DateTime,
};
use Espo\Entities\ScheduledJob;
use Throwable;
use DateTimeImmutable;
@@ -87,7 +86,7 @@ class CheckInboundEmails implements JobPreperable
}
}
public function prepare(ScheduledJob $scheduledJob, DateTimeImmutable $executeTime): void
public function prepare(ScheduledJobData $data, DateTimeImmutable $executeTime): void
{
$collection = $this->entityManager
->getRDBRepository('InboundEmail')
@@ -101,7 +100,7 @@ class CheckInboundEmails implements JobPreperable
$running = $this->entityManager
->getRDBRepository('Job')
->where([
'scheduledJobId' => $scheduledJob->getId(),
'scheduledJobId' => $data->getId(),
'status' => [
JobStatus::RUNNING,
JobStatus::READY,
@@ -118,7 +117,7 @@ class CheckInboundEmails implements JobPreperable
$countPending = $this->entityManager
->getRDBRepository('Job')
->where([
'scheduledJobId' => $scheduledJob->getId(),
'scheduledJobId' => $data->getId(),
'status' => JobStatus::PENDING,
'targetType' => 'InboundEmail',
'targetId' => $entity->getId(),
@@ -132,8 +131,8 @@ class CheckInboundEmails implements JobPreperable
$jobEntity = $this->entityManager->getEntity('Job');
$jobEntity->set([
'name' => $scheduledJob->getName(),
'scheduledJobId' => $scheduledJob->getId(),
'name' => $data->getName(),
'scheduledJobId' => $data->getId(),
'executeTime' => $executeTime->format(DateTime::SYSTEM_DATE_TIME_FORMAT),
'targetType' => 'InboundEmail',
'targetId' => $entity->getId(),