X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=sql%2FPg-upgrade2%2Fcontacts_convert_cp_birthday_to_date.pl;h=ab4a0175a81b99a9e6c20fcebf48856d880f793e;hb=a6e0a7f493d24aec0eebede85eeaa5e724bd2e11;hp=2f10670c459618a0556a404040b50bbbb5a304ef;hpb=5c7cee5835f16a5b7e2f440788b414af2d036e85;p=kivitendo-erp.git diff --git a/sql/Pg-upgrade2/contacts_convert_cp_birthday_to_date.pl b/sql/Pg-upgrade2/contacts_convert_cp_birthday_to_date.pl index 2f10670c4..ab4a0175a 100644 --- a/sql/Pg-upgrade2/contacts_convert_cp_birthday_to_date.pl +++ b/sql/Pg-upgrade2/contacts_convert_cp_birthday_to_date.pl @@ -1,23 +1,27 @@ # @tag: contacts_convert_cp_birthday_to_date # @description: Umstellung cp_birthday von Freitext auf Datumsfeld # @depends: release_2_7_0 -package contacts_convert_cp_birthday_to_date; +package SL::DBUpgrade2::contacts_convert_cp_birthday_to_date; + use strict; +use utf8; -die 'This script cannot be run from the command line.' if !$::form; +use parent qw(SL::DBUpgrade2::Base); sub convert_to_date { - my ($str) = @_; + my ($self, $str) = @_; - return '' if !$str; + return '' if !$str || ($str =~ m/00.*00.*00.*00/); # 0000-00-00 may be present in old databases. - my $sth = $dbh->prepare('SELECT ?::date AS date') or return undef; - $sth->execute($str) or return undef; + my $sth = $self->dbh->prepare('SELECT ?::date AS date') or return undef; + $sth->execute($str) or return undef; return $sth->fetchrow_hashref->{date}; } -sub update { +sub run { + my ($self) = @_; + my @data = (); my @auto_data = (); my $sql = <prepare($sql) or die $dbh->errstr; - $sth->execute or die $dbh->errstr; + my $sth = $self->dbh->prepare($sql) or die $self->dbh->errstr; + $sth->execute or die $self->dbh->errstr; my $i = -1; while (my $row = $sth->fetchrow_hashref) { $i++; - $row->{cp_birthday} = convert_to_date($::form->{form_submitted} ? $::form->{'cp_birthday_'. $i} : $row->{cp_birthday_old}); + $row->{cp_birthday} = $self->convert_to_date($::form->{form_submitted} ? $::form->{'cp_birthday_'. $i} : $row->{cp_birthday_old}); $row->{row_index} = $i; if ( defined($row->{cp_birthday}) ) { @@ -59,7 +63,7 @@ SQL ALTER TABLE contacts ADD COLUMN cp_birthday date; SQL - $dbh->do($sql); + $self->dbh->do($sql); $sql = <prepare($sql) or die $dbh->errstr; + $sth = $self->dbh->prepare($sql) or die $self->dbh->errstr; foreach (grep { $_->{cp_birthday} ne '' } @auto_data) { - $sth->execute($_->{cp_birthday}, $_->{cp_id}) or die $dbh->errstr; + $sth->execute($_->{cp_birthday}, $_->{cp_id}) or die $self->dbh->errstr; } return 1; } } -return update(); +1;