From e8ff2ef3704e940c59a3231c6e309077797aa4f9 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 8 Apr 2022 09:47:51 -0400 Subject: [PATCH] CiviGrant - Cleanup managed entities - fixes dev/core#3161 - Ensure labels are translated - Set stricter cleanup policy for entities that should be removed on uninstall - Make grant_status options unmanaged. They will not be updated by the system ever, but they will be deleted on uninstall because the option group is a managed entity. --- .../Incremental/php/FiveFortySeven.php | 89 -------- ext/civigrant/CRM/Grant/Upgrader.php | 29 +++ .../managed/Navigation_Grants.mgd.php | 30 +-- ...arch_options_OptionValue_CiviGrant.mgd.php | 9 +- .../managed/OptionGroup_grant_status.mgd.php | 203 +----------------- .../managed/OptionGroup_grant_type.mgd.php | 5 +- ...up_mapping_type_OptionValue_Export.mgd.php | 7 +- ...OptionValue_CRM_Report_Form_Grants.mgd.php | 8 +- .../SavedSearch_CiviGrant_Summary.mgd.php | 4 +- 9 files changed, 73 insertions(+), 311 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FiveFortySeven.php b/CRM/Upgrade/Incremental/php/FiveFortySeven.php index 758527ece2..7fcf0bfcc8 100644 --- a/CRM/Upgrade/Incremental/php/FiveFortySeven.php +++ b/CRM/Upgrade/Incremental/php/FiveFortySeven.php @@ -130,95 +130,6 @@ class CRM_Upgrade_Incremental_php_FiveFortySeven extends CRM_Upgrade_Incremental CRM_Extension_System::singleton()->getManager()->refresh(); $managedItems = [ - 'OptionGroup_advanced_search_options_OptionValue_CiviGrant' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'advanced_search_options', - 'name' => 'CiviGrant', - ], - ], - 'OptionGroup_mapping_type_OptionValue_Export Grant' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'mapping_type', - 'name' => 'Export Grant', - ], - ], - 'OptionGroup_grant_status' => [ - 'entity' => 'OptionGroup', - 'values' => [ - 'name' => 'grant_status', - ], - ], - 'OptionGroup_grant_status_OptionValue_Submitted' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'grant_status', - 'name' => 'Submitted', - ], - ], - 'OptionGroup_grant_status_OptionValue_Eligible' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'grant_status', - 'name' => 'Eligible', - ], - ], - 'OptionGroup_grant_status_OptionValue_Ineligible' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'grant_status', - 'name' => 'Ineligible', - ], - ], - 'OptionGroup_grant_status_OptionValue_Paid' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'grant_status', - 'name' => 'Paid', - ], - ], - 'OptionGroup_grant_status_OptionValue_Awaiting Information' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'grant_status', - 'name' => 'Awaiting Information', - ], - ], - 'OptionGroup_grant_status_OptionValue_Withdrawn' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'grant_status', - 'name' => 'Withdrawn', - ], - ], - 'OptionGroup_grant_status_OptionValue_Approved for Payment' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'grant_status', - 'name' => 'Approved for Payment', - ], - ], - 'OptionGroup_grant_type' => [ - 'entity' => 'OptionGroup', - 'values' => [ - 'name' => 'grant_type', - ], - ], - 'OptionGroup_report_template_OptionValue_CRM_Report_Form_Grant_Detail' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'report_template', - 'name' => 'CRM_Report_Form_Grant_Detail', - ], - ], - 'OptionGroup_report_template_OptionValue_CRM_Report_Form_Grant_Statistics' => [ - 'entity' => 'OptionValue', - 'values' => [ - 'option_group_id:name' => 'report_template', - 'name' => 'CRM_Report_Form_Grant_Statistics', - ], - ], 'Navigation_Grants' => [ 'entity' => 'Navigation', 'values' => [ diff --git a/ext/civigrant/CRM/Grant/Upgrader.php b/ext/civigrant/CRM/Grant/Upgrader.php index 1798462a98..e6e188e32a 100644 --- a/ext/civigrant/CRM/Grant/Upgrader.php +++ b/ext/civigrant/CRM/Grant/Upgrader.php @@ -6,4 +6,33 @@ use CRM_Grant_ExtensionUtil as E; */ class CRM_Grant_Upgrader extends CRM_Extension_Upgrader_Base { + public function install() { + // Ensure option group exists (in case OptionGroup_grant_status.mgd.php hasn't loaded yet) + \Civi\Api4\OptionGroup::save(FALSE) + ->addRecord([ + 'name' => 'grant_status', + 'title' => E::ts('Grant status'), + ]) + ->setMatch(['name']) + ->execute(); + + // Create unmanaged option values. They will not be updated by the system ever, + // but they will be deleted on uninstall because the option group is a managed entity. + \Civi\Api4\OptionValue::save(FALSE) + ->setDefaults([ + 'option_group_id.name' => 'grant_status', + ]) + ->setRecords([ + ['value' => 1, 'name' => 'Submitted', 'label' => E::ts('Submitted'), 'is_default' => TRUE], + ['value' => 2, 'name' => 'Eligible', 'label' => E::ts('Eligible')], + ['value' => 3, 'name' => 'Ineligible', 'label' => E::ts('Ineligible')], + ['value' => 4, 'name' => 'Paid', 'label' => E::ts('Paid')], + ['value' => 5, 'name' => 'Awaiting Information', 'label' => E::ts('Awaiting Information')], + ['value' => 6, 'name' => 'Withdrawn', 'label' => E::ts('Withdrawn')], + ['value' => 7, 'name' => 'Approved for Payment', 'label' => E::ts('Approved for Payment')], + ]) + ->setMatch(['option_group_id', 'name']) + ->execute(); + } + } diff --git a/ext/civigrant/managed/Navigation_Grants.mgd.php b/ext/civigrant/managed/Navigation_Grants.mgd.php index 6191e7c3a8..d69029d4e5 100644 --- a/ext/civigrant/managed/Navigation_Grants.mgd.php +++ b/ext/civigrant/managed/Navigation_Grants.mgd.php @@ -1,14 +1,16 @@ 'Navigation_Grants', 'entity' => 'Navigation', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, 'values' => [ - 'label' => 'Grants', + 'label' => E::ts('Grants'), 'name' => 'Grants', 'url' => NULL, 'icon' => 'crm-i fa-money', @@ -25,12 +27,12 @@ return [ [ 'name' => 'Navigation_Grants_Navigation_Dashboard', 'entity' => 'Navigation', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, 'values' => [ - 'label' => 'Dashboard', + 'label' => E::ts('Dashboard'), 'name' => 'Dashboard', 'url' => 'civicrm/grant?reset=1', 'icon' => NULL, @@ -46,12 +48,12 @@ return [ [ 'name' => 'Navigation_Grants_Navigation_New_Grant', 'entity' => 'Navigation', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, 'values' => [ - 'label' => 'New Grant', + 'label' => E::ts('New Grant'), 'name' => 'New Grant', 'url' => 'civicrm/grant/add?reset=1&action=add&context=standalone', 'icon' => NULL, @@ -67,12 +69,12 @@ return [ [ 'name' => 'Navigation_Grants_Navigation_Find_Grants', 'entity' => 'Navigation', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, 'values' => [ - 'label' => 'Find Grants', + 'label' => E::ts('Find Grants'), 'name' => 'Find Grants', 'url' => 'civicrm/grant/search?reset=1', 'icon' => NULL, @@ -88,12 +90,12 @@ return [ [ 'name' => 'Navigation_CiviGrant', 'entity' => 'Navigation', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, 'values' => [ - 'label' => 'CiviGrant', + 'label' => E::ts('CiviGrant'), 'name' => 'CiviGrant', 'url' => NULL, 'icon' => NULL, @@ -110,12 +112,12 @@ return [ [ 'name' => 'Navigation_CiviGrant_Navigation_Grant_Types', 'entity' => 'Navigation', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, 'values' => [ - 'label' => 'Grant Types', + 'label' => E::ts('Grant Types'), 'name' => 'Grant Types', 'url' => 'civicrm/admin/options/grant_type?reset=1', 'icon' => NULL, @@ -132,12 +134,12 @@ return [ [ 'name' => 'Navigation_CiviGrant_Navigation_Grant_Status', 'entity' => 'Navigation', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, 'values' => [ - 'label' => 'Grant Status', + 'label' => E::ts('Grant Status'), 'name' => 'Grant Status', 'url' => 'civicrm/admin/options/grant_status?reset=1', 'icon' => NULL, diff --git a/ext/civigrant/managed/OptionGroup_advanced_search_options_OptionValue_CiviGrant.mgd.php b/ext/civigrant/managed/OptionGroup_advanced_search_options_OptionValue_CiviGrant.mgd.php index 757d2d9342..647b30f798 100644 --- a/ext/civigrant/managed/OptionGroup_advanced_search_options_OptionValue_CiviGrant.mgd.php +++ b/ext/civigrant/managed/OptionGroup_advanced_search_options_OptionValue_CiviGrant.mgd.php @@ -1,15 +1,17 @@ 'OptionGroup_advanced_search_options_OptionValue_CiviGrant', 'entity' => 'OptionValue', - 'cleanup' => 'unused', - 'update' => 'unmodified', + 'cleanup' => 'always', + 'update' => 'always', 'params' => [ 'version' => 4, 'values' => [ 'option_group_id.name' => 'advanced_search_options', - 'label' => 'Grants', + 'label' => E::ts('Grants'), 'value' => '12', 'name' => 'CiviGrant', 'grouping' => NULL, @@ -26,6 +28,7 @@ return [ 'domain_id' => NULL, 'visibility_id' => NULL, ], + 'match' => ['option_group_id', 'name'], ], ], ]; diff --git a/ext/civigrant/managed/OptionGroup_grant_status.mgd.php b/ext/civigrant/managed/OptionGroup_grant_status.mgd.php index 2ebab03245..c040a7187c 100644 --- a/ext/civigrant/managed/OptionGroup_grant_status.mgd.php +++ b/ext/civigrant/managed/OptionGroup_grant_status.mgd.php @@ -1,217 +1,24 @@ 'OptionGroup_grant_status', 'entity' => 'OptionGroup', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, 'values' => [ 'name' => 'grant_status', - 'title' => 'Grant status', + 'title' => E::ts('Grant status'), 'description' => NULL, 'data_type' => NULL, 'is_reserved' => TRUE, 'is_active' => TRUE, 'is_locked' => FALSE, ], - ], - ], - [ - 'name' => 'OptionGroup_grant_status_OptionValue_Submitted', - 'entity' => 'OptionValue', - 'cleanup' => 'unused', - 'update' => 'unmodified', - 'params' => [ - 'version' => 4, - 'values' => [ - 'option_group_id.name' => 'grant_status', - 'label' => 'Submitted', - 'value' => '1', - 'name' => 'Submitted', - 'grouping' => NULL, - 'filter' => 0, - 'is_default' => TRUE, - 'weight' => 1, - 'description' => NULL, - 'is_optgroup' => FALSE, - 'is_reserved' => FALSE, - 'is_active' => TRUE, - 'icon' => NULL, - 'color' => NULL, - 'component_id' => NULL, - 'domain_id' => NULL, - 'visibility_id' => NULL, - ], - ], - ], - [ - 'name' => 'OptionGroup_grant_status_OptionValue_Eligible', - 'entity' => 'OptionValue', - 'cleanup' => 'unused', - 'update' => 'unmodified', - 'params' => [ - 'version' => 4, - 'values' => [ - 'option_group_id.name' => 'grant_status', - 'label' => 'Eligible', - 'value' => '2', - 'name' => 'Eligible', - 'grouping' => NULL, - 'filter' => 0, - 'is_default' => FALSE, - 'weight' => 2, - 'description' => NULL, - 'is_optgroup' => FALSE, - 'is_reserved' => FALSE, - 'is_active' => TRUE, - 'icon' => NULL, - 'color' => NULL, - 'component_id' => NULL, - 'domain_id' => NULL, - 'visibility_id' => NULL, - ], - ], - ], - [ - 'name' => 'OptionGroup_grant_status_OptionValue_Ineligible', - 'entity' => 'OptionValue', - 'cleanup' => 'unused', - 'update' => 'unmodified', - 'params' => [ - 'version' => 4, - 'values' => [ - 'option_group_id.name' => 'grant_status', - 'label' => 'Ineligible', - 'value' => '3', - 'name' => 'Ineligible', - 'grouping' => NULL, - 'filter' => 0, - 'is_default' => FALSE, - 'weight' => 3, - 'description' => NULL, - 'is_optgroup' => FALSE, - 'is_reserved' => FALSE, - 'is_active' => TRUE, - 'icon' => NULL, - 'color' => NULL, - 'component_id' => NULL, - 'domain_id' => NULL, - 'visibility_id' => NULL, - ], - ], - ], - [ - 'name' => 'OptionGroup_grant_status_OptionValue_Paid', - 'entity' => 'OptionValue', - 'cleanup' => 'unused', - 'update' => 'unmodified', - 'params' => [ - 'version' => 4, - 'values' => [ - 'option_group_id.name' => 'grant_status', - 'label' => 'Paid', - 'value' => '4', - 'name' => 'Paid', - 'grouping' => NULL, - 'filter' => 0, - 'is_default' => FALSE, - 'weight' => 4, - 'description' => NULL, - 'is_optgroup' => FALSE, - 'is_reserved' => FALSE, - 'is_active' => TRUE, - 'icon' => NULL, - 'color' => NULL, - 'component_id' => NULL, - 'domain_id' => NULL, - 'visibility_id' => NULL, - ], - ], - ], - [ - 'name' => 'OptionGroup_grant_status_OptionValue_Awaiting Information', - 'entity' => 'OptionValue', - 'cleanup' => 'unused', - 'update' => 'unmodified', - 'params' => [ - 'version' => 4, - 'values' => [ - 'option_group_id.name' => 'grant_status', - 'label' => 'Awaiting Information', - 'value' => '5', - 'name' => 'Awaiting Information', - 'grouping' => NULL, - 'filter' => 0, - 'is_default' => FALSE, - 'weight' => 5, - 'description' => NULL, - 'is_optgroup' => FALSE, - 'is_reserved' => FALSE, - 'is_active' => TRUE, - 'icon' => NULL, - 'color' => NULL, - 'component_id' => NULL, - 'domain_id' => NULL, - 'visibility_id' => NULL, - ], - ], - ], - [ - 'name' => 'OptionGroup_grant_status_OptionValue_Withdrawn', - 'entity' => 'OptionValue', - 'cleanup' => 'unused', - 'update' => 'unmodified', - 'params' => [ - 'version' => 4, - 'values' => [ - 'option_group_id.name' => 'grant_status', - 'label' => 'Withdrawn', - 'value' => '6', - 'name' => 'Withdrawn', - 'grouping' => NULL, - 'filter' => 0, - 'is_default' => FALSE, - 'weight' => 6, - 'description' => NULL, - 'is_optgroup' => FALSE, - 'is_reserved' => FALSE, - 'is_active' => TRUE, - 'icon' => NULL, - 'color' => NULL, - 'component_id' => NULL, - 'domain_id' => NULL, - 'visibility_id' => NULL, - ], - ], - ], - [ - 'name' => 'OptionGroup_grant_status_OptionValue_Approved for Payment', - 'entity' => 'OptionValue', - 'cleanup' => 'unused', - 'update' => 'unmodified', - 'params' => [ - 'version' => 4, - 'values' => [ - 'option_group_id.name' => 'grant_status', - 'label' => 'Approved for Payment', - 'value' => '7', - 'name' => 'Approved for Payment', - 'grouping' => NULL, - 'filter' => 0, - 'is_default' => FALSE, - 'weight' => 7, - 'description' => NULL, - 'is_optgroup' => FALSE, - 'is_reserved' => FALSE, - 'is_active' => TRUE, - 'icon' => NULL, - 'color' => NULL, - 'component_id' => NULL, - 'domain_id' => NULL, - 'visibility_id' => NULL, - ], + 'match' => ['name'], ], ], ]; diff --git a/ext/civigrant/managed/OptionGroup_grant_type.mgd.php b/ext/civigrant/managed/OptionGroup_grant_type.mgd.php index 4f1ccf826b..ade40dbd79 100644 --- a/ext/civigrant/managed/OptionGroup_grant_type.mgd.php +++ b/ext/civigrant/managed/OptionGroup_grant_type.mgd.php @@ -1,9 +1,11 @@ 'OptionGroup_grant_type', 'entity' => 'OptionGroup', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, @@ -16,6 +18,7 @@ return [ 'is_active' => TRUE, 'is_locked' => FALSE, ], + 'match' => ['name'], ], ], ]; diff --git a/ext/civigrant/managed/OptionGroup_mapping_type_OptionValue_Export.mgd.php b/ext/civigrant/managed/OptionGroup_mapping_type_OptionValue_Export.mgd.php index 33532b150c..b1e605cb9e 100644 --- a/ext/civigrant/managed/OptionGroup_mapping_type_OptionValue_Export.mgd.php +++ b/ext/civigrant/managed/OptionGroup_mapping_type_OptionValue_Export.mgd.php @@ -1,15 +1,17 @@ 'OptionGroup_mapping_type_OptionValue_Export Grant', 'entity' => 'OptionValue', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, 'values' => [ 'option_group_id.name' => 'mapping_type', - 'label' => 'Export Grant', + 'label' => E::ts('Export Grant'), 'value' => '13', 'name' => 'Export Grant', 'grouping' => NULL, @@ -26,6 +28,7 @@ return [ 'domain_id' => NULL, 'visibility_id' => NULL, ], + 'match' => ['option_group_id', 'name'], ], ], ]; diff --git a/ext/civigrant/managed/OptionGroup_report_template_OptionValue_CRM_Report_Form_Grants.mgd.php b/ext/civigrant/managed/OptionGroup_report_template_OptionValue_CRM_Report_Form_Grants.mgd.php index ed7a5367e4..8a6141da44 100644 --- a/ext/civigrant/managed/OptionGroup_report_template_OptionValue_CRM_Report_Form_Grants.mgd.php +++ b/ext/civigrant/managed/OptionGroup_report_template_OptionValue_CRM_Report_Form_Grants.mgd.php @@ -1,4 +1,6 @@ 'OptionGroup_report_template_OptionValue_CRM_Report_Form_Grant_Detail', @@ -9,7 +11,7 @@ return [ 'version' => 4, 'values' => [ 'option_group_id.name' => 'report_template', - 'label' => 'Grant Report (Detail)', + 'label' => E::ts('Grant Report (Detail)'), 'value' => 'grant/detail', 'name' => 'CRM_Report_Form_Grant_Detail', 'grouping' => NULL, @@ -26,6 +28,7 @@ return [ 'domain_id' => NULL, 'visibility_id' => NULL, ], + 'match' => ['name'], ], ], [ @@ -37,7 +40,7 @@ return [ 'version' => 4, 'values' => [ 'option_group_id.name' => 'report_template', - 'label' => 'Grant Report (Statistics)', + 'label' => E::ts('Grant Report (Statistics)'), 'value' => 'grant/statistics', 'name' => 'CRM_Report_Form_Grant_Statistics', 'grouping' => NULL, @@ -54,6 +57,7 @@ return [ 'domain_id' => NULL, 'visibility_id' => NULL, ], + 'match' => ['option_group_id', 'name'], ], ], ]; diff --git a/ext/civigrant/managed/SavedSearch_CiviGrant_Summary.mgd.php b/ext/civigrant/managed/SavedSearch_CiviGrant_Summary.mgd.php index c4ba425b3b..e182af1bba 100644 --- a/ext/civigrant/managed/SavedSearch_CiviGrant_Summary.mgd.php +++ b/ext/civigrant/managed/SavedSearch_CiviGrant_Summary.mgd.php @@ -5,7 +5,7 @@ return [ [ 'name' => 'SavedSearch_CiviGrant_Summary', 'entity' => 'SavedSearch', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, @@ -41,7 +41,7 @@ return [ [ 'name' => 'SavedSearch_CiviGrant_Summary_SearchDisplay_Grant_Tab', 'entity' => 'SearchDisplay', - 'cleanup' => 'unused', + 'cleanup' => 'always', 'update' => 'unmodified', 'params' => [ 'version' => 4, -- 2.25.1