From 8aa7662f3194444afc6b549a2e99af18917804ba Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 29 Jan 2021 10:33:09 +0100 Subject: [PATCH 1/3] add SeedDMS_Core_User->isType() and SeedDMS_Core_Group->isType() --- SeedDMS_Core/Core/inc.ClassGroup.php | 9 +++++++++ SeedDMS_Core/Core/inc.ClassUser.php | 9 +++++++++ SeedDMS_Core/package.xml | 2 ++ 3 files changed, 20 insertions(+) diff --git a/SeedDMS_Core/Core/inc.ClassGroup.php b/SeedDMS_Core/Core/inc.ClassGroup.php index 4e7b9ba47..696613600 100644 --- a/SeedDMS_Core/Core/inc.ClassGroup.php +++ b/SeedDMS_Core/Core/inc.ClassGroup.php @@ -124,6 +124,15 @@ class SeedDMS_Core_Group { /* {{{ */ return $groups; } /* }}} */ + /** + * Check if this object is of type 'group'. + * + * @param string $type type of object + */ + public function isType($type) { /* {{{ */ + return $type == 'group'; + } /* }}} */ + /** * @param SeedDMS_Core_DMS $dms */ diff --git a/SeedDMS_Core/Core/inc.ClassUser.php b/SeedDMS_Core/Core/inc.ClassUser.php index 495b4b310..983390707 100644 --- a/SeedDMS_Core/Core/inc.ClassUser.php +++ b/SeedDMS_Core/Core/inc.ClassUser.php @@ -250,6 +250,15 @@ class SeedDMS_Core_User { /* {{{ */ return $users; } /* }}} */ + /** + * Check if this object is of type 'user'. + * + * @param string $type type of object + */ + public function isType($type) { /* {{{ */ + return $type == 'user'; + } /* }}} */ + /** * @param SeedDMS_Core_DMS $dms */ diff --git a/SeedDMS_Core/package.xml b/SeedDMS_Core/package.xml index d5a0e96f8..833378c09 100644 --- a/SeedDMS_Core/package.xml +++ b/SeedDMS_Core/package.xml @@ -25,6 +25,8 @@ GPL License - add SeedDMS_Core_DatabaseAccess::hasTable() +- add SeedDMS_Core_User->isType() and SeedDMS_Core_Group->isType() +- add SeedDMS_Core_User->getDMS() and SeedDMS_Core_Group->getDMS() From ae2eebd5629d6be9f972af4227dc2eb092b4ed89 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 29 Jan 2021 10:33:35 +0100 Subject: [PATCH 2/3] use new method SeedDMS_Core_User->isType() --- inc/inc.ClassEmailNotify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/inc.ClassEmailNotify.php b/inc/inc.ClassEmailNotify.php index 630697969..20fffcfce 100644 --- a/inc/inc.ClassEmailNotify.php +++ b/inc/inc.ClassEmailNotify.php @@ -84,7 +84,7 @@ class SeedDMS_EmailNotify extends SeedDMS_Notify { * @return false or -1 in case of error, otherwise true */ function toIndividual($sender, $recipient, $subject, $messagekey, $params=array(), $attachments=array()) { /* {{{ */ - if(is_object($recipient) && !strcasecmp(get_class($recipient), $this->_dms->getClassname('user')) && !$recipient->isDisabled() && $recipient->getEmail()!="") { + if(is_object($recipient) && $recipient->isType('user') && !$recipient->isDisabled() && $recipient->getEmail()!="") { $to = $recipient->getEmail(); $lang = $recipient->getLanguage(); } elseif(is_string($recipient) && trim($recipient) != "") { From 3a9bec69afb25fbc8a0f5e96398fcbe49bfacc84 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 29 Jan 2021 10:34:01 +0100 Subject: [PATCH 3/3] log filtered out notifications --- inc/inc.ClassNotificationService.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/inc/inc.ClassNotificationService.php b/inc/inc.ClassNotificationService.php index e4d04b4e4..55de56eff 100644 --- a/inc/inc.ClassNotificationService.php +++ b/inc/inc.ClassNotificationService.php @@ -70,20 +70,29 @@ class SeedDMS_NotificationService { public function toIndividual($sender, $recipient, $subject, $message, $params=array(), $recvtype=0) { $error = true; foreach($this->services as $name => $service) { + /* Set $to to email address of user or the string passed in $recipient + * This is only used for logging + */ + if(is_object($recipient) && $recipient->isType('user') && !$recipient->isDisabled() && $recipient->getEmail()!="") { + $to = $recipient->getEmail(); + } elseif(is_string($recipient) && trim($recipient) != "") { + $to = $recipient; + } else { + $to = ''; + } + + /* Call filter of notification service if set */ if(!is_callable([$service, 'filter']) || $service->filter($sender, $recipient, $subject, $message, $params, $recvtype)) { - if(is_object($recipient) && ($dms = $recipient->getDMS()) && !strcasecmp(get_class($recipient), $dms->getClassname('user')) && !$recipient->isDisabled() && $recipient->getEmail()!="") { - $to = $recipient->getEmail(); - } elseif(is_string($recipient) && trim($recipient) != "") { - $to = $recipient; - } if(!$service->toIndividual($sender, $recipient, $subject, $message, $params)) { $error = false; $this->errors[$name] = false; - $this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to user \''.$to.'\' failed.', PEAR_LOG_ERR); + $this->logger->log('Notification service \''.$name.'\': Sending mail \''.$subject.'\' to user \''.$to.'\' failed.', PEAR_LOG_ERR); } else { - $this->logger->log('Notification service: '.$name.'. Sending mail \''.$subject.'\' to user \''.$to.'\' successful.', PEAR_LOG_INFO); + $this->logger->log('Notification service \''.$name.'\': Sending mail \''.$subject.'\' to user \''.$to.'\' successful.', PEAR_LOG_INFO); $this->errors[$name] = true; } + } else { + $this->logger->log('Notification service \''.$name.'\': Sending mail \''.$subject.'\' to user \''.$to.'\' filtered out.', PEAR_LOG_INFO); } } return $error;