source: server/trunk/web/lib/Sophie/Scan/MetaPath.pm @ 338

Last change on this file since 338 was 338, checked in by nanardon, 13 years ago
  • oops
File size: 1.2 KB
Line 
1package Sophie::Scan::MetaPath;
2
3use strict;
4use warnings;
5
6sub new {
7    my ($class, $base, $meta) = @_;
8
9    bless({ _base => $base, _meta => $meta }, $class);
10}
11
12sub base { $_[0]->{_base}->base }
13
14sub meta { $_[0]->{_meta} }
15
16sub clean_obsolete_path {
17   my ($self, @currentpaths) = @_;
18
19   foreach ($self->base->resultset('Paths')->search(
20           {
21               meta_path => $self->meta->d_meta_path_key,
22               path => { 'NOT IN' => \@currentpaths },
23           })) {
24       $_->delete;
25   }
26
27   1;
28}
29
30sub add_path {
31    my ($self, $path, $media) = @_;
32
33    my $rowpath = $self->base->resultset('Paths')->find_or_create(
34        { meta_path => $self->meta->d_meta_path_key, path => $path, },
35        { key => 'path' }
36    );
37
38    my $rowmedia = $self->base->resultset('Medias')->find_or_create(
39        { label => $media, d_arch => $self->meta->d_arch, group_label => $media },
40        { key => 'label' },
41    );
42
43    $self->base->resultset('MediasPaths')->find_or_create(
44        {
45            d_path => $rowpath->d_path_key,
46            d_media => $rowmedia->d_media_key,
47        }
48    );
49}
50
51sub set_updated {
52    my ($self) = @_;
53
54    $self->meta->update({ updated => \'now()' });
55}
56
571;
Note: See TracBrowser for help on using the repository browser.