use strict;
+use Carp;
+use File::Path ();
+
use SL::DB::MetaSetup::AuthClient;
use SL::DB::Manager::AuthClient;
use SL::DB::Helper::Util;
__PACKAGE__->meta->initialize;
+__PACKAGE__->before_save('_before_save_remember_old_name');
+__PACKAGE__->after_save('_after_save_ensure_webdav_symlink_correctness');
+__PACKAGE__->after_delete('_after_delete_delete_webdav_symlink');
+
+sub _before_save_remember_old_name {
+ my ($self) = @_;
+
+ delete $self->{__before_save_remember_old_name};
+ if ($self->id && $::lx_office_conf{features}->{webdav}) {
+ $self->{__before_save_remember_old_name} = SL::DB::AuthClient->new(id => $self->id)->load->name;
+ }
+
+ return 1;
+}
+
+sub _after_save_ensure_webdav_symlink_correctness {
+ my ($self) = @_;
+
+ $self->ensure_webdav_symlink_correctness($self->{__before_save_remember_old_name}) if $self->id && $::lx_office_conf{features}->{webdav};
+ return 1;
+}
+
+sub _after_delete_delete_webdav_symlink {
+ my ($self) = @_;
+
+ return 1 if !$::lx_office_conf{features}->{webdav};
+ my $name = $self->webdav_symlink_basename;
+ unlink "webdav/links/${name}";
+ return 1;
+}
+
sub validate {
my ($self) = @_;
return @errors;
}
+sub webdav_symlink_basename {
+ my ($self, $name) = @_;
+
+ $name = $name || $self->name || '';
+ $name =~ s:/+:_:g;
+
+ return $name;
+}
+
+sub ensure_webdav_symlink_correctness {
+ my ($self, $old_name) = @_;
+
+ return unless $::lx_office_conf{features}->{webdav};
+
+ croak "Need object ID" unless $self->id;
+
+ my $new_symlink = $self->webdav_symlink_basename;
+
+ croak "Need name" unless $new_symlink;
+
+ my $base_path = 'webdav/links';
+
+ if ($old_name) {
+ my $old_symlink = $self->webdav_symlink_basename($old_name);
+ return if $old_symlink eq $new_symlink;
+
+ if (-l "${base_path}/${old_symlink}") {
+ rename "${base_path}/${old_symlink}", "${base_path}/${new_symlink}";
+ return;
+ }
+ }
+
+ File::Path::make_path('webdav/' . $self->id);
+ symlink '../' . $self->id, "${base_path}/${new_symlink}";
+}
+
1;
[% LxERP.t8("It can be changed later but must be unique within the installation.") %]
</p>
-<form method="post" action="admin.pl">
+<form method="post" action="controller.pl">
[%- FOREACH client = SELF.clients %]
[%- L.hidden_tag("clients[+].dummy", 1) %]
[%- END %]
<p>
- [%- L.hidden_tag('action', 'list_users') %]
+ [%- L.hidden_tag('action', 'Admin/apply_dbupgrade_scripts') %]
[% L.submit_tag('dummy', LxERP.t8('Continue')) %]
</p>
</form>