Skip to content

Commit

Permalink
Merge pull request #10159 from colemanw/CRM-20425
Browse files Browse the repository at this point in the history
CRM-20425 - Configure inbound email activity status
  • Loading branch information
colemanw authored May 10, 2017
2 parents b5f9f5f + 040073c commit 43ce5c7
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 8 deletions.
22 changes: 22 additions & 0 deletions CRM/Admin/Form/MailSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function buildQuickForm() {
0 => ts('Email-to-Activity Processing'),
);
$this->add('select', 'is_default', ts('Used For?'), $usedfor);
$this->addField('activity_status', array('placeholder' => FALSE));
}

/**
Expand All @@ -94,6 +95,26 @@ public function addRules() {
$this->addFormRule(array('CRM_Admin_Form_MailSettings', 'formRule'));
}

public function getDefaultEntity() {
return 'MailSettings';
}

/**
* Add local and global form rules.
*/
public function setDefaultValues() {
$defaults = parent::setDefaultValues();

// Set activity status to "Completed" by default.
if ($this->_action != CRM_Core_Action::DELETE &&
(!$this->_id || !CRM_Core_DAO::getFieldValue('CRM_Core_BAO_MailSettings', $this->_id, 'activity_status'))
) {
$defaults['activity_status'] = 'Completed';
}

return $defaults;
}

/**
* Global validation rules for the form.
*
Expand Down Expand Up @@ -140,6 +161,7 @@ public function postProcess() {
'source',
'is_ssl',
'is_default',
'activity_status',
);

$params = array();
Expand Down
28 changes: 27 additions & 1 deletion CRM/Core/DAO/MailSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* Generated from xml/schema/CRM/Core/MailSettings.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:739e36d6ca1f8572f5f9eff77975765e)
* (GenCodeChecksum:86515d7cb55425fbad3a71d5aa000af0)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
Expand Down Expand Up @@ -134,6 +134,12 @@ class CRM_Core_DAO_MailSettings extends CRM_Core_DAO {
* @var string
*/
public $source;
/**
* Name of status to use when creating email to activity.
*
* @var string
*/
public $activity_status;
/**
* Class constructor.
*/
Expand Down Expand Up @@ -336,6 +342,26 @@ static function &fields() {
'bao' => 'CRM_Core_BAO_MailSettings',
'localizable' => 0,
) ,
'activity_status' => array(
'name' => 'activity_status',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Activity Status') ,
'description' => 'Name of status to use when creating email to activity.',
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_mail_settings',
'entity' => 'MailSettings',
'bao' => 'CRM_Core_BAO_MailSettings',
'localizable' => 0,
'html' => array(
'type' => 'Select',
) ,
'pseudoconstant' => array(
'optionGroupName' => 'activity_status',
'keyColumn' => 'name',
'optionEditPath' => 'civicrm/admin/options/activity_status',
)
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
Expand Down
14 changes: 9 additions & 5 deletions CRM/Upgrade/Incremental/php/FourSeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,13 @@ public function upgrade_4_7_18($rev) {
* @param string $rev
*/
public function upgrade_4_7_19($rev) {
$query = "SELECT id FROM civicrm_financial_account WHERE opening_balance <> 0 OR current_period_opening_balance <> 0";
$result = CRM_Core_DAO::executeQuery($query);
if (!$result->N) {
$this->addTask('Drop Column current_period_opening_balance From civicrm_financial_account table.', 'dropColumn', 'civicrm_financial_account', 'current_period_opening_balance');
$this->addTask('Drop Column opening_balance From civicrm_financial_account table.', 'dropColumn', 'civicrm_financial_account', 'opening_balance');
if (CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_financial_account', 'opening_balance')) {
$query = "SELECT id FROM civicrm_financial_account WHERE opening_balance <> 0 OR current_period_opening_balance <> 0";
$result = CRM_Core_DAO::executeQuery($query);
if (!$result->N) {
$this->addTask('Drop Column current_period_opening_balance From civicrm_financial_account table.', 'dropColumn', 'civicrm_financial_account', 'current_period_opening_balance');
$this->addTask('Drop Column opening_balance From civicrm_financial_account table.', 'dropColumn', 'civicrm_financial_account', 'opening_balance');
}
}
$this->addTask('CRM-19961 - Add domain_id column to civicrm_sms_provider', 'addColumn',
'civicrm_sms_provider', 'domain_id', 'int(10) unsigned', "Which Domain is this sms provier for");
Expand All @@ -354,6 +356,8 @@ public function upgrade_4_7_19($rev) {
public function upgrade_4_7_20($rev) {
$this->addtask('Fix Schema on civicrm_action_schedule', 'fixSchemaOnCiviCRMActionSchedule');
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
$this->addTask('Add activity_status column to civicrm_mail_settings', 'addColumn',
'civicrm_mail_settings', 'activity_status', "varchar (255) DEFAULT NULL COMMENT 'Name of status to use when creating email to activity.'");
}

/*
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/DeprecatedUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ function _civicrm_api3_deprecated_activity_buildmailparams($result, $activityTyp

$params['activity_type_id'] = $activityTypeID;

$params['status_id'] = 2;
$params['status_id'] = 'Completed';
if (!empty($result['from']['id'])) {
$params['source_contact_id'] = $params['assignee_contact_id'] = $result['from']['id'];
}
Expand Down
5 changes: 4 additions & 1 deletion CRM/Utils/Mail/EmailProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static function process($civiMail = TRUE) {

/**
* @param $civiMail
* @param CRM_Core_DAO $dao
* @param CRM_Core_DAO_MailSettings $dao
* @param bool $is_create_activities
* Create activities.
*
Expand Down Expand Up @@ -247,6 +247,9 @@ public static function _process($civiMail, $dao, $is_create_activities) {
$params = _civicrm_api3_deprecated_activity_buildmailparams($mailParams, $emailActivityTypeId);

$params['version'] = 3;
if (!empty($dao->activity_status)) {
$params['status_id'] = $dao->activity_status;
}
$result = civicrm_api('activity', 'create', $params);

if ($result['is_error']) {
Expand Down
13 changes: 13 additions & 0 deletions templates/CRM/Admin/Form/MailSettings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,20 @@

<tr class="crm-mail-settings-form-block-is_default"><td class="label">{$form.is_default.label}</td><td>{$form.is_default.html}</td></tr>
<tr><td class="label">&nbsp;</td><td class="description">{ts}How this mail account will be used. Only one box may be used for bounce processing. It will also be used as the envelope email when sending mass mailings.{/ts}</td></tr>

<tr class="crm-mail-settings-form-block-activity_status"><td class="label">{$form.activity_status.label}</td><td>{$form.activity_status.html}</td></tr>
</table>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
{/if}
</div>
{literal}
<script type="text/javascript">
CRM.$(function($) {
var $form = $('form.{/literal}{$form.formClass}{literal}');
function showActivityStatus() {
$('.crm-mail-settings-form-block-activity_status', $form).toggle($(this).val() === '0');
}
$('select[name=is_default]').each(showActivityStatus).change(showActivityStatus);
});
</script>
{/literal}
15 changes: 15 additions & 0 deletions xml/schema/Core/MailSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,19 @@
<comment>folder to poll from when using IMAP, path to poll from when using Maildir, etc.</comment>
<add>2.2</add>
</field>
<field>
<name>activity_status</name>
<title>Activity Status</title>
<type>varchar</type>
<length>255</length>
<comment>Name of status to use when creating email to activity.</comment>
<add>4.7</add>
<pseudoconstant>
<optionGroupName>activity_status</optionGroupName>
<keyColumn>name</keyColumn>
</pseudoconstant>
<html>
<type>Select</type>
</html>
</field>
</table>

0 comments on commit 43ce5c7

Please sign in to comment.