Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| tao_install_services_CheckFileSystemComponentService | |
0.00% |
0 / 59 |
|
0.00% |
0 / 5 |
552 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| checkData | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
182 | |||
| buildComponent | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
56 | |||
| buildResult | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | /** |
| 28 | * A Service implementation aiming at checking the existence and the validity of rights |
| 29 | * of file system components, in other words files and directorties. |
| 30 | * |
| 31 | * Please refer to tao/install/api.php for more information about how to call this service. |
| 32 | * |
| 33 | * @access public |
| 34 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 35 | * @package tao |
| 36 | |
| 37 | */ |
| 38 | class tao_install_services_CheckFileSystemComponentService extends tao_install_services_Service implements |
| 39 | tao_install_services_CheckService |
| 40 | { |
| 41 | /** |
| 42 | * Creates a new instance of the service. |
| 43 | * @param tao_install_services_Data $data The input data to be handled by the service. |
| 44 | * @throws InvalidArgumentException If the input data structured is malformed or is missing data. |
| 45 | */ |
| 46 | public function __construct(tao_install_services_Data $data) |
| 47 | { |
| 48 | parent::__construct($data); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Executes the main logic of the service. |
| 53 | * @return tao_install_services_Data The result of the service execution. |
| 54 | */ |
| 55 | public function execute() |
| 56 | { |
| 57 | |
| 58 | $fsc = self::buildComponent($this->getData()); |
| 59 | $report = $fsc->check(); |
| 60 | $this->setResult(self::buildResult($this->getData(), $report, $fsc)); |
| 61 | } |
| 62 | |
| 63 | protected function checkData() |
| 64 | { |
| 65 | $content = json_decode($this->getData()->getContent(), true); |
| 66 | if (!isset($content['type']) || empty($content['type'])) { |
| 67 | throw new InvalidArgumentException("Missing data: 'type' must be provided."); |
| 68 | } elseif ($content['type'] !== 'CheckFileSystemComponent') { |
| 69 | throw new InvalidArgumentException("Unexpected type: 'type' must be equal to 'CheckFileSystemComponent'."); |
| 70 | } elseif (!isset($content['value']) || empty($content['value']) || count($content['value']) == 0) { |
| 71 | throw new InvalidArgumentException("Missing data: 'value' must be provided as a not empty array."); |
| 72 | } elseif (!isset($content['value']['id']) || empty($content['value']['id'])) { |
| 73 | throw new InvalidArgumentException("Missing data: 'id' must be provided."); |
| 74 | } elseif (!isset($content['value']['rights']) || empty($content['value']['rights'])) { |
| 75 | throw new InvalidArgumentException("Missing data: 'rights' must be provided."); |
| 76 | } elseif (!isset($content['value']['location']) || empty($content['value']['location'])) { |
| 77 | throw new InvalidArgumentException("Missing data: 'location' must be provided."); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | public static function buildComponent(tao_install_services_Data $data) |
| 82 | { |
| 83 | $content = json_decode($data->getContent(), true); |
| 84 | $location = $content['value']['location']; |
| 85 | |
| 86 | if ($content['value']['id'] === 'fs_data') { |
| 87 | if ($location === '') { |
| 88 | $location = 'data'; |
| 89 | } |
| 90 | if (substr($location, 0, 1) !== '/') { |
| 91 | $location = dirname(dirname(dirname(__DIR__))) . '/' . $location; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | $rights = $content['value']['rights']; |
| 96 | $recursive = isset($content['value']['recursive']) && (bool) $content['value']['recursive']; |
| 97 | if (isset($content['value']['optional'])) { |
| 98 | $optional = $content['value']['optional']; |
| 99 | } else { |
| 100 | $optional = false; |
| 101 | } |
| 102 | |
| 103 | if (isset($content['value']['mustCheckIfEmpty'])) { |
| 104 | $mustCheckIfEmpty = $content['value']['mustCheckIfEmpty']; |
| 105 | } else { |
| 106 | $mustCheckIfEmpty = false; |
| 107 | } |
| 108 | |
| 109 | return common_configuration_ComponentFactory::buildFileSystemComponent( |
| 110 | $location, |
| 111 | $rights, |
| 112 | $optional, |
| 113 | $recursive, |
| 114 | $mustCheckIfEmpty |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | public static function buildResult( |
| 119 | tao_install_services_Data $data, |
| 120 | common_configuration_Report $report, |
| 121 | common_configuration_Component $component |
| 122 | ) { |
| 123 | $content = json_decode($data->getContent(), true); |
| 124 | $rights = $content['value']['rights']; |
| 125 | $id = $content['value']['id']; |
| 126 | |
| 127 | $data = ['type' => 'FileSystemComponentReport', |
| 128 | 'value' => [ |
| 129 | 'status' => $report->getStatusAsString(), |
| 130 | 'message' => $report->getMessage(), |
| 131 | 'id' => $id, |
| 132 | 'optional' => $component->isOptional(), |
| 133 | 'isReadable' => $component->isReadable(), |
| 134 | 'isWritable' => $component->isWritable(), |
| 135 | 'isExecutable' => $component->isExecutable(), |
| 136 | 'isEmptyDirectory' => $component->isEmptyDirectory(), |
| 137 | 'recursive' => $component->getRecursive(), |
| 138 | 'expectedRights' => $rights, |
| 139 | 'isFile' => is_file($component->getLocation()), |
| 140 | 'location' => $component->getLocation() |
| 141 | ] |
| 142 | ]; |
| 143 | |
| 144 | return new tao_install_services_Data(json_encode($data)); |
| 145 | } |
| 146 | } |