260 |
|
|
261 |
my $sql = $context ? $sql_context : $sql_message; |
my $sql = $context ? $sql_context : $sql_message; |
262 |
|
|
263 |
$sql .= " where message ilike ? or nick ilike ? " if ($args->{search}); |
sub check_date { |
264 |
$sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} }); |
my $date = shift; |
265 |
if ($args->{date}) { |
$date = eval { DateTime::Format::ISO8601->parse_datetime( $args->{date} )->ymd; }; |
|
my $date = eval { DateTime::Format::ISO8601->parse_datetime( $args->{date} )->ymd; }; |
|
266 |
if ( $@ ) { |
if ( $@ ) { |
267 |
warn "invalid date ", $args->{date}, $/; |
warn "invalid date ", $args->{date}, $/; |
268 |
$date = DateTime->now->ymd; |
$date = DateTime->now->ymd; |
269 |
} |
} |
270 |
|
return $date; |
271 |
|
} |
272 |
|
|
273 |
|
$sql .= " where message ilike ? or nick ilike ? " if ($args->{search}); |
274 |
|
$sql .= " where id in (" . join(",", @{ $tags->{ $args->{tag} } }) . ") " if ($args->{tag} && $tags->{ $args->{tag} }); |
275 |
|
if ($args->{date}) { |
276 |
$sql .= " where date(time) = ? "; |
$sql .= " where date(time) = ? "; |
277 |
$args->{date} = $date; |
$args->{date} = check_date( $args->{date} ); |
278 |
} |
} |
279 |
$sql .= " order by log.time desc"; |
$sql .= " order by log.time desc"; |
280 |
$sql .= " limit " . $args->{limit} if ($args->{limit}); |
$sql .= " limit " . $args->{limit} if ($args->{limit}); |
289 |
$sth->execute(); |
$sth->execute(); |
290 |
_log "tag '$tag' returned ", $sth->rows, " results ", $context || ''; |
_log "tag '$tag' returned ", $sth->rows, " results ", $context || ''; |
291 |
} elsif (my $date = $args->{date}) { |
} elsif (my $date = $args->{date}) { |
292 |
$sth->execute($date); |
$sth->execute( check_date($date) ); |
293 |
_log "found ", $sth->rows, " messages for date $date ", $context || ''; |
_log "found ", $sth->rows, " messages for date $date ", $context || ''; |
294 |
} else { |
} else { |
295 |
$sth->execute(); |
$sth->execute(); |
957 |
limit => $q->param('last') || $q->param('date') ? undef : 100, |
limit => $q->param('last') || $q->param('date') ? undef : 100, |
958 |
search => $search || undef, |
search => $search || undef, |
959 |
tag => $q->param('tag') || undef, |
tag => $q->param('tag') || undef, |
960 |
date => $q->param('date') || undef, |
date => check_date( $q->param('date') ), |
961 |
fmt => { |
fmt => { |
962 |
date => sub { |
date => sub { |
963 |
my $date = shift || return; |
my $date = shift || return; |