1 | package Sophie::Controller::Admin::Update; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN {extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Sophie::Controller::Admin::Update - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | sub paths :XMLRPC { |
---|
20 | my ($self, $c) = @_; |
---|
21 | |
---|
22 | return $c->stash->{xmlrpc} = [ |
---|
23 | map { |
---|
24 | { |
---|
25 | path => $_->get_column('path'), |
---|
26 | id => $_->get_column('d_path_key'), |
---|
27 | } |
---|
28 | } $c->model('Base')->resultset('Paths')->search( |
---|
29 | {}, |
---|
30 | { |
---|
31 | select => [ qw(path d_path_key) ], |
---|
32 | } |
---|
33 | )->all ] |
---|
34 | } |
---|
35 | |
---|
36 | sub paths_to_update : XMLRPC { |
---|
37 | my ($self, $c) = @_; |
---|
38 | |
---|
39 | return $c->stash->{xmlrpc} = [ |
---|
40 | map { |
---|
41 | { |
---|
42 | path => $_->get_column('path'), |
---|
43 | id => $_->get_column('d_path_key'), |
---|
44 | } |
---|
45 | } $c->model('Base')->resultset('Paths')->search( |
---|
46 | { |
---|
47 | -or => [ |
---|
48 | { updated => [ |
---|
49 | undef, |
---|
50 | \[ " < now() - '24 hours'::interval" ], |
---|
51 | ], }, |
---|
52 | { needupdate => { '>' => 0 } }, |
---|
53 | ] |
---|
54 | }, |
---|
55 | { |
---|
56 | select => [ qw(path d_path_key) ], |
---|
57 | order_by => [ 'updated' ], |
---|
58 | } |
---|
59 | )->all ] |
---|
60 | } |
---|
61 | |
---|
62 | sub set_path_needupdate : XMLRPC { |
---|
63 | my ($self, $c, @paths) = @_; |
---|
64 | |
---|
65 | #$self->model('Base')->txn_do( |
---|
66 | # sub { |
---|
67 | foreach my $path (@paths) { |
---|
68 | warn $path; |
---|
69 | my $p = $c->model('Base::Paths')->find( |
---|
70 | { path => $path } |
---|
71 | ) or next; |
---|
72 | $p->update( |
---|
73 | { |
---|
74 | needupdate => scalar(time), |
---|
75 | } |
---|
76 | ); |
---|
77 | } |
---|
78 | $c->model('Base')->storage->dbh->commit; |
---|
79 | return 1; |
---|
80 | # } |
---|
81 | #); |
---|
82 | |
---|
83 | return $c->stash->{xmlrpc} = 1; |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | =head1 AUTHOR |
---|
88 | |
---|
89 | Olivier Thauvin |
---|
90 | |
---|
91 | =head1 LICENSE |
---|
92 | |
---|
93 | This library is free software. You can redistribute it and/or modify |
---|
94 | it under the same terms as Perl itself. |
---|
95 | |
---|
96 | =cut |
---|
97 | |
---|
98 | __PACKAGE__->meta->make_immutable; |
---|
99 | |
---|
100 | 1; |
---|