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 contacts_convert_cp_birthday_to_date;
7 die 'This script cannot be run from the command line.' if !$::form;
14 my $sth = $dbh->prepare('SELECT ?::date AS date') or return undef;
15 $sth->execute($str) or return undef;
17 return $sth->fetchrow_hashref->{date};
28 cp_birthday AS cp_birthday_old
33 my $sth = $dbh->prepare($sql) or die $dbh->errstr;
34 $sth->execute or die $dbh->errstr;
37 while (my $row = $sth->fetchrow_hashref) {
39 $row->{cp_birthday} = convert_to_date($::form->{form_submitted} ? $::form->{'cp_birthday_'. $i} : $row->{cp_birthday_old});
40 $row->{row_index} = $i;
42 if ( defined($row->{cp_birthday}) ) {
43 push(@auto_data, $row);
49 $::form->{data} = \@data;
50 $::form->{auto_data} = \@auto_data;
51 $::form->{row_length} = $i;
54 print $::form->parse_html_template('dbupgrade/contacts_convert_cp_birthday_to_date_form');
58 ALTER TABLE contacts DROP COLUMN cp_birthday;
59 ALTER TABLE contacts ADD COLUMN cp_birthday date;
70 $sth = $dbh->prepare($sql) or die $dbh->errstr;
72 foreach (grep { $_->{cp_birthday} ne '' } @auto_data) {
73 $sth->execute($_->{cp_birthday}, $_->{cp_id}) or die $dbh->errstr;