From 49be66cdf74882abde5a93832a959e27baddd925 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Thu, 9 Jan 2014 12:40:29 +0100 Subject: [PATCH] =?utf8?q?Bugfix=20f=C3=BCr=202275=20=20Verk=C3=A4uferinfo?= =?utf8?q?rmationen=20im=20Druck=20kommen=20aus=20der=20Authdatenbank=20cl?= =?utf8?q?oses=20#2275=20Hat=20leider=20einen=20kleinen=20"Rattenschwanz":?= =?utf8?q?=20a)=20Beim=20L=C3=B6schen=20des=20Benutzer=20wird=20nur=20dele?= =?utf8?q?ted=20auf=20true=20gesetzt,=20jetzt=20werden=20auch=20alle=20wei?= =?utf8?q?teren=20benutzereditierbaren=20Metadaten=20gespeichert,=20daf?= =?utf8?q?=C3=BCr=20->=20=20=20b)=20muss=20die=20Tabelle=20employee=20ge?= =?utf8?q?=C3=A4ndert=20werden,=20dabei=20->=20=20=20=20=20c)=20ist=20aufg?= =?utf8?q?efallen,=20dass=20einige=20Felder=20in=20employee=20=C3=BCberhau?= =?utf8?q?pt=20keinen=20Sinn=20mehr=20haben=20(addr1),=20aber=20dann=20...?= =?utf8?q?=20=20=20=20=20=20=20d)=20braucht=20man=20auch=20nicht=20mehr=20?= =?utf8?q?workphone=20mit=20tel=20aus=20der=20auth.user=5Fconfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit zu d) -> SL/DB/Manager/Employee.pm zu b) und c) -> sql/Pg-upgrade2/employee_drop_columns.sql und SL/DB/MetaSetup/Employee.pm zu a) SL/Controller/Admin.pm Jetzt können beim Drucken entweder die Daten des Benutzers genommen werden oder die Daten kommen aus employee (Form.pm) --- SL/Controller/Admin.pm | 12 +++++++++- SL/DB/Manager/Employee.pm | 1 - SL/DB/MetaSetup/Employee.pm | 29 ++++++++++------------- SL/Form.pm | 21 ++++++++++------ sql/Pg-upgrade2/employee_drop_columns.sql | 16 +++++++++++++ 5 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 sql/Pg-upgrade2/employee_drop_columns.sql diff --git a/SL/Controller/Admin.pm b/SL/Controller/Admin.pm index 179142c73..0481926c9 100644 --- a/SL/Controller/Admin.pm +++ b/SL/Controller/Admin.pm @@ -172,6 +172,10 @@ sub action_delete_user { my @clients = @{ $self->user->clients || [] }; + # backup user metadata (email, name, etc) + my $user_config_values_ref = $self->user->config_values(); + my $login =$self->user->login; + if (!$self->user->delete) { flash('error', t8('The user could not be deleted.')); $self->edit_user_form(title => t8('Edit User')); @@ -179,9 +183,15 @@ sub action_delete_user { } # Flag corresponding entries in 'employee' as deleted. + # and restore the most important user data in employee + # TODO try and catch the whole transaction {user->delete; update employee} {exception} foreach my $client (@clients) { my $dbh = $client->dbconnect(AutoCommit => 1) || next; - $dbh->do(qq|UPDATE employee SET deleted = TRUE WHERE login = ?|, undef, $self->user->login); + $dbh->do(qq|UPDATE employee SET deleted = TRUE, name = ?, deleted_email = ?, + deleted_tel = ?, deleted_fax = ?, deleted_signature = ? WHERE login = ?|,undef, + $user_config_values_ref->{name}, $user_config_values_ref->{email}, + $user_config_values_ref->{tel}, $user_config_values_ref->{fax}, + $user_config_values_ref->{signature}, $self->user->login); $dbh->disconnect; } diff --git a/SL/DB/Manager/Employee.pm b/SL/DB/Manager/Employee.pm index b4ebf1444..8acd7da04 100644 --- a/SL/DB/Manager/Employee.pm +++ b/SL/DB/Manager/Employee.pm @@ -26,7 +26,6 @@ sub update_entries_for_authorized_users { $employee->update_attributes( name => $user_config->{name}, - workphone => $user_config->{tel}, deleted => 0, ); } diff --git a/SL/DB/MetaSetup/Employee.pm b/SL/DB/MetaSetup/Employee.pm index b79d078fa..6cdc93021 100644 --- a/SL/DB/MetaSetup/Employee.pm +++ b/SL/DB/MetaSetup/Employee.pm @@ -9,22 +9,19 @@ use base qw(SL::DB::Object); __PACKAGE__->meta->table('employee'); __PACKAGE__->meta->columns( - addr1 => { type => 'text' }, - addr2 => { type => 'text' }, - addr3 => { type => 'text' }, - addr4 => { type => 'text' }, - deleted => { type => 'boolean', default => 'false' }, - enddate => { type => 'date' }, - homephone => { type => 'text' }, - id => { type => 'integer', not_null => 1, sequence => 'id' }, - itime => { type => 'timestamp', default => 'now()' }, - login => { type => 'text' }, - mtime => { type => 'timestamp' }, - name => { type => 'text' }, - notes => { type => 'text' }, - sales => { type => 'boolean', default => 'true' }, - startdate => { type => 'date', default => 'now' }, - workphone => { type => 'text' }, + deleted => { type => 'boolean', default => 'false' }, + deleted_email => { type => 'text' }, + deleted_fax => { type => 'text' }, + deleted_signature => { type => 'text' }, + deleted_tel => { type => 'text' }, + enddate => { type => 'date' }, + id => { type => 'integer', not_null => 1, sequence => 'id' }, + itime => { type => 'timestamp', default => 'now()' }, + login => { type => 'text' }, + mtime => { type => 'timestamp' }, + name => { type => 'text' }, + sales => { type => 'boolean', default => 'true' }, + startdate => { type => 'date', default => 'now' }, ); __PACKAGE__->meta->primary_key_columns([ 'id' ]); diff --git a/SL/Form.pm b/SL/Form.pm index e115f9706..9a6bca2fd 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1926,17 +1926,24 @@ sub get_employee_data { my $myconfig = \%main::myconfig; my $dbh = $params{dbh} || $self->get_standard_dbh($myconfig); - my ($login) = selectrow_query($self, $dbh, qq|SELECT login FROM employee WHERE id = ?|, conv_i($params{id})); + my ($login, $deleted) = selectrow_query($self, $dbh, qq|SELECT login,deleted FROM employee WHERE id = ?|, conv_i($params{id})); if ($login) { - my $user = User->new(login => $login); - $self->{$params{prefix} . "_${_}"} = $user->{$_} for qw(email fax name signature tel); - $self->{$params{prefix} . "_${_}"} = $defaults->$_ for qw(address businessnumber co_ustid company duns taxnumber); - + # login already fetched and still the same client (mandant) | same for both cases (delete|!delete) $self->{$params{prefix} . '_login'} = $login; - $self->{$params{prefix} . '_name'} ||= $login; - } + $self->{$params{prefix} . "_${_}"} = $defaults->$_ for qw(address businessnumber co_ustid company duns taxnumber); + if (!$deleted) { + # get employee data from auth.user_config + my $user = User->new(login => $login); + $self->{$params{prefix} . "_${_}"} = $user->{$_} for qw(email fax name signature tel); + } else { + # get saved employee data from employee + my $employee = SL::DB::Manager::Employee->find_by(id => conv_i($params{id})); + $self->{$params{prefix} . "_${_}"} = $employee->{"deleted_$_"} for qw(email fax signature tel); + $self->{$params{prefix} . "_name"} = $employee->name; + } + } $main::lxdebug->leave_sub(); } diff --git a/sql/Pg-upgrade2/employee_drop_columns.sql b/sql/Pg-upgrade2/employee_drop_columns.sql new file mode 100644 index 000000000..a87cf05a7 --- /dev/null +++ b/sql/Pg-upgrade2/employee_drop_columns.sql @@ -0,0 +1,16 @@ +-- @tag: employee_drop_columns +-- @description: Obsolete Felder in employee entfernt und Datenfelder zum Speichern für die Historie der Mitarbeiter (nach Löschen eines Benutzer) hinzugefügt. Aktuell alle Felder die der Benutzer unter persönliche Einstellungen ändern kann +-- @depends: release_3_0_0 +-- @ignore: 0 +-- @charset: utf-8 +ALTER TABLE employee DROP COLUMN addr1; +ALTER TABLE employee DROP COLUMN addr2; +ALTER TABLE employee DROP COLUMN addr3; +ALTER TABLE employee DROP COLUMN addr4; +ALTER TABLE employee DROP COLUMN homephone; +ALTER TABLE employee DROP COLUMN workphone; +ALTER TABLE employee DROP COLUMN notes; +ALTER TABLE employee ADD COLUMN deleted_email text; +ALTER TABLE employee ADD COLUMN deleted_signature text; +ALTER TABLE employee ADD COLUMN deleted_tel text; +ALTER TABLE employee ADD COLUMN deleted_fax text; -- 2.20.1