Revision ac4921aa
Von Moritz Bunkus vor fast 9 Jahren hinzugefügt
SL/DBUpgrade2/Base.pm | ||
---|---|---|
143 | 143 |
$self->db_query(qq|ALTER TABLE $params{schema}."$params{table}" DROP CONSTRAINT "${_}"|) for map { $_->[0] } @{ $constraints }; |
144 | 144 |
} |
145 | 145 |
|
146 |
sub convert_column_to_html { |
|
147 |
my ($self, $table, $column) = @_; |
|
148 |
|
|
149 |
my $sth = $self->dbh->prepare(qq|UPDATE $table SET $column = ? WHERE id = ?|) || $self->dberror; |
|
150 |
|
|
151 |
foreach my $row (selectall_hashref_query($::form, $self->dbh, qq|SELECT id, $column FROM $table WHERE $column IS NOT NULL|)) { |
|
152 |
next if !$row->{$column} || (($row->{$column} =~ m{^<[a-z]+>}) && ($row->{$column} =~ m{</[a-z]+>$})); |
|
153 |
|
|
154 |
my $new_content = "" . $::request->presenter->escape($row->{$column}); |
|
155 |
$new_content =~ s{\r}{}g; |
|
156 |
$new_content =~ s{\n\n+}{</p><p>}g; |
|
157 |
$new_content =~ s{\n}{<br />}g; |
|
158 |
$new_content = "<p>${new_content}</p>" if $new_content; |
|
159 |
|
|
160 |
$sth->execute($new_content, $row->{id}) if $new_content ne $row->{$column}; |
|
161 |
} |
|
162 |
|
|
163 |
$sth->finish; |
|
164 |
} |
|
165 |
|
|
146 | 166 |
1; |
147 | 167 |
__END__ |
148 | 168 |
|
... | ... | |
317 | 337 |
This method is the entry point for the actual upgrade. Each upgrade |
318 | 338 |
script must provide this method. |
319 | 339 |
|
340 |
=item C<convert_column_to_html $table, $column> |
|
341 |
|
|
342 |
Converts the content of a single column from text to HTML suitable for |
|
343 |
use with the ckeditor. |
|
344 |
|
|
320 | 345 |
=back |
321 | 346 |
|
322 | 347 |
=head1 BUGS |
sql/Pg-upgrade2/requirement_spec_edit_html.pl | ||
---|---|---|
10 | 10 |
|
11 | 11 |
use parent qw(SL::DBUpgrade2::Base); |
12 | 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 | 13 |
sub run { |
34 | 14 |
my ($self) = @_; |
35 | 15 |
|
... | ... | |
41 | 21 |
map({ ($_ => 'longdescription') } qw(translation orderitems invoice delivery_order_items)), |
42 | 22 |
); |
43 | 23 |
|
44 |
$self->convert_column($_, $tables{$_}) for keys %tables; |
|
24 |
$self->convert_column_to_html($_, $tables{$_}) for keys %tables;
|
|
45 | 25 |
|
46 | 26 |
return 1; |
47 | 27 |
} |
Auch abrufbar als: Unified diff
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.