mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Check subdomain is uniuqe across dbs
This commit is contained in:
parent
3439aa9a06
commit
82286a2339
@ -44,7 +44,7 @@ class SaveClientPortalSettings extends Request
|
||||
if (Utils::isNinja()) {
|
||||
if ($this->custom_link == 'subdomain') {
|
||||
$subdomain = substr(strtolower($input['subdomain']), 0, MAX_SUBDOMAIN_LENGTH);
|
||||
$input['subdomain'] = preg_replace('/[^a-zA-Z0-9_\-\.]/', '', $subdomain);
|
||||
$input['subdomain'] = preg_replace('/[^a-zA-Z0-9\-\.]/', '', $subdomain);
|
||||
$input['iframe_url'] = null;
|
||||
} else {
|
||||
$iframeURL = substr(strtolower($input['iframe_url']), 0, MAX_IFRAME_URL_LENGTH);
|
||||
|
@ -1711,6 +1711,13 @@ Account::creating(function ($account)
|
||||
LookupAccount::createAccount($account->account_key, $account->company_id);
|
||||
});
|
||||
|
||||
Account::updating(function ($account) {
|
||||
$dirty = $account->getDirty();
|
||||
if (array_key_exists('subdomain', $dirty)) {
|
||||
LookupAccount::updateAccount($account->account_key, $account);
|
||||
}
|
||||
});
|
||||
|
||||
Account::updated(function ($account) {
|
||||
// prevent firing event if the invoice/quote counter was changed
|
||||
// TODO: remove once counters are moved to separate table
|
||||
|
@ -55,6 +55,24 @@ class LookupAccount extends LookupModel
|
||||
return $this->lookupCompany->dbServer->name;
|
||||
}
|
||||
|
||||
public static function updateAccount($accountKey, $account)
|
||||
{
|
||||
if (! env('MULTI_DB_ENABLED')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current = config('database.default');
|
||||
config(['database.default' => DB_NINJA_LOOKUP]);
|
||||
|
||||
$lookupAccount = LookupAccount::whereAccountKey($accountKey)
|
||||
->firstOrFail();
|
||||
|
||||
$lookupAccount->subdomain = $account->subdomain;
|
||||
$lookupAccount->save();
|
||||
|
||||
config(['database.default' => $current]);
|
||||
}
|
||||
|
||||
public static function validateField($field, $value, $account = false)
|
||||
{
|
||||
if (! env('MULTI_DB_ENABLED')) {
|
||||
@ -62,7 +80,7 @@ class LookupAccount extends LookupModel
|
||||
}
|
||||
|
||||
$current = config('database.default');
|
||||
|
||||
|
||||
config(['database.default' => DB_NINJA_LOOKUP]);
|
||||
|
||||
$lookupAccount = LookupAccount::where($field, '=', $value)->first();
|
||||
|
@ -467,7 +467,7 @@ iframe.src = '{{ rtrim(SITE_URL ,'/') }}/view/'
|
||||
var input = $('#subdomain');
|
||||
var val = input.val();
|
||||
if (!val) return;
|
||||
val = val.replace(/[^a-zA-Z0-9_\-]/g, '').toLowerCase().substring(0, {{ MAX_SUBDOMAIN_LENGTH }});
|
||||
val = val.replace(/[^a-zA-Z0-9\-]/g, '').toLowerCase().substring(0, {{ MAX_SUBDOMAIN_LENGTH }});
|
||||
input.val(val);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user