Skip to content

Commit

Permalink
Merge pull request #11393 from jitendrapurohit/CRM-21533
Browse files Browse the repository at this point in the history
CRM-21533 : Outbound setting reverts in non-production sites on execu…
  • Loading branch information
eileenmcnaughton authored Jan 15, 2018
2 parents f23e96c + 288e5f7 commit 69a16c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CRM/Core/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public function executeJob($job) {
}
$this->logEntry('Finished execution of ' . $job->name . ' with result: ' . $this->_apiResultToMessage($result));
$this->currentJob = FALSE;

//Disable outBound option after executing the job.
$environment = CRM_Core_Config::environment(NULL, TRUE);
if ($environment != 'Production' && !empty($job->apiParams['runInNonProductionEnvironment'])) {
Civi::settings()->set('mailing_backend', array('outBound_option' => CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED));
}
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/phpunit/api/v3/JobProcessMailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public function testMailNonProductionRun() {
'environment' => 'Staging',
);
$this->callAPISuccess('Setting', 'create', $params);
//Assert if outbound mail is disabled.
$mailingBackend = Civi::settings()->get('mailing_backend');
$this->assertEquals($mailingBackend['outBound_option'], CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED);

$this->createContactsInGroup(10, $this->_groupID);
Civi::settings()->add(array(
'mailerBatchLimit' => 2,
Expand All @@ -130,6 +134,21 @@ public function testMailNonProductionRun() {
$this->callAPISuccess('job', 'process_mailing', array('runInNonProductionEnvironment' => TRUE));
$this->_mut->assertRecipients($this->getRecipients(1, 2));

$jobId = $this->callAPISuccessGetValue('Job', array(
'return' => "id",
'api_action' => "group_rebuild",
));
$this->callAPISuccess('Job', 'create', array(
'id' => $jobId,
'parameters' => "runInNonProductionEnvironment=TRUE",
));
$jobManager = new CRM_Core_JobManager();
$jobManager->executeJobById($jobId);

//Assert if outbound mail is still disabled.
$mailingBackend = Civi::settings()->get('mailing_backend');
$this->assertEquals($mailingBackend['outBound_option'], CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED);

// Test in production mode.
$params = array(
'environment' => 'Production',
Expand Down

0 comments on commit 69a16c0

Please sign in to comment.