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
14072b6334
commit
95cbbc2dc9
@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Models\LookupToken;
|
||||
|
||||
/**
|
||||
* Class AccountToken.
|
||||
@ -39,3 +40,10 @@ class AccountToken extends EntityModel
|
||||
return $this->belongsTo('App\Models\User')->withTrashed();
|
||||
}
|
||||
}
|
||||
|
||||
AccountToken::creating(function ($token)
|
||||
{
|
||||
LookupToken::createNew($token->account->account_key, [
|
||||
'token' => $token->token,
|
||||
]);
|
||||
});
|
||||
|
@ -8,6 +8,7 @@ use Illuminate\Auth\Passwords\CanResetPassword;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Models\LookupContact;
|
||||
|
||||
/**
|
||||
* Class Contact.
|
||||
@ -165,3 +166,10 @@ class Contact extends EntityModel implements AuthenticatableContract, CanResetPa
|
||||
return "{$url}/client/dashboard/{$this->contact_key}";
|
||||
}
|
||||
}
|
||||
|
||||
Contact::creating(function ($contact)
|
||||
{
|
||||
LookupContact::createNew($contact->account->account_key, [
|
||||
'contact_key' => $contact->contact_key,
|
||||
]);
|
||||
});
|
||||
|
@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Carbon;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Utils;
|
||||
use App\Models\LookupInvitation;
|
||||
|
||||
/**
|
||||
* Class Invitation.
|
||||
@ -162,3 +163,10 @@ class Invitation extends EntityModel
|
||||
return sprintf('<img src="data:image/svg+xml;base64,%s"></img><p/>%s: %s', $this->signature_base64, trans('texts.signed'), Utils::fromSqlDateTime($this->signature_date));
|
||||
}
|
||||
}
|
||||
|
||||
Invitation::creating(function ($invitation)
|
||||
{
|
||||
LookupInvitation::createNew($invitation->account->account_key, [
|
||||
'invitation_key' => $invitation->invitation_key,
|
||||
]);
|
||||
});
|
||||
|
@ -7,13 +7,8 @@ use Eloquent;
|
||||
/**
|
||||
* Class ExpenseCategory.
|
||||
*/
|
||||
class LookupAccount extends Eloquent
|
||||
class LookupAccount extends LookupModel
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
@ -7,13 +7,8 @@ use Eloquent;
|
||||
/**
|
||||
* Class ExpenseCategory.
|
||||
*/
|
||||
class LookupCompany extends Eloquent
|
||||
class LookupCompany extends LookupModel
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
@ -7,13 +7,8 @@ use Eloquent;
|
||||
/**
|
||||
* Class ExpenseCategory.
|
||||
*/
|
||||
class LookupContact extends Eloquent
|
||||
class LookupContact extends LookupModel
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
@ -7,13 +7,8 @@ use Eloquent;
|
||||
/**
|
||||
* Class ExpenseCategory.
|
||||
*/
|
||||
class LookupInvitation extends Eloquent
|
||||
class LookupInvitation extends LookupModel
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
39
app/Models/LookupModel.php
Normal file
39
app/Models/LookupModel.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Eloquent;
|
||||
|
||||
/**
|
||||
* Class ExpenseCategory.
|
||||
*/
|
||||
class LookupModel extends Eloquent
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
|
||||
public static function createNew($accountKey, $data)
|
||||
{
|
||||
if (! env('MULTI_DB_ENABLED')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current = config('database.default');
|
||||
config(['database.default' => DB_NINJA_LOOKUP]);
|
||||
|
||||
$lookupAccount = LookupAccount::whereAccountKey($accountKey)->first();
|
||||
|
||||
if ($lookupAccount) {
|
||||
$data['lookup_account_id'] = $lookupAccount->id;
|
||||
} else {
|
||||
abort('Lookup account not found for ' . $accountKey);
|
||||
}
|
||||
|
||||
static::create($data);
|
||||
|
||||
config(['database.default' => $current]);
|
||||
}
|
||||
}
|
@ -7,13 +7,8 @@ use Eloquent;
|
||||
/**
|
||||
* Class ExpenseCategory.
|
||||
*/
|
||||
class LookupToken extends Eloquent
|
||||
class LookupToken extends LookupModel
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
@ -7,13 +7,8 @@ use Eloquent;
|
||||
/**
|
||||
* Class ExpenseCategory.
|
||||
*/
|
||||
class LookupUser extends Eloquent
|
||||
class LookupUser extends LookupModel
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
|
@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Laracasts\Presenter\PresentableTrait;
|
||||
use Session;
|
||||
use App\Models\LookupUser;
|
||||
|
||||
/**
|
||||
* Class User.
|
||||
@ -412,6 +413,17 @@ class User extends Authenticatable
|
||||
}
|
||||
}
|
||||
|
||||
User::creating(function ($user)
|
||||
{
|
||||
if (! $user->registered) {
|
||||
return;
|
||||
}
|
||||
|
||||
LookupUser::createNew($user->account->account_key, [
|
||||
'email' => $user->email,
|
||||
]);
|
||||
});
|
||||
|
||||
User::updating(function ($user) {
|
||||
User::onUpdatingUser($user);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user