Looking at #18995 I was struck by the delete hook being non-standard. In general we don't load from the DB just to pass
to the hook as the hook can do that itself. However, when I looked at other hooks
I found that they were passing out nullArray - this is a legacy method that precedes
being on a php version that supported default params when passing by reference.
It's further known to introduce intermittent hard to debug issues. This adds the new hook
and also adds standardisation to the other hooks for pre+delete.
I've left the create one for now but GroupContact is a good example of something
close to what we want to standardise on there
*/
public static function deleteBatch($batchId) {
// delete entry from batch table
- CRM_Utils_Hook::pre('delete', 'Batch', $batchId, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Batch', $batchId);
$batch = new CRM_Batch_DAO_Batch();
$batch->id = $batchId;
$batch->delete();
return FALSE;
}
- CRM_Utils_Hook::pre('delete', 'Campaign', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Campaign', $id);
$dao = new CRM_Campaign_DAO_Campaign();
$dao->id = $id;
* is successful
*/
public static function deleteCase($caseId, $moveToTrash = FALSE) {
- CRM_Utils_Hook::pre('delete', 'Case', $caseId, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Case', $caseId);
//delete activities
$activities = self::getCaseActivityDates($caseId);
$obj = new $daoName();
$obj->id = $id;
$obj->find();
- $hookParams = [];
+
if ($obj->fetch()) {
- CRM_Utils_Hook::pre('delete', $type, $id, $hookParams);
+ CRM_Utils_Hook::pre('delete', $type, $id);
$contactId = $obj->contact_id;
$obj->delete();
}
if (!$id || !is_numeric($id)) {
throw new CRM_Core_Exception('Invalid group request attempted');
}
- CRM_Utils_Hook::pre('delete', 'Group', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Group', $id);
$transaction = new CRM_Core_Transaction();
*/
public static function del($id) {
// delete from relationship table
- CRM_Utils_Hook::pre('delete', 'Relationship', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Relationship', $id);
$relationship = self::clearCurrentEmployer($id, CRM_Core_Action::DELETE);
$relationship->delete();
* $results no of deleted Contribution on success, false otherwise
*/
public static function deleteContribution($id) {
- CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Contribution', $id);
$transaction = new CRM_Core_Transaction();
*
*/
public static function del($id) {
+ CRM_Utils_Hook::pre('delete', 'UFGroup', $id);
+
//check whether this group contains any profile fields
$profileField = new CRM_Core_DAO_UFField();
$profileField->uf_group_id = $id;
$group = new CRM_Core_DAO_UFGroup();
$group->id = $id;
$group->delete();
+
+ CRM_Utils_Hook::post('delete', 'UFGroup', $id, $group);
return 1;
}
return NULL;
}
- CRM_Utils_Hook::pre('delete', 'Event', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Event', $id);
$extends = ['event'];
$groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends);
if (!$participant->find()) {
return FALSE;
}
- CRM_Utils_Hook::pre('delete', 'Participant', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Participant', $id);
$transaction = new CRM_Core_Transaction();
* @return bool|mixed
*/
public static function del($id) {
- CRM_Utils_Hook::pre('delete', 'Grant', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Grant', $id);
$grant = new CRM_Grant_DAO_Grant();
$grant->id = $id;
throw new CRM_Core_Exception(ts('No id passed to mailing del function'));
}
- CRM_Utils_Hook::pre('delete', 'Mailing', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Mailing', $id);
// delete all file attachments
CRM_Core_BAO_File::deleteEntityFile('civicrm_mailing',
throw new CRM_Core_Exception(ts('No id passed to MailingAB del function'));
}
CRM_Core_Transaction::create()->run(function () use ($id) {
- CRM_Utils_Hook::pre('delete', 'MailingAB', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'MailingAB', $id);
$dao = new CRM_Mailing_DAO_MailingAB();
$dao->id = $id;
* @return mixed
*/
public static function del($id) {
- CRM_Utils_Hook::pre('delete', 'MailingJob', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'MailingJob', $id);
$jobDAO = new CRM_Mailing_BAO_MailingJob();
$jobDAO->id = $id;
* Campaign page id.
*/
public static function deleteById($id) {
- CRM_Utils_Hook::pre('delete', 'Campaign', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Campaign', $id);
$transaction = new CRM_Core_Transaction();
* @return mixed
*/
public static function deletePledge($id) {
- CRM_Utils_Hook::pre('delete', 'Pledge', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'Pledge', $id);
$transaction = new CRM_Core_Transaction();
* @return mixed|null
*/
public static function deletePledgeBlock($id) {
- CRM_Utils_Hook::pre('delete', 'PledgeBlock', $id, CRM_Core_DAO::$_nullArray);
+ CRM_Utils_Hook::pre('delete', 'PledgeBlock', $id);
$transaction = new CRM_Core_Transaction();
* @return null
* the return value is ignored
*/
- public static function pre($op, $objectName, $id, &$params) {
+ public static function pre($op, $objectName, $id, &$params = []) {
$event = new \Civi\Core\Event\PreEvent($op, $objectName, $id, $params);
\Civi::dispatcher()->dispatch('hook_civicrm_pre', $event);
return $event->getReturnValues();
$customTable = CoreUtil::getTableName($this->getEntityName());
$ids = [];
foreach ($items as $item) {
- \CRM_Utils_Hook::pre('delete', $this->getEntityName(), $item['id'], \CRM_Core_DAO::$_nullArray);
+ \CRM_Utils_Hook::pre('delete', $this->getEntityName(), $item['id']);
\CRM_Utils_SQL_Delete::from($customTable)
->where('id = #value')
->param('#value', $item['id'])