10 |
|
|
11 |
column in_feed => |
column in_feed => |
12 |
refers_to Grep::Model::Feed by 'id', |
refers_to Grep::Model::Feed by 'id', |
13 |
|
is indexed, |
14 |
is mandatory; |
is mandatory; |
15 |
|
|
16 |
column title => |
column title => |
19 |
|
|
20 |
column link => |
column link => |
21 |
type is 'text', |
type is 'text', |
22 |
|
is distinct, |
23 |
|
is indexed, |
24 |
is mandatory; |
is mandatory; |
25 |
|
|
26 |
column content => |
column content => |
86 |
return ($val, $msg); |
return ($val, $msg); |
87 |
} |
} |
88 |
|
|
89 |
|
=head2 link_current |
90 |
|
|
91 |
|
my $item = Grep::Model::Item->link_currnet( 'http://www.example.com' ) |
92 |
|
my $item = $item->link_current( 'http://www.example.com' ); |
93 |
|
|
94 |
|
=cut |
95 |
|
|
96 |
|
my $update_every_hr = 24; # s |
97 |
|
|
98 |
|
sub link_current { |
99 |
|
my $self = shift; |
100 |
|
my $uri = shift || die "no uri?"; |
101 |
|
|
102 |
|
my $item = $self; |
103 |
|
if ( ! ref($self) || ! $self->link || ( $self->link && $self->link ne $uri ) ) { |
104 |
|
$item = Grep::Model::Item->new; |
105 |
|
#warn "load_by_cols link => $uri"; |
106 |
|
$item->load_by_cols( link => $uri ); |
107 |
|
return $item if $item->id; |
108 |
|
return 0; |
109 |
|
} |
110 |
|
|
111 |
|
return 0 unless ( $item ); |
112 |
|
|
113 |
|
die "item is not Grep::Model::Item, but ", ref( $item ) unless ref( $item ) eq 'Grep::Model::Item'; |
114 |
|
|
115 |
|
my $last_update = $item->last_update || $item->created_on; # fallback |
116 |
|
return 0 unless defined( $last_update ) && $last_update; |
117 |
|
|
118 |
|
my $newer_than = DateTime->now->subtract( hours => $update_every_hr ); |
119 |
|
#warn "$last_update > $newer_than"; |
120 |
|
return 0 if ( $last_update - $newer_than )->is_negative; |
121 |
|
return $item; |
122 |
|
} |
123 |
|
|
124 |
1; |
1; |
125 |
|
|