Fix deleting of campaigns and saving of custom data for campaign and also ensure...
authorSeamus Lee <seamuslee001@gmail.com>
Fri, 6 Sep 2019 22:11:32 +0000 (08:11 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Sat, 7 Sep 2019 21:48:08 +0000 (07:48 +1000)
CRM/Campaign/Form/Campaign.php
CRM/Utils/API/HTMLInputCoder.php
tests/phpunit/CRM/Campaign/Form/CampaignTest.php

index 813d34005586eaef82181d552c1bdd3dac01e8c2..1723cefa932658a690ef5ce374b7fb888378f03b 100644 (file)
@@ -165,6 +165,7 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
   }
 
   public function buildQuickForm() {
+    $this->add('hidden', 'id', $this->_campaignId);
     if ($this->_action & CRM_Core_Action::DELETE) {
 
       $this->addButtons([
@@ -186,7 +187,6 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
     //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 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
 
     $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 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_Form {
 
   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 @@ class CRM_Campaign_Form_Campaign extends CRM_Core_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);
index bc9a2b51810b789435eb9bc0fe0faa3ba039083d..c0f5cdecc8cb3ab9c18adfeebe9ef12d40fb0437 100644 (file)
@@ -119,6 +119,8 @@ class CRM_Utils_API_HTMLInputCoder extends CRM_Utils_API_AbstractFieldCoder {
         '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()) {
index 0750a5038cc168c3a4b7b679d6b868b154d794c8..2c3d71a65c5b52cb91d7e4a494f9162d6bbb675c 100644 (file)
@@ -55,7 +55,6 @@ class CRM_Campaign_Form_CampaignTest extends CiviUnitTestCase {
       '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']);
   }