3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class contains functions for managed entities.
21 class CRM_Core_BAO_Managed
extends CRM_Core_DAO_Managed
implements Civi\Core\HookInterface
{
24 * Callback for hook_civicrm_post().
25 * @param \Civi\Core\Event\PostEvent $event
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
)
35 // When an entity is updated, update the timestamp in corresponding Managed record
36 elseif ($event->action
=== 'edit' && $event->id
&& self
::isApi4ManagedType($event->entity
)) {
37 if (!array_key_exists('entity_modified_date', self
::getSupportedFields())) {
38 // During upgrades this column may not exist yet
41 CRM_Core_DAO
::executeQuery('UPDATE civicrm_managed SET entity_modified_date = CURRENT_TIMESTAMP WHERE entity_type = %1 AND entity_id = %2', [
42 1 => [$event->entity
, 'String'],
43 2 => [$event->id
, 'Integer'],
49 * @param string $entityName
52 public static function isApi4ManagedType(string $entityName) {
53 $type = \Civi\Api4\Utils\CoreUtil
::getInfoItem($entityName, 'type');
54 return $type && in_array('ManagedEntity', $type, TRUE);