Fixes for check data script

This commit is contained in:
David Bomba 2023-01-23 13:38:47 +11:00
parent 527b81768a
commit 3c76bfa90c

View File

@ -448,13 +448,23 @@ class CheckData extends Command
//check contact exists! //check contact exists!
if($contact_class::where('company_id', $entity->company_id)->where($client_vendor_key,$entity->{$client_vendor_key})->exists()) if($contact_class::where('company_id', $entity->company_id)->where($client_vendor_key,$entity->{$client_vendor_key})->exists())
{ {
$invitation = new $entity_obj();
$invitation->company_id = $entity->company_id; $contact = $contact_class::where('company_id', $entity->company_id)->where($client_vendor_key,$entity->{$client_vendor_key})->first();
$invitation->user_id = $entity->user_id;
$invitation->{$entity_key} = $entity->id; //double check if an archived invite exists
$invitation->{$contact_id} = $contact_class::where('company_id', $entity->company_id)->where($client_vendor_key,$entity->{$client_vendor_key})->first()->id; if($contact && $entity->invitations()->withTrashed()->where($contact_id, $contact->id)->count() != 0) {
$invitation->key = Str::random(config('ninja.key_length')); $i = $entity->invitations()->withTrashed()->where($contact_id, $contact->id)->first();
$this->logMessage("Add invitation for {$entity_key} - {$entity->id}"); $i->restore();
}
else {
$invitation = new $entity_obj();
$invitation->company_id = $entity->company_id;
$invitation->user_id = $entity->user_id;
$invitation->{$entity_key} = $entity->id;
$invitation->{$contact_id} = $contact->id;
$invitation->key = Str::random(config('ninja.key_length'));
$this->logMessage("Add invitation for {$entity_key} - {$entity->id}");
}
} }
else else
$this->logMessage("No contact present, so cannot add invitation for {$entity_key} - {$entity->id}"); $this->logMessage("No contact present, so cannot add invitation for {$entity_key} - {$entity->id}");