/** * (non-PHPdoc) * @see tao_models_classes_import_ImportHandler::import() */ public function import($class, $form) { $fileInfo = $form->getValue('source'); //import for CSV if (isset($fileInfo)) { \helpers_TimeOutHelper::setTimeOutLimit(\helpers_TimeOutHelper::MEDIUM); //get the services instances we will need $itemService = \taoItems_models_classes_ItemsService::singleton(); $uploadedFile = $fileInfo['uploaded_file']; $uploadedFileBaseName = basename($uploadedFile); // uploaded file name contains an extra prefix that we have to remove. $uploadedFileBaseName = preg_replace('/^([0-9a-z])+_/', '', $uploadedFileBaseName, 1); $uploadedFileBaseName = preg_replace('/.zip|.ZIP$/', '', $uploadedFileBaseName); $validate = count($form->getValue('disable_validation')) == 0 ? true : false; try { $importer = new Assembler(); $report = $importer->importDelivery($class, $uploadedFile); } catch (\common_Exception $e) { $report = common_report_Report::createFailure(__('An error occured during the import')); if ($e instanceof \common_exception_UserReadableException) { $report->add($e); } } \tao_helpers_File::remove($uploadedFile); \helpers_TimeOutHelper::reset(); } else { throw new \common_exception_Error('No file provided as parameter \'source\' for Delivery Assembly import'); } return $report; }
/** * * @param unknown $params */ public function __invoke($params) { if (count($params) < 1) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Usage: %s ASSEMBLY_FILE [ASSEMBLY_FILE_2] [ASSEMBLY_FILE_3] ...', __CLASS__)); } \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf'); $deliveryClass = DeliveryAssemblyService::singleton()->getRootClass()->createSubClass('Import ' . \tao_helpers_Date::displayeDate(time())); $importer = new Assembler(); $report = new \common_report_Report(\common_report_Report::TYPE_INFO, __('Importing %1$s files into \'%2$s\'', count($params), $deliveryClass->getLabel())); while (!empty($params)) { $file = array_shift($params); $report->add($importer->importDelivery($deliveryClass, $file)); } return $report; }