Joywork/import/ImportStartStrategy.php
2026-05-22 21:21:54 +03:00

48 lines
1.2 KiB
PHP

<?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;
}
}