Joywork/import/ImportStartStrategy.php

48 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
<?php
class ImportStartStrategy
{
/**
* @var ImporterService
*/
private $importerService;
/**
* @inheritDoc
*/
public function __construct() {
$this->importerService = new ImporterService();
}
/**
* Определяем пришло время импорта или нет
* @param \DateTimeImmutable $date
* @return bool
*/
public function isRunnable($date) {
$isImporterActive = $this->importerService->isActive();
if ($isImporterActive) {
return false;
}
$lastImportDate = $this->importerService->getImportDate();
if (empty($lastImportDate)){
return true;
}
$lastImportDate = new \DateTimeImmutable($lastImportDate);
// если последний раз выгрузка была вчера, то запускаем импорт
if ((int)$lastImportDate->format('d') !== (int)$date->format('d')) {
return true;
}
if ($this->importerService->isForceStart()) {
$this->importerService->setForceImport(false);
return true;
}
return false;
}
}