Skip to content

Commit

Permalink
Delete Contact Notes when contact is deleted also delete contact refe…
Browse files Browse the repository at this point in the history
…rences when delting a client
  • Loading branch information
johnnyq committed Nov 23, 2024
1 parent 724d4a3 commit a80fddf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion post/user/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,16 @@
mysqli_query($mysqli, "DELETE FROM certificates WHERE certificate_client_id = $client_id");
mysqli_query($mysqli, "DELETE FROM documents WHERE document_client_id = $client_id");

// Delete Contacts and contact tags
// Delete Contacts including contact tags, notes
$sql = mysqli_query($mysqli, "SELECT contact_id FROM contacts WHERE contact_client_id = $client_id");
while($row = mysqli_fetch_array($sql)) {
$contact_id = $row['contact_id'];
mysqli_query($mysqli, "DELETE FROM contact_tags WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_assets WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_documents WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_files WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_logins WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_notes WHERE contact_note_contact_id = $contact_id");
}
mysqli_query($mysqli, "DELETE FROM contacts WHERE contact_client_id = $client_id");

Expand Down
2 changes: 2 additions & 0 deletions post/user/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@
mysqli_query($mysqli, "DELETE FROM contact_documents WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_files WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_logins WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_notes WHERE contact_note_contact_id = $contact_id");

// Individual Logging
logAction("Contact", "Delete", "$session_name deleted $contact_name", $client_id);
Expand Down Expand Up @@ -787,6 +788,7 @@
mysqli_query($mysqli, "DELETE FROM contact_documents WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_files WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_logins WHERE contact_id = $contact_id");
mysqli_query($mysqli, "DELETE FROM contact_notes WHERE contact_note_contact_id = $contact_id");

//Logging
logAction("Contact", "Delete", "$session_name deleted contact $contact_name", $client_id);
Expand Down

0 comments on commit a80fddf

Please sign in to comment.