From ac4921aa8a932435696edaadfc35a3eac5217e9c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 10 Feb 2016 13:29:54 +0100 Subject: [PATCH] SL::DBUpgrade2::Base: Spalte-zu-HTML-Funktion ausgelagert Damit diese Funktion auch aus anderen Datenbankupgradescripten heraus benutzt werden kann, wurde sie nun in die Basisklasse verschoben. --- SL/DBUpgrade2/Base.pm | 25 +++++++++++++++++++ sql/Pg-upgrade2/requirement_spec_edit_html.pl | 22 +--------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/SL/DBUpgrade2/Base.pm b/SL/DBUpgrade2/Base.pm index 594fb7fba..024282f65 100644 --- a/SL/DBUpgrade2/Base.pm +++ b/SL/DBUpgrade2/Base.pm @@ -143,6 +143,26 @@ SQL $self->db_query(qq|ALTER TABLE $params{schema}."$params{table}" DROP CONSTRAINT "${_}"|) for map { $_->[0] } @{ $constraints }; } +sub convert_column_to_html { + 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; +} + 1; __END__ @@ -317,6 +337,11 @@ C yet. This method is the entry point for the actual upgrade. Each upgrade script must provide this method. +=item C + +Converts the content of a single column from text to HTML suitable for +use with the ckeditor. + =back =head1 BUGS diff --git a/sql/Pg-upgrade2/requirement_spec_edit_html.pl b/sql/Pg-upgrade2/requirement_spec_edit_html.pl index c6c7b9ff2..507565300 100644 --- a/sql/Pg-upgrade2/requirement_spec_edit_html.pl +++ b/sql/Pg-upgrade2/requirement_spec_edit_html.pl @@ -10,26 +10,6 @@ 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) = @_; @@ -41,7 +21,7 @@ sub run { map({ ($_ => 'longdescription') } qw(translation orderitems invoice delivery_order_items)), ); - $self->convert_column($_, $tables{$_}) for keys %tables; + $self->convert_column_to_html($_, $tables{$_}) for keys %tables; return 1; } -- 2.20.1