Skip to content

Commit

Permalink
run migrations in ServiceManager boot method
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Nov 27, 2024
1 parent 11b5148 commit 653ddde
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
32 changes: 27 additions & 5 deletions modules/backend/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<?php namespace Backend;

use Backend;
use BackendMenu;
use BackendAuth;
use Backend\Models\UserRole;
use Backend\Classes\WidgetManager;
use System\Classes\MailManager;
use Backend\Facades\Backend;
use Backend\Facades\BackendAuth;
use Backend\Facades\BackendMenu;
use Backend\Models\AccessLog;
use Backend\Models\UserRole;
use Exception;
use Illuminate\Support\Facades\Event;
use System\Classes\CombineAssets;
use System\Classes\MailManager;
use System\Classes\SettingsManager;
use System\Classes\UpdateManager;
use Winter\Storm\Auth\Models\User as UserBase;
use Winter\Storm\Support\Facades\Config;
use Winter\Storm\Support\Facades\Flash;
use Winter\Storm\Support\Facades\Mail;
use Winter\Storm\Support\ModuleServiceProvider;

class ServiceProvider extends ModuleServiceProvider
Expand Down Expand Up @@ -45,6 +53,20 @@ public function register()
public function boot()
{
parent::boot('backend');

Event::listen('backend.user.login', function (\Backend\Models\User $user) {
$runMigrationsOnLogin = (bool) Config::get('cms.runMigrationsOnLogin', Config::get('app.debug', false));
if ($runMigrationsOnLogin) {
try {
// Load version updates
UpdateManager::instance()->update();
} catch (Exception $e) {
Flash::error($e->getMessage());
}
}
// Log the sign in event
AccessLog::add($user);
});
}

/**
Expand Down
17 changes: 0 additions & 17 deletions modules/backend/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

use Backend\Facades\Backend;
use Backend\Facades\BackendAuth;
use Backend\Models\AccessLog;
use Exception;
use Illuminate\Support\Facades\Event;
use System\Classes\UpdateManager;
use Winter\Storm\Auth\Models\User as UserBase;
use Winter\Storm\Support\Facades\Config;
use Winter\Storm\Support\Facades\Flash;
use Winter\Storm\Support\Facades\Mail;

/**
Expand Down Expand Up @@ -160,18 +155,6 @@ public function afterLogin()
*
*/
Event::fire('backend.user.login', [$this]);

$runMigrationsOnLogin = (bool) Config::get('cms.runMigrationsOnLogin', Config::get('app.debug', false));
if ($runMigrationsOnLogin) {
try {
// Load version updates
UpdateManager::instance()->update();
} catch (Exception $e) {
Flash::error($e->getMessage());
}
}
// Log the sign in event
AccessLog::add($this);
}

/**
Expand Down

0 comments on commit 653ddde

Please sign in to comment.