mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 06:34:34 -04:00
Fix broken 'force' migration: (#3489)
* Fix breaking 'force' migration: - Uploaded migration file now has to be passed with abs path * Cleanup
This commit is contained in:
parent
a0fe5e9a81
commit
64eed274e1
@ -65,7 +65,7 @@ class ImportMigrations extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getUser(): User
|
public function getUser(): User
|
||||||
{
|
{
|
||||||
$user = factory(\App\Models\User::class)->create([
|
$user = factory(\App\Models\User::class)->create([
|
||||||
'email' => $this->faker->email,
|
'email' => $this->faker->email,
|
||||||
@ -96,12 +96,12 @@ class ImportMigrations extends Command
|
|||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAccount(): Account
|
public function getAccount(): Account
|
||||||
{
|
{
|
||||||
return factory(\App\Models\Account::class)->create();
|
return factory(\App\Models\Account::class)->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCompany(Account $account): Company
|
public function getCompany(Account $account): Company
|
||||||
{
|
{
|
||||||
$company = factory(Company::class)->create([
|
$company = factory(Company::class)->create([
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Console\Commands\ImportMigrations;
|
||||||
|
use App\DataMapper\CompanySettings;
|
||||||
use App\Exceptions\MigrationValidatorFailed;
|
use App\Exceptions\MigrationValidatorFailed;
|
||||||
use App\Exceptions\NonExistingMigrationFile;
|
use App\Exceptions\NonExistingMigrationFile;
|
||||||
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
||||||
@ -23,6 +25,7 @@ use App\Jobs\Util\StartMigration;
|
|||||||
use App\Mail\MigrationFailed;
|
use App\Mail\MigrationFailed;
|
||||||
use App\Models\Account;
|
use App\Models\Account;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\CompanyToken;
|
||||||
use App\Models\CompanyUser;
|
use App\Models\CompanyUser;
|
||||||
use App\Transformers\AccountTransformer;
|
use App\Transformers\AccountTransformer;
|
||||||
use App\Transformers\CompanyUserTransformer;
|
use App\Transformers\CompanyUserTransformer;
|
||||||
@ -193,20 +196,39 @@ class MigrationController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function startMigration(Request $request, Company $company)
|
public function startMigration(Request $request, Company $company)
|
||||||
{
|
{
|
||||||
if ($request->has('force') && !empty($request->force))
|
$user = auth()->user();
|
||||||
|
|
||||||
|
if ($request->has('force') && !empty($request->force)) {
|
||||||
$this->purgeCompany($company);
|
$this->purgeCompany($company);
|
||||||
|
|
||||||
|
$account = (new ImportMigrations())->getAccount();
|
||||||
|
$company = (new ImportMigrations())->getCompany($account);
|
||||||
|
|
||||||
|
CompanyToken::create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'company_id' => $company->id,
|
||||||
|
'account_id' => $account->id,
|
||||||
|
'name' => $request->token_name ?? Str::random(12),
|
||||||
|
'token' => $request->token ?? \Illuminate\Support\Str::random(64),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user->companies()->attach($company->id, [
|
||||||
|
'account_id' => $account->id,
|
||||||
|
'is_owner' => 1,
|
||||||
|
'is_admin' => 1,
|
||||||
|
'is_locked' => 0,
|
||||||
|
'notifications' => CompanySettings::notificationDefaults(),
|
||||||
|
'permissions' => '',
|
||||||
|
'settings' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$migration_file = $request->file('migration')
|
$migration_file = $request->file('migration')
|
||||||
->storeAs('migrations', $request->file('migration')->getClientOriginalName());
|
->storeAs('migrations', $request->file('migration')->getClientOriginalName());
|
||||||
|
|
||||||
if (app()->environment() == 'testing') return;
|
if (app()->environment() == 'testing') return;
|
||||||
|
|
||||||
$user = auth()->user();
|
StartMigration::dispatch(base_path("storage/app/public/$migration_file"), $user, $company);
|
||||||
\Log::error($user);
|
|
||||||
\Log::error($company);
|
|
||||||
\Log::error("starting migration");
|
|
||||||
|
|
||||||
StartMigration::dispatch($migration_file, $user, $company);
|
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'_id' => Str::uuid(),
|
'_id' => Str::uuid(),
|
||||||
|
@ -44,7 +44,7 @@ class StartMigration implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function __construct($filepath, User $user, Company $company)
|
public function __construct($filepath, User $user, Company $company)
|
||||||
{
|
{
|
||||||
$this->filepath = base_path("storage/$filepath");
|
$this->filepath = $filepath;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user