custom/Espo/Custom/Resources/metadata/app/scheduledJobs.json
Code:
{ "IcalSourceImport": { "jobClassName": "Espo\\Custom\\Jobs\\IcalSourceImport" } }
custom/Espo/Custom/Resources/i18n/en_US/ScheduledJob.json
Code:
{ "options": { "job": { "IcalSourceImport": "IcalSource Importer" } } }
custom/Espo/Custom/Jobs/IcalSourceImport.php
PHP Code:
<?php
namespace Espo\Custom\Jobs;
use Espo\Core\Di\EntityManagerAware;
use Espo\Core\Di\EntityManagerSetter;
use Espo\Core\Job\JobDataLess;
use Espo\Custom\Entities\IcalSource;
use Espo\ORM\Query\Part\Condition;
class IcalSourceImport implements JobDataLess, EntityManagerAware {
use EntityManagerSetter;
public function run(): void {
$icalSources = $this->entityManager->getRDBRepository(IcalSource::ENTITY_TYPE)->where(
Condition::and(
Condition::equal(Condition::column('active'), true),
Condition::or(
Condition::lessOrEqual(Condition::column('nextSync'), (new \DateTime('now', new \DateTimeZone('utc')))->format('Y-m-d H:i:s')),
Condition::equal(Condition::column('nextSync'), null)
)
)
)->find();
}
}