diff --git a/app/Console/Commands/RegenerateAssetTags.php b/app/Console/Commands/RegenerateAssetTags.php new file mode 100644 index 0000000000..9e436df6dd --- /dev/null +++ b/app/Console/Commands/RegenerateAssetTags.php @@ -0,0 +1,105 @@ +confirm('This will regenerate all of the asset tags within your system. This action is data-destructive and should be used with caution. Do you wish to continue?')) + { + + $output['info'] = []; + $output['warn'] = []; + $output['error'] = []; + $settings = Setting::getSettings(); + + $start_tag = ($this->option('start')) ? $this->option('start') : (($settings->next_auto_tag_base) ? Setting::getSettings()->next_auto_tag_base : 1) ; + + $this->info('Starting at '.$start_tag); + + $total_assets = Asset::orderBy('id','asc')->get(); + $bar = $this->output->createProgressBar(count($total_assets)); + + try { + Artisan::call('backup:run'); + } catch (\Exception $e) { + $output['error'][] = $e; + } + + foreach ($total_assets as $asset) { + + $start_tag++; + $output['info'][] = 'Asset tag:'.$asset->asset_tag; + $asset->asset_tag = $settings->auto_increment_prefix.$settings->auto_increment_prefix.$start_tag; + + if ($settings->zerofill_count > 0) { + $asset->asset_tag = $settings->auto_increment_prefix.Asset::zerofill($start_tag, $settings->zerofill_count); + } + + $output['info'][] = 'New Asset tag:'.$asset->asset_tag; + + // Use forceSave here to override model level validation + $asset->forceSave(); + } + + $bar->finish(); + $this->info("\n"); + + + if (($this->option('output')=='all') || ($this->option('output')=='info')) { + foreach ($output['info'] as $key => $output_text) { + $this->info($output_text); + } + } + if (($this->option('output')=='all') || ($this->option('output')=='warn')) { + foreach ($output['warn'] as $key => $output_text) { + $this->warn($output_text); + } + } + if (($this->option('output')=='all') || ($this->option('output')=='error')) { + foreach ($output['error'] as $key => $output_text) { + $this->error($output_text); + } + } + } + + + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 9a49718df3..9a0d3090e5 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -28,6 +28,7 @@ class Kernel extends ConsoleKernel Commands\RecryptFromMcrypt::class, Commands\ResetDemoSettings::class, Commands\SyncAssetLocations::class, + Commands\RegenerateAssetTags::class, ]; /**