mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Refactor Migration codebase
This commit is contained in:
parent
50a0532bf4
commit
391df15a96
@ -8,16 +8,17 @@ use App\Http\Requests\MigrationCompaniesRequest;
|
|||||||
use App\Http\Requests\MigrationEndpointRequest;
|
use App\Http\Requests\MigrationEndpointRequest;
|
||||||
use App\Http\Requests\MigrationForwardRequest;
|
use App\Http\Requests\MigrationForwardRequest;
|
||||||
use App\Http\Requests\MigrationTypeRequest;
|
use App\Http\Requests\MigrationTypeRequest;
|
||||||
|
use App\Jobs\HostedMigration;
|
||||||
use App\Libraries\Utils;
|
use App\Libraries\Utils;
|
||||||
use App\Models\Account;
|
use App\Models\Account;
|
||||||
use App\Services\Migration\AuthService;
|
use App\Services\Migration\AuthService;
|
||||||
use App\Services\Migration\CompanyService;
|
use App\Services\Migration\CompanyService;
|
||||||
use App\Services\Migration\CompleteService;
|
use App\Services\Migration\CompleteService;
|
||||||
use App\Traits\GenerateMigrationResources;
|
use App\Traits\GenerateMigrationResources;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Validator;
|
use Validator;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class StepsController extends BaseController
|
class StepsController extends BaseController
|
||||||
{
|
{
|
||||||
@ -48,6 +49,17 @@ class StepsController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function start()
|
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');
|
return view('migration.start');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,16 +80,13 @@ class StepsController extends BaseController
|
|||||||
{
|
{
|
||||||
session()->put('MIGRATION_TYPE', $request->option);
|
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(
|
return redirect(
|
||||||
url('/migration/companies?hosted=true')
|
url('/migration/companies?hosted=true')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//old
|
||||||
// return redirect(
|
// return redirect(
|
||||||
// url('/migration/auth')
|
// url('/migration/auth')
|
||||||
// );
|
// );
|
||||||
@ -124,6 +133,7 @@ class StepsController extends BaseController
|
|||||||
|
|
||||||
public function endpoint()
|
public function endpoint()
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->shouldGoBack('endpoint')) {
|
if ($this->shouldGoBack('endpoint')) {
|
||||||
return redirect(
|
return redirect(
|
||||||
url($this->access['endpoint']['redirect'])
|
url($this->access['endpoint']['redirect'])
|
||||||
@ -214,27 +224,14 @@ class StepsController extends BaseController
|
|||||||
url($this->access['companies']['redirect'])
|
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;
|
$this->dispatch(new HostedMigration(auth()->user(), $request->all(), config('database.default')));
|
||||||
//
|
|
||||||
//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'));
|
|
||||||
|
|
||||||
if ($completeService->isSuccessful()) {
|
return view('migration.completed');
|
||||||
return view('migration.completed');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,7 @@ class HostedMigration extends Job
|
|||||||
|
|
||||||
private $v4_secret;
|
private $v4_secret;
|
||||||
|
|
||||||
private $migration_token;
|
public $migration_token;
|
||||||
|
|
||||||
public $account;
|
|
||||||
|
|
||||||
public function __construct(User $user, array $data, $db)
|
public function __construct(User $user, array $data, $db)
|
||||||
{
|
{
|
||||||
@ -40,18 +38,19 @@ class HostedMigration extends Job
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
config(['database.default' => $this->db]);
|
config(['database.default' => $this->db]);
|
||||||
|
|
||||||
//Create or get a token
|
//Create or get a token
|
||||||
$this->getToken();
|
$this->getToken();
|
||||||
//build the contents to be posted
|
|
||||||
|
|
||||||
$completeService = (new CompleteService($this->migration_token));
|
$completeService = (new CompleteService($this->migration_token));
|
||||||
|
|
||||||
$migrationData = $this->generateMigrationData($data);
|
$migrationData = $this->generateMigrationData($this->data);
|
||||||
|
|
||||||
$completeService->data($migrationData)
|
$completeService->data($migrationData)
|
||||||
->endpoint('https://v5-app1.invoicing.co')
|
->endpoint('https://v5-app1.invoicing.co')
|
||||||
|
// ->endpoint('http://ninja.test:8000')
|
||||||
->start();
|
->start();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -59,6 +58,7 @@ class HostedMigration extends Job
|
|||||||
private function getToken()
|
private function getToken()
|
||||||
{
|
{
|
||||||
$url = 'https://invoicing.co/api/v1/get_migration_account';
|
$url = 'https://invoicing.co/api/v1/get_migration_account';
|
||||||
|
// $url = 'http://ninja.test:8000/api/v1/get_migration_account';
|
||||||
|
|
||||||
$headers = [
|
$headers = [
|
||||||
'X-API-HOSTED-SECRET' => $this->v4_secret,
|
'X-API-HOSTED-SECRET' => $this->v4_secret,
|
||||||
@ -75,13 +75,15 @@ class HostedMigration extends Job
|
|||||||
'password' => '',
|
'password' => '',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$body = \Unirest\Request\Body::json($body);
|
||||||
|
|
||||||
$response = Request::post($url, $headers, $body);
|
$response = Request::post($url, $headers, $body);
|
||||||
|
|
||||||
if (in_array($response->code, [200])) {
|
if (in_array($response->code, [200])) {
|
||||||
|
|
||||||
$data = $response->body();
|
$data = $response->body;
|
||||||
|
info(print_r($data,1));
|
||||||
$this->migration_token = $data['token'];
|
$this->migration_token = $data->token;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
info("getting token failed");
|
info("getting token failed");
|
||||||
@ -89,6 +91,7 @@ class HostedMigration extends Job
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ class CompleteService
|
|||||||
|
|
||||||
public function start()
|
public function start()
|
||||||
{
|
{
|
||||||
|
|
||||||
$files = [];
|
$files = [];
|
||||||
|
|
||||||
foreach ($this->data as $companyKey => $companyData) {
|
foreach ($this->data as $companyKey => $companyData) {
|
||||||
|
@ -363,8 +363,6 @@ info("get company");
|
|||||||
|
|
||||||
private function getClientSettings($client)
|
private function getClientSettings($client)
|
||||||
{
|
{
|
||||||
info("get client settings");
|
|
||||||
|
|
||||||
|
|
||||||
$settings = new \stdClass();
|
$settings = new \stdClass();
|
||||||
$settings->currency_id = $client->currency_id ? (string) $client->currency_id : (string) $client->account->currency_id;
|
$settings->currency_id = $client->currency_id ? (string) $client->currency_id : (string) $client->account->currency_id;
|
||||||
@ -381,7 +379,6 @@ info("get company");
|
|||||||
|
|
||||||
protected function getClientContacts($client)
|
protected function getClientContacts($client)
|
||||||
{
|
{
|
||||||
info("get client contacts");
|
|
||||||
|
|
||||||
$contacts = Contact::where('client_id', $client->id)->withTrashed()->get();
|
$contacts = Contact::where('client_id', $client->id)->withTrashed()->get();
|
||||||
|
|
||||||
@ -995,7 +992,7 @@ info("get company");
|
|||||||
|
|
||||||
public function getResourceInvitations($items, $resourceKeyId)
|
public function getResourceInvitations($items, $resourceKeyId)
|
||||||
{
|
{
|
||||||
info("get resource {$resourceKeyId} invitations");
|
// info("get resource {$resourceKeyId} invitations");
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
@ -1068,7 +1065,7 @@ info("get company");
|
|||||||
|
|
||||||
public function getInvoiceItems($items)
|
public function getInvoiceItems($items)
|
||||||
{
|
{
|
||||||
info("get invoice items");
|
// info("get invoice items");
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
@ -1394,12 +1391,9 @@ info("get company");
|
|||||||
|
|
||||||
$fees_and_limits = $this->transformFeesAndLimits($gateway_type);
|
$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);
|
$translated_gateway_type = $this->translateGatewayTypeId($gateway_type);
|
||||||
|
|
||||||
info("translated gateway_type = {$translated_gateway_type}");
|
|
||||||
|
|
||||||
$fees->{$translated_gateway_type} = $fees_and_limits;
|
$fees->{$translated_gateway_type} = $fees_and_limits;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user