From 1107b319e0d517f72a2a15f4828f0cd5ba670e83 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 7 Sep 2019 08:11:32 +1000 Subject: [PATCH 1/4] Fix deleting of campaigns and saving of custom data for campaign and also ensure that goal_general is not html encoded as it is a wysiwyg field --- CRM/Campaign/Form/Campaign.php | 15 ++++++++++----- CRM/Utils/API/HTMLInputCoder.php | 2 ++ tests/phpunit/CRM/Campaign/Form/CampaignTest.php | 1 - 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CRM/Campaign/Form/Campaign.php b/CRM/Campaign/Form/Campaign.php index 813d34005586..1723cefa9326 100644 --- a/CRM/Campaign/Form/Campaign.php +++ b/CRM/Campaign/Form/Campaign.php @@ -165,6 +165,7 @@ public function setDefaultValues() { } public function buildQuickForm() { + $this->add('hidden', 'id', $this->_campaignId); if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons([ @@ -186,7 +187,6 @@ public function buildQuickForm() { //lets assign custom data type and subtype. $this->assign('customDataType', 'Campaign'); $this->assign('entityID', $this->_campaignId); - $this->assign('id', $this->_campaignId); $this->assign('customDataSubType', CRM_Utils_Array::value('campaign_type_id', $this->_values)); $attributes = CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Campaign'); @@ -292,14 +292,18 @@ public function postProcess() { $session = CRM_Core_Session::singleton(); $params = $this->controller->exportValues($this->_name); - if (isset($this->_campaignId)) { + // To properly save the DAO we need to ensure we don't have a blank id key passed through. + if (empty($params['id'])) { + unset($params['id']); + } + if (!empty($params['id'])) { if ($this->_action & CRM_Core_Action::DELETE) { - CRM_Campaign_BAO_Campaign::del($this->_campaignId); + CRM_Campaign_BAO_Campaign::del($params['id']); CRM_Core_Session::setStatus(ts('Campaign has been deleted.'), ts('Record Deleted'), 'success'); $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=campaign')); return; } - $params['id'] = $this->_campaignId; + $this->_campaignId = $params['id']; } else { $params['created_id'] = $session->get('userID'); @@ -328,7 +332,7 @@ public function postProcess() { public static function submit($params = [], $form) { $groups = []; - if (is_array($params['includeGroups'])) { + if (!empty($params['includeGroups']) && is_array($params['includeGroups'])) { foreach ($params['includeGroups'] as $key => $id) { if ($id) { $groups['include'][] = $id; @@ -355,6 +359,7 @@ public static function submit($params = [], $form) { $form->_campaignId, 'Campaign' ); + // dev/core#1067 Clean Money before passing onto BAO to do the create. $params['goal_revenue'] = CRM_Utils_Rule::cleanMoney($params['goal_revenue']); $result = civicrm_api3('Campaign', 'create', $params); diff --git a/CRM/Utils/API/HTMLInputCoder.php b/CRM/Utils/API/HTMLInputCoder.php index bc9a2b51810b..c0f5cdecc8cb 100644 --- a/CRM/Utils/API/HTMLInputCoder.php +++ b/CRM/Utils/API/HTMLInputCoder.php @@ -119,6 +119,8 @@ public function getSkipFields() { 'operator', // CRM-20468 'content', + // CiviCampaign Goal Details + 'goal_general', ]; $custom = CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_custom_field WHERE html_type = "RichTextEditor"'); while ($custom->fetch()) { diff --git a/tests/phpunit/CRM/Campaign/Form/CampaignTest.php b/tests/phpunit/CRM/Campaign/Form/CampaignTest.php index 0750a5038cc1..2c3d71a65c5b 100644 --- a/tests/phpunit/CRM/Campaign/Form/CampaignTest.php +++ b/tests/phpunit/CRM/Campaign/Form/CampaignTest.php @@ -55,7 +55,6 @@ public function testSubmit($thousandSeparator) { 'custom' => [], 'campaign_type_id' => 1, ], $form); - var_dump($form); $campaign = $this->callAPISuccess('campaign', 'get', ['id' => $result['id']]); $this->assertEquals('10000', $campaign['values'][$campaign['id']]['goal_revenue']); } From 382c48e1be3d167c5f294e919c64b22f43d78689 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 6 Sep 2019 15:12:00 -0700 Subject: [PATCH 2/4] SyntaxConformanceTest::testSqlOperators - Skip "Dedupe" entity on MySQL 5.5 Overview -------- This disables a particularly flaky test-scenario. Technical Details ----------------- The `SyntaxConformanceTest::testSqlOperators()` has been rather flaky for a while. (I think this goes back either to the creation of the test or the expansion of Dedupe API -- in other words, the test of this scenario has always been flaky.) When the test fails, it looks like this: ``` api_v3_SyntaxConformanceTest::testSqlOperators with data set #28 ('Dedupe') incorrect count returned from Dedupe getcount Failed asserting that 0 matches expected 2. /home/jenkins/bknix-min/build/build-1/web/sites/all/modules/civicrm/Civi/Test/Api3TestTrait.php:191 /home/jenkins/bknix-min/build/build-1/web/sites/all/modules/civicrm/tests/phpunit/api/v3/SyntaxConformanceTest.php:1131 /home/jenkins/bknix-min/build/build-1/web/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php:215 /home/jenkins/bknix-min/civicrm-buildkit/extern/phpunit6/phpunit6.phar:570 ``` I've spent a chunk of time investigating the flakiness and found: 1. The test usually (possibly always?) passes on MySQL 5.7. 2. The test often (but not always) fails on MySQL 5.5. 3. The version of PHP (php70 vs php72) does not make much difference. 4. The test never seems to fail when run by itself. The smallest scenario which seemd to reliably produce the failure was: ``` env SYNTAX_CONFORMANCE_ENTITIES='ContactType Country Dedupe Domain StateProvince' \ CIVICRM_UF=UnitTests \ phpunit5 \ --stop-on-failure --tap \ tests/phpunit/api/v3/SyntaxConformanceTest.php \ --filter '(testCustomDataGet|testLimit|testSqlOperators)' ``` 5. The reproducibility differed on two laptops. The laptops were largely identical wrt PHP/MySQL binaries+configuration (macOS, bknix@master-loco, `min` cfg). They differed in OS version and hardware specs. The slower machine (low-wattage 2-core CPU; 8gb; Mojave) produced test-failures much more reliably than the faster machine (high-wattage 4-core CPU; 16gb; Sierra). Rationalizations for why it's OK to sip: * The test will continue to be monitored on MySQL 5.7+. * The test *does* pass reliably when run by itself on MySQL 5.5. * [Civi doesn't officially support MySQL 5.5](https://docs.civicrm.org/sysadmin/en/latest/requirements/#mysql-version), so we're not required to faff-about over a failure that only occurs on MySQL 5.5. See also: https://chat.civicrm.org/civicrm/pl/s7nbkro8yjfgzk5z4epo8g9jph --- tests/phpunit/api/v3/SyntaxConformanceTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 49c9976d5441..3388b3e48561 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -583,6 +583,15 @@ public static function toBeSkipped_getSqlOperators() { //a bit of a pseudoapi - keys by domain 'Setting', ]; + + // The testSqlOperators fails sporadically on MySQL 5.5, which is deprecated anyway. + // Test data providers should be able to run in pre-boot environment, so we connect directly to SQL server. + require_once 'DB.php'; + $db = DB::connect(CIVICRM_DSN); + if ($db->connection instanceof mysqli && $db->connection->server_version < 50600) { + $entitiesWithout[] = 'Dedupe'; + } + return $entitiesWithout; } From a98c8ecb87633bd27103ac11fec9643ba3418d6e Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 7 Sep 2019 11:09:49 +1200 Subject: [PATCH 3/4] dev/core#1236 fix miscasting on setContactSubType I think it makes sense to cast here rather than require a string --- CRM/Import/ImportProcessor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRM/Import/ImportProcessor.php b/CRM/Import/ImportProcessor.php index 4cd1d9b256e7..79ddc3b640e3 100644 --- a/CRM/Import/ImportProcessor.php +++ b/CRM/Import/ImportProcessor.php @@ -112,8 +112,8 @@ public function getContactSubType(): string { * * @param string $contactSubType */ - public function setContactSubType(string $contactSubType) { - $this->contactSubType = $contactSubType; + public function setContactSubType($contactSubType) { + $this->contactSubType = (string) $contactSubType; } /** From 7d1e62951150da184c965c6462625148e3b698d3 Mon Sep 17 00:00:00 2001 From: yashodha Date: Thu, 5 Sep 2019 18:41:22 +0530 Subject: [PATCH 4/4] (dev/core#1065) fix condition so that the contact field appears for standalone/tab context for create mode fix for create grant from tab --- CRM/Grant/Form/Grant.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CRM/Grant/Form/Grant.php b/CRM/Grant/Form/Grant.php index d03961fb02e1..de05a0c7cb8d 100644 --- a/CRM/Grant/Form/Grant.php +++ b/CRM/Grant/Form/Grant.php @@ -142,6 +142,11 @@ public function setDefaultValues() { $defaults['amount_granted'] = CRM_Utils_Money::format($defaults['amount_granted'], NULL, '%a'); } } + else { + if ($this->_contactID) { + $defaults['contact_id'] = $this->_contactID; + } + } return $defaults; }