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

Improve metadata support for table civicrm_mailing_job in search #15634

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,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 @@ -474,6 +469,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