4 use parent qw(Rose::Object);
 
  10 use SL::Webdav::Object;
 
  11 use SL::Webdav::VersionScheme::Serial;
 
  12 use SL::Webdav::VersionScheme::Timestamp;
 
  14 use Rose::Object::MakeMethods::Generic (
 
  15   scalar => [ qw(type number) ],
 
  16   'scalar --get_set_init' => [ qw(version_scheme) ],
 
  20   sales_quotation             => 'angebote',
 
  21   sales_order                 => 'bestellungen',
 
  22   request_quotation           => 'anfragen',
 
  23   purchase_order              => 'lieferantenbestellungen',
 
  24   sales_delivery_order        => 'verkaufslieferscheine',
 
  25   purchase_delivery_order     => 'einkaufslieferscheine',
 
  26   supplier_delivery_order     => 'beistelllieferscheine',
 
  27   rma_delivery_order          => 'retourenlieferscheine',
 
  28   credit_note                 => 'gutschriften',
 
  29   invoice                     => 'rechnungen',
 
  30   invoice_for_advance_payment => 'rechnungen',
 
  31   final_invoice               => 'rechnungen',
 
  32   purchase_invoice            => 'einkaufsrechnungen',
 
  34   service                     => 'dienstleistungen',
 
  35   assembly                    => 'erzeugnisse',
 
  37   general_ledger              => 'dialogbuchungen',
 
  38   accounts_payable            => 'kreditorenbuchungen',
 
  40   vendor                      => 'lieferanten',
 
  41   dunning                     => 'mahnungen',
 
  47   my @objects = $self->get_all_objects;
 
  50   for my $obj (@objects) {
 
  51     my $filename = join '.', grep $_, $obj->basename, $obj->extension;
 
  53     my $file = $files_by_name{$filename} ||= SL::Webdav::File->new(filename => $filename, webdav => $self, loaded => 1);
 
  54     $file->add_objects($obj);
 
  57   return values %files_by_name;
 
  63   my $path = $self->webdav_path;
 
  66   my $base_path = $ENV{'SCRIPT_NAME'};
 
  67   $base_path =~ s|[^/]+$||;
 
  68   if (opendir my $dir, $path) {
 
  69     foreach my $file (sort { lc $a cmp lc $b } map { decode("UTF-8", $_) } readdir $dir) {
 
  70       next if (($file eq '.') || ($file eq '..'));
 
  75       push @objects, SL::Webdav::Object->new(filename => $fname, webdav => $self);
 
  87   my @files = $self->get_all_files;
 
  88   map { ($_->versions)[-1] } @files;
 
  91 sub _sanitized_number {
 
  92   my $number = $_[0]->number;
 
  93   $number =~ s|[/\\]|_|g;
 
 100   die "No client set in \$::auth" unless $::auth->client;
 
 101   die "Need number"               unless $self->number;
 
 103   my $type = $type_to_path{$self->type};
 
 105   die "Unknown type"              unless $type;
 
 107   my $path = File::Spec->catdir("webdav", $::auth->client->{id}, $type, $self->_sanitized_number);
 
 110     Common::mkdir_with_parents($path);
 
 116 sub init_version_scheme {
 
 117   SL::Webdav::VersionScheme::Timestamp->new;
 
 128 SL::Webdav - Webdav manipulation
 
 132   # get list of all documents for this record
 
 135   my $webdav = SL::Webdav->new(
 
 140   # gives you SL::Webdav::File instances
 
 141   my $webdav_files = $webdav->get_all_files;
 
 143   # gives you the objects instead
 
 144   my $webdav_objects = $webdav->get_all_objects;
 
 146   # gives you only the latest objects
 
 147   my $webdav_objects = $webdav->get_all_latest;
 
 149   # physical path to this dir
 
 150   my $path = $webdav->webdav_path;
 
 154 This module is a wrapper around the webdav storage mechanism with some simple
 
 155 document management functionality.
 
 157 This is not a replacement for real document management, mostly because the
 
 158 underlying webdav storage is not fully under our control. It's common practice
 
 159 to allow people direct samba access to the webdav, so all versioning
 
 160 information needs to be encoded into the filename of a file, and nonsensical
 
 161 filenames must not break assumptions.
 
 163 This module is intended to be used if you need to scan the folder for
 
 164 previously saved files and need to build a list in order to display it.
 
 166 If you need to manipulate the versions of a file, see L<SL::Webdav::File>
 
 168 If you need to access a file directly for download or metadata, see L<SL::Webdav::Object>
 
 174 =item C<get_all_objects>
 
 176 Returns all L<SL::Webdav::Objects> found.
 
 178 =item C<get_all_files>
 
 180 Returns all objects sorted into L<SL::Webdav::File>s.
 
 182 =item C<get_all_latest>
 
 184 Returns only the latest object of each L<SL::Webdav::File> found.
 
 188 Returns the physical path to this webdav object.
 
 192 =head1 VERSIONING SCHEME
 
 194 You may register a versioning scheme object to handle versioning. It is
 
 195 expected to implement the following methods:
 
 201 Must return a string that will be used to separate the basename and version part of
 
 202 filenames when generating and parsing.
 
 204 =item C<extract_regexp>
 
 206 Must return a regexp that will match a versioning string at the end of a
 
 207 filename after the extension has been stripped off. It will be surrounded by
 
 212 Must return a comparison function that will be invoked with two
 
 213 L<SL::Webdav::Object> instances.
 
 215 =item C<first_version>
 
 217 Must return a string representing the version of the first of a series of objects.
 
 221 =item C<next_version>
 
 223 Will be called with the latest L<SL::Webdav::Object> and must return a new version string.
 
 225 =item C<keep_last_version>
 
 227 Will be called with the latest L<SL::Webdav::Object>. Truish return value will
 
 228 cause the latest object to be overwritten instead of creating a new version.
 
 232 =head1 BUGS AND CAVEATS
 
 238 File operations are inconsistently L<File::Spec>ed.
 
 244 L<SL::Webdav::File>, L<SL::Webdav::Object>
 
 248 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>