mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Multi-db fixes
This commit is contained in:
parent
1e018f1ba9
commit
8de5bfb510
@ -279,6 +279,7 @@ class AppController extends BaseController
|
||||
Artisan::call('view:clear');
|
||||
Artisan::call('config:clear');
|
||||
Artisan::call('optimize', ['--force' => true]);
|
||||
Auth::logout();
|
||||
Cache::flush();
|
||||
Session::flush();
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
|
@ -55,6 +55,7 @@ class HandleUserLoggedIn
|
||||
HistoryUtils::loadHistory($users ?: Auth::user()->id);
|
||||
|
||||
$account->loadLocalizationSettings();
|
||||
session([SESSION_DB_SERVER => config('database.default')]);
|
||||
|
||||
if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) {
|
||||
Session::flash('warning', trans('texts.iphone_app_message', ['link' => link_to(NINJA_IOS_APP_URL, trans('texts.iphone_app'))]));
|
||||
|
@ -66,11 +66,10 @@ class LookupModel extends Eloquent
|
||||
$className = get_called_class();
|
||||
$className = str_replace('Lookup', '', $className);
|
||||
$key = sprintf('server:%s:%s:%s', $className, $field, $value);
|
||||
$isUser = ($className == 'App\Models\User' && $field == 'email');
|
||||
|
||||
// check if we've cached this lookup
|
||||
if (env('MULTI_DB_CACHE_ENABLED') && $server = Cache::get($key)) {
|
||||
static::setDbServer($server, $isUser);
|
||||
static::setDbServer($server);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -81,7 +80,7 @@ class LookupModel extends Eloquent
|
||||
$entity = new $className();
|
||||
$server = $lookupModel->getDbServer();
|
||||
|
||||
static::setDbServer($server, $isUser);
|
||||
static::setDbServer($server);
|
||||
|
||||
// check entity is found on the server
|
||||
if (! $entity::where($field, '=', $value)->first()) {
|
||||
@ -94,17 +93,13 @@ class LookupModel extends Eloquent
|
||||
}
|
||||
}
|
||||
|
||||
protected static function setDbServer($server, $isUser = false)
|
||||
protected static function setDbServer($server)
|
||||
{
|
||||
if (! env('MULTI_DB_ENABLED')) {
|
||||
return;
|
||||
}
|
||||
|
||||
config(['database.default' => $server]);
|
||||
|
||||
if ($isUser) {
|
||||
session([SESSION_DB_SERVER => $server]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDbServer()
|
||||
|
Loading…
Reference in New Issue
Block a user