From: Coleman Watts Date: Sat, 21 Aug 2021 21:12:09 +0000 (-0400) Subject: Deprecate 2 del() functions in favor of generics and hook callbacks X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1f591bab280433d42e8b49f0271c6a82b165d48b;p=civicrm-core.git Deprecate 2 del() functions in favor of generics and hook callbacks dev/core#2757 --- diff --git a/CRM/Campaign/BAO/Survey.php b/CRM/Campaign/BAO/Survey.php index 93b487982b..b37e6b9bce 100644 --- a/CRM/Campaign/BAO/Survey.php +++ b/CRM/Campaign/BAO/Survey.php @@ -18,7 +18,7 @@ /** * Class CRM_Campaign_BAO_Survey. */ -class CRM_Campaign_BAO_Survey extends CRM_Campaign_DAO_Survey { +class CRM_Campaign_BAO_Survey extends CRM_Campaign_DAO_Survey implements Civi\Test\HookInterface { /** * Retrieve DB object based on input parameters. @@ -366,24 +366,31 @@ SELECT survey.id as id, } /** - * Delete the survey. + * Delete a survey. * * @param int $id - * Survey id. - * + * @deprecated * @return mixed|null */ public static function del($id) { if (!$id) { return NULL; } - $reportId = CRM_Campaign_BAO_Survey::getReportID($id); - if ($reportId) { - CRM_Report_BAO_ReportInstance::del($reportId); + self::deleteRecord(['id' => $id]); + return 1; + } + + /** + * Event fired prior to modifying a Survey. + * @param \Civi\Core\Event\PreEvent $event + */ + public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) { + if ($event->action === 'delete' && $event->id) { + $reportId = self::getReportID($event->id); + if ($reportId) { + CRM_Report_BAO_ReportInstance::deleteRecord(['id' => $reportId]); + } } - $dao = new CRM_Campaign_DAO_Survey(); - $dao->id = $id; - return $dao->delete(); } /** diff --git a/CRM/Report/BAO/ReportInstance.php b/CRM/Report/BAO/ReportInstance.php index a0950787c1..9d755dabd0 100644 --- a/CRM/Report/BAO/ReportInstance.php +++ b/CRM/Report/BAO/ReportInstance.php @@ -14,7 +14,7 @@ * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing */ -class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance { +class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance implements Civi\Test\HookInterface { /** * Takes an associative array and creates an instance object. @@ -219,22 +219,27 @@ class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance { * Delete the instance of the Report. * * @param int $id - * + * @deprecated * @return mixed - * $results no of deleted Instance on success, false otherwise */ public static function del($id = NULL) { - $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $id, 'navigation_id', 'id'); - $dao = new CRM_Report_DAO_ReportInstance(); - $dao->id = $id; - $result = $dao->delete(); - - // Delete navigation if exists. - if ($navId) { - CRM_Core_BAO_Navigation::processDelete($navId); - CRM_Core_BAO_Navigation::resetNavigation(); + self::deleteRecord(['id' => $id]); + return 1; + } + + /** + * Event fired prior to modifying a ReportInstance. + * @param \Civi\Core\Event\PreEvent $event + */ + public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) { + if ($event->action === 'delete' && $event->id) { + // When deleting a report, also delete from navigation menu + $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $event->id, 'navigation_id'); + if ($navId) { + CRM_Core_BAO_Navigation::processDelete($navId); + CRM_Core_BAO_Navigation::resetNavigation(); + } } - return $result; } /**