Merge pull request #16353 from pradpnayak/functionFix
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 23 Jan 2020 21:15:22 +0000 (10:15 +1300)
committerGitHub <noreply@github.com>
Thu, 23 Jan 2020 21:15:22 +0000 (10:15 +1300)
Wrong parameter passed to executeQuery function

13 files changed:
CRM/ACL/BAO/ACL.php
CRM/Case/Form/Case.php
CRM/Contact/BAO/Relationship.php
CRM/Contribute/BAO/Contribution.php
CRM/Core/Form/EntityFormTrait.php
CRM/Custom/Form/CustomData.php
CRM/Dashlet/Page/GettingStarted.php
CRM/Event/Form/Participant.php
CRM/Utils/System.php
Civi/ActionSchedule/RecipientBuilder.php
templates/CRM/Activity/Form/Activity.tpl
tests/phpunit/api/v3/EventTest.php
tests/phpunit/api/v3/JobTest.php

index c73f92d33c3211ad2535d803ca780e08d46b13ab..02e2b0db4fbace2f70d52d91aaa6c6c29b0241ba 100644 (file)
@@ -34,6 +34,7 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL {
    * @return array|null
    */
   public static function entityTable() {
+    CRM_Core_Error::deprecatedFunctionWarning('unused function to be removed');
     if (!self::$_entityTable) {
       self::$_entityTable = [
         'civicrm_contact' => ts('Contact'),
@@ -47,6 +48,7 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL {
    * @return array|null
    */
   public static function objectTable() {
+    CRM_Core_Error::deprecatedFunctionWarning('unused function to be removed');
     if (!self::$_objectTable) {
       self::$_objectTable = [
         'civicrm_contact' => ts('Contact'),
@@ -59,7 +61,9 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL {
   }
 
   /**
-   * @return array|null
+   * Available operations for  pseudoconstant.
+   *
+   * @return array
    */
   public static function operation() {
     if (!self::$_operation) {
@@ -92,6 +96,7 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL {
    * @throws \CRM_Core_Exception
    */
   public static function getClause($table, $id, &$tables) {
+    CRM_Core_Error::deprecatedFunctionWarning('unused function to be removed');
     $table = CRM_Utils_Type::escape($table, 'String');
     $id = CRM_Utils_Type::escape($id, 'Integer');
     $whereTables = [];
@@ -150,7 +155,7 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL {
    *
    * @throws \CRM_Core_Exception
    */
-  public static function getACLs($contact_id = NULL) {
+  protected static function getACLs($contact_id = NULL) {
     $results = [];
 
     if (empty($contact_id)) {
@@ -196,7 +201,7 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL {
    *
    * @throws \CRM_Core_Exception
    */
-  public static function getACLRoles($contact_id = NULL) {
+  protected static function getACLRoles($contact_id = NULL) {
     $contact_id = CRM_Utils_Type::escape($contact_id, 'Integer');
 
     $rule = new CRM_ACL_BAO_ACL();
@@ -233,7 +238,7 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL {
    *   Assoc array of ACL rules
    * @throws \CRM_Core_Exception
    */
-  public static function getGroupACLs($contact_id, $aclRoles = FALSE) {
+  protected static function getGroupACLs($contact_id, $aclRoles = FALSE) {
     $contact_id = CRM_Utils_Type::escape($contact_id, 'Integer');
 
     $rule = new CRM_ACL_BAO_ACL();
@@ -278,7 +283,7 @@ SELECT      acl.*
    *   Array of assoc. arrays of ACL rules
    * @throws \CRM_Core_Exception
    */
-  public static function getGroupACLRoles($contact_id) {
+  protected static function getGroupACLRoles($contact_id) {
     $contact_id = CRM_Utils_Type::escape($contact_id, 'Integer');
 
     $rule = new CRM_ACL_BAO_ACL();
@@ -632,7 +637,7 @@ ORDER BY a.object_id
    *
    * @return bool
    */
-  public static function matchType($type, $operation) {
+  protected static function matchType($type, $operation) {
     $typeCheck = FALSE;
     switch ($operation) {
       case 'All':
index 0d43ed1912af147d4d6b7bbe35ad5631692e09a4..05e832c744544b54dee470f810876e9d74bd7a29 100644 (file)
@@ -93,20 +93,6 @@ class CRM_Case_Form_Case extends CRM_Core_Form {
     return $this->_caseId;
   }
 
-  /**
-   * Get the entity subtype ID being edited
-   *
-   * @param $subTypeId
-   *
-   * @return int|null
-   */
-  public function getEntitySubTypeId($subTypeId) {
-    if ($subTypeId) {
-      return $subTypeId;
-    }
-    return $this->_caseTypeId;
-  }
-
   /**
    * Build the form object.
    */
index 325ce00de6180eda7e9e47e253461f09e77f703a..a88193f071fb94d6ef8faea177775e0cc23b978c 100644 (file)
@@ -834,7 +834,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    * @param int $id
    *   Relationship id.
    *
-   * $returns  returns the contact ids in the realtionship
+   * $returns  returns the contact ids in the relationship
    *
    * @return \CRM_Contact_DAO_Relationship
    */
index cf299da456b2cb7badf4dea0753f811af77c4108..9d7873f2457f15ce55e4f3c8629db21fcb5401c1 100644 (file)
@@ -954,7 +954,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
   }
 
   /**
-   * Get memberships realted to the contribution.
+   * Get memberships related to the contribution.
    *
    * @param int $contributionID
    *
index 61b800205de26f4a18f90cc925b85510483c8485..15ff60830a797184fd2a658b2b88cbc2937a128b 100644 (file)
@@ -21,7 +21,7 @@ trait CRM_Core_Form_EntityFormTrait {
    *
    * @var int
    */
-  protected $_entitySubTypeId;
+  protected $_entitySubTypeId = NULL;
 
   /**
    * Get entity fields for the entity to be added to the form.
@@ -83,17 +83,21 @@ trait CRM_Core_Form_EntityFormTrait {
   /**
    * Get the entity subtype ID being edited
    *
-   * @param $subTypeId
-   *
    * @return int|null
    */
-  public function getEntitySubTypeId($subTypeId) {
-    if ($subTypeId) {
-      return $subTypeId;
-    }
+  public function getEntitySubTypeId() {
     return $this->_entitySubTypeId;
   }
 
+  /**
+   * Set the entity subtype ID being edited
+   *
+   * @param $subTypeId
+   */
+  public function setEntitySubTypeId($subTypeId) {
+    $this->_entitySubTypeId = $subTypeId;
+  }
+
   /**
    * If the custom data is in the submitted data (eg. added via ajax loaded form) add to form.
    */
@@ -103,7 +107,7 @@ trait CRM_Core_Form_EntityFormTrait {
     }
     $customisableEntities = CRM_Core_SelectValues::customGroupExtends();
     if (isset($customisableEntities[$this->getDefaultEntity()])) {
-      CRM_Custom_Form_CustomData::addToForm($this);
+      CRM_Custom_Form_CustomData::addToForm($this, $this->getEntitySubTypeId());
     }
   }
 
index 8bdc0d79ace599299bbaa2604c471cfc1424ae78..e502c72e15b1ffb03bfe191184ec4279f9551901 100644 (file)
@@ -29,7 +29,7 @@ class CRM_Custom_Form_CustomData {
    *   $params['custom'] = CRM_Core_BAO_CustomField::postProcess($submitted, $this->_id, $this->getDefaultEntity());
    *
    * @param CRM_Core_Form $form
-   * @param null|string $subType values stored in civicrm_custom_group.extends_entity_column_value
+   * @param null|string $entitySubType values stored in civicrm_custom_group.extends_entity_column_value
    *   e.g Student for contact type
    * @param null|string $subName value in civicrm_custom_group.extends_entity_column_id
    * @param null|int $groupCount number of entities that could have custom data
@@ -37,15 +37,12 @@ class CRM_Custom_Form_CustomData {
    *
    * @throws \CRM_Core_Exception
    */
-  public static function addToForm(&$form, $subType = NULL, $subName = NULL, $groupCount = 1, $contact_id = NULL) {
+  public static function addToForm(&$form, $entitySubType = NULL, $subName = NULL, $groupCount = 1, $contact_id = NULL) {
     $entityName = $form->getDefaultEntity();
     $entityID = $form->getEntityId();
-    // FIXME: If the form has been converted to use entityFormTrait then getEntitySubTypeId() will exist.
-    // However, if it is only partially converted (ie. we've switched customdata to use CRM_Custom_Form_CustomData)
-    // it won't, so we check if we have a subtype before calling the function.
-    $entitySubType = NULL;
-    if ($subType) {
-      $entitySubType = $form->getEntitySubTypeId($subType);
+    // If the form has been converted to use entityFormTrait then getEntitySubTypeId() will exist.
+    if (method_exists($form, 'getEntitySubTypeId') && empty($entitySubType)) {
+      $entitySubType = $form->getEntitySubTypeId();
     }
 
     if ($form->getAction() == CRM_Core_Action::VIEW) {
index 7ce121fa69eaacf25d2af163cdd0369977b1ab17..f09a490f7e86944eced5c847ce8ea63f7c8ef586 100644 (file)
@@ -72,13 +72,15 @@ class CRM_Dashlet_Page_GettingStarted extends CRM_Core_Page {
    * @return array
    */
   private function _gettingStarted() {
-    $value = Civi::cache('community_messages')->get('dashboard_gettingStarted');
+    $tsLocale = CRM_Core_I18n::getLocale();
+    $key = 'dashboard_gettingStarted_' . $tsLocale;
+    $value = Civi::cache('community_messages')->get($key);
 
     if (!$value) {
       $value = $this->_getHtml($this->gettingStartedUrl());
 
       if ($value) {
-        Civi::cache('community_messages')->set('dashboard_gettingStarted', $value, (60 * 60 * 24 * self::CACHE_DAYS));
+        Civi::cache('community_messages')->set($key, $value, (60 * 60 * 24 * self::CACHE_DAYS));
       }
     }
 
index 365a19bbde0eb31b346084d764a62413700620ea..302b0a412b0aeb89da18028955b866d5958c2927 100644 (file)
@@ -1328,6 +1328,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
             $contributionParams['partial_payment_total'] = $amountOwed;
             // the actual amount paid
             $contributionParams['partial_amount_to_pay'] = $params['total_amount'];
+            $this->assign('balanceAmount', $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_to_pay']);
           }
         }
 
@@ -1431,11 +1432,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         }
 
         $this->assign('totalAmount', $contributionParams['total_amount']);
-        if (isset($contributionParams['partial_payment_total'])) {
-          // balance amount
-          $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_to_pay'];
-          $this->assign('balanceAmount', $balanceAmount);
-        }
         $this->assign('isPrimary', 1);
         $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
       }
index c72f5ea8ebfccf6114fb6b8ab6b685340e32919e..29b043f1568eff6d62002f278ac4c0fdba52e5f6 100644 (file)
@@ -1786,13 +1786,14 @@ class CRM_Utils_System {
     }
     else {
       $config = CRM_Core_Config::singleton();
+      $tsLocale = CRM_Core_I18n::getLocale();
       $vars = [
         '{ver}' => CRM_Utils_System::version(),
         '{uf}' => $config->userFramework,
         '{php}' => phpversion(),
         '{sid}' => self::getSiteID(),
         '{baseUrl}' => $config->userFrameworkBaseURL,
-        '{lang}' => $config->lcMessages,
+        '{lang}' => $tsLocale,
         '{co}' => $config->defaultContactCountry,
       ];
       return strtr($url, array_map('urlencode', $vars));
index cb267eac2d378f15a74b4c02aa7f64252a647dcd..a54bca3b83ea1ccb150c94f8218498c7f14c4fd9 100644 (file)
@@ -138,7 +138,7 @@ class RecipientBuilder {
   public function build() {
     $this->buildRelFirstPass();
 
-    if ($this->prepareAddlFilter('c.id')) {
+    if ($this->prepareAddlFilter('c.id') && $this->notTemplate()) {
       $this->buildAddlFirstPass();
     }
 
@@ -603,4 +603,25 @@ reminder.action_schedule_id = {$this->actionSchedule->id}";
     return $this->mapping->resetOnTriggerDateChange($this->actionSchedule);
   }
 
+  /**
+   * Confirm this object isn't attached to a template.
+   * Returns TRUE if this action schedule isn't attached to a template.
+   * Templates are (currently) unique to events, so we only evaluate those.
+   *
+   * @return bool;
+   */
+  private function notTemplate() {
+    if ($this->mapping->getEntity() === 'civicrm_participant') {
+      $entityId = $this->actionSchedule->entity_value;
+      $query = new \CRM_Utils_SQL_Select('civicrm_event e');
+      $sql = $query
+        ->select('is_template')
+        ->where("e.id = {$entityId}")
+        ->toSQL();
+      $dao = \CRM_Core_DAO::executeQuery($sql);
+      return !(bool) $dao->fetchValue();
+    }
+    return TRUE;
+  }
+
 }
index b56c202ad78a4a63fb68ce9dde175ac78fe88fa2..a013a7cb74a999051f0dfbdf102279a3dd5ddd5c 100644 (file)
       {if $action eq 4}
         {include file="CRM/Custom/Page/CustomDataView.tpl"}
       {else}
-        <div id="customData"></div>
         {include file="CRM/common/customDataBlock.tpl"}
       {/if}
     </td>
index e547da041fcac6e131aba6dcf7fceed307e9f67c..abebea1d530d5ac66da5de142d64246eb84cf910 100644 (file)
@@ -25,7 +25,7 @@ class api_v3_EventTest extends CiviUnitTestCase {
     $this->_params = [
       [
         'title' => 'Annual CiviCRM meet',
-        'summary' => 'If you have any CiviCRM realted issues or want to track where CiviCRM is heading, Sign up now',
+        'summary' => 'If you have any CiviCRM related issues or want to track where CiviCRM is heading, Sign up now',
         'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues',
         'event_type_id' => 1,
         'is_public' => 1,
@@ -42,7 +42,7 @@ class api_v3_EventTest extends CiviUnitTestCase {
       ],
       [
         'title' => 'Annual CiviCRM meet 2',
-        'summary' => 'If you have any CiviCRM realted issues or want to track where CiviCRM is heading, Sign up now',
+        'summary' => 'If you have any CiviCRM related issues or want to track where CiviCRM is heading, Sign up now',
         'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues',
         'event_type_id' => 1,
         'is_public' => 1,
index 54068b40c75e3c468a628fa555ea54de953374f7..57b88cfa4aeb7b6f167ca9a64bb4d92ad6ee7b0f 100644 (file)
@@ -325,6 +325,38 @@ class api_v3_JobTest extends CiviUnitTestCase {
     $this->contactDelete($orgID);
   }
 
+  /**
+   * Event templates should not send reminders to additional contacts.
+   */
+  public function testTemplateRemindAddlContacts() {
+    $contactId = $this->individualCreate();
+    $groupId = $this->groupCreate(['name' => 'Additional Contacts', 'title' => 'Additional Contacts']);
+    $this->callAPISuccess('GroupContact', 'create', [
+      'contact_id' => $contactId,
+      'group_id' => $groupId,
+    ]);
+    $event = $this->eventCreate(['is_template' => 1, 'template_title' => "I'm a template", 'title' => NULL]);
+    $eventId = $event['id'];
+
+    $actionSchedule = $this->callAPISuccess('action_schedule', 'create', [
+      'title' => "Do not send me",
+      'subject' => "I am a reminder attached to a template.",
+      'entity_value' => $eventId,
+      'mapping_id' => 5,
+      'start_action_date' => 'start_date',
+      'start_action_offset' => 1,
+      'start_action_condition' => 'before',
+      'start_action_unit' => 'day',
+      'group_id' => $groupId,
+      'limit_to' => FALSE,
+      'mode' => 'Email',
+    ]);
+
+    $this->callAPISuccess('job', 'send_reminder', []);
+    $successfulCronCount = CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_action_log");
+    $this->assertEquals(0, $successfulCronCount);
+  }
+
   /**
    * Test scheduled reminders respect limit to (since above identified addition_to handling issue).
    *