Skip to content

Commit

Permalink
Merge pull request #5 from popcm/development
Browse files Browse the repository at this point in the history
Remove all the test mailings from bulk mailing campaign.
  • Loading branch information
guanhuan committed May 14, 2014
2 parents ac91a6a + 9e72bca commit 446825e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
17 changes: 13 additions & 4 deletions CRM/Mailjet/BAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
class CRM_Mailjet_BAO_Event extends CRM_Mailjet_DAO_Event {


static function getMailjetCustomCampaignId($mailingId){
$mailing = civicrm_api3('Mailing', 'get', $params = array('id' => $mailingId));
$timestamp = strtotime($mailing['values'][$mailingId]['created_date']);
return $mailingId . 'MJ' . $timestamp;
static function getMailjetCustomCampaignId($jobId){
if($jobId !== null){
$mailingJob = civicrm_api3('MailingJob', 'get', $params = array('id' => $jobId));
if(isset($mailingJob['values'][$jobId]['job_type'])){
$jobType = $mailingJob['values'][$jobId]['job_type'];
if($jobType == 'child'){
$timestamp = strtotime($mailingJob['values'][$jobId]['scheduled_date']);
return $jobId . 'MJ' . $timestamp;
}
}
}
$timestamp = strtotime("now");
return 0 . 'MJ' . $timestamp;
}

static function recordBounce($params) {
Expand Down
15 changes: 11 additions & 4 deletions mailjet.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function mailjet_civicrm_alterMailParams(&$params, $context) {
);
$mailJobResult = civicrm_api3('MailingJob', 'get', $apiParams);
$mailingId = $mailJobResult['values'][$jobId]['mailing_id'];
$params['headers']['X-Mailjet-Campaign'] = CRM_Mailjet_BAO_Event::getMailjetCustomCampaignId($mailingId);
$params['headers']['X-Mailjet-Campaign'] = CRM_Mailjet_BAO_Event::getMailjetCustomCampaignId($jobId);
}
}

Expand All @@ -27,14 +27,19 @@ function mailjet_civicrm_alterMailParams(&$params, $context) {
function mailjet_civicrm_pageRun(&$page) {
if(get_class($page) == 'CRM_Mailing_Page_Report'){
$mailingId = $page->_mailing_id;
$mailing = civicrm_api3('Mailing', 'get', $params = array('id' => $mailingId));
$timestamp = strtotime($mailing['values'][$mailingId]['created_date']);
$mailingJobs = civicrm_api3('MailingJob', 'get', $params = array('mailing_id' => $mailingId));

$jobId = 0;
foreach($mailingJobs['values'] as $key => $job){
if($job['job_type'] == 'child'){
$jobId = $key;

require_once('packages/mailjet-0.1/php-mailjet.class-mailjet-0.1.php');
// Create a new Mailjet Object
$mj = new Mailjet(MAILJET_API_KEY, MAILJET_SECRET_KEY);
$mj->debug = 0;
$mailJetParams = array(
'custom_campaign' => CRM_Mailjet_BAO_Event::getMailjetCustomCampaignId($mailingId)
'custom_campaign' => CRM_Mailjet_BAO_Event::getMailjetCustomCampaignId($jobId)
);
$response = $mj->messageList($mailJetParams);
if(!empty($response)){
Expand All @@ -51,6 +56,8 @@ function mailjet_civicrm_pageRun(&$page) {
}
}
}
}
}
CRM_Core_Region::instance('page-header')->add(array(
'template' => 'CRM/Mailjet/Page/Report.tpl',
));
Expand Down

0 comments on commit 446825e

Please sign in to comment.