Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| AssemblyImportHandler | |
0.00% |
0 / 22 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| getLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getForm | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| import | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoDeliveryRdf\model\import; |
| 24 | |
| 25 | use oat\taoDeliveryRdf\view\form\import\ImportForm; |
| 26 | use common_report_Report; |
| 27 | |
| 28 | /** |
| 29 | * Delivery Assembly importer |
| 30 | * |
| 31 | * @access public |
| 32 | * @author Joel Bout, <joel@taotesting.com> |
| 33 | * @package taoDelivery |
| 34 | */ |
| 35 | class AssemblyImportHandler implements \tao_models_classes_import_ImportHandler |
| 36 | { |
| 37 | /** |
| 38 | * (non-PHPdoc) |
| 39 | * @see tao_models_classes_import_ImportHandler::getLabel() |
| 40 | */ |
| 41 | public function getLabel() |
| 42 | { |
| 43 | return __('Assembly import'); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * (non-PHPdoc) |
| 48 | * @see tao_models_classes_import_ImportHandler::getForm() |
| 49 | */ |
| 50 | public function getForm() |
| 51 | { |
| 52 | $form = new ImportForm(); |
| 53 | return $form->getForm(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * (non-PHPdoc) |
| 58 | * @see tao_models_classes_import_ImportHandler::import() |
| 59 | */ |
| 60 | public function import($class, $form, $userId = null) |
| 61 | { |
| 62 | |
| 63 | $fileInfo = $form->getValue('source'); |
| 64 | //import for CSV |
| 65 | if (isset($fileInfo)) { |
| 66 | \helpers_TimeOutHelper::setTimeOutLimit(\helpers_TimeOutHelper::MEDIUM); |
| 67 | |
| 68 | //get the services instances we will need |
| 69 | $itemService = \taoItems_models_classes_ItemsService::singleton(); |
| 70 | |
| 71 | $uploadedFile = $fileInfo['uploaded_file']; |
| 72 | $uploadedFileBaseName = basename($uploadedFile); |
| 73 | // uploaded file name contains an extra prefix that we have to remove. |
| 74 | $uploadedFileBaseName = preg_replace('/^([0-9a-z])+_/', '', $uploadedFileBaseName, 1); |
| 75 | $uploadedFileBaseName = preg_replace('/.zip|.ZIP$/', '', $uploadedFileBaseName); |
| 76 | |
| 77 | $validate = count($form->getValue('disable_validation')) == 0 ? true : false; |
| 78 | |
| 79 | try { |
| 80 | $importer = new Assembler(); |
| 81 | $report = $importer->importDelivery($class, $uploadedFile); |
| 82 | } catch (\common_Exception $e) { |
| 83 | $report = common_report_Report::createFailure(__('An error occured during the import')); |
| 84 | if ($e instanceof \common_exception_UserReadableException) { |
| 85 | $report->add($e); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | \tao_helpers_File::remove($uploadedFile); |
| 90 | |
| 91 | \helpers_TimeOutHelper::reset(); |
| 92 | } else { |
| 93 | throw new \common_exception_Error('No file provided as parameter \'source\' for Delivery Assembly import'); |
| 94 | } |
| 95 | return $report; |
| 96 | } |
| 97 | } |