From: Steve Sutton Date: Thu, 15 Jun 2017 17:09:24 +0000 (-0400) Subject: Working on breaking up member file processing X-Git-Tag: v2.10.0^2~11^2~22 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=c8a3fbb24ab77d64080905dbab933817e685c0c9;p=WP-Plugins%2Fglm-member-db.git Working on breaking up member file processing breaking up into 20 members at a time. --- diff --git a/models/admin/import/index.php b/models/admin/import/index.php index 9b4ac946..f9278fea 100644 --- a/models/admin/import/index.php +++ b/models/admin/import/index.php @@ -93,6 +93,30 @@ class GlmMembersAdmin_import_index */ public $wpOptionPrefix = 'glm_members_import_'; + /** + * memberProcessCountPerRound + * + * @var float + * @access public + */ + public $memberProcessCountPerRound = 20; + + /** + * numberProcessed + * + * @var float + * @access public + */ + public $numberProcessed = 0; + + /** + * totalMembers + * + * @var float + * @access public + */ + public $totalMembers = 0; + /** * Constructor * @@ -327,6 +351,9 @@ class GlmMembersAdmin_import_index $fileData[$fileHeader]['results'] = $this->processFile( $uploadPath . '/' . $file['name'], $file['type'] ); } } + // Here we need to check to see if we processed all members. + // If not we need to use the process.html view. + // Also the counter has to increment the total processed so far. $view = 'processMembers.html'; break; @@ -345,24 +372,35 @@ class GlmMembersAdmin_import_index } $templateData = array( - 'errors' => $this->errors, - 'data' => false, - 'fileData' => $fileData, - 'clearData' => $clearData, - 'csvData' => '
$fileData: ' . print_r( $fileData, true ) . '
', - 'readyToProcess' => $readyToProcess + 'errors' => $this->errors, + 'numberProcessed' => $this->numberProcessed, + 'data' => false, + 'fileData' => $fileData, + 'clearData' => $clearData, + 'csvData' => '
$fileData: ' . print_r( $fileData, true ) . '
', + 'readyToProcess' => $readyToProcess ); // Return status, suggested view, and data to controller return array( 'status' => true, 'menuItemRedirect' => false, 'modelRedirect' => false, - 'view' => 'admin/import/'.$view, + 'view' => 'admin/import/' . $view, 'data' => $templateData ); } + /** + * readCSVFileHeaders + * + * Read the cvs file. Just the first line is read. + * + * @param mixed $fileName Name of the file (path) + + * @access public + * @return void + */ public function readCSVFileHeaders( $fileName ) { $fileHeaders = array(); @@ -375,6 +413,16 @@ class GlmMembersAdmin_import_index return $fileHeaders; } + /** + * readCSVFile + * + * Read the entire csv file. First line is used for headers of the returned + * array. + * + * @param mixed $fileName + * @access public + * @return void + */ public function readCSVFile( $fileName ) { $fileData = array(); @@ -591,6 +639,10 @@ class GlmMembersAdmin_import_index return ( $errorCount == 0 ); break; case 'member': + $start = 1; + if ( isset( $_REQUEST['start'] ) ) { + $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT ); + } $memberData = $this->readCSVFile( $fileName ); $ret .= '

Processing Member File

'; // Get default member type @@ -613,8 +665,17 @@ class GlmMembersAdmin_import_index ); $memberTypeId = $this->mpdb->insert_id; } - $dupeNames = 0; - foreach ( $memberData as $data ) { + $dupeNames = 0; + $this->totalMembers = count( $memberData ); + + // Find out how many are left to process. + $testEnd = $start + $this->memberProcessCountPerRound; + $ending = ( $testEnd <= $this->totalMembers ) ? $testEnd : $this->totalMembers; + + // We have to add one to $ending (array starts at 1 not 0). + $ending++; + for ( $index = $start; $index < $ending; $index++ ) { + $data = $memberData[$index]; // Check for duplicate member $memberId = $this->wpdb->get_var( $this->wpdb->prepare( @@ -673,13 +734,11 @@ class GlmMembersAdmin_import_index 'region' => ((isset($data['region']) && isset($this->regions[$data['region']]['new_id'])) ? $this->regions[$data['region']]['new_id']: 0), 'county' => ((isset($data['county']) && isset($this->counties[$data['county']]['new_id'])) ? $this->counties[$data['county']]['new_id']: 0), 'zip' => $data['zip'], - 'mailing_addr1' => $data['mailing_addr1'], 'mailing_addr2' => $data['mailing_addr2'], 'mailing_city' => ((isset($data['mailing_city']) && isset($this->cities[$data['mailing_city']]['new_id'])) ? $this->cities[$data['mailing_city']]['new_id']: 0), 'mailing_state' => $data['mailing_state'], 'mailing_zip' => $data['mailing_zip'], - 'lat' => $data['lat'], 'lon' => $data['lon'], 'phone' => $data['phone'], @@ -779,6 +838,8 @@ class GlmMembersAdmin_import_index } } } + // Add this record to the processed counter. + $this->numberProcessed++; } //$ret .= '
$this->members: ' . print_r( $this->members, true ) . '
'; $ret .= '

...

';