use Civi\Api4\CustomField;
use Civi\Api4\Event;
use Civi\Api4\UserJob;
+use Civi\UserJob\UserJobInterface;
/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
-abstract class CRM_Import_Parser {
+abstract class CRM_Import_Parser implements UserJobInterface {
/**
* Settings
*/
- const MAX_WARNINGS = 25, DEFAULT_TIMEOUT = 30;
+ const MAX_ERRORS = 10000, MAX_WARNINGS = 25, DEFAULT_TIMEOUT = 30;
/**
* Return codes
$batchSize = $totalRows;
}
$task = new CRM_Queue_Task(
- [get_class($this), 'runImport'],
- ['userJobID' => $this->getUserJobID(), 'limit' => $batchSize],
+ [get_class($this), 'runJob'],
+ // Offset is unused by our import classes, but required by the interface.
+ ['userJobID' => $this->getUserJobID(), 'limit' => $batchSize, 'offset' => 0],
ts('Processed %1 rows out of %2', [1 => $offset + $batchSize, 2 => $totalRowCount])
);
$queue->createItem($task);
* @throws \CRM_Core_Exception Exception thrown if field requirements are not met.
*/
protected function validateRequiredFields(array $requiredFields, array $params, $prefixString = ''): void {
+ if (empty($requiredFields)) {
+ return;
+ }
$missingFields = [];
foreach ($requiredFields as $key => $required) {
if (!is_array($required)) {
}
else {
foreach ($required as $field => $label) {
- if (empty($params[$field])) {
+ if (!isset($params[$field]) || $params[$field] === '') {
$missing[$field] = $label;
}
}
*/
protected function getFieldEntity(string $fieldName) {
if ($fieldName === 'do_not_import') {
- return NULL;
+ return '';
}
if (in_array($fieldName, ['email_greeting_id', 'postal_greeting_id', 'addressee_id'], TRUE)) {
return 'Contact';
*
* @param int $userJobID
* @param int $limit
+ * @param int $offset
*
* @return bool
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
- public static function runImport($taskContext, $userJobID, $limit) {
- $userJob = UserJob::get()->addWhere('id', '=', $userJobID)->addSelect('type_id')->execute()->first();
+ public static function runJob(\CRM_Queue_TaskContext $taskContext, int $userJobID, int $limit, int $offset): bool {
+ $userJob = UserJob::get()->addWhere('id', '=', $userJobID)->addSelect('job_type')->execute()->first();
$parserClass = NULL;
foreach (CRM_Core_BAO_UserJob::getTypes() as $userJobType) {
- if ($userJob['type_id'] === $userJobType['id']) {
+ if ($userJob['job_type'] === $userJobType['id']) {
$parserClass = $userJobType['class'];
}
}