[Bps-public-commit] rt-extension-assets branch, search-for-unset-cfs, created. 1.01_1-1-gefb4508

Kevin Falcone falcone at bestpractical.com
Tue Sep 30 13:12:26 EDT 2014


The branch, search-for-unset-cfs has been created
        at  efb45080635a0e4dc5b394bbc573d79828bd4a51 (commit)

- Log -----------------------------------------------------------------
commit efb45080635a0e4dc5b394bbc573d79828bd4a51
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Tue Sep 30 13:02:59 2014 -0400

    Support the NULL value for Custom Fields
    
    /Elements/SelectCustomFieldValue which is used on the Asset Search page
    presents -, (no value), rest of values for Select type CFs.
    
    (no value) is NULL in the backend because Query Builder turns that into
    CF.{foo} IS NOT NULL.
    
    Assets has a much simpler search and was only really supporting the -
    (unpicked) or value version.  It's simple to case on NULL as an argument
    to do a join out and generate the IS NOT NULL, rather than the query
    which was generated which was Content not like '%NULL%' which might
    match, but never in the intended manner.

diff --git a/lib/RT/Extension/Assets.pm b/lib/RT/Extension/Assets.pm
index b38ba80..0860d92 100644
--- a/lib/RT/Extension/Assets.pm
+++ b/lib/RT/Extension/Assets.pm
@@ -242,12 +242,22 @@ RT->AddJavaScript("RTx-Assets.js");
                     my $cf = RT::Asset->new( $session{CurrentUser} )
                       ->LoadCustomFieldByIdentifier( $1 );
                     next unless $cf->id;
-                    $args{'Assets'}->LimitCustomField(
-                        CUSTOMFIELD => $cf->Id,
-                        OPERATOR    => ($negative ? "NOT LIKE" : "LIKE"),
-                        VALUE       => $value,
-                        ENTRYAGGREGATOR => "AND",
-                    );
+                    if ( $value eq 'NULL' ) {
+                        $args{'Assets'}->LimitCustomField(
+                            CUSTOMFIELD => $cf->Id,
+                            OPERATOR    => ($negative ? "IS NOT" : "IS"),
+                            VALUE       => 'NULL',
+                            QUOTEVALUE  => 0,
+                            ENTRYAGGREGATOR => "AND",
+                        );
+                    } else {
+                        $args{'Assets'}->LimitCustomField(
+                            CUSTOMFIELD => $cf->Id,
+                            OPERATOR    => ($negative ? "NOT LIKE" : "LIKE"),
+                            VALUE       => $value,
+                            ENTRYAGGREGATOR => "AND",
+                        );
+                    }
                 }
                 else {
                     next;

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list