diff --git a/Core/ModuleStateFixer.php b/Core/ModuleStateFixer.php index c77d15c..13ced21 100644 --- a/Core/ModuleStateFixer.php +++ b/Core/ModuleStateFixer.php @@ -52,6 +52,7 @@ public function fix($module, $oConfig = null) } $moduleId = $module->getId(); + $this->needCacheClear = false; if (!$this->initialCacheClearDone) { //clearing some cache to be sure that fix runs not against a stale cache @@ -61,15 +62,22 @@ public function fix($module, $oConfig = null) } $this->output->debug("initial cache cleared"); $this->initialCacheClearDone = true; + $this->cleanUp(); } $this->module = $module; - $this->needCacheClear = false; $this->restoreModuleInformation($module, $moduleId); $somethingWasFixed = $this->needCacheClear; $this->clearCache($module); return $somethingWasFixed; } + /** + * After fixing all modules call this method to clean up trash that is not related to any installed module + */ + public function cleanUp() { + $this->cleanUpControllers(); + } + /** * Add module template files to config for smarty. * @@ -355,14 +363,35 @@ protected function setModuleControllers($moduleControllers, $moduleId, $module) } public function getModuleControllerEntries($moduleId){ - $classProviderStorage = $this->getClassProviderStorage(); - $dbMap = $classProviderStorage->get(); + $dbMap = $this->getAllControllers(); //for some unknown reasons the core uses lowercase module id to reference controllers $moduleIdLc = strtolower($moduleId); $controllersForThatModuleInDb = isset($dbMap[$moduleIdLc]) ? $dbMap[$moduleIdLc] : []; return $controllersForThatModuleInDb; } + /** + * @return mixed + */ + private function getAllControllers() + { + $classProviderStorage = $this->getClassProviderStorage(); + $dbMap = $classProviderStorage->get(); + return $dbMap; + } + + public function cleanUpControllers(){ + $allFromDb = $this->getAllControllers(); + $aVersions = (array) $this->getConfig()->getConfigParam('aModuleVersions'); + $cleaned = array_intersect_key($allFromDb,$aVersions); + if ($this->diff($allFromDb, $cleaned)) { + $this->needCacheClear = true; + $classProviderStorage = $this->getClassProviderStorage(); + $classProviderStorage->set($cleaned); + } + } + + /** * Reset module cache *