mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-20 00:11:35 +02:00
Multi-db support
This commit is contained in:
parent
517804f987
commit
782ae969a4
@ -105,6 +105,29 @@ class CheckData extends Command
|
||||
|
||||
private function checkContacts()
|
||||
{
|
||||
// check for contacts with the contact_key value set
|
||||
$contacts = DB::table('contacts')
|
||||
->whereNull('contact_key')
|
||||
->orderBy('id')
|
||||
->get(['id']);
|
||||
$this->logMessage(count($contacts) . ' contacts without a contact_key');
|
||||
|
||||
if (count($contacts) > 0) {
|
||||
$this->isValid = false;
|
||||
}
|
||||
|
||||
if ($this->option('fix') == 'true') {
|
||||
foreach ($contacts as $contact) {
|
||||
DB::table('contacts')
|
||||
->where('id', $contact->id)
|
||||
->whereNull('contact_key')
|
||||
->update([
|
||||
'contact_key' => strtolower(str_random(RANDOM_KEY_LENGTH)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// check for missing contacts
|
||||
$clients = DB::table('clients')
|
||||
->leftJoin('contacts', function($join) {
|
||||
$join->on('contacts.client_id', '=', 'clients.id')
|
||||
@ -138,6 +161,7 @@ class CheckData extends Command
|
||||
}
|
||||
}
|
||||
|
||||
// check for more than one primary contact
|
||||
$clients = DB::table('clients')
|
||||
->leftJoin('contacts', function($join) {
|
||||
$join->on('contacts.client_id', '=', 'clients.id')
|
||||
|
@ -144,7 +144,7 @@ class InitLookup extends Command
|
||||
} else {
|
||||
LookupUser::create([
|
||||
'lookup_account_id' => $lookupAccount->id,
|
||||
'email' => $user['email'],
|
||||
'email' => $user['email'] ?: null,
|
||||
'user_id' => $user['user_id'],
|
||||
]);
|
||||
}
|
||||
|
@ -31,28 +31,32 @@ class PruneData extends Command
|
||||
|
||||
// delete accounts who never registered, didn't create any invoices,
|
||||
// hansn't logged in within the past 6 months and isn't linked to another account
|
||||
$sql = 'select a.id
|
||||
from (select id, last_login from accounts) a
|
||||
left join users u on u.account_id = a.id and u.public_id = 0
|
||||
left join invoices i on i.account_id = a.id
|
||||
left join user_accounts ua1 on ua1.user_id1 = u.id
|
||||
left join user_accounts ua2 on ua2.user_id2 = u.id
|
||||
left join user_accounts ua3 on ua3.user_id3 = u.id
|
||||
left join user_accounts ua4 on ua4.user_id4 = u.id
|
||||
left join user_accounts ua5 on ua5.user_id5 = u.id
|
||||
where u.registered = 0
|
||||
and a.last_login < DATE_SUB(now(), INTERVAL 6 MONTH)
|
||||
and (ua1.id is null and ua2.id is null and ua3.id is null and ua4.id is null and ua5.id is null)
|
||||
group by a.id
|
||||
having count(i.id) = 0';
|
||||
$sql = 'select c.id
|
||||
from companies c
|
||||
left join accounts a on a.company_id = c.id
|
||||
left join clients c on c.account_id = a.id
|
||||
left join tasks t on t.account_id = a.id
|
||||
left join expenses e on e.account_id = a.id
|
||||
left join users u on u.account_id = a.id and u.registered = 1
|
||||
where c.created_at < DATE_SUB(now(), INTERVAL 6 MONTH)
|
||||
group by c.id
|
||||
having count(c.id) = 0
|
||||
and count(t.id) = 0
|
||||
and count(e.id) = 0
|
||||
and count(u.id) = 0';
|
||||
|
||||
$results = DB::select($sql);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$this->info("Deleting {$result->id}");
|
||||
DB::table('accounts')
|
||||
->where('id', '=', $result->id)
|
||||
->delete();
|
||||
$this->info("Deleting company: {$result->id}");
|
||||
try {
|
||||
DB::table('companies')
|
||||
->where('id', '=', $result->id)
|
||||
->delete();
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
// most likely because a user_account record exists which doesn't cascade delete
|
||||
$this->info("Unable to delete companyId: {$result->id}");
|
||||
}
|
||||
}
|
||||
|
||||
$this->info('Done');
|
||||
|
@ -415,6 +415,7 @@ class AccountRepository
|
||||
$contact->user_id = $ninjaUser->id;
|
||||
$contact->account_id = $ninjaAccount->id;
|
||||
$contact->public_id = $account->id;
|
||||
$contact->contact_key = strtolower(str_random(RANDOM_KEY_LENGTH));
|
||||
$contact->is_primary = true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user