From f9797b82b48bee7e8174cd834d50713c341c6e02 Mon Sep 17 00:00:00 2001 From: Jon Bendtsen Date: Mon, 18 Mar 2024 22:25:29 +0100 Subject: [PATCH 1/5] the surrounding lines contained an ' as ' in the SQL statement, works both with and without, but this brings consistency --- htdocs/societe/notify/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/notify/card.php b/htdocs/societe/notify/card.php index 0e0031e6f9c..69d8ce43b50 100644 --- a/htdocs/societe/notify/card.php +++ b/htdocs/societe/notify/card.php @@ -233,7 +233,7 @@ if ($result > 0) { $sql .= " c.rowid as contactid, c.lastname, c.firstname, c.email"; $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; $sql .= " ".MAIN_DB_PREFIX."notify_def as n,"; - $sql .= " ".MAIN_DB_PREFIX."socpeople c"; + $sql .= " ".MAIN_DB_PREFIX."socpeople as c"; $sql .= " WHERE a.rowid = n.fk_action"; $sql .= " AND c.rowid = n.fk_contact"; $sql .= " AND c.fk_soc = ".((int) $object->id); From 1a35b20cb73fa2874b6e1935f79b36b8c08dc874 Mon Sep 17 00:00:00 2001 From: Jon Bendtsen Date: Mon, 18 Mar 2024 22:28:10 +0100 Subject: [PATCH 2/5] only counts notifications for existing contacts. SQL code copy from htdocs/societe/notify/card.php --- htdocs/core/lib/company.lib.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 5e69aaba3df..902ed1f0cfe 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -321,10 +321,17 @@ function societe_prepare_head(Societe $object) if (!is_null($dataretrieved)) { $nbNotif = $dataretrieved; } else { + + // List of notifications enabled for contacts $sql = "SELECT COUNT(n.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n"; - $sql .= " WHERE fk_soc = ".((int) $object->id); - $resql = $db->query($sql); + $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; + $sql .= " ".MAIN_DB_PREFIX."notify_def as n,"; + $sql .= " ".MAIN_DB_PREFIX."socpeople as c"; + $sql .= " WHERE a.rowid = n.fk_action"; + $sql .= " AND c.rowid = n.fk_contact"; + $sql .= " AND c.fk_soc = ".((int) $object->id); + + $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); $nbNotif = $obj->nb; From fce674e3472b0cdc0c47f6027935dd48824acc5d Mon Sep 17 00:00:00 2001 From: Jon Bendtsen Date: Mon, 18 Mar 2024 22:42:57 +0100 Subject: [PATCH 3/5] precommit check failed --- htdocs/core/lib/company.lib.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 902ed1f0cfe..bb9620d4a3b 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -321,7 +321,6 @@ function societe_prepare_head(Societe $object) if (!is_null($dataretrieved)) { $nbNotif = $dataretrieved; } else { - // List of notifications enabled for contacts $sql = "SELECT COUNT(n.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; @@ -330,8 +329,7 @@ function societe_prepare_head(Societe $object) $sql .= " WHERE a.rowid = n.fk_action"; $sql .= " AND c.rowid = n.fk_contact"; $sql .= " AND c.fk_soc = ".((int) $object->id); - - $resql = $db->query($sql); + $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); $nbNotif = $obj->nb; From f20ca9b0023291c53d13035943e4bbd69109e084 Mon Sep 17 00:00:00 2001 From: Jon Bendtsen Date: Mon, 18 Mar 2024 23:51:44 +0100 Subject: [PATCH 4/5] actually delete notifications belonging to a contact when a contact is deleted --- htdocs/contact/class/contact.class.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 1c800456b76..d5d96b58f34 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1298,6 +1298,18 @@ class Contact extends CommonObject } } + if (!$error) { + // Remove Notifications + $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def WHERE fk_contact = ".((int) $this->id); + dol_syslog(__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->error .= $this->db->lasterror(); + $errorflag = -1; + } + } + if (!$error) { // Remove category $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".((int) $this->id); From aebbb97627d560d1a3577c1d5a057f36b267d4a4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Mar 2024 14:05:40 +0100 Subject: [PATCH 5/5] Update company.lib.php --- htdocs/core/lib/company.lib.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index a32933a7ce4..99133109c0b 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -325,10 +325,8 @@ function societe_prepare_head(Societe $object) $sql = "SELECT COUNT(n.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; $sql .= " ".MAIN_DB_PREFIX."notify_def as n,"; - $sql .= " ".MAIN_DB_PREFIX."socpeople as c"; $sql .= " WHERE a.rowid = n.fk_action"; - $sql .= " AND c.rowid = n.fk_contact"; - $sql .= " AND c.fk_soc = ".((int) $object->id); + $sql .= " AND n.fk_soc = ".((int) $object->id); $resql = $db->query($sql); if ($resql) { $obj = $db->fetch_object($resql);