Skip to content

Commit

Permalink
[wip] bulk create
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 2, 2019
1 parent fd6065e commit 069196e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CRM/Core/BAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,25 @@ protected static function doCreate($params) {
return $customField;
}

/**
* Create several fields at once in a mysql efficient way.
*
* The intention is that apiv4 would expose any BAO with bulkCreate as a new action.
*
* Note that in the first instance this supports 'create' only. It's possible edit
* is fine in the same function - just treading slowly.
*
* @param array $params
* Array of arrays as would be passed into create
* @param array $defaults
* Default parameters to be be merged into each of the params.
*/
public function bulkCreate($params, $defaults) {
foreach ($params as $fieldParams) {
$fieldParams = array_merge($defaults, $fieldParams);
}
}

/**
* Fetch object based on array of properties.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,4 +636,15 @@ public function testGetFieldsForImport() {
$this->assertEquals($expected, CRM_Core_BAO_CustomField::getFieldsForImport());
}

/**
* Test the bulk create function works.
*/
public function testBulkCreate() {
$customGroup = $this->customGroupCreate([
'extends' => 'Individual',
'title' => 'my bulk group',
]);
CRM_Core_BAO_CustomField::bulkCreate([]);
}

}

0 comments on commit 069196e

Please sign in to comment.