Skip to content

Commit

Permalink
Merge pull request #19828 from eileenmcnaughton/act_contact_hook
Browse files Browse the repository at this point in the history
dev/core#2390 Add hook support for Activity Contact
  • Loading branch information
colemanw authored Mar 21, 2021
2 parents 1c63499 + 4cdd873 commit b5aefc2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
20 changes: 8 additions & 12 deletions CRM/Activity/BAO/ActivityContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions CRM/Contact/BAO/DashboardContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,11 @@ public static function getAttribute($class, $fieldName = NULL) {
* 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') {
Expand Down

0 comments on commit b5aefc2

Please sign in to comment.