Page MenuHomeIn-Portal Phabricator

D431.diff
No OneTemporary

File Metadata

Created
Mon, Jan 6, 5:04 AM

D431.diff

Index: branches/5.2.x/core/kernel/db/dblist.php
===================================================================
--- branches/5.2.x/core/kernel/db/dblist.php
+++ branches/5.2.x/core/kernel/db/dblist.php
@@ -725,6 +725,10 @@
*/
public function extractCalculatedFields($clause, $aggregated = 1, $replace_table = false)
{
+ if ( !$clause ) {
+ return '';
+ }
+
$fields = $this->getCalculatedFields($aggregated);
if ( is_array($fields) && count($fields) > 0 ) {
@@ -759,23 +763,18 @@
if (!$system_filters_only) {
$where->addFilter('view_where', $this->WhereFilter[self::FLT_VIEW] );
- $search_w = $this->WhereFilter[self::FLT_SEARCH]->getSQL();
- if ($search_w || $for_counting) { // move search_having to search_where in case search_where isset or we are counting
- $search_h = $this->extractCalculatedFields( $this->HavingFilter[self::FLT_SEARCH]->getSQL() );
- $search_w = ($search_w && $search_h) ? $search_w.' OR '.$search_h : $search_w.$search_h;
- $where->addFilter('search_where', $search_w );
- }
+ // Handle general grid search filter. Append transformed having clause into where clause.
+ $search_w = $this->WhereFilter[self::FLT_SEARCH]->getSQL();
+ $search_h = $this->extractCalculatedFields($this->HavingFilter[self::FLT_SEARCH]->getSQL());
+ $search_w = ($search_w && $search_h) ? $search_w . ' OR ' . $search_h : $search_w . $search_h;
+ $where->addFilter('search_where', $search_w);
- // CUSTOM
+ // Handle custom per-column grid filters. Append transformed having clause into where clause.
$search_w = $this->WhereFilter[self::FLT_CUSTOM]->getSQL();
-
- if ($search_w || $for_counting) { // move search_having to search_where in case search_where isset or we are counting
- $search_h = $this->extractCalculatedFields( $this->HavingFilter[self::FLT_CUSTOM]->getSQL() );
- $search_w = ($search_w && $search_h) ? $search_w.' AND '.$search_h : $search_w.$search_h;
- $where->addFilter('custom_where', $search_w );
- }
- // CUSTOM
+ $search_h = $this->extractCalculatedFields($this->HavingFilter[self::FLT_CUSTOM]->getSQL());
+ $search_w = ($search_w && $search_h) ? $search_w . ' AND ' . $search_h : $search_w . $search_h;
+ $where->addFilter('custom_where', $search_w);
}
if( $for_counting ) // add system_having and view_having to where
@@ -821,12 +820,8 @@
}
if (!$system_filters_only) {
+ // Don't add search/custom having filters here, because they're added to the where clause.
$having->addFilter('view_having', $this->HavingFilter[kDBList::FLT_VIEW] );
- $having->addFilter('custom_having', $this->HavingFilter[kDBList::FLT_CUSTOM] );
- $search_w = $this->WhereFilter[kDBList::FLT_SEARCH]->getSQL();
- if (!$search_w) {
- $having->addFilter('search_having', $this->HavingFilter[kDBList::FLT_SEARCH] );
- }
}
return $having->getSQL();

Event Timeline