/** * @param int $timeout */ public function runIncompleteImportJobs($timeout = 55) { $startTime = time(); $incompleteImportTables = CRM_Contact_Import_ImportJob::getIncompleteImportTables(); foreach ($incompleteImportTables as $importTable) { $importJob = new CRM_Contact_Import_ImportJob($importTable); $importJob->runImport(NULL, $timeout); $currentTime = time(); if ($currentTime - $startTime >= $timeout) { break; } } }
/** * Process the mapped fields and map it into the uploaded file * preview the file and extract some summary statistics * * @return void * @access public */ public function postProcess() { $importJobParams = array('doGeocodeAddress' => $this->controller->exportValue('DataSource', 'doGeocodeAddress'), 'invalidRowCount' => $this->get('invalidRowCount'), 'conflictRowCount' => $this->get('conflictRowCount'), 'onDuplicate' => $this->get('onDuplicate'), 'dedupe' => $this->get('dedupe'), 'newGroupName' => $this->controller->exportValue($this->_name, 'newGroupName'), 'newGroupDesc' => $this->controller->exportValue($this->_name, 'newGroupDesc'), 'groups' => $this->controller->exportValue($this->_name, 'groups'), 'allGroups' => $this->get('groups'), 'newTagName' => $this->controller->exportValue($this->_name, 'newTagName'), 'newTagDesc' => $this->controller->exportValue($this->_name, 'newTagDesc'), 'tag' => $this->controller->exportValue($this->_name, 'tag'), 'allTags' => $this->get('tag'), 'mapper' => $this->controller->exportValue('MapField', 'mapper'), 'mapFields' => $this->get('fields'), 'contactType' => $this->get('contactType'), 'contactSubType' => $this->get('contactSubType'), 'primaryKeyName' => $this->get('primaryKeyName'), 'statusFieldName' => $this->get('statusFieldName'), 'statusID' => $this->get('statusID'), 'totalRowCount' => $this->get('totalRowCount')); $tableName = $this->get('importTableName'); $importJob = new CRM_Contact_Import_ImportJob($tableName); $importJob->setJobParams($importJobParams); // If ACL applies to the current user, update cache before running the import. if (!CRM_Core_Permission::check('view all contacts')) { $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); CRM_ACL_BAO_Cache::updateEntry($userID); } // run the import $importJob->runImport($this); // update cache after we done with runImport if (!CRM_Core_Permission::check('view all contacts')) { CRM_ACL_BAO_Cache::updateEntry($userID); } // clear all caches CRM_Contact_BAO_Contact_Utils::clearContactCaches(); // add all the necessary variables to the form $importJob->setFormVariables($this); // check if there is any error occured $errorStack = CRM_Core_Error::singleton(); $errors = $errorStack->getErrors(); $errorMessage = array(); if (is_array($errors)) { foreach ($errors as $key => $value) { $errorMessage[] = $value['message']; } // there is no fileName since this is a sql import // so fudge it $config = CRM_Core_Config::singleton(); $errorFile = $config->uploadDir . "sqlImport.error.log"; if ($fd = fopen($errorFile, 'w')) { fwrite($fd, implode('\\n', $errorMessage)); } fclose($fd); $this->set('errorFile', $errorFile); $urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); $urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); $urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Contact_Import_Parser'; $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams)); } //hack to clean db //if job complete drop table. $importJob->isComplete(TRUE); }