Backup before running updates

This commit is contained in:
Marcus Moore 2025-04-03 14:39:40 -07:00
parent 18ef88bd67
commit 9a8e5bf61e
No known key found for this signature in database

View file

@ -14,7 +14,7 @@ class FixBulkAccessoryCheckinActionLogEntries extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'snipeit:fix-bulk-accessory-action-log-entries {--dry-run : Run the sync process but don\'t update the database}'; protected $signature = 'snipeit:fix-bulk-accessory-action-log-entries {--dry-run : Run the sync process but don\'t update the database} {--skip-backup : Skip pre-execution backup}';
/** /**
* The console command description. * The console command description.
@ -24,15 +24,15 @@ class FixBulkAccessoryCheckinActionLogEntries extends Command
protected $description = 'This script attempts to fix timestamps and missing created_by values for bulk checkin entries in the log table'; protected $description = 'This script attempts to fix timestamps and missing created_by values for bulk checkin entries in the log table';
private bool $dryrun = false; private bool $dryrun = false;
private bool $skipBackup = false;
/** /**
* Execute the console command. * Execute the console command.
*/ */
public function handle() public function handle()
{ {
if ($this->option('dry-run')) { $this->skipBackup = $this->option('skip-backup');
$this->dryrun = true; $this->dryrun = $this->option('dry-run');
}
if ($this->dryrun) { if ($this->dryrun) {
$this->info('This is a DRY RUN - no changes will be saved.'); $this->info('This is a DRY RUN - no changes will be saved.');
@ -71,6 +71,11 @@ class FixBulkAccessoryCheckinActionLogEntries extends Command
return 0; return 0;
} }
if (!$this->dryrun && !$this->skipBackup) {
$this->info('Backing up the database before making changes...');
$this->call('snipeit:backup');
}
if ($this->dryrun) { if ($this->dryrun) {
$this->newLine(); $this->newLine();
$this->info('DRY RUN. NOT ACTUALLY UPDATING LOGS.'); $this->info('DRY RUN. NOT ACTUALLY UPDATING LOGS.');