2024-07-10 10:21:24 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\AssetModel;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
class RemoveExplicitEols extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2024-07-10 10:56:44 -07:00
|
|
|
protected $signature = 'snipeit:remove-explicit-eols {--model_name=}';
|
2024-07-10 10:21:24 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2024-07-10 10:57:47 -07:00
|
|
|
protected $description = 'remove explicit eols on assets with selected model so they may inherit the asset model eol';
|
2024-07-10 10:21:24 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$assetModel= AssetModel::where('name', '=', $this->option('model_name'))->first();
|
|
|
|
|
|
|
|
if($assetModel){
|
|
|
|
$assets = Asset::where('model_id', '=', $assetModel->id)->get();
|
2024-07-10 10:56:44 -07:00
|
|
|
|
|
|
|
foreach ($assets as $asset) {
|
|
|
|
$asset->eol_explicit = 0;
|
|
|
|
$asset->asset_eol_date = null;
|
|
|
|
$asset->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->info($assets->count().' Assets updated successfully');
|
2024-07-10 10:21:24 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->error('Asset model not found');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|