mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 12:42:36 +01:00
[V1] Update 'migrations:export' message (#3470)
* Update command message * Export migrations command improvements
This commit is contained in:
parent
d9a3b5453a
commit
3f25b62ab6
@ -17,14 +17,14 @@ class ExportMigrations extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'migrations:export';
|
||||
protected $signature = 'migrations:export {--user=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Export account migrations to folder';
|
||||
protected $description = 'Export account migrations to folder.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@ -43,39 +43,53 @@ class ExportMigrations extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
foreach (User::all() as $user) {
|
||||
$this->account = $user->account;
|
||||
$this->info('Note: Migrations will be stored inside of (storage/migrations) folder.');
|
||||
|
||||
$date = date('Y-m-d');
|
||||
$accountKey = $this->account->account_key;
|
||||
if($this->option('user')) {
|
||||
$record = User::findOrFail($this->option('user'));
|
||||
return $this->export($record);
|
||||
}
|
||||
|
||||
$output = fopen('php://output', 'w') or Utils::fatalError();
|
||||
$users = User::all();
|
||||
|
||||
$fileName = "{$accountKey}-{$date}-invoiceninja";
|
||||
|
||||
$data = [
|
||||
'company' => $this->getCompany(),
|
||||
'users' => $this->getUsers(),
|
||||
'tax_rates' => $this->getTaxRates(),
|
||||
'clients' => $this->getClients(),
|
||||
'products' => $this->getProducts(),
|
||||
'invoices' => $this->getInvoices(),
|
||||
'quotes' => $this->getQuotes(),
|
||||
'payments' => array_merge($this->getPayments(), $this->getCredits()),
|
||||
'credits' => $this->getCreditsNotes(),
|
||||
'documents' => $this->getDocuments(),
|
||||
'company_gateways' => $this->getCompanyGateways(),
|
||||
'client_gateway_tokens' => $this->getClientGatewayTokens(),
|
||||
];
|
||||
|
||||
$file = storage_path("migrations/{$fileName}.zip");
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
$zip->open($file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
|
||||
$zip->addFromString('migration.json', json_encode($data, JSON_PRETTY_PRINT));
|
||||
$zip->close();
|
||||
|
||||
$this->info('User with id #'. $user->id . ' exported.');
|
||||
foreach($users as $user) {
|
||||
$this->export($user);
|
||||
}
|
||||
}
|
||||
|
||||
private function export($user)
|
||||
{
|
||||
$this->account = $user->account;
|
||||
|
||||
$date = date('Y-m-d');
|
||||
$accountKey = $this->account->account_key;
|
||||
|
||||
$output = fopen('php://output', 'w') or Utils::fatalError();
|
||||
|
||||
$fileName = "{$accountKey}-{$date}-invoiceninja";
|
||||
|
||||
$data = [
|
||||
'company' => $this->getCompany(),
|
||||
'users' => $this->getUsers(),
|
||||
'tax_rates' => $this->getTaxRates(),
|
||||
'clients' => $this->getClients(),
|
||||
'products' => $this->getProducts(),
|
||||
'invoices' => $this->getInvoices(),
|
||||
'quotes' => $this->getQuotes(),
|
||||
'payments' => array_merge($this->getPayments(), $this->getCredits()),
|
||||
'credits' => $this->getCreditsNotes(),
|
||||
'documents' => $this->getDocuments(),
|
||||
'company_gateways' => $this->getCompanyGateways(),
|
||||
'client_gateway_tokens' => $this->getClientGatewayTokens(),
|
||||
];
|
||||
|
||||
$file = storage_path("migrations/{$fileName}.zip");
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
$zip->open($file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
|
||||
$zip->addFromString('migration.json', json_encode($data, JSON_PRETTY_PRINT));
|
||||
$zip->close();
|
||||
|
||||
$this->info('User with id #' . $user->id . ' exported.');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user