mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 13:00:57 -04:00
Implement future migration refactor for v4 when we upgrade to L6
This commit is contained in:
parent
ff6767b5e4
commit
e63d9828f1
@ -24,6 +24,7 @@ use App\Models\CompanyToken;
|
|||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
@ -232,9 +233,22 @@ class MigrationController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function startMigration(Request $request)
|
public function startMigration(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// v4 Laravel 6
|
||||||
|
|
||||||
|
// $companies = [];
|
||||||
|
|
||||||
|
// foreach($request->all() as $input){
|
||||||
|
|
||||||
|
// if($input instanceof UploadedFile)
|
||||||
|
// nlog('is file');
|
||||||
|
// else
|
||||||
|
// $companies[] = json_decode($input);
|
||||||
|
// }
|
||||||
|
|
||||||
nlog("Starting Migration");
|
nlog("Starting Migration");
|
||||||
|
|
||||||
$companies = json_decode($request->companies);
|
$companies = json_decode($request->companies,1);
|
||||||
|
|
||||||
if (app()->environment() === 'local') {
|
if (app()->environment() === 'local') {
|
||||||
nlog($request->all());
|
nlog($request->all());
|
||||||
@ -250,19 +264,31 @@ class MigrationController extends BaseController
|
|||||||
} finally {
|
} finally {
|
||||||
// Controller logic here
|
// Controller logic here
|
||||||
|
|
||||||
foreach ($companies as $company) {
|
foreach($companies as $company)
|
||||||
$is_valid = $request->file($company->company_index)->isValid();
|
{
|
||||||
|
|
||||||
if (!$is_valid) {
|
$company = (array)$company;
|
||||||
continue;
|
|
||||||
}
|
// v4 Laravel 6
|
||||||
|
// $input = $request->all();
|
||||||
|
|
||||||
|
// foreach ($input as $company) {
|
||||||
|
|
||||||
|
// if($company instanceof UploadedFile)
|
||||||
|
// continue;
|
||||||
|
// else
|
||||||
|
// $company = json_decode($company,1);
|
||||||
|
|
||||||
|
// if (!$company || !is_int($company['company_index'] || !$request->file($company['company_index'])->isValid())) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
|
||||||
$company_count = $user->account->companies()->count();
|
$company_count = $user->account->companies()->count();
|
||||||
|
|
||||||
// Look for possible existing company (based on company keys).
|
// Look for possible existing company (based on company keys).
|
||||||
$existing_company = Company::whereRaw('BINARY `company_key` = ?', [$company->company_key])->first();
|
$existing_company = Company::whereRaw('BINARY `company_key` = ?', [$company['company_key']])->first();
|
||||||
|
|
||||||
App::forgetInstance('translator');
|
App::forgetInstance('translator');
|
||||||
$t = app('translator');
|
$t = app('translator');
|
||||||
@ -291,7 +317,7 @@ class MigrationController extends BaseController
|
|||||||
|
|
||||||
$checks = [
|
$checks = [
|
||||||
'existing_company' => $existing_company ? (bool)1 : false,
|
'existing_company' => $existing_company ? (bool)1 : false,
|
||||||
'force' => property_exists($company, 'force') ? (bool) $company->force : false,
|
'force' => array_key_exists('force', $company) ? (bool) $company['force'] : false,
|
||||||
];
|
];
|
||||||
|
|
||||||
// If there's existing company and ** no ** force is provided - skip migration.
|
// If there's existing company and ** no ** force is provided - skip migration.
|
||||||
@ -378,10 +404,10 @@ class MigrationController extends BaseController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$migration_file = $request->file($company->company_index)
|
$migration_file = $request->file($company['company_index'])
|
||||||
->storeAs(
|
->storeAs(
|
||||||
'migrations',
|
'migrations',
|
||||||
$request->file($company->company_index)->getClientOriginalName(),
|
$request->file($company['company_index'])->getClientOriginalName(),
|
||||||
'public'
|
'public'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -485,7 +485,7 @@ class Company extends BaseModel
|
|||||||
{
|
{
|
||||||
if (Ninja::isHosted()) {
|
if (Ninja::isHosted()) {
|
||||||
|
|
||||||
if($this->portal_mode == 'domain')
|
if($this->portal_mode == 'domain' && strlen($this->portal_domain) > 3)
|
||||||
return $this->portal_domain;
|
return $this->portal_domain;
|
||||||
|
|
||||||
return "https://{$this->subdomain}." . config('ninja.app_domain');
|
return "https://{$this->subdomain}." . config('ninja.app_domain');
|
||||||
|
@ -48,7 +48,7 @@ trait Inviteable
|
|||||||
$entity_type = Str::snake(class_basename($this->entityType()));
|
$entity_type = Str::snake(class_basename($this->entityType()));
|
||||||
|
|
||||||
if(Ninja::isHosted()){
|
if(Ninja::isHosted()){
|
||||||
$domain = isset($this->company->portal_domain) ? $this->company->portal_domain : $this->company->domain();
|
$domain = $this->company->domain();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$domain = config('ninja.app_url');
|
$domain = config('ninja.app_url');
|
||||||
@ -75,7 +75,7 @@ trait Inviteable
|
|||||||
{
|
{
|
||||||
|
|
||||||
if(Ninja::isHosted())
|
if(Ninja::isHosted())
|
||||||
$domain = isset($this->company->portal_domain) ? $this->company->portal_domain : $this->company->domain();
|
$domain = $this->company->domain();
|
||||||
else
|
else
|
||||||
$domain = config('ninja.app_url');
|
$domain = config('ninja.app_url');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user