41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\Amministratore;
|
|
use App\Services\Admin\AdministratorProvisioningService;
|
|
|
|
class ProvisionAdministrators extends Command
|
|
{
|
|
protected $signature = 'netgescon:provision-admin {admin_id?} {--all} {--force} {--no-db}';
|
|
protected $description = 'Provisioning cartelle e database dedicato per amministratori';
|
|
|
|
public function handle(): int
|
|
{
|
|
$service = new AdministratorProvisioningService();
|
|
$force = (bool)$this->option('force');
|
|
$createDb = !$this->option('no-db');
|
|
|
|
$query = Amministratore::query();
|
|
if ($id = $this->argument('admin_id')) {
|
|
$query->where('id', $id);
|
|
} elseif (!$this->option('all')) {
|
|
$this->error('Specifica un admin_id oppure usa --all');
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$count = 0;
|
|
$query->chunkById(50, function ($chunk) use (&$count, $service, $force, $createDb) {
|
|
foreach ($chunk as $amm) {
|
|
$res = $service->provision($amm, $createDb, $force);
|
|
$this->line("#{$amm->id} {$amm->codice_amministratore} - db: {$res['database']} changed=" . ($res['changed'] ? 'yes' : 'no'));
|
|
$count++;
|
|
}
|
|
});
|
|
|
|
$this->info("Provisioning completato per {$count} amministratori.");
|
|
return self::SUCCESS;
|
|
}
|
|
}
|