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

Refactor Migration codebase

This commit is contained in:
David Bomba 2021-07-17 18:58:42 +10:00
parent 50a0532bf4
commit 391df15a96
4 changed files with 35 additions and 40 deletions

View File

@ -8,16 +8,17 @@ use App\Http\Requests\MigrationCompaniesRequest;
use App\Http\Requests\MigrationEndpointRequest;
use App\Http\Requests\MigrationForwardRequest;
use App\Http\Requests\MigrationTypeRequest;
use App\Jobs\HostedMigration;
use App\Libraries\Utils;
use App\Models\Account;
use App\Services\Migration\AuthService;
use App\Services\Migration\CompanyService;
use App\Services\Migration\CompleteService;
use App\Traits\GenerateMigrationResources;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Validator;
use Illuminate\Http\Request;
class StepsController extends BaseController
{
@ -48,6 +49,17 @@ class StepsController extends BaseController
*/
public function start()
{
if(Utils::isNinja()){
session()->put('MIGRATION_ENDPOINT', 'https://v5-app1.invoicing.co');
// session()->put('MIGRATION_ENDPOINT', 'http://ninja.test:8000');
session()->put('MIGRATION_ACCOUNT_TOKEN','');
session()->put('MIGRAITON_API_SECRET', null);
return $this->companies();
}
return view('migration.start');
}
@ -68,16 +80,13 @@ class StepsController extends BaseController
{
session()->put('MIGRATION_TYPE', $request->option);
if ($request->option == 0) {
if ($request->option == 0 || $request->option == '0') {
session()->put('MIGRATION_ENDPOINT', 'https://v5-app1.invoicing.co');
//refactor here to make this a little more magical
//
return redirect(
url('/migration/companies?hosted=true')
);
//old
// return redirect(
// url('/migration/auth')
// );
@ -124,6 +133,7 @@ class StepsController extends BaseController
public function endpoint()
{
if ($this->shouldGoBack('endpoint')) {
return redirect(
url($this->access['endpoint']['redirect'])
@ -214,27 +224,14 @@ class StepsController extends BaseController
url($this->access['companies']['redirect'])
);
}
$bool = true;
if($request->has('hosted') && $request->input('hosted') == 'true')
if(Utils::isNinja())
{
//push a job with $request->all() and the auth()->user() reference;
//
//In that job we will
//
//Create data file
//
//Send along a custom protected route
//
//auth as the end user
//and process as per normal.
//
//we should include a success failure email to contact@ so we can follow up.
HostedMigration::dispatch(auth()->user(), $request->all(), config('database.default'));
$this->dispatch(new HostedMigration(auth()->user(), $request->all(), config('database.default')));
if ($completeService->isSuccessful()) {
return view('migration.completed');
}
return view('migration.completed');
}

View File

@ -23,9 +23,7 @@ class HostedMigration extends Job
private $v4_secret;
private $migration_token;
public $account;
public $migration_token;
public function __construct(User $user, array $data, $db)
{
@ -40,18 +38,19 @@ class HostedMigration extends Job
*/
public function handle()
{
config(['database.default' => $this->db]);
//Create or get a token
$this->getToken();
//build the contents to be posted
$completeService = (new CompleteService($this->migration_token));
$migrationData = $this->generateMigrationData($data);
$migrationData = $this->generateMigrationData($this->data);
$completeService->data($migrationData)
->endpoint('https://v5-app1.invoicing.co')
// ->endpoint('http://ninja.test:8000')
->start();
}
@ -59,6 +58,7 @@ class HostedMigration extends Job
private function getToken()
{
$url = 'https://invoicing.co/api/v1/get_migration_account';
// $url = 'http://ninja.test:8000/api/v1/get_migration_account';
$headers = [
'X-API-HOSTED-SECRET' => $this->v4_secret,
@ -75,13 +75,15 @@ class HostedMigration extends Job
'password' => '',
];
$body = \Unirest\Request\Body::json($body);
$response = Request::post($url, $headers, $body);
if (in_array($response->code, [200])) {
$data = $response->body();
$this->migration_token = $data['token'];
$data = $response->body;
info(print_r($data,1));
$this->migration_token = $data->token;
} else {
info("getting token failed");
@ -89,6 +91,7 @@ class HostedMigration extends Job
}
return $this;
}

View File

@ -40,6 +40,7 @@ class CompleteService
public function start()
{
$files = [];
foreach ($this->data as $companyKey => $companyData) {

View File

@ -363,8 +363,6 @@ info("get company");
private function getClientSettings($client)
{
info("get client settings");
$settings = new \stdClass();
$settings->currency_id = $client->currency_id ? (string) $client->currency_id : (string) $client->account->currency_id;
@ -381,8 +379,7 @@ info("get company");
protected function getClientContacts($client)
{
info("get client contacts");
$contacts = Contact::where('client_id', $client->id)->withTrashed()->get();
$transformed = [];
@ -995,7 +992,7 @@ info("get company");
public function getResourceInvitations($items, $resourceKeyId)
{
info("get resource {$resourceKeyId} invitations");
// info("get resource {$resourceKeyId} invitations");
$transformed = [];
@ -1068,7 +1065,7 @@ info("get company");
public function getInvoiceItems($items)
{
info("get invoice items");
// info("get invoice items");
$transformed = [];
@ -1394,12 +1391,9 @@ info("get company");
$fees_and_limits = $this->transformFeesAndLimits($gateway_type);
info("generated fees and limits = ");
info(print_r($fees_and_limits,1));
$translated_gateway_type = $this->translateGatewayTypeId($gateway_type);
info("translated gateway_type = {$translated_gateway_type}");
$fees->{$translated_gateway_type} = $fees_and_limits;
}