flexisip-account-manager/flexiapi/app/Console/Commands/ExportToExternalAccounts.php
Timothée Jaussoin 7a17897193 Add ExternalAccounts and related features
- Consume an ExternalAccount on Account creation
- Add a tombstone to an ExternalAccount to ensure non re-usage
- Add related tests
- Generalize Utils
- Stop public registration when there is no ExternalAccounts left
- Add GenerateExternalAccounts, ExportToExternalAccounts and ImportExternalAccounts console scripts
- Provision the ExternalAccount using the depends_on/idkey pair
2022-07-12 17:05:17 +02:00

51 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Account;
use Illuminate\Console\Command;
class ExportToExternalAccounts extends Command
{
protected $signature = 'accounts:export-to-externals {group} {--o|output=}';
protected $description = 'Export accounts from a group as external ones';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$accounts = Account::where('group', $this->argument('group'))
->with('passwords')
->get();
if ($accounts->count() == 0) {
$this->error('Nothing to export');
return;
}
$this->info('Exporting '.$accounts->count().' accounts');
$data = [];
foreach ($accounts as $account) {
array_push($data, [
'username' => $account->username,
'domain' => $account->domain,
'group' => $account->group,
'password' => $account->passwords->first()->password,
'algorithm' => $account->passwords->first()->algorithm,
]);
}
file_put_contents(
$this->option('output') ?? getcwd() . '/exported_accounts.json',
json_encode($data)
);
$this->info('Exported');
}
}