/** * (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; }
/** * (non-PHPdoc) * @see tao_models_classes_export_ExportHandler::export() */ public function export($formValues, $destination) { if (!isset($formValues['exportInstance']) || empty($formValues['exportInstance'])) { throw new \common_Exception('No instance selected'); } $delivery = new core_kernel_classes_Resource($formValues['exportInstance']); $path = Assembler::exportCompiledDelivery($delivery); return $path; }
/** * * @param unknown $params */ public function __invoke($params) { if (count($params) != 2) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Usage: %s DELIVERY_URI OUTPUT_FILE', __CLASS__)); } $deliveryUri = array_shift($params); $delivery = new \core_kernel_classes_Resource($deliveryUri); if (!$delivery->exists()) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Delivery \'%s\' not found', $deliveryUri)); } $file = array_shift($params); \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf'); $tmpFile = Assembler::exportCompiledDelivery($delivery); \tao_helpers_File::move($tmpFile, $file); return new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Exported %1$s to %2$s', $delivery->getLabel(), $file)); }
/** * (non-PHPdoc) * @see \oat\oatbox\action\Action::__invoke() */ public function __invoke($params) { \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf'); if (count($params) != 2) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Usage: %s DELIVERY_CLASS_URI OUTPUT_DIRECTORY', __CLASS__)); } $deliveryClassUri = array_shift($params); $deliveryClass = new \core_kernel_classes_Class($deliveryClassUri); $dir = array_shift($params); if (!file_exists($dir) && !mkdir($dir)) { return new \common_report_Report(\common_report_Report::TYPE_ERROR, __('Directory %s doesn\'t exist', $dir)); } $dir = rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $report = new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Exporting %s', $deliveryClass->getLabel())); foreach ($deliveryClass->getInstances(true) as $delivery) { $destFile = $dir . \tao_helpers_File::getSafeFileName($delivery->getLabel()) . '.zip'; $tmpFile = Assembler::exportCompiledDelivery($delivery); \tao_helpers_File::move($tmpFile, $destFile); $report->add(new \common_report_Report(\common_report_Report::TYPE_SUCCESS, __('Exported %1$s to %2$s', $delivery->getLabel(), $destFile))); } return $report; }