Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ExportAssemblyClass | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
__invoke | |
0.00% |
0 / 31 |
|
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) 2015-2018 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
19 | * |
20 | */ |
21 | |
22 | namespace oat\taoDeliveryRdf\model\export; |
23 | |
24 | use oat\oatbox\extension\AbstractAction; |
25 | |
26 | /** |
27 | * Exports the specified Assembly Class |
28 | * |
29 | * @author Joel Bout |
30 | * |
31 | */ |
32 | class ExportAssemblyClass extends AbstractAction |
33 | { |
34 | /** |
35 | * (non-PHPdoc) |
36 | * @see \oat\oatbox\action\Action::__invoke() |
37 | */ |
38 | public function __invoke($params) |
39 | { |
40 | |
41 | \common_ext_ExtensionsManager::singleton()->getExtensionById('taoDeliveryRdf'); |
42 | |
43 | if (count($params) != 2) { |
44 | return new \common_report_Report( |
45 | \common_report_Report::TYPE_ERROR, |
46 | __('Usage: %s DELIVERY_CLASS_URI OUTPUT_DIRECTORY', __CLASS__) |
47 | ); |
48 | } |
49 | |
50 | $deliveryClassUri = array_shift($params); |
51 | $deliveryClass = new \core_kernel_classes_Class($deliveryClassUri); |
52 | |
53 | $dir = array_shift($params); |
54 | if (!file_exists($dir) && !mkdir($dir)) { |
55 | return new \common_report_Report( |
56 | \common_report_Report::TYPE_ERROR, |
57 | __('Directory %s doesn\'t exist', $dir) |
58 | ); |
59 | } |
60 | $dir = rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
61 | |
62 | $report = new \common_report_Report( |
63 | \common_report_Report::TYPE_SUCCESS, |
64 | __('Exporting %s', $deliveryClass->getLabel()) |
65 | ); |
66 | /** @var AssemblyExporterService $assembler */ |
67 | $assembler = $this->getServiceLocator()->get(AssemblyExporterService::class); |
68 | foreach ($deliveryClass->getInstances(true) as $delivery) { |
69 | $destFile = $dir . \tao_helpers_File::getSafeFileName($delivery->getLabel()) . '.zip'; |
70 | $tmpFile = $assembler->exportCompiledDelivery($delivery); |
71 | \tao_helpers_File::move($tmpFile, $destFile); |
72 | $report->add( |
73 | new \common_report_Report( |
74 | \common_report_Report::TYPE_SUCCESS, |
75 | __('Exported %1$s to %2$s', $delivery->getLabel(), $destFile) |
76 | ) |
77 | ); |
78 | } |
79 | |
80 | return $report; |
81 | } |
82 | } |