CiviGrant - Cleanup managed entities - fixes dev/core#3161
authorColeman Watts <coleman@civicrm.org>
Fri, 8 Apr 2022 13:47:51 +0000 (09:47 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 8 Apr 2022 13:49:59 +0000 (09:49 -0400)
- 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.

CRM/Upgrade/Incremental/php/FiveFortySeven.php
ext/civigrant/CRM/Grant/Upgrader.php
ext/civigrant/managed/Navigation_Grants.mgd.php
ext/civigrant/managed/OptionGroup_advanced_search_options_OptionValue_CiviGrant.mgd.php
ext/civigrant/managed/OptionGroup_grant_status.mgd.php
ext/civigrant/managed/OptionGroup_grant_type.mgd.php
ext/civigrant/managed/OptionGroup_mapping_type_OptionValue_Export.mgd.php
ext/civigrant/managed/OptionGroup_report_template_OptionValue_CRM_Report_Form_Grants.mgd.php
ext/civigrant/managed/SavedSearch_CiviGrant_Summary.mgd.php

index 758527ece2afd64701fa8e58b1dc7b516c6ac842..7fcf0bfcc81aeb21a0b9630d415196a5ede39d82 100644 (file)
@@ -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' => [
index 1798462a98414c2744b85fbc044f29c9a9f6b19c..e6e188e32ad8a3307f0864e611142ea31c4c3ca2 100644 (file)
@@ -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();
+  }
+
 }
index 6191e7c3a8b73702251a529abda706f6e4f2553e..d69029d4e5b0dcb5dc076c2c16971c177c061491 100644 (file)
@@ -1,14 +1,16 @@
 <?php
+use CRM_Grant_ExtensionUtil as E;
+
 return [
   [
     'name' => '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,
index 757d2d93424d45e0ea528fa549a6b4444daf5498..647b30f798713f4670e6065af88e74a943512b9a 100644 (file)
@@ -1,15 +1,17 @@
 <?php
+use CRM_Grant_ExtensionUtil as E;
+
 return [
   [
     'name' => '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'],
     ],
   ],
 ];
index 2ebab03245301cfc92216a891d0567a7d6f30a77..c040a7187c52d21f80ee70db234d38811b32a320 100644 (file)
 <?php
+use CRM_Grant_ExtensionUtil as E;
+
 return [
   [
     'name' => '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'],
     ],
   ],
 ];
index 4f1ccf826bea4044f872f147a743c5d07ab01278..ade40dbd79ec02585ce543d764757e1153509f60 100644 (file)
@@ -1,9 +1,11 @@
 <?php
+use CRM_Grant_ExtensionUtil as E;
+
 return [
   [
     'name' => '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'],
     ],
   ],
 ];
index 33532b150c2500d8f96f6372a58c9c8d198a54aa..b1e605cb9e6ecfd2c63d2a1f73e011395eaaa286 100644 (file)
@@ -1,15 +1,17 @@
 <?php
+use CRM_Grant_ExtensionUtil as E;
+
 return [
   [
     'name' => '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'],
     ],
   ],
 ];
index ed7a5367e4e6cf5a08df688216453e2f8cfa0345..8a6141da441bc9169a5eb5ecad40679045a248f7 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+use CRM_Grant_ExtensionUtil as E;
+
 return [
   [
     'name' => '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'],
     ],
   ],
 ];
index c4ba425b3b12d35029f5040c1f30afaa50df9a3b..e182af1bba30434dbfa7b7e6f784f97451992773 100644 (file)
@@ -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,