source: server/trunk/web/lib/Sophie/Controller/User/Folder.pm @ 235

Last change on this file since 235 was 207, checked in by nanardon, 14 years ago
  • add analyse functions (need yet to be improve)
File size: 6.3 KB
Line 
1package Sophie::Controller::User::Folder;
2use Moose;
3use namespace::autoclean;
4use XML::Simple;
5use MIME::Base64;
6
7BEGIN {extends 'Catalyst::Controller'; }
8
9=head1 NAME
10
11Sophie::Controller::User::Folder - Catalyst Controller
12
13=head1 DESCRIPTION
14
15Catalyst Controller.
16
17=head1 METHODS
18
19=cut
20
21
22=head2 index
23
24=cut
25
26sub index :Path :Args(0) {
27    my ( $self, $c ) = @_;
28
29    $c->response->body('Matched Sophie::Controller::User::folder in User::folder.');
30}
31
32sub list :XMLRPC :Local {
33    my ($self, $c ) = @_;
34
35    $c->stash->{xmlrpc} = [
36        map { { $_->get_columns } }
37        $c->model('Base::UsersRpms')->search(
38        {
39            ($c->user_exists
40            ? ( user_fkey => $c->model('Base::Users')->find({ mail =>
41                        $c->user->mail })->ukey )
42            : ( sessions_fkey => 'session:' . $c->sessionid ) ),
43        }
44    )->all ]
45}
46
47sub delete :XMLRPC :Local {
48    my ($self, $c, $pid ) = @_;
49    $pid ||= $c->req->param('delete');
50
51    my $pkg = $c->model('Base::UsersRpms')->search(
52        {
53            -and => [ {
54            ($c->user_exists
55            ? ( user_fkey => $c->model('Base::Users')->find({ mail =>
56                        $c->user->mail })->ukey )
57            : ( sessions_fkey => 'session:' . $c->sessionid ) ),
58            },
59            { id => $pid },
60            ]
61        }
62    )->first;
63    if ($pkg) {
64        $pkg->delete;
65        $c->model('Base')->storage->dbh->commit;
66        $c->stash->{xmlrpc} = 'Delete';
67    } else {
68        $c->stash->{xmlrpc} = 'No package found';
69    }
70}
71
72sub clear : XMLRPC : Local {
73    my ($self, $c, $pid ) = @_;
74    $pid ||= $c->req->param('delete');
75
76    my $pkg = $c->model('Base::UsersRpms')->search(
77        {
78            -and => [ {
79            ($c->user_exists
80            ? ( user_fkey => $c->model('Base::Users')->find({ mail =>
81                        $c->user->mail })->ukey )
82            : ( sessions_fkey => 'session:' . $c->sessionid ) ),
83            },
84            ]
85        }
86    )->delete;
87    $c->model('Base')->storage->dbh->commit;
88    $c->stash->{xmlrpc} = 'Empty';
89}
90
91sub load_rpm : XMLRPCLocal {
92    my ($self, $c, $string) = @_;
93
94    my $ref = XMLin($string, ForceArray => 1);
95    my $tags = $ref->{rpmTag} or return;
96
97
98    my $User = $c->user
99        ? $c->model('Base')->resultset('Users')->find( { mail => $c->user->mail } )
100        : undef;
101    $c->session;
102    $c->store_session_data('session:' . $c->sessionid, $c->session);
103
104    my $pkgid = unpack('H*',MIME::Base64::decode($tags->{Sigmd5}{base64}[0]));
105
106    my $newrpm = $c->model('Base::UsersRpms')->create(
107        {
108            name => $tags->{Name}{string}[0],
109            evr => sprintf('%s%s-%s',
110                defined($tags->{Epoch}{integer}[0]) ?
111                $tags->{Epoch}{integer}[0] . ':' : '',
112                $tags->{Version}{string}[0],
113                $tags->{Release}{string}[0],
114            ),
115            user_fkey => $User,
116            sessions_fkey => 'session:' . $c->sessionid,
117            pkgid => $pkgid,
118        }
119    );
120    {
121        my @populate;
122        foreach my $fcount (0 .. $#{$tags->{Basenames}{string}}) {
123            push(@populate,
124                {
125                    pid => $newrpm->id,
126                    basename => $tags->{Basenames}{string}[$fcount],
127                    dirname  => $tags->{Dirnames}{string}[
128                        $tags->{Dirindexes}{integer}[$fcount]
129                    ],
130                }
131            );
132        }
133        $c->model('Base::UsersFiles')->populate(\@populate) if(@populate);
134    }
135    {
136        my @populate;
137        foreach my $dtype (qw(Provide Require Conflict Obsolete Suggest Enhanced)) {
138            my $initial = substr($dtype, 0, 1);
139            $tags->{"${dtype}name"} or next;
140            foreach my $fcount (0 .. $#{$tags->{"${dtype}name"}{string}}) {
141                push(@populate,
142                    {
143                        pid => $newrpm->id,
144                        deptype => $initial,
145                        depname => $tags->{"${dtype}name"}{string}[$fcount],
146                        evr => ref $tags->{"${dtype}version"}{string}[$fcount]
147                        ? ''
148                        : $tags->{"${dtype}version"}{string}[$fcount],
149                        flags => $tags->{"${dtype}flags"}{integer}[$fcount] || 0,
150                    }
151                );
152            }
153        }
154        $c->model('Base::UsersDeps')->populate(\@populate) if(@populate);
155    }
156    $c->model('Base')->storage->dbh->commit;
157
158    $c->stash->{xmlrpc} = $newrpm->id;
159}
160
161sub bydep : XMLRPCLocal {
162    my ($self, $c, $pool, $deptype, $depname, $sense, $evr) = @_;
163
164    $c->stash->{xmlrpc} = [ $c->model('Base::UsersRpms')->search(
165        {
166            -and => [
167                { id => $pool, },
168                { 
169                    id => {
170                        IN => $c->model('Base::UsersDeps')->search({
171                            deptype => $deptype,
172                            depname => $depname,
173                            ( $evr
174                                ?  (-nest => \[
175                                    "rpmdepmatch(flags, evr, rpmsenseflag(?), ?)",
176                                    [ plain_text => $sense],
177                                    [ plain_text => $evr ],
178                                ])
179                            : ()),
180                        })->get_column('pid')->as_query,
181                    }
182                },
183            ],
184        }
185    )->get_column('id')->all ];
186}
187
188sub byfile : XMLRPCLocal {
189    my ($self, $c, $pool, $file) = @_;
190    my ($dirname, $basename) = $file =~ m:^(.*/)?([^/]+)$:;
191
192
193    $c->stash->{xmlrpc} = [ $c->model('Base::UsersRpms')->search(
194        {
195            -and => [
196                { id => $pool, },
197                { 
198                    id => {
199                        IN => $c->model('Base::UsersFiles')->search({
200                                ($dirname
201                                    ? (dirname => $dirname)
202                                    : ()),
203                                basename => $basename,
204                        })->get_column('pid')->as_query,
205                    }
206                },
207            ],
208        }
209    )->get_column('id')->all ];
210}
211
212
213=head1 AUTHOR
214
215Olivier Thauvin
216
217=head1 LICENSE
218
219This library is free software. You can redistribute it and/or modify
220it under the same terms as Perl itself.
221
222=cut
223
224__PACKAGE__->meta->make_immutable;
225
2261;
227
Note: See TracBrowser for help on using the repository browser.