diff --git a/app/Http/Controllers/Migration/StepsController.php b/app/Http/Controllers/Migration/StepsController.php index 9fe58ea40161..890b6f0e0c28 100644 --- a/app/Http/Controllers/Migration/StepsController.php +++ b/app/Http/Controllers/Migration/StepsController.php @@ -224,7 +224,7 @@ class StepsController extends BaseController $fileName = "{$accountKey}-{$date}-invoiceninja"; - $migrationData[$company['id']]['data'] = [ + $localMigrationData['data'] = [ 'company' => $this->getCompany(), 'users' => $this->getUsers(), 'tax_rates' => $this->getTaxRates(), @@ -247,16 +247,18 @@ class StepsController extends BaseController 'tasks' => $this->getTasks(), ]; - $migrationData[$company['id']]['force'] = array_key_exists('force', $company) ? true : false; + $localMigrationData['force'] = array_key_exists('force', $company) ? true : false; $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->addFromString('migration.json', json_encode($localMigrationData, JSON_PRETTY_PRINT)); $zip->close(); - $migrationData[$company['id']]['file'] = $file; + $localMigrationData['file'] = $file; + + $migrationData[] = $localMigrationData; } return $migrationData; diff --git a/app/Services/Migration/AuthService.php b/app/Services/Migration/AuthService.php index 1743aee3ef16..7e1ec8bb2ad4 100644 --- a/app/Services/Migration/AuthService.php +++ b/app/Services/Migration/AuthService.php @@ -38,24 +38,21 @@ class AuthService $body = Body::json($data); - $response = Request::post($this->getUrl(), $this->getHeaders(), $body); + try { + $response = Request::post($this->getUrl(), $this->getHeaders(), $body); - if ($response->code == 200) { - - try { - $this->isSuccessful = true; - $this->token = $response->body->data[0]->token->token; - } catch (\Exception $e) { - info($e->getMessage()); + $this->isSuccessful = true; + $this->token = $response->body->data[0]->token->token; + if (in_array($response->code, [401, 422, 500])) { $this->isSuccessful = false; - $this->errors = [trans('texts.migration_went_wrong')]; + $this->processErrors($response->body); } - } + } catch (\Exception $e) { + info($e->getMessage()); - if (in_array($response->code, [401, 422, 500])) { $this->isSuccessful = false; - $this->processErrors($response->body); + $this->errors = [trans('texts.migration_went_wrong')]; } return $this;