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

Add APIv4 Batch.create spec #20501

Merged
merged 1 commit into from
Jun 4, 2021

Conversation

monishdeb
Copy link
Member

Overview

Add APIv4 Batch.create spec

Before

No default spec for APIv4 Batch.create spec

After

Add APIv4 Batch.create spec as declared here

Comments

ping @colemanw @eileenmcnaughton @seamuslee001

I think this was missed in #19931 !!!

@civibot
Copy link

civibot bot commented Jun 4, 2021

(Standard links)

@civibot civibot bot added the master label Jun 4, 2021
$spec->getFieldByName('created_date')->setDefaultValue('now');
$spec->getFieldByName('modified_id')->setDefaultValue('user_contact_id');
$spec->getFieldByName('modified_date')->setDefaultValue('now');
$spec->getFieldByName('status_id')->setRequired(TRUE);
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason why we aren't setting these to be required at the DB level?

Copy link
Member Author

@monishdeb monishdeb Jun 4, 2021

Choose a reason for hiding this comment

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

Yeah I found that it is set true at DB level as per schema here but in addition I think the API4 spec still need a declaration to indicate the field is required for validation and on API explorer UI as there are other such occurrences in core

civicrm-core$ grep -irn "setRequired(TRUE" Civi/Api4/Service/Spec/ | wc -l
      23

Copy link
Contributor

Choose a reason for hiding this comment

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

I would have thought that its only needed if the db isn't requiring it right @colemanw ?

Copy link
Member Author

Choose a reason for hiding this comment

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

My bad, yes you are right. On further check it seems like the spec wrapper add the required property as per DAO::fields information. Updated the PR and removed the setRequired on status_id and title. Although I will submit a separate PR to remove the setRequired call on required (not pseudo) fields in other EntitySpecProvider files. Thanks for raising this.

Comment on lines 36 to 38
$entity_table = new FieldSpec('entity_table', 'Batch', 'String');
$entity_table->setTitle('Batch Entity Table - remove?');
$spec->addFieldSpec($entity_table);
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what this extra field is for. I don't see any handling for an entity_table param in the CRM_Batch_BAO_Batch::create() function.

@monishdeb
Copy link
Member Author

@eileenmcnaughton @colemanw on separate topic, is there a reason why essential field is not required in DB but required as per spec? Like civicrm_email.email is not required in DB but set required in spec :

Civi/Api4//Service/Spec/Provider/EmailCreationSpecProvider.php:30:    $spec->getFieldByName('email')->setRequired(TRUE);

similarly civicrm_group.title, civicrm_phone.phone etc.

@colemanw
Copy link
Member

colemanw commented Jun 4, 2021

I can't think of a good reason to not require those in the DB. It would be a small hassle to write the upgrade script so I guess no one has volunteered to do it.

@colemanw
Copy link
Member

colemanw commented Jun 4, 2021

This PR looks complete.

@seamuslee001 seamuslee001 merged commit f0f67f2 into civicrm:master Jun 4, 2021
@seamuslee001 seamuslee001 deleted the api4_batch_spec branch June 4, 2021 21:42
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