summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2013-02-07 21:09:11 -0800
committerIvan Kohler <ivan@freeside.biz>2013-02-07 21:09:11 -0800
commitb808053966fd3c43edefa1b7c4b93cbeb7cf546e (patch)
tree871fc6df930b7939d72b9ad975453179273cd418
parentd14c7526763013113dcddd4ec60c383a5f1c5473 (diff)
fix leading and trailing spaces in customer,, contact, prospect names and companies, RT#19860
-rw-r--r--FS/FS/Record.pm21
-rw-r--r--FS/FS/contact.pm4
-rw-r--r--FS/FS/cust_main.pm36
-rw-r--r--FS/FS/prospect_main.pm6
4 files changed, 59 insertions, 8 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 16031e1..42af68c 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -2513,10 +2513,29 @@ sub ut_name {
# warn "ut_name allowed alphanumerics: +(sort grep /\w/, map { chr() } 0..255), "\n";
$self->getfield($field) =~ /^([\w \,\.\-\']+)$/
or return gettext('illegal_name'). " $field: ". $self->getfield($field);
- $self->setfield($field,$1);
+ my $name = $1;
+ $name =~ s/^\s+//;
+ $name =~ s/\s+$//;
+ $name =~ s/\s+/ /g;
+ $self->setfield($field, $name);
'';
}
+=item ut_namen COLUMN
+
+Check/untaint proper names; allows alphanumerics, spaces and the following
+punctuation: , . - '
+
+May not be null.
+
+=cut
+
+sub ut_namen {
+ my( $self, $field ) = @_;
+ return $self->setfield($field, '') if $self->getfield($field) =~ /^$/;
+ $self->ut_name($field);
+}
+
=item ut_zip COLUMN
Check/untaint zip codes.
diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm
index f84af42..8fcd724 100644
--- a/FS/FS/contact.pm
+++ b/FS/FS/contact.pm
@@ -326,8 +326,8 @@ sub check {
|| $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
|| $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
|| $self->ut_foreign_keyn('classnum', 'contact_class', 'classnum')
- || $self->ut_textn('last')
- || $self->ut_textn('first')
+ || $self->ut_namen('last')
+ || $self->ut_namen('first')
|| $self->ut_textn('title')
|| $self->ut_textn('comment')
|| $self->ut_enum('disabled', [ '', 'Y' ])
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index be910c6..bcb8fc0 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -1792,6 +1792,12 @@ sub check {
|| $self->ut_enum('locale', [ '', FS::Locales->locales ])
;
+ my $company = $self->company;
+ $company =~ s/^\s+//;
+ $company =~ s/\s+$//;
+ $company =~ s/\s+/ /g;
+ $self->company($company);
+
#barf. need message catalogs. i18n. etc.
$error .= "Please select an advertising source."
if $error =~ /^Illegal or empty \(numeric\) refnum: /;
@@ -5080,12 +5086,12 @@ sub process_censustract_update {
}
#starting to take quite a while for big dbs
+# (JRNL: journaled so it only happens once per database)
# - seq scan of h_cust_main (yuck), but not going to index paycvv, so
-# - seq scan of cust_main on signupdate... index signupdate? will that help?
-# - seq scan of cust_main on paydate... index on substrings? maybe set an
-# upgrade journal flag now that we have that, yyyy-m-dd paydates are ancient
-# - seq scan of cust_main on payinfo.. certainly not going toi ndex that...
-# upgrade journal again? this is also an ancient problem
+# JRNL seq scan of cust_main on signupdate... index signupdate? will that help?
+# JRNL seq scan of cust_main on paydate... index on substrings? maybe set an
+# JRNL seq scan of cust_main on payinfo.. certainly not going toi ndex that...
+# JRNL leading/trailing spaces in first, last, company
# - otaker upgrade? journal and call it good? (double check to make sure
# we're not still setting otaker here)
#
@@ -5140,6 +5146,26 @@ sub _upgrade_data { #class method
local($ignore_banned_card) = 1;
local($skip_fuzzyfiles) = 1;
local($import) = 1; #prevent automatic geocoding (need its own variable?)
+
+ unless ( FS::upgrade_journal->is_done('cust_main__trimspaces') ) {
+
+ foreach my $cust_main ( qsearch({
+ 'table' => 'cust_main',
+ 'hashref' => {},
+ 'extra_sql' => 'WHERE '.
+ join(' OR ',
+ map "$_ LIKE ' %' OR $_ LIKE '% ' OR $_ LIKE '% %'",
+ qw( first last company )
+ ),
+ }) ) {
+ my $error = $cust_main->replace;
+ die $error if $error;
+ }
+
+ FS::upgrade_journal->set_done('cust_main__trimspaces');
+
+ }
+
$class->_upgrade_otaker(%opts);
FS::cust_main::Location->_upgrade_data(%opts);
diff --git a/FS/FS/prospect_main.pm b/FS/FS/prospect_main.pm
index b5d51d3..a04af86 100644
--- a/FS/FS/prospect_main.pm
+++ b/FS/FS/prospect_main.pm
@@ -208,6 +208,12 @@ sub check {
;
return $error if $error;
+ my $company = $self->company;
+ $company =~ s/^\s+//;
+ $company =~ s/\s+$//;
+ $company =~ s/\s+/ /g;
+ $self->company($company);
+
$self->SUPER::check;
}