From: Allen Shaw Date: Sun, 30 Sep 2018 00:41:09 +0000 (-0500) Subject: Toward CRM-19751: change db scmema so on_hold is INT instead of BOOLEAN. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f61d1b83fdca7d106edcc212009747eb3932153d;p=civicrm-core.git Toward CRM-19751: change db scmema so on_hold is INT instead of BOOLEAN. --- diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index e5db7e134d..d738d945e7 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -5974,7 +5974,15 @@ AND displayRelType.is_active = 1 $wc = "contact_a.$fieldName"; } else { - $wc = "$tableName.id"; + // Special handling for on_hold, so that we actually use the 'where' + // property in order to limit the query by the on_hold status of the email, + // instead of using email.id which would be nonsensical. + if ($field['name'] == 'on_hold') { + $wc = "{$field['where']}"; + } + else { + $wc = "$tableName.id"; + } } } else { diff --git a/CRM/Core/DAO/Email.php b/CRM/Core/DAO/Email.php index 9d7d24eba2..1901e047af 100644 --- a/CRM/Core/DAO/Email.php +++ b/CRM/Core/DAO/Email.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/Email.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:08f53d44527d7d174b4aa1bd545b028c) + * (GenCodeChecksum:efd9de6842b24f9800e2a65fd2199cf4) */ /** @@ -71,9 +71,9 @@ class CRM_Core_DAO_Email extends CRM_Core_DAO { public $is_billing; /** - * Is this address on bounce hold? + * Implicit FK to civicrm_option_value where option_group = email_on_hold. * - * @var boolean + * @var int unsigned */ public $on_hold; @@ -228,9 +228,9 @@ class CRM_Core_DAO_Email extends CRM_Core_DAO { ], 'on_hold' => [ 'name' => 'on_hold', - 'type' => CRM_Utils_Type::T_BOOLEAN, + 'type' => CRM_Utils_Type::T_INT, 'title' => ts('On Hold'), - 'description' => 'Is this address on bounce hold?', + 'description' => 'Implicit FK to civicrm_option_value where option_group = email_on_hold.', 'required' => TRUE, 'export' => TRUE, 'where' => 'civicrm_email.on_hold', @@ -242,8 +242,11 @@ class CRM_Core_DAO_Email extends CRM_Core_DAO { 'bao' => 'CRM_Core_BAO_Email', 'localizable' => 0, 'html' => [ - 'type' => 'CheckBox', + 'type' => 'Select', ], + 'pseudoconstant' => [ + 'callback' => 'CRM_Core_PseudoConstant::emailOnHoldOptions', + ] ], 'is_bulkmail' => [ 'name' => 'is_bulkmail', diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 5cef5e081e..a9c213ee59 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -1571,4 +1571,17 @@ WHERE id = %1 return Civi::$statics[__CLASS__]['taxRates']; } + /** + * Get participant status class options. + * + * @return array + */ + public static function emailOnHoldOptions() { + return array( + '0' => ts('No'), + '1' => ts('On Hold Bounce'), + '2' => ts('On Hold Opt Out'), + ); + } + } diff --git a/tests/phpunit/CRM/Core/BAO/EmailTest.php b/tests/phpunit/CRM/Core/BAO/EmailTest.php index b2abc69c66..a97290d2fa 100644 --- a/tests/phpunit/CRM/Core/BAO/EmailTest.php +++ b/tests/phpunit/CRM/Core/BAO/EmailTest.php @@ -70,7 +70,7 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { 'Database check for created email address.' ); - // Now call add() to update on_hold=true and check record state + // Now call add() to update on_hold=1 ("On Hold Bounce") and check record state $params = array(); $params = array( 'id' => $emailId, @@ -94,7 +94,31 @@ class CRM_Core_BAO_EmailTest extends CiviUnitTestCase { 'Check if on_hold=1 in updated email record.' ); - // Now call add() with on_hold=false and verify that reset_date is set. + // Now call add() to update on_hold=2 ("On Hold Opt-out") and check record state + $params = array(); + $params = array( + 'id' => $emailId, + 'contact_id' => $contactId, + 'on_hold' => 2, + ); + + CRM_Core_BAO_Email::add($params); + + // Use assertDBNotNull to get back value of hold_date and check that it's in the current year. + // NOTE: The assertEquals will fail IF this test is run just as the year is changing (low likelihood). + $holdDate = $this->assertDBNotNull('CRM_Core_DAO_Email', $emailId, 'hold_date', 'id', + 'Retrieve hold_date from the updated email record.' + ); + + $this->assertEquals(substr($holdDate, 0, 4), substr(date('YmdHis'), 0, 4), + 'Compare hold_date (' . $holdDate . ') in DB to current year.' + ); + + $this->assertDBCompareValue('CRM_Core_DAO_Email', $emailId, 'on_hold', 'id', 2, + 'Check if on_hold=2 in updated email record.' + ); + + // Now call add() with on_hold=null (not on hold) and verify that reset_date is set. $params = array(); $params = array( 'id' => $emailId, diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php index e480e78042..8214dfaf00 100644 --- a/tests/phpunit/api/v3/MailingTest.php +++ b/tests/phpunit/api/v3/MailingTest.php @@ -356,7 +356,7 @@ class api_v3_MailingTest extends CiviUnitTestCase { )); $this->callAPISuccess('Email', 'create', array( 'id' => $emailId, - 'on_hold' => TRUE, + 'on_hold' => 1, )); $this->callAPISuccess('GroupContact', 'create', array( diff --git a/xml/schema/Core/Email.xml b/xml/schema/Core/Email.xml index bc9cedb877..c9881ac4f8 100644 --- a/xml/schema/Core/Email.xml +++ b/xml/schema/Core/Email.xml @@ -109,14 +109,18 @@ on_hold + On Hold true - boolean + int unsigned 0 true - Is this address on bounce hold? + Implicit FK to civicrm_option_value where option_group = email_on_hold. + + CRM_Core_PseudoConstant::emailOnHoldOptions + 1.1 - CheckBox + Select