From: eileen Date: Thu, 18 Mar 2021 06:57:05 +0000 (+1300) Subject: dev/core#2390 Add hook support for Activity Contact X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4cdd873a5edce32f469de98e5ad4e0e04d3dcff0;p=civicrm-core.git dev/core#2390 Add hook support for Activity Contact Alternative to https://github.com/civicrm/civicrm-core/pull/19623 per comments on that PR. --- diff --git a/CRM/Activity/BAO/ActivityContact.php b/CRM/Activity/BAO/ActivityContact.php index 4ac6652f7c..b68260e1be 100644 --- a/CRM/Activity/BAO/ActivityContact.php +++ b/CRM/Activity/BAO/ActivityContact.php @@ -20,33 +20,29 @@ */ class CRM_Activity_BAO_ActivityContact extends CRM_Activity_DAO_ActivityContact { - /** - * Class constructor. - */ - public function __construct() { - parent::__construct(); - } - /** * Function to add activity contact. * * @param array $params * The values for this table: activity id, contact id, record type. * - * @return object + * @return CRM_Activity_DAO_ActivityContact * activity_contact object + * + * @throws \CRM_Core_Exception + * @throws \PEAR_Exception */ - public static function create($params) { - $activityContact = new CRM_Activity_DAO_ActivityContact(); - $activityContact->copyValues($params); + public static function create(array $params): CRM_Activity_DAO_ActivityContact { try { - return $activityContact->save(); + return self::writeRecord($params); } catch (PEAR_Exception $e) { // This check used to be done first, creating an extra query before each insert. // However, in none of the core tests was this ever called with values that already // existed, meaning that this line would never or almost never be hit. // hence it's better to save the select query here. + $activityContact = new CRM_Activity_DAO_ActivityContact(); + $activityContact->copyValues($params); if ($activityContact->find(TRUE)) { return $activityContact; } diff --git a/CRM/Contact/BAO/DashboardContact.php b/CRM/Contact/BAO/DashboardContact.php index c6ff99f689..145494860b 100644 --- a/CRM/Contact/BAO/DashboardContact.php +++ b/CRM/Contact/BAO/DashboardContact.php @@ -17,10 +17,11 @@ class CRM_Contact_BAO_DashboardContact extends CRM_Contact_DAO_DashboardContact /** * @param array $record + * * @return CRM_Contact_DAO_DashboardContact - * @throws CRM_Core_Exception + * @throws \CRM_Core_Exception */ - public static function writeRecord(array $record) { + public static function writeRecord(array $record): CRM_Core_DAO { self::checkEditPermission($record); return parent::writeRecord($record); } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index b80bc54575..506a971ba7 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -887,10 +887,11 @@ class CRM_Core_DAO extends DB_DataObject { * Otherwise a new record will be created. * * @param array $record - * @return CRM_Core_DAO - * @throws CRM_Core_Exception + * + * @return $this + * @throws \CRM_Core_Exception */ - public static function writeRecord(array $record) { + public static function writeRecord(array $record): CRM_Core_DAO { $hook = empty($record['id']) ? 'create' : 'edit'; $className = CRM_Core_DAO_AllCoreTables::getCanonicalClassName(static::class); if ($className === 'CRM_Core_DAO') {