From 0ccbeedc3c5d6f86095ed663919a42bd3df814cc Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 15 Jan 2014 15:09:31 +0100 Subject: [PATCH] =?utf8?q?Datenbankupgrade=20f=C3=BCr=20Spalten,=20die=20n?= =?utf8?q?un=20HTML=20enthalten=20k=C3=B6nnen/sollen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sql/Pg-upgrade2/requirement_spec_edit_html.pl | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 sql/Pg-upgrade2/requirement_spec_edit_html.pl diff --git a/sql/Pg-upgrade2/requirement_spec_edit_html.pl b/sql/Pg-upgrade2/requirement_spec_edit_html.pl new file mode 100644 index 000000000..600e16dd7 --- /dev/null +++ b/sql/Pg-upgrade2/requirement_spec_edit_html.pl @@ -0,0 +1,49 @@ +# @tag: requirement_spec_edit_html +# @description: Pflichtenhefte: diverse Text-Felder in HTML umwandeln +# @depends: requirement_spec_items_update_trigger_fix2 requirement_spec_items_update_trigger_fix requirement_specs_orders requirement_specs_section_templates requirement_specs +package SL::DBUpgrade2::requirement_spec_edit_html; + +use strict; +use utf8; + +use SL::DBUtils; + +use parent qw(SL::DBUpgrade2::Base); + +sub convert_column { + my ($self, $table, $column) = @_; + + my $sth = $self->dbh->prepare(qq|UPDATE $table SET $column = ? WHERE id = ?|) || $self->dberror; + + foreach my $row (selectall_hashref_query($::form, $self->dbh, qq|SELECT id, $column FROM $table WHERE $column IS NOT NULL|)) { + next if !$row->{$column} || (($row->{$column} =~ m{^<[a-z]+>}) && ($row->{$column} =~ m{$})); + + my $new_content = "" . $::request->presenter->escape($row->{$column}); + $new_content =~ s{\r}{}g; + $new_content =~ s{\n\n+}{

}g; + $new_content =~ s{\n}{
}g; + $new_content = "

${new_content}

" if $new_content; + + $sth->execute($new_content, $row->{id}) if $new_content ne $row->{$column}; + } + + $sth->finish; +} + +sub run { + my ($self) = @_; + + my %tables = ( + requirement_spec_predefined_texts => 'text', + requirement_spec_text_blocks => 'text', + requirement_spec_items => 'description', + parts => 'notes', + map({ ($_ => 'longdescription') } qw(translation orderitems invoice delivery_order_items)), + ); + + $self->convert_column($_, $tables{$_}) for sort { $a <=> $b } keys %tables; + + return 1; +} + +1; -- 2.20.1