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-11 10:03:51 -07:00
|
|
|
protected $signature = 'snipeit:remove-explicit-eols {--model_name= : The name of the asset model to update (use "all" to update all models)}';
|
2024-07-10 10:21:24 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2024-07-10 11:09:57 -07:00
|
|
|
protected $description = 'Removes 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()
|
|
|
|
{
|
2024-07-11 10:52:47 -07:00
|
|
|
$startTime = microtime(true);
|
|
|
|
|
2024-07-11 10:03:51 -07:00
|
|
|
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();
|
|
|
|
$this->updateAssets($assets);
|
|
|
|
} else {
|
|
|
|
$this->error('Asset model not found');
|
2024-07-10 10:56:44 -07:00
|
|
|
}
|
2024-07-10 10:21:24 -07:00
|
|
|
}
|
2024-07-11 10:52:47 -07:00
|
|
|
$endTime = microtime(true);
|
|
|
|
$executionTime = ($endTime - $startTime);
|
|
|
|
$this->info('Command executed in ' . round($executionTime, 2) . ' seconds.');
|
2024-07-11 10:03:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private function updateAssets($assets)
|
|
|
|
{
|
|
|
|
foreach ($assets as $asset) {
|
|
|
|
$asset->eol_explicit = 0;
|
|
|
|
$asset->asset_eol_date = null;
|
|
|
|
$asset->save();
|
2024-07-10 10:21:24 -07:00
|
|
|
}
|
2024-07-11 10:03:51 -07:00
|
|
|
|
|
|
|
$this->info($assets->count() . ' Assets updated successfully');
|
2024-07-10 10:21:24 -07:00
|
|
|
}
|
|
|
|
}
|