/**
  * Example: Run an external SQL script when the module is uninstalled
  **/
 public function uninstall()
 {
     $bounceType = array(1 => array('name' => self::HARD_BOUNCE), 2 => array('name' => self::SOFT_BOUNCE), 3 => array('name' => self::BLOCKED), 4 => array('name' => self::SPAM));
     foreach ($bounceType as $type) {
         $bounceTypeDAO = new CRM_Mailing_DAO_BounceType();
         $bounceTypeDAO->copyValues($type);
         if (!$bounceTypeDAO->find(true)) {
             $bounceTypeDAO->delete();
         }
     }
 }
Пример #2
0
/**
 * Implementation of hook_civicrm_install
 */
function mte_civicrm_install()
{
    $mailingParams = array('subject' => '***All Transactional Emails***', 'name' => ts('Transaction Emails'), 'url_tracking' => TRUE, 'forward_replies' => FALSE, 'auto_responder' => FALSE, 'open_tracking' => TRUE, 'is_completed' => FALSE);
    //create entry in civicrm_mailing
    $mailing = CRM_Mailing_BAO_Mailing::add($mailingParams, CRM_Core_DAO::$_nullArray);
    //add entry in civicrm_mailing_job
    //MTE-17
    $config = CRM_Core_Config::singleton();
    if (property_exists($config, 'civiVersion')) {
        $civiVersion = $config->civiVersion;
    } else {
        $civiVersion = CRM_Core_BAO_Domain::version();
    }
    $jobCLassName = 'CRM_Mailing_DAO_MailingJob';
    if (version_compare('4.4alpha1', $civiVersion) > 0) {
        $jobCLassName = 'CRM_Mailing_DAO_Job';
    }
    $changeENUM = FALSE;
    if (version_compare('4.5alpha1', $civiVersion) > 0) {
        $changeENUM = TRUE;
    }
    CRM_Core_Smarty::singleton()->assign('changeENUM', $changeENUM);
    _mte_civix_civicrm_install();
    $saveJob = new $jobCLassName();
    $saveJob->start_date = $saveJob->end_date = date('YmdHis');
    $saveJob->status = 'Complete';
    $saveJob->job_type = "Special: All transactional emails being sent through Mandrill";
    $saveJob->mailing_id = $mailing->id;
    $saveJob->save();
    // create mailing bounce type
    $mailingBounceType = array('1' => array('name' => 'Mandrill Hard', 'description' => 'Mandrill hard bounce', 'hold_threshold' => 1), '2' => array('name' => 'Mandrill Soft', 'description' => 'Mandrill soft bounce', 'hold_threshold' => 3), '3' => array('name' => 'Mandrill Spam', 'description' => 'User marked a transactional email sent via Mandrill as spam', 'hold_threshold' => 1), '4' => array('name' => 'Mandrill Reject', 'description' => 'Mandrill rejected delivery to this email address', 'hold_threshold' => 1));
    foreach ($mailingBounceType as $value) {
        $bounceType = new CRM_Mailing_DAO_BounceType();
        $bounceType->copyValues($value);
        if (!$bounceType->find(true)) {
            $bounceType->save();
        }
    }
    return TRUE;
}
Пример #3
0
 /**
  * adds $value['foo_display'] for each $value['foo'] enum from civicrm_mailing_bounce_type
  *
  * @param array $values (reference)  the array up for enhancing
  * @return void
  */
 function addDisplayEnums(&$values)
 {
     $enumFields =& CRM_Mailing_DAO_BounceType::getEnums();
     foreach ($enumFields as $enum) {
         if (isset($values[$enum])) {
             $values[$enum . '_display'] = CRM_Mailing_DAO_BounceType::tsEnum($enum, $values[$enum]);
         }
     }
 }
Пример #4
0
 /**
  * Get rows for the event browser
  *
  * @param int $mailing_id       ID of the mailing
  * @param int $job_id           optional ID of the job
  * @param boolean $is_distinct  Group by queue id?
  * @param int $offset           Offset
  * @param int $rowCount         Number of rows
  * @param array $sort           sort array
  *
  * @return array                Result set
  * @access public
  * @static
  */
 public static function &getRows($mailing_id, $job_id = NULL, $is_distinct = FALSE, $offset = NULL, $rowCount = NULL, $sort = NULL)
 {
     $dao = new CRM_Core_Dao();
     $bounce = self::getTableName();
     $bounceType = CRM_Mailing_DAO_BounceType::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_MailingJob::getTableName();
     $contact = CRM_Contact_BAO_Contact::getTableName();
     $email = CRM_Core_BAO_Email::getTableName();
     $query = "\n            SELECT      {$contact}.display_name as display_name,\n                        {$contact}.id as contact_id,\n                        {$email}.email as email,\n                        {$bounce}.time_stamp as date,\n                        {$bounce}.bounce_reason as reason,\n                        {$bounceType}.name as bounce_type\n            FROM        {$contact}\n            INNER JOIN  {$queue}\n                    ON  {$queue}.contact_id = {$contact}.id\n            INNER JOIN  {$email}\n                    ON  {$queue}.email_id = {$email}.id\n            INNER JOIN  {$bounce}\n                    ON  {$bounce}.event_queue_id = {$queue}.id\n            LEFT JOIN   {$bounceType}\n                    ON  {$bounce}.bounce_type_id = {$bounceType}.id\n            INNER JOIN  {$job}\n                    ON  {$queue}.job_id = {$job}.id\n                    AND {$job}.is_test = 0\n            INNER JOIN  {$mailing}\n                    ON  {$job}.mailing_id = {$mailing}.id\n            WHERE       {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
     if (!empty($job_id)) {
         $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
     }
     if ($is_distinct) {
         $query .= " GROUP BY {$queue}.id ";
     }
     $orderBy = "sort_name ASC, {$bounce}.time_stamp DESC";
     if ($sort) {
         if (is_string($sort)) {
             $sort = CRM_Utils_Type::escape($sort, 'String');
             $orderBy = $sort;
         } else {
             $orderBy = trim($sort->orderBy());
         }
     }
     $query .= " ORDER BY {$orderBy} ";
     if ($offset || $rowCount) {
         //Added "||$rowCount" to avoid displaying all records on first page
         $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
     }
     $dao->query($query);
     $results = array();
     while ($dao->fetch()) {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
         $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'type' => empty($dao->bounce_type) ? ts('Unknown') : $dao->bounce_type, 'reason' => $dao->reason, 'date' => CRM_Utils_Date::customFormat($dao->date));
     }
     return $results;
 }
Пример #5
0
 /**
  * @return array
  */
 public function bounce_type()
 {
     $data = array('' => ts('--Please Select--'));
     $bounce_type = new CRM_Mailing_DAO_BounceType();
     $query = "SELECT name FROM civicrm_mailing_bounce_type";
     $bounce_type->query($query);
     while ($bounce_type->fetch()) {
         $data[$bounce_type->name] = $bounce_type->name;
     }
     return $data;
 }
Пример #6
0
 /**
  * Get rows for the event browser
  *
  * @param int $mailing_id       ID of the mailing
  * @param int $job_id           optional ID of the job
  * @param boolean $is_distinct  Group by queue id?
  * @param int $offset           Offset
  * @param int $rowCount         Number of rows
  * @param array $sort           sort array
  * @return array                Result set
  * @access public
  * @static
  */
 function &getRows($mailing_id, $job_id = null, $is_distinct = false, $offset = null, $rowCount = null, $sort = null)
 {
     $dao =& new CRM_Core_Dao();
     $bounce = CRM_Mailing_Event_BAO_Bounce::getTableName();
     $bounceType = CRM_Mailing_DAO_BounceType::getTableName();
     $queue = CRM_Mailing_Event_BAO_Queue::getTableName();
     $mailing = CRM_Mailing_BAO_Mailing::getTableName();
     $job = CRM_Mailing_BAO_Job::getTableName();
     $contact = CRM_Contact_BAO_Contact::getTableName();
     $email = CRM_Core_BAO_Email::getTableName();
     $query = "\n            SELECT      {$contact}.display_name as display_name,\n                        {$contact}.id as contact_id,\n                        {$email}.email as email,\n                        {$bounce}.time_stamp as date,\n                        {$bounce}.bounce_reason as reason,\n                        {$bounceType}.name as bounce_type\n            FROM        {$contact}\n            INNER JOIN  {$queue}\n                    ON  {$queue}.contact_id = {$contact}.id\n            INNER JOIN  {$email}\n                    ON  {$queue}.email_id = {$email}.id\n            INNER JOIN  {$bounce}\n                    ON  {$bounce}.event_queue_id = {$queue}.id\n            LEFT JOIN   {$bounceType}\n                    ON  {$bounce}.bounce_type_id = {$bounceType}.id\n            INNER JOIN  {$job}\n                    ON  {$queue}.job_id = {$job}.id\n            INNER JOIN  {$mailing}\n                    ON  {$job}.mailing_id = {$mailing}.id\n            WHERE       {$mailing}.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer');
     if (!empty($job_id)) {
         $query .= " AND {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
     }
     if ($is_distinct) {
         $query .= " GROUP BY {$queue}.id ";
     }
     $query .= " ORDER BY {$contact}.sort_name, {$bounce}.time_stamp ";
     if ($offset) {
         $query .= ' LIMIT ' . CRM_Utils_Type::escape($offset, 'Integer') . ', ' . CRM_Utils_Type::escape($rowCount, 'Integer');
     }
     $dao->query($query);
     $results = array();
     while ($dao->fetch()) {
         $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$dao->contact_id}");
         $results[] = array('name' => "<a href=\"{$url}\">{$dao->display_name}</a>", 'email' => $dao->email, 'type' => empty($dao->bounce_type) ? ts('Unknown') : $dao->bounce_type, 'reason' => $dao->reason, 'date' => CRM_Utils_Date::customFormat($dao->date));
     }
     return $results;
 }
Пример #7
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['mailing_bounce_type'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Пример #8
0
 function bounce_type()
 {
     require_once 'CRM/Mailing/DAO/BounceType.php';
     $data = array('' => '--Please Select--');
     $bounce_type = new CRM_Mailing_DAO_BounceType();
     $query = "SELECT name FROM civicrm_mailing_bounce_type";
     $bounce_type->query($query);
     while ($bounce_type->fetch()) {
         $data[$bounce_type->name] = $bounce_type->name;
     }
     return $data;
 }