| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 0.00% | 0 / 30 |  | 0.00% | 0 / 2 | CRAP |  | 0.00% | 0 / 1 | 
| tao_install_utils_ChecksHelper |  | 0.00% | 0 / 30 |  | 0.00% | 0 / 2 | 210 |  | 0.00% | 0 / 1 | 
| getConfigChecker |  | 0.00% | 0 / 16 |  | 0.00% | 0 / 1 | 132 | |||
| getRawChecks |  | 0.00% | 0 / 14 |  | 0.00% | 0 / 1 | 12 | |||
| 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) 2014 (original work) Open Assessment Technologies SA; | 
| 19 | * | 
| 20 | * | 
| 21 | */ | 
| 22 | |
| 23 | use oat\oatbox\extension\Manifest; | 
| 24 | |
| 25 | /** | 
| 26 | * A helper to get the required checks for an extension | 
| 27 | * | 
| 28 | * @author Joel Bout <joel@taotesting.com> | 
| 29 | * @access public | 
| 30 | * @package tao | 
| 31 | |
| 32 | * | 
| 33 | */ | 
| 34 | class tao_install_utils_ChecksHelper | 
| 35 | { | 
| 36 | /** | 
| 37 | * Get the ComponentCollection corresponding to the distribution. It | 
| 38 | * the configuration checks to perform for all extensions involved in the | 
| 39 | * | 
| 40 | * @access public | 
| 41 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> | 
| 42 | * @param array $extensionIds | 
| 43 | * @return common_configuration_ComponentCollection | 
| 44 | */ | 
| 45 | public static function getConfigChecker($extensionIds) | 
| 46 | { | 
| 47 | $returnValue = new common_configuration_ComponentCollection(); | 
| 48 | $checkArray = []; | 
| 49 | // resolve dependencies | 
| 50 | foreach (self::getRawChecks($extensionIds) as $c) { | 
| 51 | $checkArray[] = $c; | 
| 52 | $comp = common_configuration_ComponentFactory::buildFromArray($c); | 
| 53 | |
| 54 | if (!empty($c['value']['id'])) { | 
| 55 | $componentArray[$c['value']['id']] = $comp; | 
| 56 | } | 
| 57 | |
| 58 | $returnValue->addComponent($comp); | 
| 59 | |
| 60 | if (!empty($c['value']['silent']) && $c['value']['silent'] == true) { | 
| 61 | $returnValue->silent($comp); | 
| 62 | } | 
| 63 | } | 
| 64 | |
| 65 | // Deal with the dependencies. | 
| 66 | foreach ($checkArray as $config) { | 
| 67 | if (!empty($config['value']['dependsOn']) && is_array($config['value']['dependsOn'])) { | 
| 68 | foreach ($config['value']['dependsOn'] as $d) { | 
| 69 | // Find the component it depends on and tell the ComponentCollection. | 
| 70 | if (!empty($componentArray[$config['value']['id']]) && !empty($componentArray[$d])) { | 
| 71 | $returnValue->addDependency($componentArray[$config['value']['id']], $componentArray[$d]); | 
| 72 | } | 
| 73 | } | 
| 74 | } | 
| 75 | } | 
| 76 | |
| 77 | return $returnValue; | 
| 78 | } | 
| 79 | |
| 80 | public static function getRawChecks($extensionIds) | 
| 81 | { | 
| 82 | $checks = []; | 
| 83 | |
| 84 | // resolve dependencies | 
| 85 | $toCheck = []; | 
| 86 | while (!empty($extensionIds)) { | 
| 87 | $ext = array_pop($extensionIds); | 
| 88 | $manifestPath = dirname(__FILE__) . '/../../../' . $ext . '/manifest.php'; | 
| 89 | $dependencyIds = Manifest::extractDependencies($manifestPath); | 
| 90 | $extensionIds = array_unique(array_merge($extensionIds, array_diff($dependencyIds, $toCheck))); | 
| 91 | $toCheck[] = $ext; | 
| 92 | } | 
| 93 | |
| 94 | // We extract the checks to perform from the manifests | 
| 95 | // depending on the distribution. | 
| 96 | $checkArray = []; // merge of all arrays describing checks in the manifests. | 
| 97 | $componentArray = []; // array of Component instances. array keys are the IDs. | 
| 98 | |
| 99 | foreach ($toCheck as $ext) { | 
| 100 | $manifestPath = dirname(__FILE__) . '/../../../' . $ext . '/manifest.php'; | 
| 101 | $checks = array_merge($checks, Manifest::extractChecks($manifestPath)); | 
| 102 | } | 
| 103 | return $checks; | 
| 104 | } | 
| 105 | } |