Skip to content

Commit

Permalink
ESDEV-4546 Fix wrong EditionSelector
Browse files Browse the repository at this point in the history
The EditionSelector had a hidden dependency for the UnifiedNamespaceClassmap.php. The UnifiedNamespaceClassMap is not a class any more. Therfor we use the directories of the editions in the vendor folder to detect the editions.
  • Loading branch information
Gregor Hyneck committed Jul 25, 2017
1 parent 217eb29 commit 3cd414d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 21 deletions.
68 changes: 57 additions & 11 deletions src/Edition/EditionSelector.php
Expand Up @@ -22,6 +22,7 @@
namespace OxidEsales\Facts\Edition;

use OxidEsales\Facts\Config\ConfigFile;
use OxidEsales\Facts\Facts;

/**
* Class is responsible for returning edition of OXID eShop.
Expand Down Expand Up @@ -89,33 +90,77 @@ public function isCommunity()
}

/**
* Find edition by classmap only.
* Check for forced edition in config file. If edition is not specified,
* determine it by ClassMap existence.
*
* @return string
*
* @throws \Exception
*/
protected function findEdition()
{
try {
$edition = $this->findEditionByConfigFile();
if (empty($edition)) {
$edition = $this->findEditionByEditionFiles();
}
} catch (\Exception $exception) {
try {
$edition = $this->findEditionByEditionFiles();
} catch (\Exception $exception) {
throw $exception;
}
}

return strtoupper($edition);
}


/**
* Find edition by directories of the editions in the vendor directory
*
* @return string
*
* @throws \Exception
*/
static public function findEditionByClassMap()
private function findEditionByEditionFiles()
{
$edition = static::COMMUNITY;
if (class_exists(\OxidEsales\EshopEnterprise\Core\Autoload\UnifiedNameSpaceClassMap::class)) {
$facts = $this->getFacts();
$edition = '';
if (is_dir($facts->getEnterpriseEditionRootPath()) === true) {
$edition = static::ENTERPRISE;
} elseif (class_exists(\OxidEsales\EshopProfessional\Core\Autoload\UnifiedNameSpaceClassMap::class)) {
} elseif (is_dir($facts->getProfessionalEditionRootPath()) === true) {
$edition = static::PROFESSIONAL;
} elseif (is_dir($facts->getCommunityEditionSourcePath()) === true) {
$edition = static::COMMUNITY;
}

if ($edition === '') {
throw new \Exception("Shop directory structure is not setup properly. Edition could not be detected");
}

return $edition;
}

/**
* Check for forced edition in config file. If edition is not specified,
* determine it by ClassMap existence.
*
* @return Facts
*/
private function getFacts()
{
return new Facts();
}

/**
* @return string
*
* @throws \Exception
*/
protected function findEdition()
private function findEditionByConfigFile()
{
$edition = $this->getConfigFile()->getVar('edition') ?: self::findEditionByClassMap();
$configFile = $this->getConfigFile();
$edition = $configFile->getVar('edition');

return strtoupper($edition);
return $edition;
}

/**
Expand All @@ -128,6 +173,7 @@ protected function getConfigFile()
if (is_null($this->configFile)) {
$this->configFile = new ConfigFile();
}

return $this->configFile;
}
}
12 changes: 2 additions & 10 deletions src/Facts.php
Expand Up @@ -164,16 +164,8 @@ public function getOutPath()
*/
public function getEdition()
{
try {
$editionSelector = new EditionSelector();
$edition = $editionSelector->getEdition();
} catch (\Exception $exception) {
if ($exception->getCode() == ConfigFile::ERROR_CODE_CONFIGFILE_NOT_FOUND) {
$edition = EditionSelector::findEditionByClassMap();
} else {
throw $exception;
}
}
$editionSelector = new EditionSelector();
$edition = $editionSelector->getEdition();

return $edition;
}
Expand Down

0 comments on commit 3cd414d

Please sign in to comment.