Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensions - Setup <classloader> during "enable" and "uninstall" #20116

Merged
merged 2 commits into from
Apr 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 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,24 @@ 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) {
try {
$extPath = dirname($this->mapper->keyToPath($info->key));
}
catch (CRM_Extension_Exception_MissingException $e) {
// This could happen if there was a dirty removal (i.e. deleting ext-code before uninstalling).
return;
}

$classloader = CRM_Extension_System::singleton()->getClassLoader();
$classloader->installExtension($info, $extPath);
}

}