46 lines
1.7 KiB
PHP
46 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\SeasonalSection;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
/**
|
|
* Update published attribute reading its
|
|
* publish_at and unpublish_at attributes.
|
|
*/
|
|
class SeasonalSectionStatusUpdate
|
|
{
|
|
/**
|
|
* Called when the job will be executed.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
/** @var \Illuminate\Database\Eloquent\Collection<array-key, \App\Models\SeasonalSection> */
|
|
$seasonalsectionsListToPublish = SeasonalSection::query()
|
|
->where('publish_at', '<=', Carbon::now()->toDateTime())
|
|
->whereNotNull('publish_at')
|
|
->where('published', false)->get();
|
|
Log::debug(__CLASS__ . " seasonalsections to publish " . $seasonalsectionsListToPublish->count());
|
|
foreach ($seasonalsectionsListToPublish as $seasonalsections) {
|
|
$seasonalsections->publish_at = null;
|
|
$seasonalsections->published = true;
|
|
$seasonalsections->saveOrFail();
|
|
}
|
|
/** @var \Illuminate\Database\Eloquent\Collection<array-key, \App\Models\SeasonalSection> */
|
|
$seasonalsectionsListToUnPublish = SeasonalSection::query()
|
|
->where('unpublish_at', '<=', Carbon::now()->toDateTime())
|
|
->whereNotNull('unpublish_at')
|
|
->where('published', true)->get();
|
|
Log::debug(__CLASS__ . " seasonalsections to unpublish " . $seasonalsectionsListToPublish->count());
|
|
foreach ($seasonalsectionsListToUnPublish as $seasonalsections) {
|
|
$seasonalsections->publish_at = null;
|
|
$seasonalsections->unpublish_at = null;
|
|
$seasonalsections->published = false;
|
|
$seasonalsections->saveOrFail();
|
|
}
|
|
}
|
|
}
|