Only attempt to disable entity if v3 create+is_active is an option
authoreileen <emcnaughton@wikimedia.org>
Wed, 5 May 2021 01:57:18 +0000 (13:57 +1200)
committereileen <emcnaughton@wikimedia.org>
Wed, 5 May 2021 05:39:18 +0000 (17:39 +1200)
CRM/Core/ManagedEntities.php

index f918bb0348f7a5d96140ccda6a4c923f9733cb6f..d35ef2d104c14061bdc7020329d3d0e0e20fa9c3 100644 (file)
@@ -301,10 +301,17 @@ class CRM_Core_ManagedEntities {
    * inactive.
    *
    * @param CRM_Core_DAO_Managed $dao
+   *
+   * @throws \CiviCRM_API3_Exception
    */
-  public function disableEntity($dao) {
-    // FIXME: if ($dao->entity_type supports is_active) {
-    if (TRUE) {
+  public function disableEntity($dao): void {
+    $actions = civicrm_api3($dao->entity_type, 'getactions', [])['values'];
+    $supportsDisable = FALSE;
+    if (in_array('create', $actions, TRUE) && in_array('getfields', $actions)) {
+      $fields = civicrm_api3($dao->entity_type, 'getfields', ['action' => 'create'])['values'];
+      $supportsDisable = array_key_exists('is_active', $fields);
+    }
+    if ($supportsDisable) {
       // FIXME cascading for payproc types?
       $params = [
         'version' => 3,