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 enotice when updating a custom group with is_multiple = 1 #12243

Merged
merged 1 commit into from
Jun 5, 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
29 changes: 15 additions & 14 deletions CRM/Core/BAO/CustomGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,24 @@ public static function create(&$params) {
$params['max_multiple'] >= '0'
) ? $params['max_multiple'] : 'null' : 'null';

$tableName = $oldTableName = NULL;
$tableName = $tableNameNeedingIndexUpdate = NULL;
if (isset($params['id'])) {
$group->id = $params['id'];
//check whether custom group was changed from single-valued to multiple-valued
$isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
$params['id'],
'is_multiple'
);

if ((!empty($params['is_multiple']) || $isMultiple) &&
($params['is_multiple'] != $isMultiple)
) {
$oldTableName = CRM_Core_DAO::getFieldValue(
'CRM_Core_DAO_CustomGroup',
if (isset($params['is_multiple'])) {
//check whether custom group was changed from single-valued to multiple-valued
$isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
$params['id'],
'table_name'
'is_multiple'
);

if ($params['is_multiple'] != $isMultiple) {
$tableNameNeedingIndexUpdate = CRM_Core_DAO::getFieldValue(
'CRM_Core_DAO_CustomGroup',
$params['id'],
'table_name'
);
}
}
}
else {
Expand Down Expand Up @@ -202,8 +203,8 @@ public static function create(&$params) {
// now create the table associated with this group
self::createTable($group);
}
elseif ($oldTableName) {
CRM_Core_BAO_SchemaHandler::changeUniqueToIndex($oldTableName, CRM_Utils_Array::value('is_multiple', $params));
elseif ($tableNameNeedingIndexUpdate) {
CRM_Core_BAO_SchemaHandler::changeUniqueToIndex($tableNameNeedingIndexUpdate, CRM_Utils_Array::value('is_multiple', $params));
}

if (CRM_Utils_Array::value('overrideFKConstraint', $params) == 1) {
Expand Down
10 changes: 9 additions & 1 deletion tests/phpunit/api/v3/CustomGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,19 @@ public function testCustomGroupCreateGroup() {
'help_post' => 'This is Post Help For Test Group 8',
);

$customGroup = $this->callAPISuccess('custom_group', 'create', $params);
$customGroup = $this->callAPISuccess('CustomGroup', 'create', $params);
Copy link
Member

Choose a reason for hiding this comment

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

These ought to be equivalent. Any reason why this change was made?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that our preferred format for the entity is the camel case so it was for that reason

$this->assertNotNull($customGroup['id']);
$this->assertEquals($customGroup['values'][$customGroup['id']]['extends'], 'Group');
}

/**
* Test an empty update does not trigger e-notices when is_multiple has been set.
*/
public function testCustomGroupEmptyUpdate() {
$customGroup = $this->callAPISuccess('CustomGroup', 'create', array_merge($this->_params, ['is_multiple' => 1]));
$this->callAPISuccess('CustomGroup', 'create', ['id' => $customGroup['id']]);
}

/**
* Check with Activity - Meeting Type
*/
Expand Down