/** * (non-PHPdoc) * @see tao_models_classes_import_ImportHandler::import() */ public function import($class, $form) { $fileInfo = $form->getValue('source'); if (isset($fileInfo)) { helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::LONG); //the zip extraction is a long process that can exced the 30s timeout //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; $importService = new ImportService(); try { $report = $importService->importXhtmlFile($uploadedFile, $class, $validate); } catch (Exception $e) { $report = common_report_Report::createFailure(__('An unexpected error occured during the OWI Item import.')); if ($e instanceof common_exception_UserReadableException) { $report->add($e); } } helpers_TimeOutHelper::reset(); tao_helpers_File::remove($uploadedFile); } else { throw new common_exception_Error('No file provided as parameter \'source\' for OWI import'); } return $report; }
public function testCompileComplete() { $itemClass = new \core_kernel_classes_Class(TAO_ITEM_CLASS); $report = $this->importService->importXhtmlFile($this->dataFolder . 'complete.zip', $itemClass, false); $complete = $report->getData(); $this->assertInstanceOf('\\core_kernel_classes_Resource', $complete); $storage = \tao_models_classes_service_FileStorage::singleton(); $compiler = new OwiItemCompiler($complete, $storage); $report = $compiler->compile(); $this->assertEquals($report->getType(), \common_report_Report::TYPE_SUCCESS, 'this test try to retrieve http://forge.taotesting.com/themes/tao-theme/images/logo.gif check if available'); $serviceCall = $report->getData(); $this->assertNotNull($serviceCall); $this->assertInstanceOf('\\tao_models_classes_service_ServiceCall', $serviceCall); $itemService = \taoItems_models_classes_ItemsService::singleton(); $this->assertTrue($itemService->deleteItem($complete)); }
<?php /* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; under version 2 * of the License (non-upgradable). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); * * */ use oat\taoOpenWebItem\model\import\ImportService; $itemClass = taoItems_models_classes_ItemsService::singleton()->getRootClass(); $files = array(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Googlemaps.zip', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Mammals.zip', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MammalsRTL.zip'); $service = new ImportService(); foreach ($files as $file) { $report = $service->importXhtmlFile($file, $itemClass, false); $path_parts = pathinfo($file); $label = $path_parts['filename']; $report->getData()->setLabel($label); }