1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 12:42:36 +01:00

Fix the way we process migration

This commit is contained in:
Benjamin Beganović 2020-11-12 11:04:50 +01:00
parent 4019ff08d6
commit 666a9398d3
2 changed files with 15 additions and 16 deletions

View File

@ -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;

View File

@ -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;