summaryrefslogtreecommitdiff
path: root/FS/FS/cust_main/Location.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2014-04-24 12:06:48 -0700
committerMark Wells <mark@freeside.biz>2014-04-24 12:06:48 -0700
commit0296a565242ead37c8b60cd388b5e11c7e03f757 (patch)
tree49cbf51314883fa07d6d17adca5b83e16f053982 /FS/FS/cust_main/Location.pm
parentf5f14337e9657c96f35fa34a824fffab40bee2c1 (diff)
avoid excess memory usage in cust_main location upgrade, #28841
Diffstat (limited to 'FS/FS/cust_main/Location.pm')
-rw-r--r--FS/FS/cust_main/Location.pm21
1 files changed, 12 insertions, 9 deletions
diff --git a/FS/FS/cust_main/Location.pm b/FS/FS/cust_main/Location.pm
index 4f382af..9899f72 100644
--- a/FS/FS/cust_main/Location.pm
+++ b/FS/FS/cust_main/Location.pm
@@ -4,6 +4,7 @@ use strict;
use vars qw( $DEBUG $me @location_fields );
use FS::Record qw(qsearch qsearchs);
use FS::UID qw(dbh);
+use FS::Cursor;
use FS::cust_location;
use Carp qw(carp);
@@ -137,6 +138,7 @@ sub _upgrade_data {
|| new FS::contact_class { classname => 'Service'};
if ( !$service_contact_class->classnum ) {
+ warn "Creating service contact class.\n";
$error = $service_contact_class->insert;
die "error creating contact class for Service: $error" if $error;
}
@@ -158,11 +160,12 @@ sub _upgrade_data {
}
}
- foreach my $cust_main (qsearch('cust_main', {
- bill_locationnum => '',
- address1 => { op=>'!=', value=>'' },
- }))
- {
+ warn "Migrating customer locations.\n";
+ my $search = FS::Cursor->new('cust_main',
+ { bill_locationnum => '',
+ address1 => { op=>'!=', value=>'' }
+ });
+ while (my $cust_main = $search->fetch) {
# Step 1: extract billing and service addresses into cust_location
my $custnum = $cust_main->custnum;
my $bill_location = FS::cust_location->new(
@@ -287,9 +290,9 @@ sub _upgrade_data {
if $error;
# Step 4: set packages at the "default service location" to ship_location
- foreach my $cust_pkg (
- qsearch('cust_pkg', { custnum => $custnum, locationnum => '' })
- ) {
+ my $pkg_search =
+ FS::Cursor->new('cust_pkg', { custnum => $custnum, locationnum => '' });
+ while (my $cust_pkg = $pkg_search->fetch) {
# not a location change
$cust_pkg->set('locationnum', $cust_main->ship_locationnum);
$error = $cust_pkg->replace;
@@ -297,7 +300,7 @@ sub _upgrade_data {
if $error;
}
- } #foreach $cust_main
+ } #while (my $cust_main...)
# repair an error in earlier upgrades
if (!FS::upgrade_journal->is_done('cust_location_censustract_repair')