Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| tao_install_services_CheckTAOForgeConnectionService | |
0.00% |
0 / 24 |
|
0.00% |
0 / 5 |
90 | |
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 / 3 |
|
0.00% |
0 / 1 |
20 | |||
| buildComponent | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| buildResult | |
0.00% |
0 / 11 |
|
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 availability of |
| 29 | * TAO Forge registration remote services (URL: http://forge.taotesting.com or http://forge.tao.lu). |
| 30 | * |
| 31 | * Please refer to tao/install/api.php for more information about how to call this service. |
| 32 | * |
| 33 | * @access public |
| 34 | * @author Cyril Hazotte, <cyril@taotesting.com> |
| 35 | * @package tao |
| 36 | |
| 37 | */ |
| 38 | class tao_install_services_CheckTAOForgeConnectionService 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 | $ext = self::buildComponent($this->getData()); |
| 58 | $report = $ext->check(); |
| 59 | $this->setResult(self::buildResult($this->getData(), $report, $ext)); |
| 60 | } |
| 61 | |
| 62 | protected function checkData() |
| 63 | { |
| 64 | |
| 65 | // Check data integrity. |
| 66 | $content = json_decode($this->getData()->getContent(), true); |
| 67 | if (!isset($content['type']) || empty($content['type']) || $content['type'] !== 'CheckTAOForgeConnection') { |
| 68 | throw new InvalidArgumentException("Unexpected type: 'type' must be equal to 'CheckTAOForgeConnection'."); |
| 69 | } |
| 70 | // TODO check URL format |
| 71 | //... |
| 72 | } |
| 73 | |
| 74 | public static function buildComponent(tao_install_services_Data $data) |
| 75 | { |
| 76 | |
| 77 | $content = json_decode($data->getContent(), true); |
| 78 | /*$extensionName = $content['value']['name'];*/ |
| 79 | if (isset($content['value']['optional'])) { |
| 80 | $optional = $content['value']['optional']; |
| 81 | } else { |
| 82 | $optional = false; |
| 83 | } |
| 84 | echo 'buildResult optional: ' . $optional . "\r\n"; |
| 85 | |
| 86 | // false is NOT GOOD |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | public static function buildResult( |
| 91 | tao_install_services_Data $data, |
| 92 | common_configuration_Report $report, |
| 93 | common_configuration_Component $component |
| 94 | ) { |
| 95 | |
| 96 | $content = json_decode($data->getContent(), true); |
| 97 | $id = $content['value']['id']; |
| 98 | |
| 99 | $url = $content['value']['host']; |
| 100 | |
| 101 | echo 'buildResult host: ' . $url . "\r\n"; |
| 102 | |
| 103 | $data = ['type' => 'TAOForgeConnectionReport', |
| 104 | 'value' => ['status' => $report->getStatusAsString(), |
| 105 | 'message' => $report->getMessage(), |
| 106 | 'optional' => $component->isOptional(), |
| 107 | 'name' => $component->getName(), |
| 108 | 'id' => $id]]; |
| 109 | |
| 110 | return new tao_install_services_Data(json_encode($data)); |
| 111 | } |
| 112 | } |