From a699a59ef4fd7bab94d6256a586b203dcff924c3 Mon Sep 17 00:00:00 2001 From: Frank Becker Date: Fri, 13 Apr 2012 01:05:17 -0400 Subject: Bug 740536 - Webservice for maximum time of audit_log r=dkl, a=LpSolit --- Bugzilla/WebService/Bugzilla.pm | 71 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'Bugzilla/WebService/Bugzilla.pm') diff --git a/Bugzilla/WebService/Bugzilla.pm b/Bugzilla/WebService/Bugzilla.pm index 82f6f8630..f441cee90 100644 --- a/Bugzilla/WebService/Bugzilla.pm +++ b/Bugzilla/WebService/Bugzilla.pm @@ -11,7 +11,8 @@ use strict; use base qw(Bugzilla::WebService); use Bugzilla::Constants; use Bugzilla::Util qw(datetime_from); -use Bugzilla::WebService::Util qw(filter_wants); +use Bugzilla::WebService::Util qw(validate filter_wants); +use Bugzilla::Util qw(trick_taint); use DateTime; @@ -114,6 +115,33 @@ sub time { }; } +sub last_audit_time { + my ($self, $params) = validate(@_, 'class'); + my $dbh = Bugzilla->dbh; + + my $sql_statement = "SELECT MAX(at_time) FROM audit_log"; + my $class_values = $params->{class}; + my @class_values_quoted; + foreach my $class_value (@$class_values) { + push (@class_values_quoted, $dbh->quote($class_value)) + if $class_value =~ /^Bugzilla(::[a-zA-Z0-9_]+)*$/; + } + + if (@class_values_quoted) { + $sql_statement .= " WHERE " . $dbh->sql_in('class', \@class_values_quoted); + } + + my $last_audit_time = $dbh->selectrow_array("$sql_statement"); + + # All Webservices return times in UTC; Use UTC here for backwards compat. + # Hardcode values where appropriate + $last_audit_time = datetime_from($last_audit_time, 'UTC'); + + return { + last_audit_time => $self->type('dateTime', $last_audit_time) + }; +} + sub parameters { my ($self, $args) = @_; my $user = Bugzilla->login(); @@ -390,3 +418,44 @@ never be stable. =back =back + +=head2 last_audit_time + +B + +=over + +=item B + +Gets the latest time of the audit_log table. + +=item B + +You can pass the optional parameter C to get the maximum for only +the listed classes. + +=over + +=item C (array) - An array of strings representing the class names. + +B The class names are defined as "Bugzilla::". For the product +use Bugzilla:Product. + +=back + +=item B + +A hash with a single item, C, that is the maximum of the +at_time from the audit_log. + +=item B (none) + +=item B + +=over + +=item Added in Bugzilla B<4.4>. + +=back + +=back -- cgit v1.2.3-24-g4f1b