mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 16:54:31 -04:00
Multi-db fixes
This commit is contained in:
parent
1ce6454ac2
commit
c0ba35c771
@ -171,6 +171,13 @@ Invitation::creating(function ($invitation)
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Invitation::updating(function ($invitation) {
|
||||||
|
$dirty = $invitation->getDirty();
|
||||||
|
if (array_key_exists('message_id', $dirty)) {
|
||||||
|
LookupInvitation::updateInvitation($invitation->account->account_key, $invitation);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Invitation::deleted(function ($invitation)
|
Invitation::deleted(function ($invitation)
|
||||||
{
|
{
|
||||||
if ($invitation->forceDeleting) {
|
if ($invitation->forceDeleting) {
|
||||||
|
@ -18,4 +18,30 @@ class LookupInvitation extends LookupModel
|
|||||||
'message_id',
|
'message_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static function updateInvitation($accountKey, $invitation)
|
||||||
|
{
|
||||||
|
if (! env('MULTI_DB_ENABLED')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $invitation->message_id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$current = config('database.default');
|
||||||
|
config(['database.default' => DB_NINJA_LOOKUP]);
|
||||||
|
|
||||||
|
$lookupAccount = LookupAccount::whereAccountKey($accountKey)
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
$lookupInvitation = LookupInvitation::whereLookupAccountId($lookupAccount->id)
|
||||||
|
->whereInvitationKey($invitation->invitation_key)
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
$lookupInvitation->message_id = $invitation->message_id;
|
||||||
|
$lookupInvitation->save();
|
||||||
|
|
||||||
|
config(['database.default' => $current]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ return [
|
|||||||
// multi-database setup
|
// multi-database setup
|
||||||
'db-ninja-0' => [
|
'db-ninja-0' => [
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
'host' => env('DB_HOST', env('DB_HOST0', 'localhost')),
|
'host' => env('DB_HOST0', env('DB_HOST', 'localhost')),
|
||||||
'database' => env('DB_DATABASE0', env('DB_DATABASE', 'forge')),
|
'database' => env('DB_DATABASE0', env('DB_DATABASE', 'forge')),
|
||||||
'username' => env('DB_USERNAME0', env('DB_USERNAME', 'forge')),
|
'username' => env('DB_USERNAME0', env('DB_USERNAME', 'forge')),
|
||||||
'password' => env('DB_PASSWORD0', env('DB_PASSWORD', '')),
|
'password' => env('DB_PASSWORD0', env('DB_PASSWORD', '')),
|
||||||
@ -76,7 +76,7 @@ return [
|
|||||||
|
|
||||||
'db-ninja-1' => [
|
'db-ninja-1' => [
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
'host' => env('DB_HOST', env('DB_HOST1', 'localhost')),
|
'host' => env('DB_HOST1', env('DB_HOST', 'localhost')),
|
||||||
'database' => env('DB_DATABASE1', env('DB_DATABASE', 'forge')),
|
'database' => env('DB_DATABASE1', env('DB_DATABASE', 'forge')),
|
||||||
'username' => env('DB_USERNAME1', env('DB_USERNAME', 'forge')),
|
'username' => env('DB_USERNAME1', env('DB_USERNAME', 'forge')),
|
||||||
'password' => env('DB_PASSWORD1', env('DB_PASSWORD', '')),
|
'password' => env('DB_PASSWORD1', env('DB_PASSWORD', '')),
|
||||||
@ -89,7 +89,7 @@ return [
|
|||||||
|
|
||||||
'db-ninja-2' => [
|
'db-ninja-2' => [
|
||||||
'driver' => 'mysql',
|
'driver' => 'mysql',
|
||||||
'host' => env('DB_HOST', env('DB_HOST2', 'localhost')),
|
'host' => env('DB_HOST2', env('DB_HOST', 'localhost')),
|
||||||
'database' => env('DB_DATABASE2', env('DB_DATABASE', 'forge')),
|
'database' => env('DB_DATABASE2', env('DB_DATABASE', 'forge')),
|
||||||
'username' => env('DB_USERNAME2', env('DB_USERNAME', 'forge')),
|
'username' => env('DB_USERNAME2', env('DB_USERNAME', 'forge')),
|
||||||
'password' => env('DB_PASSWORD2', env('DB_PASSWORD', '')),
|
'password' => env('DB_PASSWORD2', env('DB_PASSWORD', '')),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user