[Rt-commit] [rtir] 01/01: Warn on old CF names in searches

Jim Brandt jbrandt at bestpractical.com
Fri Jun 7 16:21:44 EDT 2013


This is an automated email from the git hooks/post-receive script.

jbrandt pushed a commit to branch 2.9/warn-on-old-search-formats
in repository rtir.

commit 53c54abd3efd1571da74f49194c8718b7569d0a9
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed May 29 13:56:23 2013 -0400

    Warn on old CF names in searches
    
    Warn on startup and when searching if old CF names with
    the _RTIR_ prefix or State are found in queries or formats.
---
 html/RTIR/Search/Results.html |  5 ++++
 lib/RT/IR/Config.pm           | 61 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/html/RTIR/Search/Results.html b/html/RTIR/Search/Results.html
index 22003a5..d0b8b92 100644
--- a/html/RTIR/Search/Results.html
+++ b/html/RTIR/Search/Results.html
@@ -68,6 +68,11 @@ my $title = loc("Results");
 
 my $Type = RT::IR::TicketType( Queue => $Queue ) || '';
 $Format ||= RT->Config->Get('RTIRSearchResultFormats')->{ $Type . 'Default' };
+
+# Warn if old CFs are found
+RT::IR::Config::CheckObsoleteCFSyntax($Format);
+RT::IR::Config::CheckObsoleteCFSyntax($Query);
+
 if ( $Type ) {
     $BaseQuery ||= RT::IR->Query( Queue => $Queue );
     $Query     ||= RT::IR->ActiveQuery( Queue => $Queue );
diff --git a/lib/RT/IR/Config.pm b/lib/RT/IR/Config.pm
index f8be4d2..5eeb0ed 100644
--- a/lib/RT/IR/Config.pm
+++ b/lib/RT/IR/Config.pm
@@ -18,6 +18,67 @@ sub Init {
         },
     );
     %RT::Config::META = (%meta, %RT::Config::META);
+
+    # Tack on the PostLoadCheck here so it runs no matter where
+    # RTIRSearchResultFormats gets loaded from. It will still
+    # squash any other PostLoadChecks for this config entry, but those
+    # should go here.
+    $RT::Config::META{RTIRSearchResultFormats}{PostLoadCheck} =
+        sub {
+            my ($self, $value) = @_;
+            foreach my $format ( keys %{$value} ){
+                CheckObsoleteCFSyntax($value->{$format},
+                    $RT::Config::META{RTIRSearchResultFormats}{Source}{File});
+            }
+        };
+
+    return;
+}
+
+=head1 CheckObsoleteCFSyntax
+
+RTIR upgrades changed the naming of installed custom fields,
+removing the _RTIR_ prefix from the custom field names and removing
+State in favor of RT's default Status.
+
+This function checks queries and formats for references to the old
+CF names and warns that they need to be updated.
+
+Takes: $string, $location
+
+String that can be a format or query that might have an old CF format.
+
+Location is where the format or query is, if available.
+
+Returns: Nothing, just issues a warning in the logs.
+
+=cut
+
+sub CheckObsoleteCFSyntax {
+    my $string = shift;
+    my $location = shift;
+    return unless $string;
+
+    $location = 'unknown' unless $location;
+
+    if ( $string =~ /__CustomField\.\{State\}__/
+         or $string =~ /CF\.\{State\}/ ){
+
+        RT::Logger->warning('The custom field State has been replaced with the RT Status field.'
+                        . ' You should update your custom searches and result formats accordingly.'
+                        . ' See the UPGRADING file and the $RTIRSearchResultFormats option'
+                        . ' in the default RTIR_Config.pm file. Found in: ' . $string
+                        . ' from ' . $location );
+    }
+
+    if ( $string =~ /__CustomField\.\{_RTIR_(\w+)\}__/
+         or $string =~ /CF\.\{_RTIR_\w+\}/ ){
+
+        RT::Logger->warning('The _RTIR_ prefix has been removed from all RTIR custom fields.'
+                        . ' You should update your custom searches and result formats accordingly.'
+                        . ' See the UPGRADING file for details. Found in: ' . $string
+                        . ' from ' . $location );
+    }
     return;
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Rt-commit mailing list