From 3c76bfa90cf1281d44831e9f031c63975958a629 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 23 Jan 2023 13:38:47 +1100 Subject: [PATCH] Fixes for check data script --- app/Console/Commands/CheckData.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 7ffba27472b4..c943863d8731 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -448,13 +448,23 @@ class CheckData extends Command //check contact 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; - $invitation->user_id = $entity->user_id; - $invitation->{$entity_key} = $entity->id; - $invitation->{$contact_id} = $contact_class::where('company_id', $entity->company_id)->where($client_vendor_key,$entity->{$client_vendor_key})->first()->id; - $invitation->key = Str::random(config('ninja.key_length')); - $this->logMessage("Add invitation for {$entity_key} - {$entity->id}"); + + $contact = $contact_class::where('company_id', $entity->company_id)->where($client_vendor_key,$entity->{$client_vendor_key})->first(); + + //double check if an archived invite exists + if($contact && $entity->invitations()->withTrashed()->where($contact_id, $contact->id)->count() != 0) { + $i = $entity->invitations()->withTrashed()->where($contact_id, $contact->id)->first(); + $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 $this->logMessage("No contact present, so cannot add invitation for {$entity_key} - {$entity->id}");