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#2486 Add v4 Mailing api (+ MailingJob) #22624

Merged
merged 5 commits into from
Feb 19, 2022

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jan 26, 2022

Overview

dev/core#2486 Add v4 Mailing api (+ MailingJob)

Before

No v4 api for Mailing

After

Tada

Technical Details

@colemanw @seamuslee001 @totten this is a starting point but there are some bizarre things regarding the Mailing create function

  1. there is some permissions stuff in the v3 api layer - we could probably just move this to the BAO
  2. weird voodoo number 1 _evil_bao_validator_ - this is where either flexmailer or the legacy method validate
  3. weird voodoo number 2 - if you just want to create the entity & not have it start firing stuff out you have to pass in 'skip_evil_bao_auto_schedule' and _skip_evil_bao_auto_recipients_ ..... - UPDATE agreed setPopulateReceipients - default to FALSE

I'm not quite sure how best to deal with 2 & 3. Note we did talk about moving the legacy Mailing stuff to an extension - which probably would have made this easier at least WRT 2

Comments

https://lab.civicrm.org/dev/core/-/issues/2486

@civibot
Copy link

civibot bot commented Jan 26, 2022

(Standard links)

@civibot civibot bot added the master label Jan 26, 2022
@monishdeb
Copy link
Member

@eileenmcnaughton there is a related test failure:

api\v4\Entity\ConformanceTest::testConformance with data set "MailingJob" ('MailingJob')
API_Exception: At least one Mailing is required in test

/home/jenkins/bknix-dfl/build/core-22624-62lv4/web/sites/all/modules/civicrm/tests/phpunit/api/v4/Service/TestCreationParameterProvider.php:155
/home/jenkins/bknix-dfl/build/core-22624-62lv4/web/sites/all/modules/civicrm/tests/phpunit/api/v4/Service/TestCreationParameterProvider.php:99
/home/jenkins/bknix-dfl/build/core-22624-62lv4/web/sites/all/modules/civicrm/tests/phpunit/api/v4/Service/TestCreationParameterProvider.php:59
/home/jenkins/bknix-dfl/build/core-22624-62lv4/web/sites/all/modules/civicrm/tests/phpunit/api/v4/Entity/ConformanceTest.php:298
/home/jenkins/bknix-dfl/build/core-22624-62lv4/web/sites/all/modules/civicrm/tests/phpunit/api/v4/Entity/ConformanceTest.php:168
/home/jenkins/bknix-dfl/extern/phpunit8/phpunit8.phar:671

@eileenmcnaughton
Copy link
Contributor Author

thanks @monishdeb - could be worse :-)

* @since 5.47
* @package Civi\Api4
*/
class MailingJob extends Generic\DAOEntity {
Copy link
Member

Choose a reason for hiding this comment

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

Should we make MailingJob readonly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

@eileenmcnaughton the @readonly annotation isn't right. Instead you have to use the ReadOnlyEntity trait.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@colemanw thanks - fixed

@eileenmcnaughton
Copy link
Contributor Author

@colemanw I'm not sure why MailingJob doesn't create the 'Mailing' it requires in testConformance.

Note the only reason we need MailingJob is that once we want to start to get other details - eg. bounces we need to join through MailingJob to MailingEventQueue to MailingEventBounce

@colemanw
Copy link
Member

@eileenmcnaughton I fixed the conformance test which triggered a new test run. But the previous run showed other problems: https://test.civicrm.org/job/CiviCRM-Core-PR/47154/#showFailuresLink

@colemanw
Copy link
Member

@eileenmcnaughton looks like just one test error left...

public static function createAndRun($mailing) {
$validator = new \Civi\FlexMailer\Validator();
return $validator->run(array(
public static function createAndRun(array $params): array {
Copy link
Member

Choose a reason for hiding this comment

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

@colemanw @eileenmcnaughton - The failures in ValidatorTest are complaining because the signature changed (DAO => array).

It should be straight-forward to update the test:

diff --git a/ext/flexmailer/tests/phpunit/Civi/FlexMailer/ValidatorTest.php b/ext/flexmailer/tests/phpunit/Civi/FlexMailer/ValidatorTest.php
index 35541e5e67..642d4527b2 100644
--- a/ext/flexmailer/tests/phpunit/Civi/FlexMailer/ValidatorTest.php
+++ b/ext/flexmailer/tests/phpunit/Civi/FlexMailer/ValidatorTest.php
@@ -86,9 +86,7 @@ class ValidatorTest extends \CiviUnitTestCase {
    * @dataProvider getExamples
    */
   public function testExamples($mailingData, $expectedErrors): void {
-    $mailing = new \CRM_Mailing_DAO_Mailing();
-    $mailing->copyValues($mailingData);
-    $actualErrors = Validator::createAndRun($mailing);
+    $actualErrors = Validator::createAndRun($mailingData);
     $this->assertEquals(
       array_keys($actualErrors),
       array_keys($expectedErrors)

Grepped universe for createAndRun -- I don't see anything outside of civicrm-core that uses it.

@colemanw colemanw merged commit a597092 into civicrm:master Feb 19, 2022
@colemanw colemanw deleted the mailing branch February 19, 2022 17:37
@eileenmcnaughton
Copy link
Contributor Author

Thanks @totten @colemanw

@colemanw ideally we would expose bounces etc in search kit next.

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.

4 participants