Skip to content

Commit

Permalink
OXDEV-7248 Refactor edtion
Browse files Browse the repository at this point in the history
  • Loading branch information
liulka-oxid committed Nov 13, 2024
1 parent 2ff9cbd commit 17c9c7f
Show file tree
Hide file tree
Showing 27 changed files with 127 additions and 395 deletions.
2 changes: 1 addition & 1 deletion source/Application/Controller/Admin/ShopConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function loadConfVars($shopId, $moduleId)
*/
public function informationSendingToOxidConfigurable()
{
return !Edition::from(Registry::getConfig()->getEdition())->isCommunityEdition();
return !Registry::getConfig()->getEdition()->isCommunityEdition();
}

/**
Expand Down
6 changes: 2 additions & 4 deletions source/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ public function isDemoShop()
return ContainerFacade::getParameter('oxid_esales.demo_shop_mode');
}

public function getEdition(): string
public function getEdition(): Edition
{
return ContainerFacade::get(BasicContextInterface::class)->getEdition();
}
Expand All @@ -1376,9 +1376,7 @@ public function getEdition(): string
*/
public function getFullEdition(): string
{
return Edition::from(
ContainerFacade::get(BasicContextInterface::class)->getEdition()
)->getFullEditionName();
return $this->getEdition()->getFullEditionName();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions source/Core/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Core\ShopVersion;
use OxidEsales\EshopCommunity\Internal\Transition\ShopEvents\AfterRequestProcessedEvent;
use OxidEsales\Facts\Facts;

/**
* Base view class. Collects and passes data to template engine, sets some global
Expand Down Expand Up @@ -633,7 +632,7 @@ public function getShopVersion()
*/
public function getShopEdition()
{
return (new Facts())->getEdition();
return Registry::getConfig()->getEdition()->value;
}

/**
Expand Down
10 changes: 2 additions & 8 deletions source/Core/OnlineRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace OxidEsales\EshopCommunity\Core;

use OxidEsales\Facts\Facts;

/**
* Online check base request class.
*
Expand Down Expand Up @@ -58,16 +56,12 @@ class OnlineRequest
*/
public $productId = 'eShop';

/**
* Class constructor, initiates public class parameters.
*/
public function __construct()
{
$oConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
$this->clusterId = $this->getClusterId();
$this->edition = (new Facts())->getEdition();
$this->edition = \OxidEsales\Eshop\Core\Registry::getConfig()->getEdition()->value;
$this->version = ShopVersion::getVersion();
$this->shopUrl = $oConfig->getShopUrl();
$this->shopUrl = \OxidEsales\Eshop\Core\Registry::getConfig()->getShopUrl();
}

/**
Expand Down
7 changes: 3 additions & 4 deletions source/Core/ShopIdCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace OxidEsales\EshopCommunity\Core;

use Doctrine\DBAL\DriverManager;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContext;

use function array_fill_keys;
Expand Down Expand Up @@ -40,7 +39,7 @@ protected function getShopUrlMap(): array
}

$urlMap = $this->variablesCache->getFromCache('urlMap');
if ($urlMap !== null) {
if (is_array($urlMap)) {
self::$urlMap = $urlMap;

return $urlMap;
Expand All @@ -52,7 +51,7 @@ protected function getShopUrlMap(): array
$variableName = $row['oxvarname'];
$urlValues = $row['oxvarvalue'];

if ($variableName === 'aLanguageURLs') {
if ($variableName === 'aLanguageURLs' || $variableName === 'aLanguageSSLURLs') {
$urls = unserialize($urlValues, ['allowed_classes' => false]);
if (is_array($urls) && count($urls)) {
$urls = array_filter($urls);
Expand All @@ -76,7 +75,7 @@ private function fetchUrlsFromConfigTable(): array
->prepare(
"SELECT oxshopid, oxvarname, oxvarvalue
FROM oxconfig
WHERE oxvarname IN ('aLanguageURLs','sMallShopURL','sMallSSLShopURL')"
WHERE oxvarname IN ('aLanguageURLs', 'aLanguageSSLURLs', 'sMallShopURL','sMallSSLShopURL')"
);
$statement->execute();

Expand Down
4 changes: 2 additions & 2 deletions source/Core/ViewConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ public function getShopLogo()
if ($this->_sShopLogo === null) {
$sLogoImage = ContainerFacade::getParameter('oxid_esales.shop_logo');
if (empty($sLogoImage)) {
$sLogoImage = 'logo_' . strtolower(Registry::getConfig()->getEdition()) . '.png';
$sLogoImage = 'logo_' . strtolower(Registry::getConfig()->getEdition()->value) . '.png';
}
$this->setShopLogo($sLogoImage);
}
Expand Down Expand Up @@ -1306,7 +1306,7 @@ private function isModuleEnabled($moduleId): bool
*/
public function getEdition()
{
return Registry::getConfig()->getEdition();
return Registry::getConfig()->getEdition()->value;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions source/Internal/Framework/DIContainer/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ private function loadEditionServices(): void

private function getEditionsRootPaths(): array
{
return match (Edition::from($this->basicContext->getEdition())) {
return match ($this->basicContext->getEdition()) {
Edition::Community => [
$this->basicContext->getCommunityEditionSourcePath(),
$this->basicContext->getEditionSourcePath(Edition::Community),
],
Edition::Professional => [
$this->basicContext->getCommunityEditionSourcePath(),
$this->basicContext->getProfessionalEditionRootPath()
$this->basicContext->getEditionSourcePath(Edition::Community),
$this->basicContext->getEditionSourcePath(Edition::Professional),
],
Edition::Enterprise => [
$this->basicContext->getCommunityEditionSourcePath(),
$this->basicContext->getProfessionalEditionRootPath(),
$this->basicContext->getEnterpriseEditionRootPath(),
$this->basicContext->getEditionSourcePath(Edition::Community),
$this->basicContext->getEditionSourcePath(Edition::Professional),
$this->basicContext->getEditionSourcePath(Edition::Enterprise),
],
};
}
Expand Down
16 changes: 0 additions & 16 deletions source/Internal/Framework/Edition.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ public function isCommunityEdition(): bool
};
}

public function isProfessionalEdition(): bool
{
return match ($this) {
self::Professional => true,
default => false,
};
}

public function isEnterpriseEdition(): bool
{
return match ($this) {
self::Professional => true,
default => false,
};
}

public function getFullEditionName(): string
{
return match ($this) {
Expand Down
20 changes: 3 additions & 17 deletions source/Internal/Framework/Migration/MigrationExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,13 @@

use OxidEsales\DoctrineMigrationWrapper\Migrations;
use OxidEsales\DoctrineMigrationWrapper\MigrationsBuilder;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;

class MigrationExecutor implements MigrationExecutorInterface
{
public function __construct(protected ContextInterface $context)
{
}

public function execute(): void
{
$migrations = $this->createMigrations();
$migrations->execute(Migrations::MIGRATE_COMMAND);
}

/**
* @return Migrations
*/
private function createMigrations(): Migrations
{
$migrationsBuilder = new MigrationsBuilder();

return $migrationsBuilder->build($this->context->getFacts());
(new MigrationsBuilder())
->build()
->execute(Migrations::MIGRATE_COMMAND);
}
}
3 changes: 1 addition & 2 deletions source/Internal/Framework/Migration/services.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
services:
_defaults:
autowire: true
public: false

OxidEsales\EshopCommunity\Internal\Framework\Migration\MigrationExecutorInterface:
class: OxidEsales\EshopCommunity\Internal\Framework\Migration\MigrationExecutor
class: OxidEsales\EshopCommunity\Internal\Framework\Migration\MigrationExecutor
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,34 @@

namespace OxidEsales\EshopCommunity\Internal\Framework\Templating\Locator;

use OxidEsales\EshopCommunity\Internal\Framework\Edition;
use OxidEsales\EshopCommunity\Internal\Framework\Theme\Bridge\AdminThemeBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContext;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;

class EditionMenuFileLocator implements NavigationFileLocatorInterface
{
/**
* @var string
*/
private $themeName;

/**
* @var string
*/
private $fileName = 'menu.xml';
private string $themeName;
private string $fileName = 'menu.xml';

public function __construct(
AdminThemeBridgeInterface $adminThemeBridge,
private BasicContextInterface $context,
private Filesystem $fileSystem
private readonly BasicContextInterface $context,
private readonly Filesystem $fileSystem
) {
$this->themeName = $adminThemeBridge->getActiveTheme();
}

/**
* Returns a full path for a given file name.
*
* @return array An array of file paths
*
* @throws \Exception
*/
public function locate(): array
{
$filePath = $this->getMenuFileDirectory() . DIRECTORY_SEPARATOR . $this->fileName;
return $this->validateFile($filePath);
}

/**
* @return string
*
* @throws \Exception
*/
private function getMenuFileDirectory(): string
{
return $this->getEditionsRootPaths() . DIRECTORY_SEPARATOR .
'Application' . DIRECTORY_SEPARATOR .
'views' . DIRECTORY_SEPARATOR .
$this->themeName;
}

private function getEditionsRootPaths(): string
{
return match (Edition::from($this->context->getEdition())) {
Edition::Community => $this->context->getSourcePath(),
Edition::Professional => $this->context->getProfessionalEditionRootPath(),
Edition::Enterprise => $this->context->getEnterpriseEditionRootPath(),
};
}

private function validateFile(string $file): array
{
$existingFiles = [];
if ($this->fileSystem->exists($file)) {
$existingFiles[] = $file;
}
return $existingFiles;
$filePath = Path::join(
$this->context->getEditionSourcePath($this->context->getEdition()),
'Application',
'views',
$this->themeName,
$this->fileName,
);

return $this->fileSystem->exists($filePath) ? [$filePath] : [];
}
}
Loading

0 comments on commit 17c9c7f

Please sign in to comment.