mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Multi-db support
This commit is contained in:
parent
479340c07a
commit
d5a63ffeef
@ -16,8 +16,8 @@ class DatabaseLookup
|
|||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
// user's value is set when logging in
|
|
||||||
if ($guard == 'user') {
|
if ($guard == 'user') {
|
||||||
|
// user's value is set when logging in
|
||||||
if (! session('SESSION_USER_DB_SERVER')) {
|
if (! session('SESSION_USER_DB_SERVER')) {
|
||||||
return redirect('/logout');
|
return redirect('/logout');
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ class DatabaseLookup
|
|||||||
if ($token = $request->header('X-Ninja-Token')) {
|
if ($token = $request->header('X-Ninja-Token')) {
|
||||||
LookupAccountToken::setServerByField('token', $token);
|
LookupAccountToken::setServerByField('token', $token);
|
||||||
}
|
}
|
||||||
} else {
|
} elseif ($guard == 'contact') {
|
||||||
if (request()->invitation_key) {
|
if (request()->invitation_key) {
|
||||||
LookupInvitation::setServerByField('invitation_key', request()->invitation_key);
|
LookupInvitation::setServerByField('invitation_key', request()->invitation_key);
|
||||||
} elseif (request()->contact_key) {
|
} elseif (request()->contact_key) {
|
||||||
|
@ -19,4 +19,26 @@ class LookupUser extends LookupModel
|
|||||||
'user_id',
|
'user_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static function updateUser($accountKey, $userId, $email)
|
||||||
|
{
|
||||||
|
if (! env('MULTI_DB_ENABLED')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$current = config('database.default');
|
||||||
|
config(['database.default' => DB_NINJA_LOOKUP]);
|
||||||
|
|
||||||
|
$lookupAccount = LookupAccount::whereAccountKey($accountKey)
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
$lookupUser = LookupUser::whereLookupAccountId($lookupAccount->id)
|
||||||
|
->whereUserId($userId)
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
$lookupUser->email = $email;
|
||||||
|
$lookupUser->save();
|
||||||
|
|
||||||
|
config(['database.default' => $current]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -423,6 +423,11 @@ User::creating(function ($user)
|
|||||||
|
|
||||||
User::updating(function ($user) {
|
User::updating(function ($user) {
|
||||||
User::onUpdatingUser($user);
|
User::onUpdatingUser($user);
|
||||||
|
|
||||||
|
$dirty = $user->getDirty();
|
||||||
|
if (isset($dirty['email'])) {
|
||||||
|
LookupUser::updateUser($user->account->account_key, $user->id, $user->email);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
User::updated(function ($user) {
|
User::updated(function ($user) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user