1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 22:22:32 +01:00

Multi-db fixes

This commit is contained in:
Hillel Coren 2017-05-10 11:38:21 +03:00
parent 1e018f1ba9
commit 8de5bfb510
3 changed files with 5 additions and 8 deletions

View File

@ -279,6 +279,7 @@ class AppController extends BaseController
Artisan::call('view:clear'); Artisan::call('view:clear');
Artisan::call('config:clear'); Artisan::call('config:clear');
Artisan::call('optimize', ['--force' => true]); Artisan::call('optimize', ['--force' => true]);
Auth::logout();
Cache::flush(); Cache::flush();
Session::flush(); Session::flush();
Artisan::call('migrate', ['--force' => true]); Artisan::call('migrate', ['--force' => true]);

View File

@ -55,6 +55,7 @@ class HandleUserLoggedIn
HistoryUtils::loadHistory($users ?: Auth::user()->id); HistoryUtils::loadHistory($users ?: Auth::user()->id);
$account->loadLocalizationSettings(); $account->loadLocalizationSettings();
session([SESSION_DB_SERVER => config('database.default')]);
if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) { 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'))])); Session::flash('warning', trans('texts.iphone_app_message', ['link' => link_to(NINJA_IOS_APP_URL, trans('texts.iphone_app'))]));

View File

@ -66,11 +66,10 @@ class LookupModel extends Eloquent
$className = get_called_class(); $className = get_called_class();
$className = str_replace('Lookup', '', $className); $className = str_replace('Lookup', '', $className);
$key = sprintf('server:%s:%s:%s', $className, $field, $value); $key = sprintf('server:%s:%s:%s', $className, $field, $value);
$isUser = ($className == 'App\Models\User' && $field == 'email');
// check if we've cached this lookup // check if we've cached this lookup
if (env('MULTI_DB_CACHE_ENABLED') && $server = Cache::get($key)) { if (env('MULTI_DB_CACHE_ENABLED') && $server = Cache::get($key)) {
static::setDbServer($server, $isUser); static::setDbServer($server);
return; return;
} }
@ -81,7 +80,7 @@ class LookupModel extends Eloquent
$entity = new $className(); $entity = new $className();
$server = $lookupModel->getDbServer(); $server = $lookupModel->getDbServer();
static::setDbServer($server, $isUser); static::setDbServer($server);
// check entity is found on the server // check entity is found on the server
if (! $entity::where($field, '=', $value)->first()) { 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')) { if (! env('MULTI_DB_ENABLED')) {
return; return;
} }
config(['database.default' => $server]); config(['database.default' => $server]);
if ($isUser) {
session([SESSION_DB_SERVER => $server]);
}
} }
public function getDbServer() public function getDbServer()