Skip to content

Commit

Permalink
CiviGrant - Migrate option values to managed entities
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Nov 16, 2021
1 parent 2f3e03e commit 0fd1ed2
Show file tree
Hide file tree
Showing 8 changed files with 648 additions and 24 deletions.
146 changes: 146 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveFortyFive.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,152 @@ public static function migrateCiviGrant(CRM_Queue_TaskContext $ctx): bool {
$ext->file = 'civigrant';
$ext->is_active = (int) $civiGrantEnabled;
$ext->save();

$managedItems = [
'OptionGroup_advanced_search_options_OptionValue_CiviGrant' => [
'entity' => 'OptionValue',
'values' => [
'option_group_id:name' => 'advanced_search_options',
'name' => 'CiviGrant',
],
],
'OptionGroup_contact_view_options_OptionValue_CiviGrant' => [
'entity' => 'OptionValue',
'values' => [
'option_group_id:name' => 'contact_view_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_grant_type_OptionValue_Emergency' => [
'entity' => 'OptionValue',
'values' => [
'option_group_id:name' => 'grant_type',
'name' => 'Emergency',
],
],
'OptionGroup_grant_type_OptionValue_Family Support' => [
'entity' => 'OptionValue',
'values' => [
'option_group_id:name' => 'grant_type',
'name' => 'Family Support',
],
],
'OptionGroup_grant_type_OptionValue_General Protection' => [
'entity' => 'OptionValue',
'values' => [
'option_group_id:name' => 'grant_type',
'name' => 'General Protection',
],
],
'OptionGroup_grant_type_OptionValue_Impunity' => [
'entity' => 'OptionValue',
'values' => [
'option_group_id:name' => 'grant_type',
'name' => 'Impunity',
],
],
'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',
],
],
];
// Create an entry in civicrm_managed for each existing record that will be managed by the extension
foreach ($managedItems as $name => $item) {
$where = [];
foreach ($item['values'] as $k => $v) {
$where[] = [$k, '=', $v];
}
$record = civicrm_api4($item['entity'], 'get', ['where' => $where])->first();
if ($record) {
$mgd = new CRM_Core_DAO_Managed();
$mgd->name = $name;
$mgd->module = 'civigrant';
$mgd->entity_type = $item['entity'];
if (!$mgd->find(TRUE)) {
$mgd->entity_id = $record['id'];
$mgd->cleanup = 'unused';
$mgd->save();
}
}
}
}

return TRUE;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
return [
[
'name' => 'OptionGroup_advanced_search_options_OptionValue_CiviGrant',
'entity' => 'OptionValue',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'option_group_id:name' => 'advanced_search_options',
'label' => 'Grants',
'value' => '12',
'name' => 'CiviGrant',
'grouping' => NULL,
'filter' => 0,
'is_default' => NULL,
'weight' => 14,
'description' => NULL,
'is_optgroup' => FALSE,
'is_reserved' => FALSE,
'is_active' => TRUE,
'icon' => NULL,
'color' => NULL,
'component_id' => NULL,
'domain_id' => NULL,
'visibility_id' => NULL,
],
],
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
return [
[
'name' => 'OptionGroup_contact_view_options_OptionValue_CiviGrant',
'entity' => 'OptionValue',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'option_group_id:name' => 'contact_view_options',
'label' => 'Grants',
'value' => '11',
'name' => 'CiviGrant',
'grouping' => NULL,
'filter' => 0,
'is_default' => NULL,
'weight' => 11,
'description' => NULL,
'is_optgroup' => FALSE,
'is_reserved' => FALSE,
'is_active' => TRUE,
'icon' => NULL,
'color' => NULL,
'component_id' => NULL,
'domain_id' => NULL,
'visibility_id' => NULL,
],
],
],
];
Loading

0 comments on commit 0fd1ed2

Please sign in to comment.