summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-05-03 10:14:37 +0200
committerYorhel <git@yorhel.nl>2011-05-03 10:14:37 +0200
commit8da57d32fae2989438c8b509821c339464d26c82 (patch)
treef5f2e136d37e38e2f6ac1df65ca1382dfc9aa37c /lib
parent50a94610a570c16f1e4c9ffcadc60739d4a30b82 (diff)
affiliates: Expose some columns and allow price without lastfetch
This allows the price info to be manually set without worrying about the lastfetch. Would be useful with MangaGamer.
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Affiliates.pm12
-rw-r--r--lib/VNDB/Handler/Affiliates.pm8
-rw-r--r--lib/VNDB/Handler/VNPage.pm3
3 files changed, 17 insertions, 6 deletions
diff --git a/lib/VNDB/DB/Affiliates.pm b/lib/VNDB/DB/Affiliates.pm
index 51320b47..51f8c2dc 100644
--- a/lib/VNDB/DB/Affiliates.pm
+++ b/lib/VNDB/DB/Affiliates.pm
@@ -36,7 +36,7 @@ sub dbAffiliateGet {
return $self->dbAll(qq|
SELECT af.id, af.rid, af.hidden, af.priority, af.affiliate, af.url, af.version,
- extract('epoch' from af.lastfetch) as lastfetch, af.price$select
+ extract('epoch' from af.lastfetch) as lastfetch, af.price, af.data$select
FROM affiliate_links af
$join
!W
@@ -53,15 +53,19 @@ sub dbAffiliateDel {
sub dbAffiliateEdit {
my($self, $id, %ops) = @_;
my %set;
- exists($ops{$_}) && ($set{"$_ = ?"} = $ops{$_}) for(qw|rid priority hidden affiliate url version|);
+ exists($ops{$_}) && ($set{"$_ = ?"} = $ops{$_}) for(qw|rid priority hidden affiliate url version price data|);
+ $set{"lastfetch = TIMESTAMP WITH TIME ZONE 'epoch' + ? * INTERVAL '1 second'"} = $ops{lastfetch} || $ops{lastfetch} eq '0' ? $ops{lastfetch} : undef if exists $ops{lastfetch};
return if !keys %set;
$self->dbExec('UPDATE affiliate_links !H WHERE id = ?', \%set, $id);
}
+
sub dbAffiliateAdd {
my($self, %ops) = @_;
- $self->dbExec('INSERT INTO affiliate_links (rid, priority, hidden, affiliate, url, version) VALUES(!l)',
- [@ops{qw| rid priority hidden affiliate url version|}]);
+ $self->dbExec(q|INSERT INTO affiliate_links (rid, priority, hidden, affiliate, url, version, price, data, lastfetch)
+ VALUES(!l, TIMESTAMP WITH TIME ZONE 'epoch' + ? * INTERVAL '1 second')|,
+ [@ops{qw| rid priority hidden affiliate url version price data|}],
+ $ops{lastfetch} || $ops{lastfetch} eq '0' ? $ops{lastfetch} : undef);
}
diff --git a/lib/VNDB/Handler/Affiliates.pm b/lib/VNDB/Handler/Affiliates.pm
index 679d6ee2..0482e597 100644
--- a/lib/VNDB/Handler/Affiliates.pm
+++ b/lib/VNDB/Handler/Affiliates.pm
@@ -114,6 +114,9 @@ sub edit {
{ post => 'affiliate',required => 1, enum => [0..$#{$self->{affiliates}}] },
{ post => 'url', required => 1 },
{ post => 'version', required => 0, default => '' },
+ { post => 'price', required => 0, default => '' },
+ { post => 'lastfetch',required => 0, min => 0 },
+ { post => 'data', required => 0, default => '' },
);
if(!$frm->{_err}) {
$self->dbAffiliateEdit($id, %$frm) if $id;
@@ -123,7 +126,7 @@ sub edit {
}
if($id) {
- $frm->{$_} = $r->{$_} for(qw|rid priority hidden affiliate url version|);
+ $frm->{$_} = $r->{$_} for(qw|rid priority hidden affiliate url version price lastfetch data|);
} else {
$frm->{rid} = $self->reqGet('rid');
}
@@ -137,6 +140,9 @@ sub edit {
[ $_, $self->{affiliates}[$_]{name} ], grep $self->{affiliates}[$_], 0..$#{$self->{affiliates}} ] ],
[ input => short => 'url', name => 'URL', width => 400 ],
[ input => short => 'version', name => 'Version', width => 400 ],
+ [ input => short => 'price', name => 'Price' ],
+ [ input => short => 'lastfetch', name => 'Lastfetch', post => ' UNIX timestamp' ],
+ [ input => short => 'data', name => 'Data', width => 400 ],
]);
$self->htmlFooter;
}
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 01a80e7c..0358d09a 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -430,7 +430,8 @@ sub _affiliate_links {
|| ($f->{default_version} && $f->{default_version}->($self, $link, $rel))
|| $version;
txt " at $f->{name}";
- acronym class => 'pricenote', title => sprintf('Last updated: %s.', $en->age($link->{lastfetch})), " for $link->{price}"
+ acronym class => 'pricenote', title =>
+ $link->{lastfetch} ? sprintf('Last updated: %s.', $en->age($link->{lastfetch})) : '', " for $link->{price}"
if $link->{price};
txt ' ยป';
end;