[rt-devel] CLI nested keyword search

Florian Weimer Weimer at CERT.Uni-Stuttgart.DE
Sun Mar 17 10:27:47 EST 2002


The patch below adds nested keyword search support for the command
line.

Previously, it didn't work because LoadByNameAndParentId does not deal
with paths, only with atomic names (which do not contain delimiters).

-- 
Florian Weimer 	                  Weimer at CERT.Uni-Stuttgart.DE
University of Stuttgart           http://CERT.Uni-Stuttgart.DE/people/fw/
RUS-CERT                          +49-711-685-5973/fax +49-711-685-5898

-------------- next part --------------
Index: bin/rt
===================================================================
RCS file: /raid/cvsroot/rt/bin/rt,v
retrieving revision 1.8
diff -u -u -r1.8 rt
--- bin/rt	2002/03/01 06:39:03	1.8
+++ bin/rt	2002/03/17 15:27:09
@@ -469,7 +469,7 @@
 
 	    # load the keyword
 	    my $k = RT::Keyword->new($RT::SystemUser);
-	    unless ($k->LoadByNameAndParentId($keyword, $keyselect->Keyword)) {
+	    unless ($k->LoadByPathRelative("/$keyword", $keyselect->Keyword)) {
 		$RT::Logger->debug("Keyword '$keyword' not found");
 		print STDERR "Keyword '$keyword' not found\n";
 		exit(-1);
Index: lib/RT/Keyword.pm
===================================================================
RCS file: /raid/cvsroot/rt/lib/RT/Keyword.pm,v
retrieving revision 1.4
diff -u -u -r1.4 Keyword.pm
--- lib/RT/Keyword.pm	2001/12/14 19:03:08	1.4
+++ lib/RT/Keyword.pm	2002/03/17 15:27:10
@@ -146,6 +146,27 @@
     my $self = shift;
 
     my $path = shift;
+    return $self->LoadByPathRelative($path, 0);
+}
+
+
+# }}}
+
+# {{{ sub LoadByPath 
+
+=head2 LoadByPathRelative PATH PARENTID
+
+LoadByPathRelative takes a string and a number.  Whatever character starts the string is assumed to be a delimter.  The routine parses the keyword path description and tries to load the keyword
+described by that path.  Although the path starts with a delimiter, it is assumed to be relative to the keyword given by the parent ID. LoadByPathRelative returns a numerical status and a textual message.
+A non-zero status means 'Success'.
+
+=cut
+
+sub LoadByPathRelative {
+    my $self = shift;
+
+    my $path = shift;
+    my $parent = shift;
     
     my $delimiter = substr($path,0,1);
     my @path_elements = split($delimiter, $path);
@@ -153,7 +174,6 @@
     #throw awya the first bogus path element
     shift @path_elements;
     
-    my $parent = 0;
     my ($tempkey);
     #iterate through all the path elements loading up a
     #keyword object. when we're done, this object becomes 


More information about the Rt-devel mailing list