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 credit_note => 'gutschriften',
27 invoice => 'rechnungen',
28 purchase_invoice => 'einkaufsrechnungen',
30 service => 'dienstleistungen',
31 assembly => 'erzeugnisse',
33 general_ledger => 'dialogbuchungen',
34 accounts_payable => 'kreditorenbuchungen',
36 vendor => 'lieferanten',
42 my @objects = $self->get_all_objects;
45 for my $obj (@objects) {
46 my $filename = join '.', grep $_, $obj->basename, $obj->extension;
48 my $file = $files_by_name{$filename} ||= SL::Webdav::File->new(filename => $filename, webdav => $self, loaded => 1);
49 $file->add_objects($obj);
52 return values %files_by_name;
58 my $path = $self->webdav_path;
61 my $base_path = $ENV{'SCRIPT_NAME'};
62 $base_path =~ s|[^/]+$||;
63 if (opendir my $dir, $path) {
64 foreach my $file (sort { lc $a cmp lc $b } map { decode("UTF-8", $_) } readdir $dir) {
65 next if (($file eq '.') || ($file eq '..'));
70 push @objects, SL::Webdav::Object->new(filename => $fname, webdav => $self);
82 my @files = $self->get_all_files;
83 map { ($_->versions)[-1] } @files;
86 sub _sanitized_number {
87 my $number = $_[0]->number;
88 $number =~ s|[/\\]|_|g;
95 die "No client set in \$::auth" unless $::auth->client;
96 die "Need number" unless $self->number;
98 my $type = $type_to_path{$self->type};
100 die "Unknown type" unless $type;
102 my $path = File::Spec->catdir("webdav", $::auth->client->{id}, $type, $self->_sanitized_number);
105 Common::mkdir_with_parents($path);
111 sub init_version_scheme {
112 SL::Webdav::VersionScheme::Timestamp->new;
123 SL::Webdav - Webdav manipulation
127 # get list of all documents for this record
130 my $webdav = SL::Webdav->new(
135 # gives you SL::Webdav::File instances
136 my $webdav_files = $webdav->get_all_files;
138 # gives you the objects instead
139 my $webdav_objects = $webdav->get_all_objects;
141 # gives you only the latest objects
142 my $webdav_objects = $webdav->get_all_latest;
144 # physical path to this dir
145 my $path = $webdav->webdav_path;
149 This module is a wrapper around the webdav storage mechanism with some simple
150 document management functionality.
152 This is not a replacement for real document management, mostly because the
153 underlying webdav storage is not fully under our control. It's common practice
154 to allow people direct samba access to the webdav, so all versioning
155 information needs to be encoded into the filename of a file, and nonsensical
156 filenames must not break assumptions.
158 This module is intended to be used if you need to scan the folder for
159 previously saved files and need to build a list in order to display it.
161 If you need to manipulate the versions of a file, see L<SL::Webdav::File>
163 If you need to access a file directly for download or metadata, see L<SL::Webdav::Object>
169 =item C<get_all_objects>
171 Returns all L<SL::Webdav::Objects> found.
173 =item C<get_all_files>
175 Returns all objects sorted into L<SL::Webdav::File>s.
177 =item C<get_all_latest>
179 Returns only the latest object of each L<SL::Webdav::File> found.
183 Returns the physical path to this webdav object.
187 =head1 VERSIONING SCHEME
189 You may register a versioning scheme object to handle versioning. It is
190 expected to implement the following methods:
196 Must return a string that will be used to separate the basename and version part of
197 filenames when generating and parsing.
199 =item C<extract_regexp>
201 Must return a regexp that will match a versioning string at the end of a
202 filename after the extension has been stripped off. It will be surrounded by
207 Must return a comparison function that will be invoked with two
208 L<SL::Webdav::Object> instances.
210 =item C<first_version>
212 Must return a string representing the version of the first of a series of objects.
216 =item C<next_version>
218 Will be called with the latest L<SL::Webdav::Object> and must return a new version string.
220 =item C<keep_last_version>
222 Will be called with the latest L<SL::Webdav::Object>. Truish return value will
223 cause the latest object to be overwritten instead of creating a new version.
227 =head1 BUGS AND CAVEATS
233 File operations are inconsistently L<File::Spec>ed.
239 L<SL::Webdav::File>, L<SL::Webdav::Object>
243 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>