1 # @tag: contacts_convert_cp_birthday_to_date
2 # @description: Umstellung cp_birthday von Freitext auf Datumsfeld
3 # @depends: release_2_7_0
4 package SL::DBUpgrade2::contacts_convert_cp_birthday_to_date;
9 use parent qw(SL::DBUpgrade2::Base);
12 my ($self, $str) = @_;
14 return '' if !$str || ($str =~ m/00.*00.*00.*00/); # 0000-00-00 may be present in old databases.
16 my $sth = $self->dbh->prepare('SELECT ?::date AS date') or return undef;
17 $sth->execute($str) or return undef;
19 return $sth->fetchrow_hashref->{date};
32 cp_birthday AS cp_birthday_old
37 my $sth = $self->dbh->prepare($sql) or die $self->dbh->errstr;
38 $sth->execute or die $self->dbh->errstr;
41 while (my $row = $sth->fetchrow_hashref) {
43 $row->{cp_birthday} = $self->convert_to_date($::form->{form_submitted} ? $::form->{'cp_birthday_'. $i} : $row->{cp_birthday_old});
44 $row->{row_index} = $i;
46 if ( defined($row->{cp_birthday}) ) {
47 push(@auto_data, $row);
53 $::form->{data} = \@data;
54 $::form->{auto_data} = \@auto_data;
55 $::form->{row_length} = $i;
58 print $::form->parse_html_template('dbupgrade/contacts_convert_cp_birthday_to_date_form');
62 ALTER TABLE contacts DROP COLUMN cp_birthday;
63 ALTER TABLE contacts ADD COLUMN cp_birthday date;
74 $sth = $self->dbh->prepare($sql) or die $self->dbh->errstr;
76 foreach (grep { $_->{cp_birthday} ne '' } @auto_data) {
77 $sth->execute($_->{cp_birthday}, $_->{cp_id}) or die $self->dbh->errstr;