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

dev/core#1093 add a bulkCreate action for many customFields in one go #14694

Merged
merged 2 commits into from
Jul 11, 2019

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jul 2, 2019

Overview

Add bulkCreate function for CustomField with a view towards this being a new protocol for how bulk create actions would look from a code POV which we could expose via apiv4

Before

No function for efficiently creating multiple fields

After

Function exists. There is a view to expose this via apiv4 but at this stage that has been left off to allow 'maturing' - unit test added

Technical Details

Preliminary cleanup changes are split off into smaller commits

#14705
#14697
#14693 (merged)
#14689 (merged)

Comments

I haven't switched Utils_Migrate to use the bulk action but that is the next logical step since it is kinda creating complexity to do 'bulk-action-lite'

https://lab.civicrm.org/dev/core/issues/1093

@civibot
Copy link

civibot bot commented Jul 2, 2019

(Standard links)

@civibot civibot bot added the master label Jul 2, 2019
@eileenmcnaughton eileenmcnaughton changed the title [REF] refactors towards supporting a bulkCreate action dev/core#1093 [REF] refactors towards supporting a bulkCreate action Jul 2, 2019
@eileenmcnaughton eileenmcnaughton changed the title dev/core#1093 [REF] refactors towards supporting a bulkCreate action [wip] dev/core#1093 [REF] refactors towards supporting a bulkCreate action Jul 2, 2019
@eileenmcnaughton eileenmcnaughton force-pushed the cust_field_bulk branch 2 times, most recently from aa7555a to 7084881 Compare July 2, 2019 06:14
@eileenmcnaughton eileenmcnaughton changed the title [wip] dev/core#1093 [REF] refactors towards supporting a bulkCreate action dev/core#1093 add a bulkCreate action for many customFields in one go Jul 2, 2019
@eileenmcnaughton eileenmcnaughton force-pushed the cust_field_bulk branch 2 times, most recently from 76df6f6 to 861d07d Compare July 3, 2019 22:38
@eileenmcnaughton eileenmcnaughton force-pushed the cust_field_bulk branch 4 times, most recently from 4238cc4 to 0c62271 Compare July 4, 2019 01:11
@pradpnayak
Copy link
Contributor

This needs rebasing

@eileenmcnaughton
Copy link
Contributor Author

rebased

@colemanw
Copy link
Member

colemanw commented Jul 4, 2019

Api4 signature could look like this: civicrm/org.civicrm.api4#180

@colemanw
Copy link
Member

colemanw commented Jul 5, 2019

@eileenmcnaughton looks like a brittle test fell over on a whitespace change made in this PR:

CRM_Core_BAO_SchemaHandlerTest::testBuildFieldChangeSql
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'ALTER TABLE big_table\n
+'ALTER TABLE big_table \n

@eileenmcnaughton
Copy link
Contributor Author

@colemanw good spotting - that was also what the sub-pr got stuck on - #14727

@eileenmcnaughton eileenmcnaughton force-pushed the cust_field_bulk branch 3 times, most recently from 6b874d1 to b78a8a1 Compare July 5, 2019 04:09
@eileenmcnaughton
Copy link
Contributor Author

@colemanw now all the preliminary refactoring is done this is pretty simple - I have renamed it to bulkSave per your recommendation

@eileenmcnaughton
Copy link
Contributor Author

test this please

@eileenmcnaughton
Copy link
Contributor Author

@colemanw we are down to one unrelated fail here!

$params = [
'table_name' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id, 'table_name'),
];
$sql = str_repeat(' ', 8);
Copy link
Member

@colemanw colemanw Jul 6, 2019

Choose a reason for hiding this comment

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

????????

<?php
  echo str_repeat('?', 8);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah weird but retained from 'create'

$params = array_merge($defaults, $fieldParams);
$operation = empty($params['id']) ? 'add' : 'modify';
$customField = self::createCustomFieldRecord($params);
// Only doing 'add' for now - so hard coded & no indexExists.
Copy link
Member

Choose a reason for hiding this comment

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

What would it take to get this working with update? Then it would be ready for api4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh - I think I mostly altered it but not in this spot - will fix

@eileenmcnaughton eileenmcnaughton force-pushed the cust_field_bulk branch 3 times, most recently from c2b9d75 to 0638164 Compare July 8, 2019 21:40
wmfgerrit pushed a commit to wikimedia/wikimedia-fundraising-crm that referenced this pull request Jul 8, 2019
The updates the way we add bulk fields to custom tables. It uses work I did upstream

civicrm/civicrm-core#14694
and ported here
https://gerrit.wikimedia.org/r/#/c/wikimedia/fundraising/crm/civicrm/+/520665/

to consolidate DB changes into a single sql call

This took about 25 mins on staging to add 'all the fields' but note that this change does not
add those fields as yet

Update field add

Bug: T170972
Change-Id: Ifabe56b4d9956d5a42a03948db20385ab51832f4
This function is only used by one place and feels like the wrong separation of concerns - ie
we have a single create action & a multiple create action. They both need to share the generation
of the sql to run but can handle the batching of that & rebuilding of triggers etc
separately
@eileenmcnaughton eileenmcnaughton force-pushed the cust_field_bulk branch 2 times, most recently from b303735 to d49c025 Compare July 10, 2019 23:15
Add bulkCreate function for CustomField with a view towards this being a new protocol for how bulk create actions would look from a code POV which we could expose via apiv4
@eileenmcnaughton
Copy link
Contributor Author

@colemanw it passed! (& test cover was good - I couldn't sneak anything past it)

@@ -295,7 +295,7 @@ public static function buildForeignKeySQL($params, $separator, $prefix, $tableNa
* @return bool
*/
public static function alterFieldSQL($params, $indexExist = FALSE, $triggerRebuild = TRUE) {

CRM_Core_Error::deprecatedFunctionWarning('function no longer in use / supported');
Copy link
Member

Choose a reason for hiding this comment

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

Probably should add a @deprecated annotation too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok - I'll add that to the last PR (rather than invalidate tests on this)

@colemanw
Copy link
Member

Code & test coverage looks good. Merging.

@colemanw colemanw merged commit 2752a7b into civicrm:master Jul 11, 2019
@colemanw colemanw deleted the cust_field_bulk branch July 11, 2019 20:07
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Aug 27, 2019
…y (ish)

I have worked to extract functions upstream to support 'create' and 'bulkCreate' with a view to api support.

civicrm#14694

This backports the additional functions to support bulk create (all changes to make this not a duplication of
code are upstream but not in this port since it would make this a crazy complex & risky backport)

Change-Id: Id437f335d122c993ca6b94d04bd7048c89f991e7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants