Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ImportRdf | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
42 | |||
| 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\tao\model\import; |
| 24 | |
| 25 | use oat\oatbox\action\Action; |
| 26 | use oat\generis\model\kernel\persistence\file\FileIterator; |
| 27 | use oat\generis\model\data\ModelManager; |
| 28 | |
| 29 | /** |
| 30 | * System import of RDF files, will not transform URIs |
| 31 | * |
| 32 | * @access public |
| 33 | * @author Joel Bout, <joel@taotesting.com> |
| 34 | * @package tao |
| 35 | */ |
| 36 | class ImportRdf implements Action |
| 37 | { |
| 38 | public function __invoke($params) |
| 39 | { |
| 40 | if (count($params) < 1) { |
| 41 | return new \common_report_Report( |
| 42 | \common_report_Report::TYPE_ERROR, |
| 43 | __('Usage: ImportRdf RDF_FILE [MODEL_ID]') |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | $filename = array_shift($params); |
| 48 | if (!file_exists($filename) || !is_readable($filename)) { |
| 49 | return new \common_report_Report( |
| 50 | \common_report_Report::TYPE_ERROR, |
| 51 | __('Unable to open file %s', $filename) |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | if (empty($params)) { |
| 56 | $iterator = new FileIterator($filename); |
| 57 | } else { |
| 58 | $modelId = array_shift($params); |
| 59 | $iterator = new FileIterator($filename, $modelId); |
| 60 | } |
| 61 | |
| 62 | $rdf = ModelManager::getModel()->getRdfInterface(); |
| 63 | $triples = 0; |
| 64 | foreach ($iterator as $triple) { |
| 65 | $triples++; |
| 66 | $rdf->add($triple); |
| 67 | } |
| 68 | return new \common_report_Report( |
| 69 | \common_report_Report::TYPE_SUCCESS, |
| 70 | __('Successfully imported %s tripples', $triples) |
| 71 | ); |
| 72 | } |
| 73 | } |