mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -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([
|
||||
'email' => $this->faker->email,
|
||||
@ -96,12 +96,12 @@ class ImportMigrations extends Command
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function getAccount(): Account
|
||||
public function getAccount(): Account
|
||||
{
|
||||
return factory(\App\Models\Account::class)->create();
|
||||
}
|
||||
|
||||
private function getCompany(Account $account): Company
|
||||
public function getCompany(Account $account): Company
|
||||
{
|
||||
$company = factory(Company::class)->create([
|
||||
'account_id' => $account->id,
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Console\Commands\ImportMigrations;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Exceptions\MigrationValidatorFailed;
|
||||
use App\Exceptions\NonExistingMigrationFile;
|
||||
use App\Exceptions\ProcessingMigrationArchiveFailed;
|
||||
@ -23,6 +25,7 @@ use App\Jobs\Util\StartMigration;
|
||||
use App\Mail\MigrationFailed;
|
||||
use App\Models\Account;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\CompanyUser;
|
||||
use App\Transformers\AccountTransformer;
|
||||
use App\Transformers\CompanyUserTransformer;
|
||||
@ -193,20 +196,39 @@ class MigrationController extends BaseController
|
||||
*/
|
||||
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);
|
||||
|
||||
$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')
|
||||
->storeAs('migrations', $request->file('migration')->getClientOriginalName());
|
||||
|
||||
if (app()->environment() == 'testing') return;
|
||||
|
||||
$user = auth()->user();
|
||||
\Log::error($user);
|
||||
\Log::error($company);
|
||||
\Log::error("starting migration");
|
||||
|
||||
StartMigration::dispatch($migration_file, $user, $company);
|
||||
StartMigration::dispatch(base_path("storage/app/public/$migration_file"), $user, $company);
|
||||
|
||||
return response()->json([
|
||||
'_id' => Str::uuid(),
|
||||
|
@ -44,7 +44,7 @@ class StartMigration implements ShouldQueue
|
||||
*/
|
||||
public function __construct($filepath, User $user, Company $company)
|
||||
{
|
||||
$this->filepath = base_path("storage/$filepath");
|
||||
$this->filepath = $filepath;
|
||||
$this->user = $user;
|
||||
$this->company = $company;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user