Skip to content

Commit

Permalink
cleanup controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
keywan-ghadami-oxid committed Jan 6, 2019
1 parent 648df50 commit e34afd7
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions Core/ModuleStateFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit e34afd7

Please sign in to comment.