Eileen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/240289
Change subject: Revert "Revert commits on wrong branch"
......................................................................
Revert "Revert commits on wrong branch"
This reverts commit d7d3409ec84c036c87d72b289a69172d4e201962.
This time we reapply on the RIGHT branch!
Change-Id: I4c587b37dbbbc2389236fce90aa544419bad4c22
---
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, 102 insertions(+), 58 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm
refs/changes/89/240289/1
diff --git a/civicrm b/civicrm
index dbeff64..0e31ff7 160000
--- a/civicrm
+++ b/civicrm
-Subproject commit dbeff641f99bfa73fd820e20ccd61ebb822a5d25
+Subproject commit 0e31ff753a9e05a63d92c08ea97db9f201ea795e
diff --git a/sites/all/modules/wmf_civicrm/bootstrap.inc
b/sites/all/modules/wmf_civicrm/bootstrap.inc
index 03f5eb0..14ebf15 100644
--- a/sites/all/modules/wmf_civicrm/bootstrap.inc
+++ b/sites/all/modules/wmf_civicrm/bootstrap.inc
@@ -34,6 +34,9 @@
*
* @param array $financial_types
*
+ * @return array
+ * Financial types in th DB.
+ *
* @throws \CiviCRM_API3_Exception
*/
function wmf_civicrm_create_financial_types($financial_types)
@@ -44,69 +47,118 @@
$missingTypes = array_diff($financial_types,
$existingFinancialTypes['values']);
foreach ($missingTypes as $type)
{
- civicrm_api3('FinancialType', 'create', array(
+ $result = civicrm_api3('FinancialType', 'create', array(
'is_active' => 1,
'is_deductible' => 1,
'accounting_code' => strtoupper($type),
'name' => $type,
));
+ $existingFinancialTypes[$result['id']] = $type;
+ }
+ return $existingFinancialTypes;
+}
+
+/**
+ * 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))
{
- $api->OptionValue->Create(array(
- 'option_group_id' => $option_group->id,
- 'name' => $value,
- 'label' => $value,
- 'is_active' => 1,
- ));
+ $api->OptionValue->Create(array_merge(array(
+ 'option_group_id' => $option_group->id,
+ 'name' => $key,
+ 'label' => $key,
+ 'is_active' => 1,
+ )), $value);
}
}
}
+/**
+ * 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 2e07ff0..bc3f57a 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.install
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.install
@@ -99,7 +99,6 @@
'option_group_id' => $option_group_id,
'label' => ts( $value ),
'value' => $value,
- 'weight' => 'next',
) );
if ( !$success ) {
throw new Exception( $api->errorMsg() );
@@ -852,6 +851,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',
@@ -1193,17 +1196,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)");
}
/**
@@ -1342,28 +1341,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,3 +1430,14 @@
wmf_civicrm_create_option_values( 'payment_instrument', array('Trilogy') );
return array();
}
+
+/**
+ * Add option value 'tag_used_for' for civicrm_contribution.
+ *
+ * This might exist as it had to be added to update 7022 so check first.d
+ */
+function wmf_civicrm_update_7035() {
+ wmf_civicrm_bootstrap_civi();
+ wmf_civicrm_create_option_values( 'payment_instrument', array('Trilogy') );
+ return array();
+}
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 6a49470..9d2ad15 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/240289
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4c587b37dbbbc2389236fce90aa544419bad4c22
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: civi-4.6.9-deploy
Gerrit-Owner: Eileen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits