Skip to content

Commit

Permalink
ESDEV-4340 Fix #1 Remove disabled modules from class chain.
Browse files Browse the repository at this point in the history
  • Loading branch information
hkreuter authored and robertblank committed Mar 28, 2017
1 parent 3c1d2d8 commit fee9656
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 76 deletions.
80 changes: 34 additions & 46 deletions source/Core/Module/ModuleChainsGenerator.php
Expand Up @@ -70,13 +70,32 @@ public function createClassChain($className, $classAlias = null)
* @param string $className Class name.
* @param string $classAlias Class alias, used for searching module extensions. Class is used if no alias given.
*
* @return string
* @return array
*/
public function getActiveChain($className, $classAlias = null)
{
if (!$classAlias) {
$classAlias = $className;
}
$fullChain = $this->getFullChain($className, $classAlias);
$activeChain = array();
if (!empty($fullChain)) {
$activeChain = $this->filterInactiveExtensions($fullChain);
}
return $activeChain;
}

/**
* Build full class chain.
*
* @param string $className
* @param string $classAlias
*
* @return array
*/
public function getFullChain($className, $classAlias)
{
$fullChain = array();
$lowerCaseClassAlias = strtolower($classAlias);
$lowerCaseClassName = strtolower($className);

Expand All @@ -85,7 +104,6 @@ public function getActiveChain($className, $classAlias = null)
$modules = array_change_key_case($modules);
$allExtendedClasses = array_keys($modules);
$currentExtendedClasses = array_intersect($allExtendedClasses, [$lowerCaseClassName, $lowerCaseClassAlias]);
$activeChain = array();
if (!empty($currentExtendedClasses)) {
/*
* there may be 2 class chains, matching the same class:
Expand Down Expand Up @@ -118,10 +136,9 @@ public function getActiveChain($className, $classAlias = null)
*/
$fullChain = array_merge(reset($classChains), next($classChains));
}

$activeChain = $this->filterInactiveExtensions($fullChain);
}
return $activeChain;

return $fullChain;
}

/**
Expand Down Expand Up @@ -152,58 +169,25 @@ public function filterInactiveExtensions($classChain)
*
* @return array
*/
public function cleanModuleFromClassChain($moduleId, $classChain)
public function cleanModuleFromClassChain($moduleId, array $classChain)
{
//WIP, need to also handle aModuleExtensions
$variablesLocator = $this->getModuleVariablesLocator();
$registeredExtensions = $variablesLocator->getModuleVariable('aModuleExtensions');

$cleanedClassChain = $this->cleanModuleFromClassChainByPath($moduleId, $classChain);
return $cleanedClassChain;
}
$toBeRemovedFromChain = array();
if (isset($registeredExtensions[$moduleId])) {
$toBeRemovedFromChain = array_combine($registeredExtensions[$moduleId], $registeredExtensions[$moduleId]);
}

/**
* Clean classes from chain for given module id.
* This function removes all classes from class chain for classes inside a deactivated module's directory.
*
* @param string $moduleId
* @param array $classChain
*
* @return array
*/
public function cleanModuleFromClassChainByPath($moduleId, $classChain)
{
foreach ($classChain as $key => $moduleClass) {
$moduleDirectory = $this->getModuleDirectoryByModuleId($moduleId);
if ($this->modulePathMatch($moduleClass, $moduleDirectory)) {
if (isset($toBeRemovedFromChain[$moduleClass])) {
unset($classChain[$key]);
}
}

return $classChain;
}

/**
* Check if given class is connected to given module directory.
* NOTE: for old style modules, the shop config variable 'aModules' contains the path to the module file
* relative to shop/modules directory.
*
* @param string $moduleClass
* @param string $moduleDirectory
*
* @return bool
*/
protected function modulePathMatch($moduleClass, $moduleDirectory)
{
$match = false;
if (strpos($moduleClass, $moduleDirectory . "/") === 0) {
$match = true;
} elseif (strpos($moduleDirectory, ".") && (strpos($moduleDirectory, strtolower($moduleClass)) === 0)) {
// If module consists of one file without own dir (getting module.php as id, instead of module)
$match = true;
}

return $match;
}

/**
* Get Ids of all deactivated module.
* If none are deactivated, returns an empty array.
Expand Down Expand Up @@ -373,6 +357,8 @@ public function disableModule($modulePath)
}

/**
* Getter for ModuleVariablesLocator.
*
* @return \OxidEsales\Eshop\Core\Module\ModuleVariablesLocator
*/
public function getModuleVariablesLocator()
Expand All @@ -381,6 +367,8 @@ public function getModuleVariablesLocator()
}

/**
* Getter for module array.
*
* @param \OxidEsales\Eshop\Core\Module\ModuleVariablesLocator $variablesLocator
*
* @return array
Expand Down

0 comments on commit fee9656

Please sign in to comment.