*/ final class UpdateSlidesStatus implements Action { public function __construct( private readonly LoggerInterface $logger, ) { } /** * @param \App\Contracts\ActionInputEmpty $input */ #[\Override] public function __invoke(ActionInput $input): void { Assert::isInstanceOf($input, ActionInputEmpty::class); $now = Date::now(); $unpublishQuery = Slide::query() ->where('date_end', '<=', $now) ->whereNotNull('date_end') ->where('status', true); $unpublishCount = $unpublishQuery->count(); $this->logger->debug(self::class . ' slides to unpublish ' . $unpublishCount); if ($unpublishCount > 0) { $unpublishQuery->update([ 'status' => false, ]); } $publishQuery = Slide::query() ->where('date_start', '<=', $now) ->whereNotNull('date_start') ->where(function (Builder $query) use ($now): void { $query->whereNull('date_end') ->orWhere('date_end', '>', $now); }) ->where('status', false); $publishCount = $publishQuery->count(); $this->logger->debug(self::class . ' slides to publish ' . $publishCount); if ($publishCount > 0) { $publishQuery->update([ 'status' => true, ]); } } }