Skip to content

Commit

Permalink
Extensions - Setup <classloader> during "enable" and "uninstall"
Browse files Browse the repository at this point in the history
This is an analog/follow-up to civicrm#20091

Why is this necessary? Recall that a typical admin will go through this lifecycle:

1. Enable extension $x
2. Disable extension $x
3. Either:
   * (a) Re-enable extension $x
   * (b) Uninstall extension $x

Step `#2` disables the classloader for purposes of regular page-loading. However, when you
get to step `#3a` or `#3b`, then you need the classloader again.
  • Loading branch information
totten committed Apr 21, 2021
1 parent 1d1b7ce commit c09b5c5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion CRM/Extension/Manager/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(CRM_Extension_Mapper $mapper) {
* @param CRM_Extension_Info $info
*/
public function onPreInstall(CRM_Extension_Info $info) {
CRM_Extension_System::singleton()->getClassLoader()->installExtension($info, dirname($this->mapper->keyToPath($info->key)));
$this->registerClassloader($info);
$this->callHook($info, 'install');
$this->callHook($info, 'enable');
}
Expand Down Expand Up @@ -71,6 +71,7 @@ private function callHook(CRM_Extension_Info $info, $hookName) {
* @return bool
*/
public function onPreUninstall(CRM_Extension_Info $info) {
$this->registerClassloader($info);
$this->callHook($info, 'uninstall');
return TRUE;
}
Expand All @@ -92,7 +93,15 @@ public function onPreDisable(CRM_Extension_Info $info) {
* @param CRM_Extension_Info $info
*/
public function onPreEnable(CRM_Extension_Info $info) {
$this->registerClassloader($info);
$this->callHook($info, 'enable');
}

/**
* @param CRM_Extension_Info $info
*/
private function registerClassloader($info) {
CRM_Extension_System::singleton()->getClassLoader()->installExtension($info, dirname($this->mapper->keyToPath($info->key)));
}

}

0 comments on commit c09b5c5

Please sign in to comment.