mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 08:24:34 -04:00
Updates for silent migrations
This commit is contained in:
parent
40385a1cd7
commit
dd61b41919
@ -32,6 +32,8 @@ class MigrationController extends BaseController
|
|||||||
{
|
{
|
||||||
use DispatchesJobs;
|
use DispatchesJobs;
|
||||||
|
|
||||||
|
public bool $silent_migration = false;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@ -260,6 +262,9 @@ class MigrationController extends BaseController
|
|||||||
{
|
{
|
||||||
nlog('Starting Migration');
|
nlog('Starting Migration');
|
||||||
|
|
||||||
|
if($request->has('silent_migration'))
|
||||||
|
$this->silent_migration = true;
|
||||||
|
|
||||||
if ($request->companies) {
|
if ($request->companies) {
|
||||||
//handle Laravel 5.5 UniHTTP
|
//handle Laravel 5.5 UniHTTP
|
||||||
$companies = json_decode($request->companies, 1);
|
$companies = json_decode($request->companies, 1);
|
||||||
@ -312,7 +317,9 @@ class MigrationController extends BaseController
|
|||||||
$nmo->company = $user->account->companies()->first();
|
$nmo->company = $user->account->companies()->first();
|
||||||
$nmo->settings = $user->account->companies()->first()->settings;
|
$nmo->settings = $user->account->companies()->first()->settings;
|
||||||
$nmo->to_user = $user;
|
$nmo->to_user = $user;
|
||||||
NinjaMailerJob::dispatch($nmo, true);
|
|
||||||
|
if(!$this->silent_migration)
|
||||||
|
NinjaMailerJob::dispatch($nmo, true);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} elseif ($existing_company && $company_count > 10) {
|
} elseif ($existing_company && $company_count > 10) {
|
||||||
@ -321,7 +328,9 @@ class MigrationController extends BaseController
|
|||||||
$nmo->company = $user->account->companies()->first();
|
$nmo->company = $user->account->companies()->first();
|
||||||
$nmo->settings = $user->account->companies()->first()->settings;
|
$nmo->settings = $user->account->companies()->first()->settings;
|
||||||
$nmo->to_user = $user;
|
$nmo->to_user = $user;
|
||||||
NinjaMailerJob::dispatch($nmo, true);
|
|
||||||
|
if(!$this->silent_migration)
|
||||||
|
NinjaMailerJob::dispatch($nmo, true);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -341,7 +350,8 @@ class MigrationController extends BaseController
|
|||||||
$nmo->settings = $user->account->companies()->first();
|
$nmo->settings = $user->account->companies()->first();
|
||||||
$nmo->to_user = $user;
|
$nmo->to_user = $user;
|
||||||
|
|
||||||
NinjaMailerJob::dispatch($nmo, true);
|
if(!$this->silent_migration)
|
||||||
|
NinjaMailerJob::dispatch($nmo, true);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'_id' => Str::uuid(),
|
'_id' => Str::uuid(),
|
||||||
@ -431,9 +441,9 @@ class MigrationController extends BaseController
|
|||||||
nlog($migration_file);
|
nlog($migration_file);
|
||||||
|
|
||||||
if (Ninja::isHosted()) {
|
if (Ninja::isHosted()) {
|
||||||
StartMigration::dispatch($migration_file, $user, $fresh_company)->onQueue('migration');
|
StartMigration::dispatch($migration_file, $user, $fresh_company, $this->silent_migration)->onQueue('migration');
|
||||||
} else {
|
} else {
|
||||||
StartMigration::dispatch($migration_file, $user, $fresh_company);
|
StartMigration::dispatch($migration_file, $user, $fresh_company, $this->silent_migration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ class ProtectedDownloadController extends BaseController
|
|||||||
return response()->streamDownload(function () use ($hashed_path) {
|
return response()->streamDownload(function () use ($hashed_path) {
|
||||||
echo Storage::get($hashed_path);
|
echo Storage::get($hashed_path);
|
||||||
}, basename($hashed_path), []);
|
}, basename($hashed_path), []);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +165,8 @@ class Import implements ShouldQueue
|
|||||||
|
|
||||||
public $timeout = 10000000;
|
public $timeout = 10000000;
|
||||||
|
|
||||||
|
public $silent_migration;
|
||||||
|
|
||||||
// public $backoff = 86430;
|
// public $backoff = 86430;
|
||||||
|
|
||||||
// public $maxExceptions = 2;
|
// public $maxExceptions = 2;
|
||||||
@ -176,12 +178,13 @@ class Import implements ShouldQueue
|
|||||||
* @param User $user
|
* @param User $user
|
||||||
* @param array $resources
|
* @param array $resources
|
||||||
*/
|
*/
|
||||||
public function __construct(string $file_path, Company $company, User $user, array $resources = [])
|
public function __construct(string $file_path, Company $company, User $user, array $resources = [], $silent_migration = false)
|
||||||
{
|
{
|
||||||
$this->file_path = $file_path;
|
$this->file_path = $file_path;
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->resources = $resources;
|
$this->resources = $resources;
|
||||||
|
$this->silent_migration = $silent_migration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function middleware()
|
public function middleware()
|
||||||
@ -263,8 +266,9 @@ class Import implements ShouldQueue
|
|||||||
$t = app('translator');
|
$t = app('translator');
|
||||||
$t->replace(Ninja::transformTranslations($this->company->settings));
|
$t->replace(Ninja::transformTranslations($this->company->settings));
|
||||||
|
|
||||||
Mail::to($this->user->email, $this->user->name())
|
if(!$this->silent_migration)
|
||||||
->send(new MigrationCompleted($this->company->id, $this->company->db, implode("<br>", $check_data)));
|
Mail::to($this->user->email, $this->user->name())->send(new MigrationCompleted($this->company->id, $this->company->db, implode("<br>", $check_data)));
|
||||||
|
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
nlog($e->getMessage());
|
nlog($e->getMessage());
|
||||||
}
|
}
|
||||||
@ -641,7 +645,6 @@ class Import implements ShouldQueue
|
|||||||
|
|
||||||
$user = $user_repository->save($modified, $this->fetchUser($resource['email']), true, true);
|
$user = $user_repository->save($modified, $this->fetchUser($resource['email']), true, true);
|
||||||
$user->email_verified_at = now();
|
$user->email_verified_at = now();
|
||||||
// $user->confirmation_code = '';
|
|
||||||
|
|
||||||
if ($modified['deleted_at']) {
|
if ($modified['deleted_at']) {
|
||||||
$user->deleted_at = now();
|
$user->deleted_at = now();
|
||||||
@ -1590,7 +1593,9 @@ class Import implements ShouldQueue
|
|||||||
$nmo->company = $this->company;
|
$nmo->company = $this->company;
|
||||||
$nmo->settings = $this->company->settings;
|
$nmo->settings = $this->company->settings;
|
||||||
$nmo->to_user = $this->user;
|
$nmo->to_user = $this->user;
|
||||||
NinjaMailerJob::dispatch($nmo, true);
|
|
||||||
|
if(!$this->silent_migration)
|
||||||
|
NinjaMailerJob::dispatch($nmo, true);
|
||||||
|
|
||||||
$modified['gateway_key'] = 'd14dd26a47cecc30fdd65700bfb67b34';
|
$modified['gateway_key'] = 'd14dd26a47cecc30fdd65700bfb67b34';
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,8 @@ class StartMigration implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
private $company;
|
private $company;
|
||||||
|
|
||||||
|
private $silent_migration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
@ -60,11 +62,12 @@ class StartMigration implements ShouldQueue
|
|||||||
|
|
||||||
public $timeout = 0;
|
public $timeout = 0;
|
||||||
|
|
||||||
public function __construct($filepath, User $user, Company $company)
|
public function __construct($filepath, User $user, Company $company, $silent_migration = false)
|
||||||
{
|
{
|
||||||
$this->filepath = $filepath;
|
$this->filepath = $filepath;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
|
$this->silent_migration = $silent_migration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,7 +119,7 @@ class StartMigration implements ShouldQueue
|
|||||||
throw new NonExistingMigrationFile('Migration file does not exist, or it is corrupted.');
|
throw new NonExistingMigrationFile('Migration file does not exist, or it is corrupted.');
|
||||||
}
|
}
|
||||||
|
|
||||||
(new Import($file, $this->company, $this->user))->handle();
|
(new Import($file, $this->company, $this->user, [], $this->silent_migration))->handle();
|
||||||
|
|
||||||
Storage::deleteDirectory(public_path("storage/migrations/{$filename}"));
|
Storage::deleteDirectory(public_path("storage/migrations/{$filename}"));
|
||||||
|
|
||||||
@ -138,7 +141,8 @@ class StartMigration implements ShouldQueue
|
|||||||
app('sentry')->captureException($e);
|
app('sentry')->captureException($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mail::to($this->user->email, $this->user->name())->send(new MigrationFailed($e, $this->company, $e->getMessage()));
|
if(!$this->silent_migration)
|
||||||
|
Mail::to($this->user->email, $this->user->name())->send(new MigrationFailed($e, $this->company, $e->getMessage()));
|
||||||
|
|
||||||
if (Ninja::isHosted()) {
|
if (Ninja::isHosted()) {
|
||||||
$migration_failed = new MigrationFailed($e, $this->company, $e->getMessage());
|
$migration_failed = new MigrationFailed($e, $this->company, $e->getMessage());
|
||||||
|
@ -39,7 +39,7 @@ class UserRepository extends BaseRepository
|
|||||||
* @param bool $unset_company_user
|
* @param bool $unset_company_user
|
||||||
* @return \App\Models\User user Object
|
* @return \App\Models\User user Object
|
||||||
*/
|
*/
|
||||||
public function save(array $data, User $user, $unset_company_user = false)
|
public function save(array $data, User $user, $unset_company_user = false, $is_migrating = false)
|
||||||
{
|
{
|
||||||
$details = $data;
|
$details = $data;
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ class UserRepository extends BaseRepository
|
|||||||
$user->password = Hash::make($data['password']);
|
$user->password = Hash::make($data['password']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $user->confirmation_code) {
|
if (! $user->confirmation_code && !$is_migrating) {
|
||||||
$user->confirmation_code = $this->createDbHash($company->db);
|
$user->confirmation_code = $this->createDbHash($company->db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user