info('Note: Migrations will be stored inside of (storage/migrations) folder.'); if($this->option('user')) { $record = User::findOrFail($this->option('user')); return $this->export($record); } $users = User::all(); 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['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.'); } }