Skip to content

Commit

Permalink
Merge pull request #15634 from eileenmcnaughton/mailing_date
Browse files Browse the repository at this point in the history
Improve metadata support for table civicrm_mailing_job in search
  • Loading branch information
eileenmcnaughton authored Oct 28, 2019
2 parents 7c7b5f6 + 2b75018 commit 73ad832
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ public function restWhere(&$values) {
$realFieldName = str_replace(['_high', '_low'], '', $name);
if (isset($this->_fields[$realFieldName])) {
$field = $this->_fields[str_replace(['_high', '_low'], '', $realFieldName)];
$this->dateQueryBuilder($values, $field['table_name'], $realFieldName, $realFieldName, $field['title']);
$this->dateQueryBuilder($values, $field['table_name'], $realFieldName, $field['name'], $field['title']);
}
return;
}
Expand Down
37 changes: 18 additions & 19 deletions CRM/Mailing/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -286,11 +288,7 @@ public static function whereClauseSingle(&$values, &$query) {
case 'mailing_date':
case 'mailing_date_low':
case 'mailing_date_high':
// process to / from date
$query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1;
$query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] = 1;
$query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1;
$query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1;
$query->dateQueryBuilder($values,
'civicrm_mailing_job', 'mailing_date', 'start_date', 'Mailing Delivery Date'
);
Expand Down Expand Up @@ -387,10 +385,7 @@ public static function whereClauseSingle(&$values, &$query) {
if ($value != 'Scheduled' && $value != 'Canceled') {
$query->_tables['civicrm_mailing_event_queue'] = $query->_whereTables['civicrm_mailing_event_queue'] = 1;
}
$query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1;
$query->_tables['civicrm_mailing_job'] = $query->_whereTables['civicrm_mailing_job'] = 1;
$query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1;

$query->_where[$grouping][] = " civicrm_mailing_job.status = '{$value}' ";
$query->_qill[$grouping][] = "Mailing Job Status IS \"$value\"";
}
Expand Down Expand Up @@ -470,6 +465,10 @@ public static function searchAction(&$row, $id) {
* @param $tables
*/
public static function tableNames(&$tables) {
if (isset($tables['civicrm_mailing_job'])) {
$tables['civicrm_mailing'] = $tables['civicrm_mailing'] ?? 1;
$tables['civicrm_mailing_recipients'] = $tables['civicrm_mailing_recipients'] ?? 1;
}
}

/**
Expand Down

0 comments on commit 73ad832

Please sign in to comment.