source: server/trunk/web/lib/Sophie/Controller/Admin/Maintenance.pm @ 422

Last change on this file since 422 was 320, checked in by nanardon, 13 years ago
  • delete old statistics at maintenance tasks
File size: 1.7 KB
Line 
1package Sophie::Controller::Admin::Maintenance;
2use Moose;
3use namespace::autoclean;
4
5BEGIN {extends 'Catalyst::Controller'; }
6
7=head1 NAME
8
9Sophie::Controller::Admin::Maintenance - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19sub begin : Private {
20    my ($self, $c) = @_;
21
22    if ($c->req->address eq '127.0.0.1' || $c->req->address eq '::1') {
23    } else {
24        $c->forward('/admin/begin')
25    }
26
27    $c->forward('/begin');
28}
29
30sub tasks : XMLRPC {
31    my ($self, $c) = @_;
32
33    $c->stash->{xmlrpc} = [ qw(
34        admin.maintenance.delete_expired_sessions
35        admin.maintenance.delete_expired_paste
36        admin.maintenance.delete_old_chat_statistics
37    ) ];
38}
39
40sub delete_expired_sessions :XMLRPC {
41    my ($self, $c) = @_;
42
43    $c->delete_expired_sessions;
44
45    $c->stash->{xmlrpc} = 'Done';
46}
47
48sub delete_expired_paste :XMLRPC {
49    my ($self, $c) = @_;
50    $c->model('Base::ChatPaste')->search({
51            -nest => \[
52            "whenpaste < now() - ?::interval",
53            [ plain_text => "30 days" ],
54        ]
55    })->delete;
56    $c->model('Base')->storage->sth->commit;
57    $c->stash->{xmlrpc} = 'Done';
58}
59
60sub delete_old_chat_statistics :XMLRPC {
61    my ($self, $c) = @_;
62    $c->model('Base::ChatStat')->search(
63        {
64            -nest => \[
65            "day < now() - ?::interval",
66            [ plain_text => "365 days" ],
67        ],
68        }
69    )->delete;
70    $c->model('Base')->storage->sth->commit;
71    $c->stash->{xmlrpc} = 'Done';
72}
73
74=head1 AUTHOR
75
76Olivier Thauvin
77
78=head1 LICENSE
79
80This library is free software. You can redistribute it and/or modify
81it under the same terms as Perl itself.
82
83=cut
84
85__PACKAGE__->meta->make_immutable;
86
871;
Note: See TracBrowser for help on using the repository browser.