Revision 0ccbeedc
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
sql/Pg-upgrade2/requirement_spec_edit_html.pl | ||
---|---|---|
1 |
# @tag: requirement_spec_edit_html |
|
2 |
# @description: Pflichtenhefte: diverse Text-Felder in HTML umwandeln |
|
3 |
# @depends: requirement_spec_items_update_trigger_fix2 requirement_spec_items_update_trigger_fix requirement_specs_orders requirement_specs_section_templates requirement_specs |
|
4 |
package SL::DBUpgrade2::requirement_spec_edit_html; |
|
5 |
|
|
6 |
use strict; |
|
7 |
use utf8; |
|
8 |
|
|
9 |
use SL::DBUtils; |
|
10 |
|
|
11 |
use parent qw(SL::DBUpgrade2::Base); |
|
12 |
|
|
13 |
sub convert_column { |
|
14 |
my ($self, $table, $column) = @_; |
|
15 |
|
|
16 |
my $sth = $self->dbh->prepare(qq|UPDATE $table SET $column = ? WHERE id = ?|) || $self->dberror; |
|
17 |
|
|
18 |
foreach my $row (selectall_hashref_query($::form, $self->dbh, qq|SELECT id, $column FROM $table WHERE $column IS NOT NULL|)) { |
|
19 |
next if !$row->{$column} || (($row->{$column} =~ m{^<[a-z]+>}) && ($row->{$column} =~ m{</[a-z]+>$})); |
|
20 |
|
|
21 |
my $new_content = "" . $::request->presenter->escape($row->{$column}); |
|
22 |
$new_content =~ s{\r}{}g; |
|
23 |
$new_content =~ s{\n\n+}{</p><p>}g; |
|
24 |
$new_content =~ s{\n}{<br />}g; |
|
25 |
$new_content = "<p>${new_content}</p>" if $new_content; |
|
26 |
|
|
27 |
$sth->execute($new_content, $row->{id}) if $new_content ne $row->{$column}; |
|
28 |
} |
|
29 |
|
|
30 |
$sth->finish; |
|
31 |
} |
|
32 |
|
|
33 |
sub run { |
|
34 |
my ($self) = @_; |
|
35 |
|
|
36 |
my %tables = ( |
|
37 |
requirement_spec_predefined_texts => 'text', |
|
38 |
requirement_spec_text_blocks => 'text', |
|
39 |
requirement_spec_items => 'description', |
|
40 |
parts => 'notes', |
|
41 |
map({ ($_ => 'longdescription') } qw(translation orderitems invoice delivery_order_items)), |
|
42 |
); |
|
43 |
|
|
44 |
$self->convert_column($_, $tables{$_}) for sort { $a <=> $b } keys %tables; |
|
45 |
|
|
46 |
return 1; |
|
47 |
} |
|
48 |
|
|
49 |
1; |
Auch abrufbar als: Unified diff
Datenbankupgrade für Spalten, die nun HTML enthalten können/sollen