Eileen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/249566
Change subject: Merge branch 'master' into civi-4.6.9
......................................................................
Merge branch 'master' into civi-4.6.9
Change-Id: Ib54beab1d4a1f3b9f43fd034dfb60f3be1253b9f
---
M civicrm
M sites/all/modules/wmf_civicrm/bootstrap.inc
M sites/all/modules/wmf_civicrm/wmf_civicrm.install
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
4 files changed, 108 insertions(+), 86 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/66/249566/1
diff --git a/civicrm b/civicrm
index 0e31ff7..7ce9941 160000
--- a/civicrm
+++ b/civicrm
-Subproject commit 0e31ff753a9e05a63d92c08ea97db9f201ea795e
+Subproject commit 7ce9941c0ffda84f1415b8ff5a855bc37c21b27a
diff --git a/sites/all/modules/wmf_civicrm/bootstrap.inc
b/sites/all/modules/wmf_civicrm/bootstrap.inc
index c7edcb9..4bba64b 100644
--- a/sites/all/modules/wmf_civicrm/bootstrap.inc
+++ b/sites/all/modules/wmf_civicrm/bootstrap.inc
@@ -29,87 +29,131 @@
return $api;
}
-function wmf_civicrm_create_contribution_types($contribution_types)
+/**
+ * Ensure that a financial type exists for every item in the array.
+ *
+ * @param array $financial_types
+ *
+ * @return array
+ * Financial types in th DB.
+ *
+ * @throws \CiviCRM_API3_Exception
+ */
+function wmf_civicrm_create_financial_types($financial_types)
{
- foreach ($contribution_types as $type)
+ $existingFinancialTypes = civicrm_api3('Contribution', 'getoptions', array(
+ 'field' => 'financial_type_id',
+ ));
+ $missingTypes = array_diff($financial_types,
$existingFinancialTypes['values']);
+ foreach ($missingTypes as $type)
{
- $contribution_type_id = CRM_Utils_Array::key(
- $type,
- CRM_Contribute_PseudoConstant::contributionType()
- );
+ $result = civicrm_api3('FinancialType', 'create', array(
+ 'is_active' => 1,
+ 'is_deductible' => 1,
+ 'accounting_code' => strtoupper($type),
+ 'name' => $type,
+ ));
+ $existingFinancialTypes[$result['id']] = $type;
+ }
+ return $existingFinancialTypes;
+}
- if (!$contribution_type_id)
- {
- $params = array(
- 'is_active' => 1,
- 'is_deductible' => 1,
- 'accounting_code' => strtoupper($type),
- 'name' => $type,
- );
- $ids = array();
- CRM_Contribute_BAO_ContributionType::add($params, $ids);
- }
+/**
+ * Create option values in CiviCRM.
+ *
+ * For more control use the option_values_detailed function below.
+ *
+ * NB - encapsulated the detailed create function has a slight performance
+ * cost since group is resolved potentially multiple times - but this
+ * function seems like a rarely run function.
+ *
+ * @param string $group_name
+ * @param array $values
+ */
+function wmf_civicrm_create_option_values( $group_name, $values )
+{
+ foreach ($values as $value) {
+ wmf_civicrm_create_option_values_detailed($group_name, array(
+ $value => array(
+ 'name' => $value,
+ )));
}
}
-function wmf_civicrm_create_option_values( $group_name, $values )
+/**
+ * Create option values in CiviCRM with details.
+ *
+ * The previous other of this only permits a flat array. This allows a more
+ * nuanced option value create.
+ *
+ * This checks for an existing option value first.
+ *
+ * @param string $group_name
+ * @param array $values
+ */
+function wmf_civicrm_create_option_values_detailed($group_name, $values)
{
$api = wmf_civicrm_bootstrap_civi();
$api->OptionGroup->Get(array(
- 'name' => $group_name,
+ 'name' => $group_name,
));
$result = $api->values();
$option_group = array_pop($result);
- foreach ($values as $value)
+ foreach ($values as $key => $value)
{
+ $params = array_merge(array(
+ 'option_group_id' => $option_group->id,
+ 'name' => $key,
+ 'label' => $key,
+ 'is_active' => 1,
+ ), $value);
+
$api->OptionValue->Get(array(
- 'option_group_id' => $option_group->id,
- 'name' => $value,
+ 'option_group_id' => $option_group->id,
+ 'name' => $params['name'],
));
$result = $api->values();
if (empty($result))
{
-<<<<<<< HEAD (7b1300 Use Civi method to cancel recurring via qc)
$api->OptionValue->Create($params);
-=======
- $api->OptionValue->Create(array(
- 'option_group_id' => $option_group->id,
- 'name' => $value,
- 'label' => $value,
- 'is_active' => 1,
- ));
->>>>>>> BRANCH (df58a9 Update SmashPig lib; disable Lynx reconciliation test)
}
}
}
+/**
+ * Ensure that a location type exists for every item in the array.
+ *
+ * @param array $financial_types
+ *
+ * @throws \CiviCRM_API3_Exception
+ */
function wmf_civicrm_create_location_types($location_types, $update_existing =
FALSE)
{
+ $existingTypes = civicrm_api3('Address', 'getoptions', array(
+ 'field' => 'location_type_id',
+ ));
+ if (!$update_existing) {
+ $location_types = array_diff($location_types,
$existingTypes['values']);
+ }
foreach ($location_types as $name => $display_name)
{
- $location_type_id = CRM_Utils_Array::key(
- $name,
- CRM_Contribute_PseudoConstant::locationType()
+ $params = array(
+ 'name' => $name,
+ 'display_name' => $display_name,
+ 'is_active' => 1,
);
-
- if (!$location_type_id || $update_existing == TRUE)
- {
- $params = array(
- 'name' => $name,
- 'display_name' => $display_name,
- 'is_active' => 1,
- );
- if ($location_type_id && $update_existing == TRUE)
- {
- $params['id'] = $location_type_id;
- }
- wmf_civicrm_add_location_type($params);
+ if ($update_existing) {
+ $params['id'] = array_search($display_name,
$existingTypes['values']);
}
+ civicrm_api3('LocationType', 'create', $params);
}
}
+/**
+ * @deprecated
+ */
function wmf_civicrm_add_location_type($params)
{
$locationType = new CRM_Core_DAO_LocationType();
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.install
b/sites/all/modules/wmf_civicrm/wmf_civicrm.install
index 0ff190d..46653c0 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.install
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.install
@@ -103,7 +103,6 @@
'option_group_id' => $option_group_id,
'label' => ts( $value ),
'value' => $value,
- 'weight' => 'next',
) );
if ( !$success ) {
throw new Exception( $api->errorMsg() );
@@ -165,7 +164,7 @@
);
wmf_civicrm_bootstrap_civi();
- wmf_civicrm_create_contribution_types($contribution_types);
+ wmf_civicrm_create_financial_types($contribution_types);
wmf_civicrm_create_option_values( 'payment_instrument',
$payment_instruments );
return array();
@@ -256,7 +255,7 @@
function wmf_civicrm_update_7003()
{
wmf_civicrm_bootstrap_civi();
- wmf_civicrm_create_contribution_types(array(
+ wmf_civicrm_create_financial_types(array(
'Merkle',
));
}
@@ -579,7 +578,7 @@
{
$api = wmf_civicrm_bootstrap_civi();
- wmf_civicrm_create_contribution_types(array(
+ wmf_civicrm_create_financial_types(array(
'Refund',
'Chargeback',
));
@@ -599,7 +598,7 @@
function wmf_civicrm_update_7008()
{
wmf_civicrm_bootstrap_civi();
- wmf_civicrm_create_contribution_types(array(
+ wmf_civicrm_create_financial_types(array(
'Arizona Lockbox',
));
}
@@ -856,6 +855,10 @@
{
$ret = array();
$api = wmf_civicrm_bootstrap_civi();
+ wmf_civicrm_create_option_values_detailed('tag_used_for', array(
+ 'Contributions' => array('value' => 'civicrm_contribution'),
+ ));
+
$success = $api->Tag->get(array(
'name' => 'RecurringRestarted',
'used_for' => 'civicrm_contribution',
@@ -1092,7 +1095,7 @@
if (!$result) {
throw new Exception('Could not find custom group wmf_donor. Please
run update 7023 first.');
}
-
+
$custom_group = array_pop($result);
for ($year = WMF_MIN_ROLLUP_YEAR; $year <= WMF_MAX_ROLLUP_YEAR;
$year++) {
@@ -1197,17 +1200,13 @@
}
/**
- * Add indexes to the civicrm_prevnext_cache table
+ * Add indexes to the civicrm_prevnext_cache table.
+ *
+ * In CiviCRM 4.6 these are in core.
*/
function wmf_civicrm_update_7025()
{
- $dbs = wmf_civicrm_get_dbs();
- $dbs->push('civicrm');
- db_query("alter table civicrm_prevnext_cache
- add index entity_id1 (entity_id1),
- add index entity_id2 (entity_id2),
- add index cacheKey (cacheKey)");
}
/**
@@ -1260,7 +1259,7 @@
}
wmf_civicrm_bootstrap_civi();
- wmf_civicrm_create_contribution_types( array(
+ wmf_civicrm_create_financial_types( array(
'Engage',
) );
}
@@ -1346,28 +1345,10 @@
* Add more custom fields that already exist on production
*/
function wmf_civicrm_update_7031() {
- $warnings = array();
$api = wmf_civicrm_bootstrap_civi();
-
- // No API available yet.
- $existingTypes = array_flip(
CRM_Contribute_PseudoConstant::contributionType() );
- if ( array_key_exists( 'Stock', $existingTypes ) ) {
- $stockContributionTypeId = $existingTypes['Stock'];
- } else {
- $params = array(
- 'accounting_code' => 'STOCK',
- 'is_active' => 1,
- 'is_deductible' => 1,
- 'name' => 'Stock',
- );
- $ids = array();
- $stockContributionType = CRM_Contribute_BAO_ContributionType::add(
$params, $ids );
- if ( is_a( $stockContributionType, 'CRM_Core_Error' ) ) {
- throw new Exception( $stockContributionType->getMessages() );
- }
- $stockContributionTypeId = $stockContributionType->id;
- }
+ $financialTypes = wmf_civicrm_create_financial_types(array('Stock'));
+ $stockContributionTypeId = array_search('Stock', $financialTypes);
$success = $api->CustomGroup->get(array(
'name' => 'Stock_Information',
@@ -1449,7 +1430,6 @@
* Add "Trilogy" payment instrument.
*/
function wmf_civicrm_update_7034() {
-<<<<<<< HEAD (7b1300 Use Civi method to cancel recurring via qc)
wmf_civicrm_bootstrap_civi();
wmf_civicrm_create_option_values( 'payment_instrument', array('Trilogy') );
return array();
@@ -1464,8 +1444,6 @@
* in master before this is merged.
*/
function wmf_civicrm_update_7060() {
-=======
->>>>>>> BRANCH (df58a9 Update SmashPig lib; disable Lynx reconciliation test)
wmf_civicrm_bootstrap_civi();
wmf_civicrm_create_option_values_detailed('tag_used_for', array(
'Contributions' => array('value' => 'civicrm_contribution'),
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index d0d2de1..c7e78ce 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -457,7 +457,7 @@
case 'contribution_type_id':
//fixme: This is probably the upside-down way to do it. Really
ought to go through the API.
//
- $result = CRM_Contribute_BAO_ContributionType::retrieve($params,
$dummy);
+ $result = CRM_Financial_BAO_FinancialType::retrieve($params,
$dummy);
if (!is_null($result)){
$civi_ids[$type][$name] = $result->id;
watchdog('wmf_civicrm', "Found id for contribution_type $name:
" . $civi_ids[$type][$name]);
@@ -469,7 +469,7 @@
$params['accounting_code'] = strtoupper($name);
$params['is_deductible'] = 1;
$params['is_active'] = 1;
- $result = CRM_Contribute_BAO_ContributionType::add($params,
$dummy);
+ $result = CRM_Financial_BAO_FinancialType::add($params,
$dummy);
$civi_ids[$type][$name] = $result->id;
watchdog('wmf_civicrm', "New id for contribution_type $name :"
. $civi_ids[$type][$name]);
}
--
To view, visit https://gerrit.wikimedia.org/r/249566
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib54beab1d4a1f3b9f43fd034dfb60f3be1253b9f
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: civi-4.6.9
Gerrit-Owner: Eileen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits