protected function _performCustomerExport() { if (!empty($this->_search)) { // there are search parameters, use them to filter customer data before exporting /** @var ISC_ADMIN_CUSTOMERS */ $customerClass = GetClass('ISC_ADMIN_CUSTOMERS'); $search = $customerClass->BuildWhereFromVars($this->_search); $where = ' WHERE 1=1 ' . $search['query'] . ' '; $join = $search['join']; unset($search); } else { $where = ''; $join = ''; } $query = 'SELECT /*:columns*/ FROM `[|PREFIX|]customers` ' . $join . ' ' . $where; if (!$this->_skip) { $count = $this->_db->FetchOne(str_replace('/*:columns*/', 'COUNT(*)', $query)); $this->_log->LogSystemNotice('emailintegration', GetLang('EmailIntegration_Log_JobCommencingCustomerExport', array( 'count' => $count, ))); $this->_keystore->set($this->_prefix . 'estimate', $count); } // no matter what the search specified, always order by id so new customers do not mess up the batch logic $query .= ' ORDER BY customerid LIMIT '; if ($this->_skip) { $query .= $this->_skip . ','; } $query .= self::BATCH_SIZE; $query = $this->_db->Query(str_replace('/*:columns*/', '`customerid`,`custconemail`,`custconfirstname`', $query)); if (!$query) { $error = GetLang('EmailIntegration_Log_JobCustomerDatabaseError'); $this->_logError($error); $this->_errorExport($error); return false; } // currently the only possible routing for existing customers is via newsletter subscription rules so we don't need to check $this->_rule here and we don't need to perform field mapping because it's always based on email and first-name $subscriptions = array(); while ($row = $this->_db->Fetch($query)) { $subscriptions[] = new Interspire_EmailIntegration_Subscription_Newsletter($row['custconemail'], $row['custconfirstname']); } ISC_EMAILINTEGRATION::routeSubscriptions('onNewsletterSubscribed', $subscriptions, false); return count($subscriptions); }