/[Grep]/lib/Grep/Action/Fetch.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Grep/Action/Fetch.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 28 by dpavlin, Mon Feb 19 16:28:00 2007 UTC revision 29 by dpavlin, Mon Feb 19 18:25:12 2007 UTC
# Line 45  use Jifty::Action schema { Line 45  use Jifty::Action schema {
45  #               available are qw/result result_short/;  #               available are qw/result result_short/;
46                  available are qw/long short title/;                  available are qw/long short title/;
47    
48            param publish =>
49                    label is 'In which queue?';
50    
51  };  };
52    
53  =head2 take_action  =head2 take_action
54    
55    Returns C<Grep::Model::ItemCollection> of fatched items from Feed which will
56    also be stored in local cache.
57    
58  =cut  =cut
59    
60  sub take_action {  sub take_action {
# Line 58  sub take_action { Line 64  sub take_action {
64    
65          my $feed = Grep::Model::Feed->new();          my $feed = Grep::Model::Feed->new();
66          my $feed_id = $self->argument_value('feed');          my $feed_id = $self->argument_value('feed');
67            my $publish = $self->argument_value('publish');
68            my $q = $self->argument_value('q');
69    
70          if (! $feed_id) {          if (! $feed_id) {
71                  $self->result->message("Need feed ID");                  $self->result->message("Need feed ID");
# Line 73  sub take_action { Line 81  sub take_action {
81    
82          my $uri = $feed->uri;          my $uri = $feed->uri;
83          if ($uri =~ m/%s/) {          if ($uri =~ m/%s/) {
84                  $uri = $feed->search_uri( $self->argument_value('q') );                  $uri = $feed->search_uri( $q );
85                  Jifty->log->info("Searching ", $feed->title, " at $uri");                  Jifty->log->info("Searching ", $feed->title, " at $uri");
86          } else {          } else {
87                  Jifty->log->info("Fetching ", $feed->title, " at $uri");                  Jifty->log->info("Fetching ", $feed->title, " at $uri");
# Line 93  sub take_action { Line 101  sub take_action {
101    
102          warn "getting entries from ", $xml_feed->title, "\n";          warn "getting entries from ", $xml_feed->title, "\n";
103    
104          my @items;          my $items = Grep::Model::ItemCollection->new();
105    
106          for my $entry ($xml_feed->entries) {          for my $entry ($xml_feed->entries) {
107                  my $i = Grep::Model::Item->new();                  my $i = Grep::Model::Item->new();
# Line 106  sub take_action { Line 114  sub take_action {
114                          summary => $entry->summary->body,                          summary => $entry->summary->body,
115                          category => $entry->category,                          category => $entry->category,
116                          author => $entry->author,                          author => $entry->author,
117                          issued => $entry->issued ? $entry->issued->strftime("%Y-%m-%d %H:%M:%S %z") : undef,                          issued => $entry->issued ? $entry->issued->strftime("%Y-%m-%d %H:%M:%S") : undef,
118                          modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S %z") : undef,                          modified => $entry->modified ? $entry->modified->strftime("%Y-%m-%d %H:%M:%S") : undef,
119                  );                  );
120    
121                  if ( $i->id ) {                  if ( $i->id ) {
122                          push @items, $i;                          $items->add_record( $i );
123    
124          #               Grep::Event::Result->new( $i )->publish;                          Jifty->log->debug("added ", $i->id, " to collection");
   
                         Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) );  
125                  } else {                  } else {
126                          warn "can't create item from entry ", dump( $entry ) unless ( $i->id );                          warn "can't add entry ", dump( $entry ) unless ( $i->id );
127                  }                  }
128    
129          }          }
130    
131          if ( @items ) {          if ( $items ) {
132    
133                  $self->result->message( $self->argument_value('q') . ' => ' .                  $self->result->message( $q . ' => ' . $xml_feed->entries . ' results' );
                         $xml_feed->entries . ' items: ' . join(",", map { $_->id } @items)  
                 );  
134    
135                  $self->result->content( items => \@items );                  if ( $publish ) {
136                  return 1;                          Grep::Event::Result->new({ q => $q, coll => $items, item_fragment => 'title' })->publish;
137                            Jifty->log->debug( $items->count, " for '$q' published" );
138                    } else {
139                            $self->result->content( items => $items );
140                            Jifty->log->debug( $items->count, " for '$q' found" );
141                    }
142    
143          } else {          } else {
144    
145                  $self->result->error( 'No results found' );                  $self->result->error( 'No results found' );
                 return 0;  
146    
147          }          }
148    
149            return $items;
150  }  }
151    
152  1;  1;

Legend:
Removed from v.28  
changed lines
  Added in v.29

  ViewVC Help
Powered by ViewVC 1.1.26