-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ManagedEntities - Always delete managed record when deleting an entity
This uses hooks to ensure managed records are always cleared out when an entity is deleted. Fixes OptionValue::delete which was previously not calling hooks.
- Loading branch information
Showing
4 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC https://civicrm.org/licensing | ||
*/ | ||
|
||
/** | ||
* This class contains functions for managed entities. | ||
*/ | ||
class CRM_Core_BAO_Managed extends CRM_Core_DAO_Managed implements Civi\Test\HookInterface { | ||
|
||
/** | ||
* Callback for hook_civicrm_post(). | ||
* @param \Civi\Core\Event\PostEvent $event | ||
*/ | ||
public static function on_hook_civicrm_post(\Civi\Core\Event\PostEvent $event) { | ||
// When an entity is deleted, delete the corresponding Managed record | ||
if ($event->action === 'delete' && $event->id && $event->entity !== 'Managed') { | ||
$entityName = [$event->entity]; | ||
// Legacy support for strangely-named v3 entities | ||
if ($event->entity === 'OptionValue') { | ||
$entityName[] = 'CustomSearch'; | ||
$entityName[] = 'ActivityType'; | ||
} | ||
if (in_array($event->entity, ['Individual', 'Household', 'Organization'], TRUE)) { | ||
$entityName[] = 'Contact'; | ||
} | ||
\Civi\Api4\Managed::delete(FALSE) | ||
->addWhere('entity_type', 'IN', $entityName) | ||
->addWhere('entity_id', '=', $event->id) | ||
->execute(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters