--- lib/Grep/Action/Fetch.pm 2007/02/19 16:28:00 28 +++ lib/Grep/Action/Fetch.pm 2007/02/19 18:25:12 29 @@ -45,10 +45,16 @@ # available are qw/result result_short/; available are qw/long short title/; + param publish => + label is 'In which queue?'; + }; =head2 take_action +Returns C of fatched items from Feed which will +also be stored in local cache. + =cut sub take_action { @@ -58,6 +64,8 @@ my $feed = Grep::Model::Feed->new(); my $feed_id = $self->argument_value('feed'); + my $publish = $self->argument_value('publish'); + my $q = $self->argument_value('q'); if (! $feed_id) { $self->result->message("Need feed ID"); @@ -73,7 +81,7 @@ my $uri = $feed->uri; if ($uri =~ m/%s/) { - $uri = $feed->search_uri( $self->argument_value('q') ); + $uri = $feed->search_uri( $q ); Jifty->log->info("Searching ", $feed->title, " at $uri"); } else { Jifty->log->info("Fetching ", $feed->title, " at $uri"); @@ -93,7 +101,7 @@ warn "getting entries from ", $xml_feed->title, "\n"; - my @items; + my $items = Grep::Model::ItemCollection->new(); for my $entry ($xml_feed->entries) { my $i = Grep::Model::Item->new(); @@ -106,37 +114,39 @@ summary => $entry->summary->body, category => $entry->category, author => $entry->author, - issued => $entry->issued ? $entry->issued->strftime("%Y-%m-%d %H:%M:%S %z") : undef, - modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S %z") : undef, + issued => $entry->issued ? $entry->issued->strftime("%Y-%m-%d %H:%M:%S") : undef, + modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S") : undef, ); if ( $i->id ) { - push @items, $i; + $items->add_record( $i ); - # Grep::Event::Result->new( $i )->publish; - - Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) ); + Jifty->log->debug("added ", $i->id, " to collection"); } else { - warn "can't create item from entry ", dump( $entry ) unless ( $i->id ); + warn "can't add entry ", dump( $entry ) unless ( $i->id ); } } - if ( @items ) { + if ( $items ) { - $self->result->message( $self->argument_value('q') . ' => ' . - $xml_feed->entries . ' items: ' . join(",", map { $_->id } @items) - ); + $self->result->message( $q . ' => ' . $xml_feed->entries . ' results' ); - $self->result->content( items => \@items ); - return 1; + if ( $publish ) { + Grep::Event::Result->new({ q => $q, coll => $items, item_fragment => 'title' })->publish; + Jifty->log->debug( $items->count, " for '$q' published" ); + } else { + $self->result->content( items => $items ); + Jifty->log->debug( $items->count, " for '$q' found" ); + } } else { $self->result->error( 'No results found' ); - return 0; } + + return $items; } 1;