41 lines
1.5 KiB
PHP
41 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\Editorial\PublicationEffects;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class RetryEditorialIndexNow extends Command
|
|
{
|
|
protected $signature = 'editorial:indexnow-retry';
|
|
|
|
protected $description = 'Retry due editorial IndexNow notifications without republishing content';
|
|
|
|
public function handle(): int
|
|
{
|
|
if (! app()->environment(['production', 'testing']) || ! config('editorial.indexnow_enabled', app()->environment('production'))) {
|
|
$this->line('IndexNow retry disabled in this environment.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
$ids = DB::table('editorial_publications')->where('effects->indexnow->status', 'pending')
|
|
->where(function ($q) {
|
|
$q->whereNull('effects->indexnow->next_attempt_at')
|
|
->orWhere('effects->indexnow->next_attempt_at', '<=', now()->timestamp);
|
|
})->orderBy('updated_at')->limit(10)->pluck('id');
|
|
$pending = 0;
|
|
foreach ($ids as $id) {
|
|
try {
|
|
$receipt = app(PublicationEffects::class)->synchronize($id);
|
|
$pending += ($receipt['effects']['indexnow']['status'] ?? '') === 'pending' ? 1 : 0;
|
|
} catch (\Throwable) {
|
|
$pending++;
|
|
}
|
|
}
|
|
$this->line(json_encode(['processed' => count($ids), 'pending' => $pending]));
|
|
|
|
return $pending ? self::FAILURE : self::SUCCESS;
|
|
}
|
|
}
|