Release v1.4.0 #146
2 changed files with 15 additions and 5 deletions
|
|
@ -47,11 +47,7 @@ public function handle(PublishRouteArticleAction $publishRouteArticle): void
|
|||
|
||||
// Get the oldest approved route_article that hasn't been published to its channel yet
|
||||
$routeArticle = RouteArticle::where('approval_status', ApprovalStatusEnum::APPROVED)
|
||||
->where('publish_attempts', '<', RouteArticle::MAX_PUBLISH_ATTEMPTS)
|
||||
->where(function ($query) {
|
||||
$query->whereNull('next_attempt_at')
|
||||
->orWhere('next_attempt_at', '<=', now());
|
||||
})
|
||||
->dueForPublishing()
|
||||
->whereDoesntHave('article.articlePublications', function ($query) {
|
||||
$query->whereColumn('article_publications.platform_channel_id', 'route_articles.platform_channel_id');
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
use App\Enums\PublishStatusEnum;
|
||||
use App\Events\RouteArticleApproved;
|
||||
use Database\Factories\RouteArticleFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
|
@ -136,4 +137,17 @@ public function hasExhaustedPublishAttempts(): bool
|
|||
{
|
||||
return $this->publish_attempts >= self::MAX_PUBLISH_ATTEMPTS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<RouteArticle> $query
|
||||
* @return Builder<RouteArticle>
|
||||
*/
|
||||
public function scopeDueForPublishing(Builder $query): Builder
|
||||
{
|
||||
return $query->where('publish_attempts', '<', self::MAX_PUBLISH_ATTEMPTS)
|
||||
->where(function (Builder $query) {
|
||||
$query->whereNull('next_attempt_at')
|
||||
->orWhere('next_attempt_at', '<=', now());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue