Export 'company_key' with migrations (#3600)

- Removed 'Hosted' option for migrating
- Passing companyKey property when sending request
This commit is contained in:
Benjamin Beganović 2020-04-07 22:43:20 +02:00 committed by GitHub
parent 0c7620a381
commit 602a15f648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 6 deletions

View File

@ -155,11 +155,12 @@ class StepsController extends BaseController
return redirect($this->access['companies']['redirect']); return redirect($this->access['companies']['redirect']);
foreach ($request->companies as $company) { foreach ($request->companies as $company) {
$completeService = (new CompleteService(session('MIGRATION_ACCOUNT_TOKEN'))) (new CompleteService(session('MIGRATION_ACCOUNT_TOKEN')))
->file($this->getMigrationFile()) ->file($this->getMigrationFile())
->force(array_key_exists('force', $company)) ->force(array_key_exists('force', $company))
->company($company['id']) ->company($company['id'])
->endpoint(session('MIGRATION_ENDPOINT')) ->endpoint(session('MIGRATION_ENDPOINT'))
->companyKey($company['key'])
->start(); ->start();
} }
@ -223,7 +224,7 @@ class StepsController extends BaseController
'client_gateway_tokens' => $this->getClientGatewayTokens(), 'client_gateway_tokens' => $this->getClientGatewayTokens(),
]; ];
$file = storage_path("{$fileName}.zip"); $file = storage_path("migrations/{$fileName}.zip");
$zip = new \ZipArchive(); $zip = new \ZipArchive();
$zip->open($file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); $zip->open($file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);

View File

@ -16,7 +16,7 @@ class CompleteService
protected $errors = []; protected $errors = [];
protected $isSuccessful; protected $isSuccessful;
protected $force = false; protected $force = false;
protected $companyKey;
public function __construct(string $token) public function __construct(string $token)
{ {
@ -51,11 +51,19 @@ class CompleteService
return $this; return $this;
} }
public function companyKey(string $key)
{
$this->companyKey = $key;
return $this;
}
public function start() public function start()
{ {
$body = [ $body = [
'migration' => \Unirest\Request\Body::file($this->file, 'application/zip'), 'migration' => \Unirest\Request\Body::file($this->file, 'application/zip'),
'force' => $this->force, 'force' => $this->force,
'company_key' => $this->companyKey,
]; ];
$response = Request::post($this->getUrl(), $this->getHeaders(), $body); $response = Request::post($this->getUrl(), $this->getHeaders(), $body);

View File

@ -24,6 +24,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<input type="checkbox" name="companies[{{ $company->id }}][force]"> <input type="checkbox" name="companies[{{ $company->id }}][force]">
<input type="hidden" name="companies[{{ $company->id }}][key]" value="{{ $company->company_key }}">
<label for="force">Force migration</label> <label for="force">Force migration</label>
<small>* All current company data will be wiped.</small> <small>* All current company data will be wiped.</small>
</div> </div>

View File

@ -12,15 +12,15 @@
<h4>In order to start the migration, we need to know where do you want to migrate.</h4><br/> <h4>In order to start the migration, we need to know where do you want to migrate.</h4><br/>
<form action="/migration/type" method="post" id="select-type-form"> <form action="/migration/type" method="post" id="select-type-form">
{{ csrf_field() }} {{ csrf_field() }}
<div class="form-check"> <!-- <div class="form-check">
<input class="form-check-input" type="radio" name="option" id="option1" value="0" checked> <input class="form-check-input" type="radio" name="option" id="option1" value="0" checked>
<label class="form-check-label" for="option1"> <label class="form-check-label" for="option1">
Hosted Hosted
</label> </label>
<p>If you chose 'hosted', we will migrate your data to official Invoice Ninja servers & take care of server handling.</p> <p>If you chose 'hosted', we will migrate your data to official Invoice Ninja servers & take care of server handling.</p>
</div> </div> -->
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="radio" name="option" id="option2" value="1"> <input class="form-check-input" type="radio" name="option" id="option2" value="1" checked">
<label class="form-check-label" for="option2"> <label class="form-check-label" for="option2">
Self-hosted Self-hosted
</label> </label>