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'));
}
# 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;
}
$employee->update_attributes(
name => $user_config->{name},
- workphone => $user_config->{tel},
deleted => 0,
);
}
__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' ]);
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();
}
--- /dev/null
+-- @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;