38 |
}]; |
}]; |
39 |
}; |
}; |
40 |
|
|
41 |
|
param item_fragment => |
42 |
|
label is 'Show', |
43 |
|
render as 'select', |
44 |
|
# valid are qw/result result_short/, |
45 |
|
# available are qw/result result_short/; |
46 |
|
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 { |
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"); |
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"); |
90 |
my $ua = LWP::UserAgent->new; |
my $ua = LWP::UserAgent->new; |
91 |
$ua->default_header( 'Cookie' => $feed->cookie ); |
$ua->default_header( 'Cookie' => $feed->cookie ); |
92 |
my $r = $ua->get( $uri ); |
my $r = $ua->get( $uri ); |
93 |
die "Can't fetch $uri: " . $r->status_line unless ( $r->is_success ); |
die $feed->title . " returned " . $r->status_line . " for $uri\n" unless ( $r->is_success ); |
94 |
|
|
95 |
my $content = $r->content; |
my $content = $r->content; |
96 |
|
|
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(); |
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 |
die "can't create item from entry ", dump( $entry ) unless ( $i->id ); |
if ( $i->id ) { |
122 |
|
$items->add_record( $i ); |
|
push @items, $i; |
|
123 |
|
|
124 |
# Grep::Event::Result->new( $i )->publish; |
Jifty->log->debug("added ", $i->id, " to collection"); |
125 |
|
} else { |
126 |
|
warn "can't add entry ", dump( $entry ) unless ( $i->id ); |
127 |
|
} |
128 |
|
|
|
Jifty->log->debug("published ", $i->id ) ; # dump( $entry, $i ) ); |
|
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({ |
137 |
|
q => $q, coll => $items, |
138 |
|
item_fragment => $self->argument_value('item_fragment'), |
139 |
|
})->publish; |
140 |
|
Jifty->log->debug( $items->count, " for '$q' published" ); |
141 |
|
} else { |
142 |
|
$self->result->content( items => $items ); |
143 |
|
Jifty->log->debug( $items->count, " for '$q' found" ); |
144 |
|
} |
145 |
|
|
146 |
} else { |
} else { |
147 |
|
|
148 |
$self->result->error( 'No results found' ); |
$self->result->error( 'No results found' ); |
|
return 0; |
|
149 |
|
|
150 |
} |
} |
151 |
|
|
152 |
|
return $items; |
153 |
} |
} |
154 |
|
|
155 |
1; |
1; |