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/#/229 Fix fatal error on send test mail #12399

Merged
merged 1 commit into from Jul 3, 2018

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jul 3, 2018

Overview

Fixes regression in rc whereby test mailings are not sent

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

Before

sending test email fails with: Error in call to Mailing_send_test : job_id is not valid : 440

After

send mail works

Technical Details

@jmcclelland can you please test this? I think that passing params through to the BAO on a different entity is a bad practice so I switched to a whitelist approach.

The original MailingJob::Create only handled the 4 params still being handled

 $job = new CRM_Mailing_BAO_MailingJob();
    $job->mailing_id = $params['mailing_id'];
    $job->status = $params['status'];
    $job->scheduled_date = $params['scheduled_date'];
    $job->is_test = $params['is_test'];
    $job->save();
    if ($params['mailing_id']) {
      CRM_Mailing_BAO_Mailing::getRecipients($params['mailing_id']);
      return $job;
    }
    else {
      throw new CRM_Core_Exception("Failed to create job: Unknown mailing ID");
    }

Comments

Thank you for testing the rc @jmcclelland

@civibot
Copy link

civibot bot commented Jul 3, 2018

(Standard links)

@@ -613,19 +614,24 @@ function civicrm_api3_mailing_send_test($params) {
if (!array_key_exists('test_group', $params) && !array_key_exists('test_email', $params)) {
throw new API_Exception("Mandatory key(s) missing from params array: test_group and/or test_email field are required");
}
civicrm_api3_verify_mandatory($params,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to the spec function

@@ -679,8 +685,7 @@ function civicrm_api3_mailing_send_test($params) {
}

$isComplete = FALSE;
$config = CRM_Core_Config::singleton();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unused

@@ -410,8 +410,10 @@ public function testMailerSendTest_email() {
$mail = $this->callAPISuccess('mailing', 'create', $this->_params);

$params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL);
// Per https://lab.civicrm.org/dev/core/issues/229 ensure this is not passed through!
$params['id'] = $mail['id'];
Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton how has this test been passing is it just that there isn't a difference in ids between the civicrm_mailing table the civicrm_mailing_job table here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seamuslee001 I was able to replicate it when I added to the test so it wasn't transposing 'mailing_id' to 'id' in the api wrapper (I haven't fully thought that through) -

in the api 'id' refers to mailing_id - but is passed to MailingJob as if it were MailingJob id - hence the bug

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(mailing id is supposed to be required here & it makes sense it should be)

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm interesting. So the test was succeeding in that it was setting a mailing_id but no id but once the id got set then it started failing is that the case?


$testEmailParams = _civicrm_api3_generic_replace_base_params($params);
Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton is this where the transposition was going on?

Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton do you think it might be worth adding id to the exclusion on the replace_base_params function instead?

FALSE
);
$testEmailParams = [
'mailing_id' => $params['mailing_id'],
Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton your 100% mailing_id is always getting passed as param right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seamuslee001 it's a required field - ie I moved a verify_mandatory call to a spec declaration

Copy link
Contributor

Choose a reason for hiding this comment

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

ok happy with that then

@seamuslee001
Copy link
Contributor

After chatting with Eileen on matermost i am good with these changes @eileenmcnaughton @jmcclelland

@eileenmcnaughton
Copy link
Contributor Author

OK - let's merge-on-pass & then @jmcclelland can test the new tarball

@seamuslee001
Copy link
Contributor

@eileenmcnaughton should we do the same with my PR as well?

@jmcclelland
Copy link
Contributor

Tested and it works - thank you! Although I'm not sure why the tests are now failing.

@jmcclelland
Copy link
Contributor

It seems that Mailing.send_test ignores the email_group parameter.

@jmcclelland
Copy link
Contributor

I just created an alternative that tries to fix the test errors by adding the ability to send to a group:

#12407

@seamuslee001
Copy link
Contributor

Merging as per the testing of @jmcclelland and as per the tag

@seamuslee001 seamuslee001 merged commit 6adbfc5 into civicrm:5.3 Jul 3, 2018
@eileenmcnaughton eileenmcnaughton deleted the jamie branch July 4, 2018 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants