Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal error when sorting by status in activity search #15923

Merged
merged 1 commit into from
Nov 29, 2019

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Nov 21, 2019

Overview

Alternate fix to #15911

Technical Details

This leverages the CRM_Core_DAO::appendPseudoConstantsToFields function (as does Contribution Search) which adds the metadata in a standardised way. It switches to referencing the $key rather than the name as $fields is keyed by uniqueNames & in the case of activity_status_id that is not the same as the field name

@civibot
Copy link

civibot bot commented Nov 21, 2019

(Standard links)

@seamuslee001
Copy link
Contributor

@eileenmcnaughton i think test failures may relate here

@eileenmcnaughton
Copy link
Contributor Author

test this plese

@pfigel
Copy link
Contributor

pfigel commented Nov 22, 2019

@eileenmcnaughton did some r-run on this, and noticed a problem with search builder. On master, two "Activity Status" options are available (one is activity_status_id, the other activity_status). When I filter by "Activity Status = Completed" on master, both options return the expected results. With this patch, the second option (activity_status) doesn't return any results.

@pfigel
Copy link
Contributor

pfigel commented Nov 22, 2019

Also: Thanks for picking this up!

@seamuslee001
Copy link
Contributor

@eileenmcnaughton @pfigel

I managed to resolve the issue and also remove the confusion a little by doing the following

seamus@civicrmdevelopment:~/buildkit/build/47-test/sites/all/modules/civicrm$ git diff
diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php
index 6cea3e0f90..5933b8c491 100644
--- a/CRM/Activity/BAO/Query.php
+++ b/CRM/Activity/BAO/Query.php
@@ -243,6 +243,9 @@ class CRM_Activity_BAO_Query {

       case 'activity_type':
       case 'activity_status':
+        if (is_numeric($value)) {
+          $value = CRM_Core_PseudoConstant::getLabel('CRM_Activity_DAO_Activity', $name . '_id', $value);
+        }
       case 'activity_priority':
         $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$name.label", $op, $value, 'String');
         list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op);
diff --git a/CRM/Activity/DAO/Activity.php b/CRM/Activity/DAO/Activity.php
index d9353fa848..67b634a482 100644
--- a/CRM/Activity/DAO/Activity.php
+++ b/CRM/Activity/DAO/Activity.php
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Activity/Activity.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:fa6ffb0aaff92c8a515aff74919c7ad3)
+ * (GenCodeChecksum:15430e9df92b4942d8836cd4e122ec89)
  */

 /**
@@ -414,7 +414,7 @@ class CRM_Activity_DAO_Activity extends CRM_Core_DAO {
         'activity_status_id' => [
           'name' => 'status_id',
           'type' => CRM_Utils_Type::T_INT,
-          'title' => ts('Activity Status'),
+          'title' => ts('Activity Status ID'),
           'description' => ts('ID of the status this activity is currently in. Foreign key to civicrm_option_value.'),
           'import' => TRUE,
           'where' => 'civicrm_activity.status_id',
diff --git a/xml/schema/Activity/Activity.xml b/xml/schema/Activity/Activity.xml
index 6b6da12249..863f0acda1 100644
--- a/xml/schema/Activity/Activity.xml
+++ b/xml/schema/Activity/Activity.xml
@@ -239,7 +239,7 @@
   <field>
     <name>status_id</name>
     <uniqueName>activity_status_id</uniqueName>
-    <title>Activity Status</title>
+    <title>Activity Status ID</title>
     <import>true</import>
     <export>true</export>
     <headerPattern>/(activity.)?status(.label$)?/i</headerPattern>

@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 I pushed up al alternate

@seamuslee001
Copy link
Contributor

@eileenmcnaughton this is now generating fatal errors for me like

Database Error Code: Unknown column 'civicrm_activity.activity_status_id' in 'where clause', 1054
Additional Details:
Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -19
    [message] => DB Error: no such field
    [mode] => 16
    [debug_info] => SELECT DISTINCT LEFT(contact_a.sort_name, 1) as sort_name
       FROM civicrm_contact contact_a   LEFT JOIN civicrm_activity_contact
                      ON ( civicrm_activity_contact.contact_id = contact_a.id )  LEFT JOIN civicrm_activity
                      ON ( civicrm_activity.id = civicrm_activity_contact.activity_id
                      AND civicrm_activity.is_deleted = 0 AND civicrm_activity.is_current_revision = 1 ) INNER JOIN civicrm_contact
                      ON ( civicrm_activity_contact.contact_id = civicrm_contact.id and civicrm_contact.is_deleted != 1 )   
      WHERE  ( civicrm_activity.activity_status_id IN ("1", "2") AND  civicrm_activity_contact.record_type_id = 3 AND civicrm_activity.is_test = 0 )  AND (contact_a.is_deleted = 0)
      
      GROUP BY sort_name
      ORDER BY sort_name asc [nativecode=1054 ** Unknown column 'civicrm_activity.activity_status_id' in 'where clause']

@seamuslee001
Copy link
Contributor

@eileenmcnaughton looks like something has gone wrong in the rebase here

@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 hopefully right now

@seamuslee001
Copy link
Contributor

I have just r-runed this and confirmed that the sorting works and also both search builders work merging

@seamuslee001 seamuslee001 merged commit 616def1 into civicrm:5.20 Nov 29, 2019
@seamuslee001 seamuslee001 deleted the act_order branch November 29, 2019 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants