Check for archived entities prior to import

This commit is contained in:
David Bomba 2021-11-02 21:03:49 +11:00
parent 757e3b1ed2
commit ed33ac7130

View File

@ -1032,10 +1032,12 @@ class CompanyImport implements ShouldQueue
unset($user_array['hashed_id']); unset($user_array['hashed_id']);
unset($user_array['id']); unset($user_array['id']);
$new_user = User::firstOrNew( /*Make sure we are searching for archived users also and restore if we find them.*/
$new_user = User::withTrashed()->firstOrNew(
['email' => $user->email], ['email' => $user->email],
$user_array, $user_array,
); )->restore();
$new_user->account_id = $this->account->id; $new_user->account_id = $this->account->id;
$new_user->save(['timestamps' => false]); $new_user->save(['timestamps' => false]);
@ -1062,10 +1064,10 @@ class CompanyImport implements ShouldQueue
unset($cu_array['company_id']); unset($cu_array['company_id']);
unset($cu_array['user_id']); unset($cu_array['user_id']);
$new_cu = CompanyUser::firstOrNew( $new_cu = CompanyUser::withTrashed()->firstOrNew(
['user_id' => $user_id, 'company_id' => $this->company->id], ['user_id' => $user_id, 'company_id' => $this->company->id],
$cu_array, $cu_array,
); )->restore();
$new_cu->account_id = $this->account->id; $new_cu->account_id = $this->account->id;
$new_cu->save(['timestamps' => false]); $new_cu->save(['timestamps' => false]);