Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| tao_install_ExtensionInstaller | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| getExtensionModel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| extendedInstall | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| installManagementRole | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
| applyAccessRules | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| registerClientLib | |
0.00% |
0 / 4 |
|
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 | * 2013-2014 (update and modification) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 25 | */ |
| 26 | |
| 27 | use oat\tao\helpers\Template; |
| 28 | use oat\tao\model\accessControl\func\AccessRule; |
| 29 | use oat\tao\model\accessControl\func\AclProxy; |
| 30 | use oat\tao\model\ClientLibRegistry; |
| 31 | use oat\tao\helpers\translation\rdf\RdfPack; |
| 32 | use oat\generis\model\data\ModelManager; |
| 33 | use oat\tao\model\extension\ExtensionModel; |
| 34 | use oat\tao\model\TaoOntology; |
| 35 | use oat\tao\model\user\TaoRoles; |
| 36 | |
| 37 | /** |
| 38 | * Specification of the Generis ExtensionInstaller class to add a new behavior: |
| 39 | * the Modules and Actions in the Ontology at installation time. |
| 40 | * |
| 41 | * @access public |
| 42 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 43 | * @package tao |
| 44 | * @since 2.4 |
| 45 | * |
| 46 | */ |
| 47 | class tao_install_ExtensionInstaller extends common_ext_ExtensionInstaller |
| 48 | { |
| 49 | // --- ASSOCIATIONS --- |
| 50 | |
| 51 | // --- ATTRIBUTES --- |
| 52 | |
| 53 | // --- OPERATIONS --- |
| 54 | |
| 55 | /** |
| 56 | * Override the default model with the translated model |
| 57 | * |
| 58 | * (non-PHPdoc) |
| 59 | * @see common_ext_ExtensionInstaller::getExtensionModel() |
| 60 | */ |
| 61 | public function getExtensionModel() |
| 62 | { |
| 63 | return new ExtensionModel($this->extension); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Will create the model of Modules and Actions (MVC) in the persistent |
| 68 | * |
| 69 | * @access public |
| 70 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 71 | * @return void |
| 72 | * @since 2.4 |
| 73 | */ |
| 74 | public function extendedInstall() |
| 75 | { |
| 76 | $this->installManagementRole(); |
| 77 | $this->applyAccessRules(); |
| 78 | $this->registerClientLib(); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Will make the Global Manager include the Management Role of the extension |
| 83 | * to install (if it exists). |
| 84 | * |
| 85 | * @access public |
| 86 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 87 | * @return void |
| 88 | * @since 2.4 |
| 89 | */ |
| 90 | public function installManagementRole() |
| 91 | { |
| 92 | |
| 93 | // Try to get a Management Role described by the extension itself. |
| 94 | // (this information comes actually from the Manifest of the extension) |
| 95 | $roleUri = $this->extension->getManifest()->getManagementRoleUri(); |
| 96 | if (! empty($roleUri)) { |
| 97 | $role = new core_kernel_classes_Resource($roleUri); |
| 98 | $roleService = tao_models_classes_RoleService::singleton(); |
| 99 | if (! $role->exists()) { |
| 100 | // Management role does not exist yet, so we create it |
| 101 | $roleClass = new core_kernel_classes_Class(TaoOntology::CLASS_URI_MANAGEMENT_ROLE); |
| 102 | $roleLabel = $this->extension->getId() . ' Manager'; |
| 103 | $role = $roleClass->createInstance($roleLabel, $roleLabel . ' Role', $role->getUri()); |
| 104 | $roleService->includeRole($role, new core_kernel_classes_Resource(TaoRoles::BACK_OFFICE)); |
| 105 | } |
| 106 | |
| 107 | // Take the Global Manager role and make it include |
| 108 | // the Management role of the currently installed extension. |
| 109 | if ($role->getUri() !== TaoRoles::GLOBAL_MANAGER) { |
| 110 | $globalManagerRole = new core_kernel_classes_Resource(TaoRoles::GLOBAL_MANAGER); |
| 111 | $roleService->includeRole($globalManagerRole, $role); |
| 112 | } |
| 113 | |
| 114 | common_Logger::d( |
| 115 | "Management Role " . $role->getUri() . " created for extension '" . $this->extension->getId() . "'." |
| 116 | ); |
| 117 | } else { |
| 118 | // There is no Management role described by the Extension Manifest. |
| 119 | common_Logger::i("No management role for extension '" . $this->extension->getId() . "'."); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Will make the Global Manager include the Management Role of the extension |
| 125 | * to install (if it exists). |
| 126 | * |
| 127 | * @access public |
| 128 | * @author Jerome Bogaerts <jerome@taotesting.com> |
| 129 | * @return void |
| 130 | * @since 2.4 |
| 131 | */ |
| 132 | public function applyAccessRules() |
| 133 | { |
| 134 | foreach ($this->extension->getManifest()->getAclTable() as $tableEntry) { |
| 135 | $rule = new AccessRule($tableEntry[0], $tableEntry[1], $tableEntry[2]); |
| 136 | AclProxy::applyRule($rule); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Extension may declare client lib to add alias into requireJs |
| 142 | * |
| 143 | * @author Lionel Lecaque, lionel@taotesting.com |
| 144 | */ |
| 145 | public function registerClientLib() |
| 146 | { |
| 147 | $jsPath = trim(Template::js('', $this->extension->getId()), '/'); |
| 148 | ClientLibRegistry::getRegistry()->register($this->extension->getId(), $jsPath); |
| 149 | |
| 150 | $cssPath = trim(Template::css('', $this->extension->getId()), '/'); |
| 151 | ClientLibRegistry::getRegistry()->register($this->extension->getId() . 'Css', $cssPath); |
| 152 | } |
| 153 | } |