mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #5928 from turbo124/v5-develop
Improve check data scripts
This commit is contained in:
commit
e4e42d4b2e
@ -236,9 +236,21 @@ class CheckData extends Command
|
|||||||
$clients->where('clients.id', '=', $this->option('client_id'));
|
$clients->where('clients.id', '=', $this->option('client_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$clients = $clients->get(['clients.id', DB::raw('count(client_contacts.id)')]);
|
$clients = $clients->get(['clients.id', 'clients.user_id', 'clients.company_id']);
|
||||||
$this->logMessage($clients->count().' clients without a single primary contact');
|
$this->logMessage($clients->count().' clients without a single primary contact');
|
||||||
|
|
||||||
|
if ($this->option('fix') == 'true') {
|
||||||
|
foreach ($clients as $client) {
|
||||||
|
$this->logMessage("Fixing missing contacts #{$client->id}");
|
||||||
|
|
||||||
|
$new_contact = ClientContactFactory::create($client->company_id, $client->user_id);
|
||||||
|
$new_contact->client_id = $client->id;
|
||||||
|
$new_contact->contact_key = Str::random(40);
|
||||||
|
$new_contact->is_primary = true;
|
||||||
|
$new_contact->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($clients->count() > 0) {
|
if ($clients->count() > 0) {
|
||||||
$this->isValid = false;
|
$this->isValid = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user