From 6ff8ed2e46297e24f612acdb0579047850d1034d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 4 Dec 2022 21:08:55 -0500 Subject: [PATCH] Hide deprecated fields from SearchKit & Afform --- CRM/Activity/DAO/Activity.php | 5 +++++ CRM/Contact/DAO/Contact.php | 2 ++ CRM/Core/DAO/Address.php | 1 + CRM/Core/DAO/Phone.php | 1 + Civi/Api4/Generic/BasicGetFieldsAction.php | 5 +++++ Civi/Api4/Service/Spec/FieldSpec.php | 15 +++++++++++++++ Civi/Api4/Service/Spec/SpecFormatter.php | 1 + .../admin/Civi/AfformAdmin/AfformAdminMeta.php | 2 +- .../Api4/Action/SearchDisplay/GetSearchTasks.php | 2 +- ext/search_kit/Civi/Search/Admin.php | 2 +- .../crmSearchTasks/crmSearchTaskUpdate.ctrl.js | 2 +- tests/phpunit/api/v4/Action/GetFieldsTest.php | 4 +++- xml/templates/dao.tpl | 3 +++ 13 files changed, 40 insertions(+), 5 deletions(-) diff --git a/CRM/Activity/DAO/Activity.php b/CRM/Activity/DAO/Activity.php index 833f7d2bb3..d9709a9b72 100644 --- a/CRM/Activity/DAO/Activity.php +++ b/CRM/Activity/DAO/Activity.php @@ -497,6 +497,7 @@ class CRM_Activity_DAO_Activity extends CRM_Core_DAO { 'bao' => 'CRM_Activity_BAO_Activity', 'localizable' => 0, 'FKClassName' => 'CRM_Core_DAO_Phone', + 'deprecated' => TRUE, 'html' => [ 'type' => 'EntityRef', 'label' => ts("Phone (called)"), @@ -515,6 +516,7 @@ class CRM_Activity_DAO_Activity extends CRM_Core_DAO { 'entity' => 'Activity', 'bao' => 'CRM_Activity_BAO_Activity', 'localizable' => 0, + 'deprecated' => TRUE, 'html' => [ 'type' => 'Text', ], @@ -662,6 +664,7 @@ class CRM_Activity_DAO_Activity extends CRM_Core_DAO { 'bao' => 'CRM_Activity_BAO_Activity', 'localizable' => 0, 'FKClassName' => 'CRM_Contact_DAO_Relationship', + 'deprecated' => TRUE, 'html' => [ 'label' => ts("Relationship"), ], @@ -679,6 +682,7 @@ class CRM_Activity_DAO_Activity extends CRM_Core_DAO { 'entity' => 'Activity', 'bao' => 'CRM_Activity_BAO_Activity', 'localizable' => 0, + 'deprecated' => TRUE, 'add' => '2.2', ], 'original_id' => [ @@ -692,6 +696,7 @@ class CRM_Activity_DAO_Activity extends CRM_Core_DAO { 'bao' => 'CRM_Activity_BAO_Activity', 'localizable' => 0, 'FKClassName' => 'CRM_Activity_DAO_Activity', + 'deprecated' => TRUE, 'html' => [ 'label' => ts("Original Activity"), ], diff --git a/CRM/Contact/DAO/Contact.php b/CRM/Contact/DAO/Contact.php index 19890da492..ebdba06ed2 100644 --- a/CRM/Contact/DAO/Contact.php +++ b/CRM/Contact/DAO/Contact.php @@ -973,6 +973,7 @@ class CRM_Contact_DAO_Contact extends CRM_Core_DAO { 'entity' => 'Contact', 'bao' => 'CRM_Contact_BAO_Contact', 'localizable' => 0, + 'deprecated' => TRUE, 'html' => [ 'type' => 'Select', 'label' => ts("Preferred Mail Format"), @@ -1582,6 +1583,7 @@ class CRM_Contact_DAO_Contact extends CRM_Core_DAO { 'entity' => 'Contact', 'bao' => 'CRM_Contact_BAO_Contact', 'localizable' => 0, + 'deprecated' => TRUE, 'html' => [ 'type' => 'Text', ], diff --git a/CRM/Core/DAO/Address.php b/CRM/Core/DAO/Address.php index 2b57160b97..66269a9a8d 100644 --- a/CRM/Core/DAO/Address.php +++ b/CRM/Core/DAO/Address.php @@ -763,6 +763,7 @@ class CRM_Core_DAO_Address extends CRM_Core_DAO { 'entity' => 'Address', 'bao' => 'CRM_Core_BAO_Address', 'localizable' => 0, + 'deprecated' => TRUE, 'add' => '1.1', ], 'country_id' => [ diff --git a/CRM/Core/DAO/Phone.php b/CRM/Core/DAO/Phone.php index b49adb0bf3..743801083b 100644 --- a/CRM/Core/DAO/Phone.php +++ b/CRM/Core/DAO/Phone.php @@ -271,6 +271,7 @@ class CRM_Core_DAO_Phone extends CRM_Core_DAO { 'entity' => 'Phone', 'bao' => 'CRM_Core_BAO_Phone', 'localizable' => 0, + 'deprecated' => TRUE, 'add' => '1.1', ], 'phone' => [ diff --git a/Civi/Api4/Generic/BasicGetFieldsAction.php b/Civi/Api4/Generic/BasicGetFieldsAction.php index b89293e16d..d114fad93f 100644 --- a/Civi/Api4/Generic/BasicGetFieldsAction.php +++ b/Civi/Api4/Generic/BasicGetFieldsAction.php @@ -391,6 +391,11 @@ class BasicGetFieldsAction extends BasicGetAction { 'description' => 'True for auto-increment, calculated, or otherwise non-editable fields.', 'default_value' => FALSE, ], + [ + 'name' => 'deprecated', + 'data_type' => 'Boolean', + 'default_value' => FALSE, + ], [ 'name' => 'output_formatters', 'data_type' => 'Array', diff --git a/Civi/Api4/Service/Spec/FieldSpec.php b/Civi/Api4/Service/Spec/FieldSpec.php index 58b1c526da..ba79059058 100644 --- a/Civi/Api4/Service/Spec/FieldSpec.php +++ b/Civi/Api4/Service/Spec/FieldSpec.php @@ -80,6 +80,11 @@ class FieldSpec { */ public $readonly = FALSE; + /** + * @var bool + */ + public $deprecated = FALSE; + /** * @var callable[] */ @@ -245,4 +250,14 @@ class FieldSpec { return $this; } + /** + * @param bool $deprecated + * @return $this + */ + public function setDeprecated($deprecated) { + $this->deprecated = (bool) $deprecated; + + return $this; + } + } diff --git a/Civi/Api4/Service/Spec/SpecFormatter.php b/Civi/Api4/Service/Spec/SpecFormatter.php index 4f280e66c2..cfdfec5586 100644 --- a/Civi/Api4/Service/Spec/SpecFormatter.php +++ b/Civi/Api4/Service/Spec/SpecFormatter.php @@ -87,6 +87,7 @@ class SpecFormatter { $field->setSerialize($data['serialize'] ?? NULL); $field->setDefaultValue($data['default'] ?? NULL); $field->setDescription($data['description'] ?? NULL); + $field->setDeprecated($data['deprecated'] ?? FALSE); self::setInputTypeAndAttrs($field, $data, $dataTypeName); $field->setPermission($data['permission'] ?? NULL); diff --git a/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php b/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php index 30b367c90d..ed1ef31e78 100644 --- a/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php +++ b/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php @@ -89,7 +89,7 @@ class AfformAdminMeta { 'loadOptions' => ['id', 'label'], 'action' => 'create', 'select' => ['name', 'label', 'input_type', 'input_attrs', 'required', 'options', 'help_pre', 'help_post', 'serialize', 'data_type', 'entity', 'fk_entity', 'readonly'], - 'where' => [['input_type', 'IS NOT NULL']], + 'where' => [['deprecated', '=', FALSE], ['input_type', 'IS NOT NULL']], ]; if (in_array($entityName, \CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)) { $params['values']['contact_type'] = $entityName; diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php index 7afcb61912..c0f03105bc 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php @@ -29,7 +29,7 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction { ->addSelect('name', 'title_plural') ->setChain([ 'actions' => ['$name', 'getActions', ['where' => [['name', 'IN', ['update', 'delete']]]], 'name'], - 'fields' => ['$name', 'getFields', ['where' => [['type', '=', 'Field']]], 'name'], + 'fields' => ['$name', 'getFields', ['where' => [['deprecated', '=', FALSE], ['type', '=', 'Field']]], 'name'], ]) ->execute()->first(); diff --git a/ext/search_kit/Civi/Search/Admin.php b/ext/search_kit/Civi/Search/Admin.php index 1cd3d6917b..0f74b1f740 100644 --- a/ext/search_kit/Civi/Search/Admin.php +++ b/ext/search_kit/Civi/Search/Admin.php @@ -143,7 +143,7 @@ class Admin { } $getFields = civicrm_api4($entity['name'], 'getFields', [ 'select' => ['name', 'title', 'label', 'description', 'type', 'options', 'input_type', 'input_attrs', 'data_type', 'serialize', 'entity', 'fk_entity', 'readonly', 'operators', 'suffixes', 'nullable'], - 'where' => [['name', 'NOT IN', ['api_key', 'hash']]], + 'where' => [['deprecated', '=', FALSE], ['name', 'NOT IN', ['api_key', 'hash']]], 'orderBy' => ['label'], ]); foreach ($getFields as $field) { diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskUpdate.ctrl.js b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskUpdate.ctrl.js index 01f41d16fd..0d0005ab09 100644 --- a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskUpdate.ctrl.js +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskUpdate.ctrl.js @@ -15,7 +15,7 @@ action: 'update', select: ['name', 'label', 'description', 'input_type', 'data_type', 'serialize', 'options', 'fk_entity', 'nullable'], loadOptions: ['id', 'name', 'label', 'description', 'color', 'icon'], - where: [["readonly", "=", false]], + where: [['deprecated', '=', FALSE], ["readonly", "=", false]], }).then(function(fields) { ctrl.fields = fields; }); diff --git a/tests/phpunit/api/v4/Action/GetFieldsTest.php b/tests/phpunit/api/v4/Action/GetFieldsTest.php index 006cd6cfaa..3de060d975 100644 --- a/tests/phpunit/api/v4/Action/GetFieldsTest.php +++ b/tests/phpunit/api/v4/Action/GetFieldsTest.php @@ -101,7 +101,7 @@ class GetFieldsTest extends Api4TestBase implements TransactionalInterface { $this->assertEquals(['name', 'label'], $fields['campaign_id']['suffixes']); } - public function testRequiredAndNullable() { + public function testRequiredAndNullableAndDeprecated() { $actFields = Activity::getFields(FALSE) ->setAction('create') ->execute()->indexBy('name'); @@ -111,6 +111,8 @@ class GetFieldsTest extends Api4TestBase implements TransactionalInterface { $this->assertFalse($actFields['activity_type_id']['nullable']); $this->assertFalse($actFields['subject']['required']); $this->assertTrue($actFields['subject']['nullable']); + $this->assertFalse($actFields['subject']['deprecated']); + $this->assertTrue($actFields['phone_id']['deprecated']); } public function testGetSuffixes() { diff --git a/xml/templates/dao.tpl b/xml/templates/dao.tpl index 7504906dbd..904aefbb8f 100644 --- a/xml/templates/dao.tpl +++ b/xml/templates/dao.tpl @@ -226,6 +226,9 @@ class {$table.className} extends CRM_Core_DAO {ldelim} {if $field.uniqueTitle} 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'), {/if} +{if $field.deprecated} + 'deprecated' => TRUE, +{/if} {if $field.html} 'html' => array( {foreach from=$field.html item=val key=key} -- 2.25.1