685 trace(
"Batching importing $class profile $import_profile_id from $file", 3);
694 throw new FakoliException(
"DataSyncManager::batchImportItems cannot be used within a browser request");
705 $process->setProgress(
"Running",
"Scanning file", 0);
709 $process->setProgress(
"Running", pluralize(
"$numRecords record").
" found", 0);
714 $matchingFields = Query::create(
DataImportFieldMapping,
"WHERE class=:cl AND import_profile_id=:pr AND matching=1")
719 $matchingConstraint =
"";
721 foreach($matchingFields as $mf)
723 if ($matchingConstraint) $matchingConstraint .=
" AND ";
724 $matchingConstraint .=
"{$mf->client_field}=:{$c}";
728 trace(
"Matching Constraint: $matchingConstraint", 3);
739 $matchingQuery = Query::create(
$class,
"WHERE $matchingConstraint");
740 $matchingQuery->filter =
new InclusionFilter($item->getPrimaryKey());
742 while($record = DataSyncManager::getRecord($adapter, $fp,
$columns,
$helper))
750 $skip = DataSyncManager::populateItem($item, $record,
$fieldMapping, $lastItem);
756 foreach($matchingFields as $mf)
758 trace(
"Matching: {$mf->client_field} = ".$item->get($mf->client_field), 3);
759 $matchingQuery->bind(
":{$c}", $item->get($mf->client_field));
766 $match = $matchingQuery->executeSingle();
768 $item->set($item->getPrimaryKey(), $match->get($match->getPrimaryKey()));
770 catch(DataNotFoundException $e)
779 if (($match && !$importMatching) || (!$match && !$importNew))
786 if (method_exists(
$helper,
'postProcess'))
788 $helper->postProcess($item, $record);
799 $counter = $skipped + $imported;
801 $percentage = intval((100 * $counter) / $numRecords);
803 $process->setProgress(
"Running",
"Processed record $counter of $numRecords", $percentage);
809 $process->setProgress(
"Completed",
"$imported records imported, $skipped records skipped", 100);
814 $process->setProgress(
"Error", $e->getMessage(), $percentage);
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
static getFieldMapping($class, $import_profile_id)
static generateFilter($fieldMapping)
static getDataAdapter($format=null)
static $import_profile_id
static countRecords($file="", $format=null)
FakoliException is the base exception class for all Fakoli errors.
if(!checkRole("admin")) $c