| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * The extension manager handles installing, disabling enabling, and |
| 14 | * uninstalling extensions. |
| 15 | * |
| 16 | * @package CRM |
| 17 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 18 | */ |
| 19 | class CRM_Extension_Manager_Base implements CRM_Extension_Manager_Interface { |
| 20 | |
| 21 | /** |
| 22 | * Whether to automatically uninstall and install during 'replace'. |
| 23 | * |
| 24 | * @var bool |
| 25 | */ |
| 26 | public $autoReplace; |
| 27 | |
| 28 | /** |
| 29 | * @param bool $autoReplace |
| 30 | * Whether to automatically uninstall and install during 'replace'. |
| 31 | */ |
| 32 | public function __construct($autoReplace = FALSE) { |
| 33 | $this->autoReplace = $autoReplace; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @inheritDoc |
| 38 | * |
| 39 | * @param CRM_Extension_Info $info |
| 40 | */ |
| 41 | public function onPreInstall(CRM_Extension_Info $info) { |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @inheritDoc |
| 46 | * |
| 47 | * @param CRM_Extension_Info $info |
| 48 | */ |
| 49 | public function onPostInstall(CRM_Extension_Info $info) { |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @inheritDoc |
| 54 | * |
| 55 | * @param CRM_Extension_Info $info |
| 56 | */ |
| 57 | public function onPostPostInstall(CRM_Extension_Info $info) { |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @inheritDoc |
| 62 | * |
| 63 | * @param CRM_Extension_Info $info |
| 64 | */ |
| 65 | public function onPreEnable(CRM_Extension_Info $info) { |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @inheritDoc |
| 70 | * |
| 71 | * @param CRM_Extension_Info $info |
| 72 | */ |
| 73 | public function onPostEnable(CRM_Extension_Info $info) { |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @inheritDoc |
| 78 | * |
| 79 | * @param CRM_Extension_Info $info |
| 80 | */ |
| 81 | public function onPreDisable(CRM_Extension_Info $info) { |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @inheritDoc |
| 86 | * |
| 87 | * @param CRM_Extension_Info $info |
| 88 | */ |
| 89 | public function onPostDisable(CRM_Extension_Info $info) { |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @inheritDoc |
| 94 | * |
| 95 | * @param CRM_Extension_Info $info |
| 96 | */ |
| 97 | public function onPreUninstall(CRM_Extension_Info $info) { |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @inheritDoc |
| 102 | * |
| 103 | * @param CRM_Extension_Info $info |
| 104 | */ |
| 105 | public function onPostUninstall(CRM_Extension_Info $info) { |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @inheritDoc |
| 110 | * |
| 111 | * @param CRM_Extension_Info $oldInfo |
| 112 | * @param CRM_Extension_Info $newInfo |
| 113 | */ |
| 114 | public function onPreReplace(CRM_Extension_Info $oldInfo, CRM_Extension_Info $newInfo) { |
| 115 | if ($this->autoReplace) { |
| 116 | $this->onPreUninstall($oldInfo); |
| 117 | $this->onPostUninstall($oldInfo); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @inheritDoc |
| 123 | * |
| 124 | * @param CRM_Extension_Info $oldInfo |
| 125 | * @param CRM_Extension_Info $newInfo |
| 126 | */ |
| 127 | public function onPostReplace(CRM_Extension_Info $oldInfo, CRM_Extension_Info $newInfo) { |
| 128 | if ($this->autoReplace) { |
| 129 | $this->onPreInstall($oldInfo); |
| 130 | $this->onPostInstall($oldInfo); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | } |