fix(settings): PHP sync for runtime can_edit after deploy
Force can_edit=1 for Montzar/price runtime keys via settings:deploy and settings:sync-runtime-can-edit, so tenant DB stays correct even when an older deploy SQL is still on the server. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\SettingsRuntimeCanEditSync;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
@@ -100,6 +101,8 @@ class DeploySettingsConstCommand extends Command
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->syncRuntimeCanEdit($db);
|
||||
|
||||
$this->info(" done: {$db}");
|
||||
}
|
||||
|
||||
@@ -129,6 +132,38 @@ class DeploySettingsConstCommand extends Command
|
||||
return $path;
|
||||
}
|
||||
|
||||
private function syncRuntimeCanEdit(string $database): void
|
||||
{
|
||||
try {
|
||||
$sync = app(SettingsRuntimeCanEditSync::class);
|
||||
$sync->useDatabase($database);
|
||||
$updated = $sync->sync();
|
||||
$this->line(" runtime can_edit sync: {$updated} row(s) updated");
|
||||
|
||||
$status = $sync->statusMap();
|
||||
if ($status !== []) {
|
||||
$preview = collect($status)
|
||||
->map(fn ($canEdit, $key) => "{$key}={$canEdit}")
|
||||
->implode(', ');
|
||||
$this->line(" runtime keys: {$preview}");
|
||||
}
|
||||
|
||||
$violations = $sync->violations();
|
||||
if ($violations !== []) {
|
||||
$this->warn(' WARN: runtime keys still can_edit≠1: '.implode(', ', array_keys($violations)));
|
||||
}
|
||||
|
||||
$fee = \App\Models\Setting::query()
|
||||
->where('key', 'fee_deduct_from_gold')
|
||||
->first(['key', 'can_edit']);
|
||||
if ($fee) {
|
||||
$this->line(" check fee_deduct_from_gold can_edit={$fee->can_edit}");
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$this->warn(' runtime can_edit sync skipped: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function findMysqlBinary(): ?string
|
||||
{
|
||||
$process = new Process(['command', '-v', 'mysql']);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\SettingsRuntimeCanEditSync;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class SyncRuntimeSettingsCanEditCommand extends Command
|
||||
{
|
||||
protected $signature = 'settings:sync-runtime-can-edit
|
||||
{database? : نام دیتابیس (پیشفرض DB_DATABASE)}';
|
||||
|
||||
protected $description = 'تثبیت can_edit=1 برای کلیدهای runtime tenant (Montzar، up/down_price، …)';
|
||||
|
||||
public function handle(SettingsRuntimeCanEditSync $sync): int
|
||||
{
|
||||
$database = trim((string) ($this->argument('database') ?: config('database.connections.'.config('database.default').'.database', '')));
|
||||
if ($database === '') {
|
||||
$this->error('DB_DATABASE خالی است یا database را بدهید.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$sync->useDatabase($database);
|
||||
$updated = $sync->sync();
|
||||
$this->info("DB {$database}: {$updated} row(s) updated");
|
||||
|
||||
foreach ($sync->statusMap() as $key => $canEdit) {
|
||||
$this->line(" {$key} => can_edit={$canEdit}");
|
||||
}
|
||||
|
||||
$violations = $sync->violations();
|
||||
if ($violations !== []) {
|
||||
$this->error('هنوز can_edit≠1: '.implode(', ', array_keys($violations)));
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->info('OK — همه کلیدهای runtime can_edit=1');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user