Commit | Line | Data |
---|---|---|
a2bf5923 CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | Copyright CiviCRM LLC. All rights reserved. | | |
5 | | | | |
6 | | This work is published under the GNU AGPLv3 license with some | | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
9 | +--------------------------------------------------------------------+ | |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
15 | * @copyright CiviCRM LLC https://civicrm.org/licensing | |
16 | */ | |
17 | ||
18 | /** | |
19 | * This class contains functions for managed entities. | |
20 | */ | |
21 | class CRM_Core_BAO_Managed extends CRM_Core_DAO_Managed implements Civi\Test\HookInterface { | |
22 | ||
23 | /** | |
24 | * Callback for hook_civicrm_post(). | |
25 | * @param \Civi\Core\Event\PostEvent $event | |
26 | */ | |
27 | public static function on_hook_civicrm_post(\Civi\Core\Event\PostEvent $event) { | |
28 | // When an entity is deleted, delete the corresponding Managed record | |
29 | if ($event->action === 'delete' && $event->id && self::isApi4ManagedType($event->entity)) { | |
30 | \Civi\Api4\Managed::delete(FALSE) | |
31 | ->addWhere('entity_type', '=', $event->entity) | |
32 | ->addWhere('entity_id', '=', $event->id) | |
33 | ->execute(); | |
34 | } | |
35 | } | |
36 | ||
37 | /** | |
38 | * @param string $entityName | |
39 | * @return bool | |
40 | */ | |
41 | public static function isApi4ManagedType(string $entityName) { | |
42 | $type = \Civi\Api4\Utils\CoreUtil::getInfoItem($entityName, 'type'); | |
43 | return $type && in_array('ManagedEntity', $type, TRUE); | |
44 | } | |
45 | ||
46 | } |