2026-05-10 19:58:47 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Сброс projects.delivered_today=0 для всех tenant'ов.
|
|
|
|
|
*
|
2026-05-11 01:00:47 +03:00
|
|
|
* Spec: docs/superpowers/specs/2026-05-10-supplier-integration-design.md §6.1 +
|
|
|
|
|
* docs/superpowers/specs/2026-05-11-plan3-supplier-sync-design.md §1.
|
2026-05-10 19:58:47 +03:00
|
|
|
* Расписание: каждый день в 00:00 МСК (timezone Europe/Moscow).
|
|
|
|
|
*
|
2026-05-11 01:00:47 +03:00
|
|
|
* Plan 3 Task 3 (WARN #3): UPDATE идёт через connection `pgsql_supplier`
|
|
|
|
|
* (BYPASSRLS-роль crm_supplier_worker), что позволяет одним statement'ом сбросить
|
|
|
|
|
* счётчики по всем tenant'ам без SET LOCAL app.current_tenant_id для каждого.
|
2026-05-10 19:58:47 +03:00
|
|
|
*/
|
|
|
|
|
class ResetDeliveredTodayCommand extends Command
|
|
|
|
|
{
|
|
|
|
|
protected $signature = 'projects:reset-delivered-today';
|
|
|
|
|
|
|
|
|
|
protected $description = 'Сброс projects.delivered_today=0 (00:00 МСК cron, spec §6.1)';
|
|
|
|
|
|
|
|
|
|
public function handle(): int
|
|
|
|
|
{
|
2026-05-11 01:00:47 +03:00
|
|
|
$affected = DB::connection('pgsql_supplier')
|
|
|
|
|
->update('UPDATE projects SET delivered_today = 0 WHERE delivered_today <> 0');
|
2026-05-10 19:58:47 +03:00
|
|
|
|
|
|
|
|
$this->info("Reset delivered_today on {$affected} project(s).");
|
|
|
|
|
|
|
|
|
|
return self::SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
}
|