diff options
author | mark <mark> | 2010-10-05 01:38:42 +0000 |
---|---|---|
committer | mark <mark> | 2010-10-05 01:38:42 +0000 |
commit | 0a8be4e691bff63c45cc79cc6b7ec667b02f062c (patch) | |
tree | b67b678b7064c1efabcc399d75bf3a16a9856830 | |
parent | 22136ecc8353ff82c9a402218ce849db6cf05dab (diff) |
script to fix stray whitespace, RT#9959
-rwxr-xr-x | bin/rt-trim-whitespace | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/bin/rt-trim-whitespace b/bin/rt-trim-whitespace new file mode 100755 index 000000000..503d9cff7 --- /dev/null +++ b/bin/rt-trim-whitespace @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use FS::Record; +use FS::UID qw(adminsuidsetup dbh driver_name); + +# Remove trailing whitespace from custom field option lists and values. + +my $dbh = adminsuidsetup(shift) or die "Usage: rt-trim-whitespace username\n"; +die "rt-trim-whitespace only works on Pg databases" if driver_name ne 'Pg'; + +my @updates = ( + customfieldvalues => 'name', + objectcustomfieldvalues => 'content', +); + +while(@updates) { + my $table = shift @updates; + my $field = shift @updates; + my $select = +"SELECT $field FROM $table WHERE $field != substring($field from ". + q!E'^(.*\\\\S)\\\\s*$'! . ')'; + + print "$select\n"; + my $rows = $dbh->do($select); + print "$rows rows found.\n"; + + if($rows) { + my $update = +"UPDATE $table SET $field = substring($field from ".q!E'^(.*\\\\S)\\\\s*$'!.')'. +" WHERE $field != substring($field from ".q!E'^(.*\\\\S)\\\\s*$'!.')'; + print "$update\n"; + my $rows = $dbh->do($update); + print "$rows updated.\n"; + } +} +$dbh->commit or die $dbh->errstr; |