[freeside-commits] freeside/bin rt-trim-whitespace,NONE,1.1

Mark Wells mark at wavetail.420.am
Mon Oct 4 18:38:44 PDT 2010


Update of /home/cvs/cvsroot/freeside/bin
In directory wavetail.420.am:/tmp/cvs-serv8963

Added Files:
	rt-trim-whitespace 
Log Message:
script to fix stray whitespace, RT#9959

--- NEW FILE: rt-trim-whitespace ---
#!/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;



More information about the freeside-commits mailing list