From 43c7504f899d560e70d033fc8a2ac9823e1fabde Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 11 Jul 2024 10:03:51 -0700 Subject: [PATCH] adds an all option, adds help context for all, seperates logic --- app/Console/Commands/RemoveExplicitEols.php | 36 +++++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/app/Console/Commands/RemoveExplicitEols.php b/app/Console/Commands/RemoveExplicitEols.php index 5956e9b10b..03163a475c 100644 --- a/app/Console/Commands/RemoveExplicitEols.php +++ b/app/Console/Commands/RemoveExplicitEols.php @@ -13,7 +13,7 @@ class RemoveExplicitEols extends Command * * @var string */ - protected $signature = 'snipeit:remove-explicit-eols {--model_name=}'; + protected $signature = 'snipeit:remove-explicit-eols {--model_name= : The name of the asset model to update (use "all" to update all models)}'; /** * The console command description. @@ -27,21 +27,29 @@ class RemoveExplicitEols extends Command */ public function handle() { - $assetModel= AssetModel::where('name', '=', $this->option('model_name'))->first(); + if ($this->option('model_name') == 'all') { + $assets = Asset::all(); + $this->updateAssets($assets); + } else { + $assetModel = AssetModel::where('name', '=', $this->option('model_name'))->first(); - if($assetModel){ - $assets = Asset::where('model_id', '=', $assetModel->id)->get(); - - foreach ($assets as $asset) { - $asset->eol_explicit = 0; - $asset->asset_eol_date = null; - $asset->save(); + if ($assetModel) { + $assets = Asset::where('model_id', '=', $assetModel->id)->get(); + $this->updateAssets($assets); + } else { + $this->error('Asset model not found'); } - - $this->info($assets->count().' Assets updated successfully'); - } - else { - $this->error('Asset model not found'); } } + + private function updateAssets($assets) + { + foreach ($assets as $asset) { + $asset->eol_explicit = 0; + $asset->asset_eol_date = null; + $asset->save(); + } + + $this->info($assets->count() . ' Assets updated successfully'); + } }