Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| common_ext_ExtensionUninstaller | |
0.00% |
0 / 28 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
| uninstall | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
20 | |||
| unregister | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| uninstallScripts | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
30 | |||
| extendedUninstall | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | use oat\oatbox\cache\SimpleCache; |
| 4 | |
| 5 | /** |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; under version 2 |
| 9 | * of the License (non-upgradable). |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | * |
| 20 | * Copyright (c) 2008-2010 (original work) 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 | * Uninstall of extensions |
| 29 | * |
| 30 | * @access public |
| 31 | * @author lionel.lecaque@tudor.lu |
| 32 | * @package common |
| 33 | * @see @license GNU General Public (GPL) Version 2 http://www.opensource.org/licenses/gpl-2.0.php |
| 34 | * @subpackage ext |
| 35 | */ |
| 36 | class common_ext_ExtensionUninstaller extends common_ext_ExtensionHandler |
| 37 | { |
| 38 | /** |
| 39 | * uninstall an extension |
| 40 | * |
| 41 | * @access public |
| 42 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 43 | * @return boolean |
| 44 | */ |
| 45 | public function uninstall() |
| 46 | { |
| 47 | |
| 48 | common_Logger::i('Uninstalling ' . $this->extension->getId(), ['UNINSTALL']); |
| 49 | |
| 50 | // uninstall possible |
| 51 | if (is_null($this->extension->getManifest()->getUninstallData())) { |
| 52 | throw new common_Exception( |
| 53 | 'Problem uninstalling extension ' . $this->extension->getId() . ' : Uninstall not supported' |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | // installed? |
| 58 | if (!common_ext_ExtensionsManager::singleton()->isInstalled($this->extension->getId())) { |
| 59 | throw new common_Exception( |
| 60 | 'Problem uninstalling extension ' . $this->extension->getId() . ' : Not installed' |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | // check dependcies |
| 65 | if (helpers_ExtensionHelper::isRequired($this->extension)) { |
| 66 | throw new common_Exception( |
| 67 | 'Problem uninstalling extension ' . $this->extension->getId() . ' : Still required' |
| 68 | ); |
| 69 | }; |
| 70 | |
| 71 | common_Logger::d('uninstall script for ' . $this->extension->getId()); |
| 72 | $this->uninstallScripts(); |
| 73 | |
| 74 | // hook |
| 75 | $this->extendedUninstall(); |
| 76 | |
| 77 | common_Logger::d('unregister extension ' . $this->extension->getId()); |
| 78 | $this->unregister(); |
| 79 | |
| 80 | // we purge the whole cache. |
| 81 | $cache = $this->getServiceManager()->get(SimpleCache::SERVICE_ID); |
| 82 | $cache->clear(); |
| 83 | |
| 84 | common_Logger::i('Uninstalled ' . $this->extension->getId()); |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Unregisters the Extension from the extensionManager |
| 90 | * |
| 91 | * @access protected |
| 92 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 93 | * @return void |
| 94 | */ |
| 95 | protected function unregister() |
| 96 | { |
| 97 | common_ext_ExtensionsManager::singleton()->unregisterExtension($this->extension); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Executes uninstall scripts |
| 102 | * specified in the Manifest |
| 103 | * |
| 104 | * @access protected |
| 105 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 106 | * @return void |
| 107 | */ |
| 108 | protected function uninstallScripts() |
| 109 | { |
| 110 | $data = $this->extension->getManifest()->getUninstallData(); |
| 111 | if (!is_null($data) && isset($data['php']) && is_array($data['php'])) { |
| 112 | foreach ($data['php'] as $script) { |
| 113 | $this->runExtensionScript($script); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Hook to extend the uninstall procedure |
| 120 | */ |
| 121 | public function extendedUninstall() |
| 122 | { |
| 123 | return; |
| 124 | } |
| 125 | } |