Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GroupNesting, GroupOrganization, Domain to work with singleValueAlter #11689

Merged
merged 1 commit into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CRM/Contact/BAO/ContactType.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,11 @@ public static function add(&$params) {
}

if (!empty($params['id'])) {
$params = array('name' => "New $contactName");
$newParams = array(
'label' => "New $contact",
'is_active' => $active,
);
CRM_Core_BAO_Navigation::processUpdate($params, $newParams);
CRM_Core_BAO_Navigation::processUpdate(['name' => "New $contactName"], $newParams);
}
else {
$name = self::getBasicType($contactName);
Expand Down
22 changes: 22 additions & 0 deletions CRM/Contact/BAO/GroupNesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@
*/
class CRM_Contact_BAO_GroupNesting extends CRM_Contact_DAO_GroupNesting {

/**
* Add Dashboard.
*
* @param array $params
* Values.
*
*
* @return object
*/
public static function create($params) {
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, 'GroupNesting', CRM_Utils_Array::value('id', $params), $params);
$dao = new CRM_Contact_BAO_GroupNesting();
$dao->copyValues($params);
if (empty($params['id'])) {
$dao->find(TRUE);
}
$dao->save();
CRM_Utils_Hook::post($hook, 'GroupNesting', $dao->id, $dao);
return $dao;
}

/**
* Adds a new group nesting record.
*
Expand Down
41 changes: 11 additions & 30 deletions CRM/Contact/BAO/GroupOrganization.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,24 @@ public function __construct() {
* @return CRM_Contact_DAO_GroupOrganization
*/
public static function add(&$params) {
$formattedValues = array();
self::formatValues($params, $formattedValues);
$dataExists = self::dataExists($formattedValues);
if (!$dataExists) {
if (!empty($params['group_organization'])) {
$params['id'] = $params['group_organization'];
}
$dataExists = self::dataExists($params);
if (!$dataExists && empty($params['id'])) {
return NULL;
}
$groupOrganization = new CRM_Contact_DAO_GroupOrganization();
$groupOrganization->copyValues($formattedValues);
// we have ensured we have group_id & organization_id so we can do a find knowing that
// this can only find a matching record
$groupOrganization->find(TRUE);
$groupOrganization->copyValues($params);
if (!isset($params['id'])) {
// we have ensured we have group_id & organization_id so we can do a find knowing that
// this can only find a matching record
$groupOrganization->find(TRUE);
}
$groupOrganization->save();
return $groupOrganization;
}

/**
* Format the params.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $formatedValues
* (reference ) an assoc array of name/value pairs.
*/
public static function formatValues(&$params, &$formatedValues) {
if (!empty($params['group_organization'])) {
$formatedValues['id'] = $params['group_organization'];
}

if (!empty($params['group_id'])) {
$formatedValues['group_id'] = $params['group_id'];
}

if (!empty($params['organization_id'])) {
$formatedValues['organization_id'] = $params['organization_id'];
}
}

/**
* Check if there is data to create the object.
*
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static function edit(&$params, &$id) {
*/
public static function create($params) {
$domain = new CRM_Core_DAO_Domain();
$domain->copyValues($params);
$domain->copyValues($params, TRUE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remind me what the second parameter does here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's new - we added array handling to that function - providing the metadata is defined - new in the xml

$domain->save();
return $domain;
}
Expand Down
2 changes: 1 addition & 1 deletion api/v3/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @return array
*/
function civicrm_api3_batch_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Batch');
}

/**
Expand Down
1 change: 0 additions & 1 deletion api/v3/ContactType.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function civicrm_api3_contact_type_create($params) {
* Array of matching contact_types
*/
function civicrm_api3_contact_type_get($params) {
civicrm_api3_verify_mandatory($params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does mandatory params happen as part of basic get?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it happens before it reaches that function in the api wrapper

return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}

Expand Down
2 changes: 1 addition & 1 deletion api/v3/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @throws \API_Exception
*/
function civicrm_api3_country_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_DAO(__FUNCTION__), $params);
return _civicrm_api3_basic_create(_civicrm_api3_get_DAO(__FUNCTION__), $params, 'Country');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/v3/FinancialItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @return array
*/
function civicrm_api3_financial_item_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'FinancialItem');
}

/**
Expand Down
9 changes: 2 additions & 7 deletions api/v3/GroupNesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,10 @@ function civicrm_api3_group_nesting_get($params) {
* Parameters array - allowed array keys include:.
*
* @return array
* TBD
* @todo Work out the return value.
* API success array
*/
function civicrm_api3_group_nesting_create($params) {
CRM_Contact_BAO_GroupNesting::add($params['parent_group_id'], $params['child_group_id']);

// FIXME: CRM_Contact_BAO_GroupNesting requires some work
$result = array('is_error' => 0);
return civicrm_api3_create_success($result, $params, 'GroupNesting');
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'GroupNesting');
}

/**
Expand Down
9 changes: 1 addition & 8 deletions api/v3/GroupOrganization.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ function civicrm_api3_group_organization_get($params) {
*/
function civicrm_api3_group_organization_create($params) {

$groupOrgBAO = CRM_Contact_BAO_GroupOrganization::add($params);

if (is_null($groupOrgBAO)) {
return civicrm_api3_create_error("group organization not created");
}

_civicrm_api3_object_to_array($groupOrgBAO, $values);
return civicrm_api3_create_success($values, $params, 'GroupOrganization', 'get', $groupOrgBAO);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'GroupOrganization');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/v3/MembershipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function civicrm_api3_membership_type_create($params) {
$params[$field] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params[$field]);
}
}
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Membership_type');
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'MembershipType');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/v3/StatusPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @return array
*/
function civicrm_api3_status_preference_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'StatusPreference');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/v3/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* API result array
*/
function civicrm_api3_tag_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Tag');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/v3/WordReplacement.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function civicrm_api3_word_replacement_get($params) {
* @return array
*/
function civicrm_api3_word_replacement_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'WordReplacement');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/GroupOrganizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testGroupOrganizationGetWithGroupId() {
'sequential' => 1,
);
$getResult = $this->callAPISuccess('group_organization', 'get', $getParams);
$this->assertEquals($createResult['values'], $getResult['values'][0]);
$this->assertEquals($createResult['values'][$createResult['id']], $getResult['values'][0]);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ public static function toBeSkipped_updatesingle($sequential = FALSE) {
'Constant',
'Entity',
'Location',
'Domain',
'Profile',
'CustomValue',
'SurveyRespondant',
Expand All @@ -452,8 +451,6 @@ public static function toBeSkipped_updatesingle($sequential = FALSE) {
'OptionGroup',
'Membership',
'Group',
'GroupOrganization',
'GroupNesting',
'File',
'EntityTag',
'CustomField',
Expand Down Expand Up @@ -573,6 +570,7 @@ public function getKnownUnworkablesUpdateSingle($entity, $key) {
'definition',
),
),
'Domain' => ['cant_update' => ['domain_version']],
'MembershipBlock' => array(
'cant_update' => array(
// The fake/auto-generated values leave us unable to properly cleanup fake data
Expand Down