mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04: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
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'migrations:export';
|
protected $signature = 'migrations:export {--user=}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Export account migrations to folder';
|
protected $description = 'Export account migrations to folder.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
@ -43,39 +43,53 @@ class ExportMigrations extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
foreach (User::all() as $user) {
|
$this->info('Note: Migrations will be stored inside of (storage/migrations) folder.');
|
||||||
$this->account = $user->account;
|
|
||||||
|
|
||||||
$date = date('Y-m-d');
|
if($this->option('user')) {
|
||||||
$accountKey = $this->account->account_key;
|
$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";
|
foreach($users as $user) {
|
||||||
|
$this->export($user);
|
||||||
$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.');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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…
x
Reference in New Issue
Block a user