Skip to content

Commit

Permalink
dev/financial#184 Fix currency name for Ghana and Belarus
Browse files Browse the repository at this point in the history
  • Loading branch information
mlutfy committed Oct 11, 2021
1 parent ec432bc commit f237726
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
51 changes: 51 additions & 0 deletions CRM/Upgrade/Incremental/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,57 @@ public static function updateGreetingOptions($ctx, string $old, string $new, $ve
return TRUE;
}

/**
* Updated a currency in civicrm_currency and related configurations
*
* @param CRM_Queue_TaskContext $ctx
* @param string $old_name
* @param string $new_name
*
* @return bool
*/
public static function updateCurrencyName($ctx, string $old_name, string $new_name): bool {
CRM_Core_DAO::executeQuery('UPDATE civicrm_currency SET name = %1 WHERE name = %2', [
1 => [$new_name, 'String'],
2 => [$old_name, 'String'],
]);

$oid = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_option_group WHERE name = 'currencies_enabled'");
if ($oid) {
CRM_Core_DAO::executeQuery('UPDATE civicrm_option_value SET value = %1 WHERE value = %2 AND option_group_id = %3', [
1 => [$new_name, 'String'],
2 => [$old_name, 'String'],
3 => [$oid, 'String'],
]);
}

$tables = [
'civicrm_contribution',
'civicrm_contribution_page',
'civicrm_contribution_recur',
'civicrm_contribution_soft',
'civicrm_event',
'civicrm_financial_item',
'civicrm_financial_trxn',
'civicrm_grant',
'civicrm_participant',
'civicrm_pcp',
'civicrm_pledge_payment',
'civicrm_pledge',
'civicrm_product',
];

foreach ($tables as $table) {
CRM_Core_DAO::executeQuery('UPDATE %3 SET currency = %1 WHERE currency = %2', [
1 => [$new_name, 'String'],
2 => [$old_name, 'String'],
3 => [$table, 'MysqlColumnNameOrAlias'],
]);
}

return TRUE;
}

/**
* Re-save any valid values from contribute settings into the normal setting
* format.
Expand Down
2 changes: 2 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveFortyThree.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public function upgrade_5_43_alpha1(string $rev): void {
);

$this->addTask('Set note_date field to NOT NULL', 'setNoteDateFieldNotNull');
$this->addTask('Update currency symbols for Ghana', 'updateCurrencyName', 'GHC', 'GHS');
$this->addTask('Update currency symbols for Belarus', 'updateCurrencyName', 'BYR', 'BYN');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sql/civicrm_generated.mysql
Original file line number Diff line number Diff line change
Expand Up @@ -2577,7 +2577,7 @@ INSERT INTO `civicrm_currency` (`id`, `name`, `symbol`, `numeric_code`, `full_na
(37,'BSD','$','044','Bahamian Dollar'),
(38,'BTN',NULL,'064','Bhutan Ngultrum'),
(39,'BWP','P','072','Botswana Pula'),
(40,'BYR','p.','974','Belarussian Rouble'),
(40,'BYN','p.','974','Belarussian Rouble'),
(41,'BZD','BZ$','084','Belize Dollar'),
(42,'CDF',NULL,'976','Franc Congolais'),
(43,'CHE',NULL,'947','WIR Euro'),
Expand All @@ -2604,7 +2604,7 @@ INSERT INTO `civicrm_currency` (`id`, `name`, `symbol`, `numeric_code`, `full_na
(65,'FJD','$','242','Fiji Dollar'),
(66,'FKP','£','238','Falkland Islands Pound'),
(67,'GEL',NULL,'981','Georgian Lari'),
(68,'GHC','¢','288','Ghanaian Cedi'),
(68,'GHS','¢','288','Ghanaian Cedi'),
(69,'GIP','£','292','Gibraltar Pound'),
(70,'GMD',NULL,'270','Gambian Dalasi'),
(71,'GNF',NULL,'324','Guinea Franc'),
Expand Down
4 changes: 2 additions & 2 deletions xml/templates/civicrm_currency.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ INSERT INTO civicrm_currency (id, name, symbol, numeric_code, full_name) VALUES
( 37, "BSD", "$", "044", "Bahamian Dollar"),
( 38, "BTN", NULL, "064", "Bhutan Ngultrum"),
( 39, "BWP", "P", "072", "Botswana Pula"),
( 40, "BYR", "p.", "974", "Belarussian Rouble"),
( 40, "BYN", "p.", "974", "Belarussian Rouble"),
( 41, "BZD","BZ$", "084", "Belize Dollar"),
( 42, "CDF", NULL, "976", "Franc Congolais"),
( 43, "CHE", NULL, "947", "WIR Euro"),
Expand All @@ -77,7 +77,7 @@ INSERT INTO civicrm_currency (id, name, symbol, numeric_code, full_name) VALUES
( 65, "FJD", "$", "242", "Fiji Dollar"),
( 66, "FKP", "£", "238", "Falkland Islands Pound"),
( 67, "GEL", NULL, "981", "Georgian Lari"),
( 68, "GHC", "¢", "288", "Ghanaian Cedi"),
( 68, "GHS", "¢", "288", "Ghanaian Cedi"),
( 69, "GIP", "£", "292", "Gibraltar Pound"),
( 70, "GMD", NULL, "270", "Gambian Dalasi"),
( 71, "GNF", NULL, "324", "Guinea Franc"),
Expand Down

0 comments on commit f237726

Please sign in to comment.