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

dev/core#561 Convert mailing date search field to using datepicker #15633

Merged
merged 1 commit into from
Oct 28, 2019

Conversation

seamuslee001
Copy link
Contributor

@seamuslee001 seamuslee001 commented Oct 28, 2019

Overview

This converts the mailing_date field on the Mailing subsection of advanced search to using date picker rather than jcalender

Before

Jcalender is used

After

Date picker is used

ping @monishdeb @eileenmcnaughton

Note that this isn't fully complete the one thing that doesn't seem to be working at this point is that the where clause doesn't seem to be getting run correctly but am not sure why

https://lab.civicrm.org/dev/core/issues/561

@civibot
Copy link

civibot bot commented Oct 28, 2019

(Standard links)

@civibot civibot bot added the master label Oct 28, 2019
@eileenmcnaughton
Copy link
Contributor

@seamuslee001 also this should go

index e53b6bf5fd..4215c09b73 100644
--- a/CRM/Contact/BAO/SavedSearch.php
+++ b/CRM/Contact/BAO/SavedSearch.php
@@ -402,7 +402,6 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_
'log_date_relative',
'birth_date_relative',
'deceased_date_relative',

  •  'mailing_date_relative',
     'relation_date_relative',
     'relation_start_date_relative',
     'relation_end_date_relative',
    

I'll do some testing....

Some more cleanup and also open tab if specified in the URL
@eileenmcnaughton
Copy link
Contributor

hmm also here

+++ b/CRM/Mailing/Form/Search.php
@@ -121,20 +121,10 @@ class CRM_Mailing_Form_Search extends CRM_Core_Form_Search {
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);
 
-    if (!empty($params['mailing_relative'])) {
-      list($params['mailing_low'], $params['mailing_high']) = CRM_Utils_Date::getFromTo($params['mailing_relative'], $params['mailing_low'], $params['mailing_high']);
-      unset($params['mailing_relative']);
-    }
-    elseif (!empty($params['mailing_high'])) {
-      $params['mailing_high'] .= ' ' . '23:59:59';
-    }
-
     $parent = $this->controller->getParent();
     if (!empty($params)) {
       $fields = [
         'mailing_name',
-        'mailing_low',
-        'mailing_high',
         'sort_name',
         'campaign_id',
         'mailing_status',

@seamuslee001
Copy link
Contributor Author

hmm also here

+++ b/CRM/Mailing/Form/Search.php
@@ -121,20 +121,10 @@ class CRM_Mailing_Form_Search extends CRM_Core_Form_Search {
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);
 
-    if (!empty($params['mailing_relative'])) {
-      list($params['mailing_low'], $params['mailing_high']) = CRM_Utils_Date::getFromTo($params['mailing_relative'], $params['mailing_low'], $params['mailing_high']);
-      unset($params['mailing_relative']);
-    }
-    elseif (!empty($params['mailing_high'])) {
-      $params['mailing_high'] .= ' ' . '23:59:59';
-    }
-
     $parent = $this->controller->getParent();
     if (!empty($params)) {
       $fields = [
         'mailing_name',
-        'mailing_low',
-        'mailing_high',
         'sort_name',
         'campaign_id',
         'mailing_status',

@eileenmcnaughton i believe that is not connected to the advanced search form as per #15181 (comment)

@eileenmcnaughton
Copy link
Contributor

Hmm - ok.

My testing shows relative date not working. I think we need to put it in the metadata

--- a/CRM/Mailing/BAO/Query.php
+++ b/CRM/Mailing/BAO/Query.php
@@ -32,21 +32,23 @@
  */
 class CRM_Mailing_BAO_Query {
 
-  public static $_mailingFields = NULL;
-
   /**
-   * @return array|null
+   * Get fields for the mailing & mailing job entity.
+   *
+   * @return array
    */
   public static function &getFields() {
-    if (!self::$_mailingFields) {
-      self::$_mailingFields = [];
-      $_mailingFields['mailing_id'] = [
-        'name' => 'mailing_id',
-        'title' => ts('Mailing ID'),
-        'where' => 'civicrm_mailing.id',
-      ];
-    }
-    return self::$_mailingFields;
+    $mailingFields = CRM_Mailing_BAO_Mailing::fields();
+    $mailingJobFields = CRM_Mailing_BAO_MailingJob::fields();
+
+    // In general it's good to return as many fields as could possibly be searched, but
+    // with the limitation that if the fields do not have unique names they might
+    // clobber other fields :-(
+    $fields = [
+      'mailing_id' => $mailingFields['id'],
+      'mailing_job_start_date' => $mailingJobFields['mailing_job_start_date'],
+    ];
+    return $fields;
   }

Although the join thing still needs fixing

@eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 I'm OK for this to be merged as is but we definitely need to follow up with a further fix per ^^

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton i tested your fix and that fixes it on relative dates but i get an unknown column error when doing it in the choose date field it builds an example query like

    [to_string] => [db_error: message="DB Error: no such field" code=-19 mode=callback callback=CRM_Core_Error::handle prefix="" info="SELECT DISTINCT LEFT(contact_a.sort_name, 1) as sort_name
       FROM civicrm_contact contact_a   LEFT JOIN civicrm_mailing_recipients ON civicrm_mailing_recipients.contact_id = contact_a.id  LEFT JOIN civicrm_mailing ON civicrm_mailing.id = civicrm_mailing_recipients.mailing_id  LEFT JOIN civicrm_mailing_job ON civicrm_mailing_job.mailing_id = civicrm_mailing.id AND civicrm_mailing_job.is_test != 1
      WHERE  ( civicrm_mailing_job.mailing_job_start_date <= '20191002235959' )  AND (contact_a.is_deleted = 0)

      GROUP BY sort_name
      ORDER BY sort_name asc [nativecode=1054 ** Unknown column 'civicrm_mailing_job.mailing_job_start_date' in 'where clause']"]
)

Relative parts of the backtrace

#12 /home/seamus/buildkit/build/47-test/sites/all/modules/civicrm/CRM/Core/DAO.php(1416): CRM_Core_DAO->query("SELECT DISTINCT LEFT(contact_a.sort_name, 1) as sort_name\n       FROM civicr...", TRUE)
#13 /home/seamus/buildkit/build/47-test/sites/all/modules/civicrm/CRM/Contact/BAO/Query.php(5015): CRM_Core_DAO::executeQuery("SELECT DISTINCT LEFT(contact_a.sort_name, 1) as sort_name\n       FROM civicr...")
#14 /home/seamus/buildkit/build/47-test/sites/all/modules/civicrm/CRM/Contact/Selector.php(1194): CRM_Contact_BAO_Query->alphabetQuery()
#15 /home/seamus/buildkit/build/47-test/sites/all/modules/civicrm/CRM/Utils/PagerAToZ.php(108): CRM_Contact_Selector->alphabetQuery()
#16 /home/seamus/buildkit/build/47-test/sites/all/modules/civicrm/CRM/Utils/PagerAToZ.php(136): CRM_Utils_PagerAToZ::getDynamicCharacters(Object(CRM_Contact_Selector), FALSE)
#17 /home/seamus/buildkit/build/47-test/sites/all/modules/civicrm/CRM/Utils/PagerAToZ.php(52): CRM_Utils_PagerAToZ::createLinks(Object(CRM_Contact_Selector), NULL, FALSE)
#18 /home/seamus/buildkit/build/47-test/sites/all/modules/civicrm/CRM/Contact/Form/Search.php(868): CRM_Utils_PagerAToZ::getAToZBar(Object(CRM_Contact_Selector), NULL)
#19 /home/seamus/buildkit/build/47-test/sites/all/modules/civicrm/CRM/Contact/Form/Search/Advanced.php(320): CRM_Contact_Form_Search->postProcess()
#20 /home/seamus/buildkit/build/47-test/sites/all/modules/civicrm/CRM/Core/Form.php(495): CRM_Contact_Form_Search_Advanced->postProcess()

@eileenmcnaughton
Copy link
Contributor

hmm - this is without your change? I don't see it but perhaps without results I'm not getting pagerAtoZ running - will try some more data

@seamuslee001
Copy link
Contributor Author

this is with my change and with your changes applied ontop

@eileenmcnaughton
Copy link
Contributor

ah - I'm currently testing with just this one - once I get my data right I'll switch to that

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 OK - I might have just pushed a fix for that

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton yep that works also just pushed a revised version incorporating the changes to CRM/Contact/BAO/SavedSearch.php but also expanding the list of known mailing fields in advanced search in CRM/Contact/Form/Search.php

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 so we should close this?

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton no just force pushed onto this pr was that i meant

@eileenmcnaughton
Copy link
Contributor

Ah OK - this should be good to merge with the other merged - MOP

@seamuslee001 seamuslee001 merged commit 7c7b5f6 into civicrm:master Oct 28, 2019
@seamuslee001 seamuslee001 deleted the dev_core_561_mailing branch October 28, 2019 04:32
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.

2 participants