RT#38217: Send email when logging conditions are met [fix to warning invocation in...
[freeside.git] / FS / FS / log.pm
index a4ad214..547beb7 100644 (file)
@@ -114,7 +114,7 @@ sub check {
     || $self->ut_textn('tablename')
     || $self->ut_numbern('tablenum')
     || $self->ut_number('level')
-    || $self->ut_text('message')
+    || $self->ut_anything('message')
   ;
   return $error if $error;
 
@@ -312,9 +312,16 @@ sub search {
 
   if ( $params->{'context'} ) {
     my $quoted = dbh->quote($params->{'context'});
-    push @where, 
-      "EXISTS(SELECT 1 FROM log_context WHERE log.lognum = log_context.lognum ".
-      "AND log_context.context = $quoted)";
+    if ( $params->{'context_height'} =~ /^\d+$/ ) {
+      my $subq = 'SELECT context FROM log_context WHERE log.lognum = log_context.lognum'.
+                 ' ORDER BY logcontextnum DESC LIMIT '.$params->{'context_height'};
+      push @where,
+        "EXISTS(SELECT 1 FROM ($subq) AS log_context_x WHERE log_context_x.context = $quoted)";
+    } else {
+      push @where, 
+        "EXISTS(SELECT 1 FROM log_context WHERE log.lognum = log_context.lognum ".
+        "AND log_context.context = $quoted)";
+    }
   }
 
   # agent virtualization