From 790e4a4584c26a74c3db20a41f122cdcaf109c18 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 11 Jun 2013 17:16:48 +0200 Subject: [PATCH] =?utf8?q?Upgrade-Script=20f=C3=BCr=20WebDAV-Migration=20z?= =?utf8?q?u=20Mandanten?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sql/Pg-upgrade2-auth/clients_webdav.pl | 124 ++++++++++++++++++ .../dbupgrade/auth/clients_webdav.html | 24 ++++ 2 files changed, 148 insertions(+) create mode 100644 sql/Pg-upgrade2-auth/clients_webdav.pl create mode 100644 templates/webpages/dbupgrade/auth/clients_webdav.html diff --git a/sql/Pg-upgrade2-auth/clients_webdav.pl b/sql/Pg-upgrade2-auth/clients_webdav.pl new file mode 100644 index 000000000..2476e8ac2 --- /dev/null +++ b/sql/Pg-upgrade2-auth/clients_webdav.pl @@ -0,0 +1,124 @@ +# @tag: clients_webdav +# @description: WebDAV-Migration für Mandanten +# @depends: clients +# @ignore: 0 +package SL::DBUpgrade2::clients_webdav; + +use strict; +use utf8; + +use parent qw(SL::DBUpgrade2::Base); + +use File::Path qw(make_path); +use IO::Dir; +use List::MoreUtils qw(any all); +use List::Util qw(first); + +use SL::DBConnect; +use SL::DBUtils; +use SL::Template; +use SL::Helper::Flash; + +use Rose::Object::MakeMethods::Generic ( + 'scalar --get_set_init' => [ qw(clients old_folders) ], +); + +sub init_clients { + my ($self) = @_; + return [ selectall_hashref_query($::form, $self->dbh, qq|SELECT * FROM auth.clients ORDER BY lower(name)|) ]; +} + +sub init_old_folders { + tie my %dir, 'IO::Dir', 'webdav'; + return [ sort grep { -d } keys %dir ]; +} + +sub _unlink_old_folders { + my ($self, %params) = @_; + + rmdir $_ for @{ $self->old_folders }; + + return 1; +} + +sub _ensure_one_client_exists { + my ($self, %params) = @_; + + return if 0 != scalar @{ $self->clients }; + + my $sql = <dbh->do($sql, undef, $::locale->text('Default Client (unconfigured)'), ($::locale->text('unconfigured')) x 4); + + undef $self->{clients}; +} + +sub _move_files_into { + my ($self, $client) = @_; + + tie my %dir, 'IO::Dir', 'webdav'; + my @entries = grep { !m/^\.\.?$/ } keys %dir; + + make_path('webdav/' . $client->{id}); + rename "webdav/$_", "webdav/" . $client->{id} . "/$_" for @entries; +} + +sub _create_folders { + my ($self, $client) = @_; + make_path('webdav/' . $client->{id} . "/$_") for qw(angebote bestellungen anfragen lieferantenbestellungen verkaufslieferscheine einkaufslieferscheine gutschriften rechnungen einkaufsrechnungen); +} + +sub _create_symlink { + my ($self, $client) = @_; + + my $name = $client->{name} // ''; + $name =~ s:/+:_:g; + + make_path('webdav/links'); + symlink '../' . $client->{id}, "webdav/links/${name}"; +} + +sub run { + my ($self) = @_; + + # WebDAV not activated? Remove old folders, and we're done. + return $self->_unlink_old_folders if !$::lx_office_conf{features}->{webdav}; + + # Ensure at least one client exists. + $self->_ensure_one_client_exists; + + my $client_to_use; + if (1 == scalar @{ $self->clients }) { + # Exactly one client? Great, use that one without bothering the + # user. + $client_to_use = $self->clients->[0]; + + } else { + # If there's more than one client then let the user select which + # client to move the old files into. Maybe she already did? + $client_to_use = first { $_->{id} == $::form->{client_id} } @{ $self->clients } if $::form->{client_id}; + + if (!$client_to_use) { + # Nope, let's select it. + print $::form->parse_html_template('dbupgrade/auth/clients_webdav', { SELF => $self, default_client => (first { $_->{is_default} } @{ $self->clients }) }); + return 2; + } + } + + # Move files for the selected client. + $self->_move_files_into($client_to_use); + + # Create the directory structures for all (even the selected client + # -- folders might be missing). + for (@{ $self->clients }) { + $self->_create_folders($_); + $self->_create_symlink($_); + } + + return 1; +} + +1; diff --git a/templates/webpages/dbupgrade/auth/clients_webdav.html b/templates/webpages/dbupgrade/auth/clients_webdav.html new file mode 100644 index 000000000..f56032301 --- /dev/null +++ b/templates/webpages/dbupgrade/auth/clients_webdav.html @@ -0,0 +1,24 @@ +[%- USE LxERP -%][%- USE L -%] + +[%- INCLUDE 'common/flash.html' %] + +

[%- LxERP.t8("Introduction of clients") %] -- [% LxERP.t8("Handling of WebDAV") %]

+ +

+ [% LxERP.t8("The WebDAV feature is activated.") %] + [% LxERP.t8("With the introduction of clients each client gets its own WebDAV folder.") %] + [% LxERP.t8("In order to migrate the old folder structure into the new structure you have to chose which client the old structure will be assigned to.") %] + [% LxERP.t8("All the other clients will start with an empty set of WebDAV folders.") %] +

+ +
+

+ [% LxERP.t8("Client to assign the existing WebDAV folders to") %]: + [% L.select_tag('client_id', SELF.clients, default=default_client.id, title_key='name') %] +

+ +

+ [%- L.hidden_tag('action', 'Admin/apply_dbupgrade_scripts') %] + [% L.submit_tag('dummy', LxERP.t8('Continue')) %] +

+
-- 2.20.1