Skip to content

Commit

Permalink
OXDEV-7248 Remove env var oxid source directory
Browse files Browse the repository at this point in the history
  • Loading branch information
AshrafOxid committed Jun 5, 2024
1 parent 97b8adc commit a6c1760
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 53 deletions.
3 changes: 2 additions & 1 deletion source/Core/UtilsFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,10 @@ private function addErrorMessageToDisplay($message): void
*/
private function makePathRelativeToShopSource(string $path): string
{

return Path::makeRelative(
$path,
(new BootstrapConfigurationFactory())->create()->getShopSourceDirectory()
ContainerFacade::getParameter('oxid_shop_source_directory')
);
}
}
2 changes: 1 addition & 1 deletion source/Core/UtilsPic.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private function makePathRelativeToShopSource(string $path): string
{
return Path::makeRelative(
$path,
(new BootstrapConfigurationFactory())->create()->getShopSourceDirectory()
ContainerFacade::getParameter('oxid_shop_source_directory')
);
}
}
1 change: 0 additions & 1 deletion source/Internal/Container/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ imports:
- { resource: bootstrap-services.yaml }

parameters:
oxid_shop_source_directory: '%env(OXID_SHOP_SOURCE_DIRECTORY)%'
oxid_cache_directory: '%env(OXID_CACHE_DIRECTORY)%'
oxid_log_level: '%env(OXID_LOG_LEVEL)%'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,5 @@ private function initEnvironment(): void
$projectRootDirectory = (new BootstrapLocator())->getProjectRoot();
$dotenvLoader = new DotenvLoader($projectRootDirectory);
$dotenvLoader->loadEnvironmentVariables();
$dotenvLoader->putEnvironmentVariable(
'OXID_SHOP_SOURCE_DIRECTORY',
Path::join($projectRootDirectory, 'source')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function get(): SystemConfiguration
{
$systemConfiguration = new SystemConfiguration();
$systemConfiguration->setDatabaseUrl(getenv('OXID_DB_URL'));
$systemConfiguration->setShopSourceDirectory(getenv('OXID_SHOP_SOURCE_DIRECTORY'));
$systemConfiguration->setCacheDirectory(getenv('OXID_CACHE_DIRECTORY'));
$systemConfiguration->setLogLevel(getenv('OXID_LOG_LEVEL'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ public function setDatabaseUrl(string $databaseUrl): void
$this->databaseUrl = $databaseUrl;
}

public function getShopSourceDirectory(): string
{
return $this->shopSourceDirectory;
}

public function setShopSourceDirectory(string $shopSourceDirectory): void
{
$this->shopSourceDirectory = $shopSourceDirectory;
}

public function getCacheDirectory(): string
{
return $this->cacheDirectory;
Expand Down
1 change: 1 addition & 0 deletions source/Internal/Framework/DIContainer/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getContainer(): SymfonyContainerBuilder
$symfonyContainer = new SymfonyContainerBuilder();
$symfonyContainer->addCompilerPass(new RegisterListenersPass());
$symfonyContainer->addCompilerPass(new AddConsoleCommandPass());
$symfonyContainer->setParameter('oxid_shop_source_directory', $this->context->getSourcePath());
$this->loadEditionServices($symfonyContainer);
$this->loadModuleServices($symfonyContainer);
$this->loadProjectServices($symfonyContainer);
Expand Down
18 changes: 5 additions & 13 deletions source/Internal/Framework/Env/DotenvLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ public function __construct(private readonly string $pathToEnvFiles)
}

public function loadEnvironmentVariables(): void
{
$this->loadDotEnv()->loadEnv(Path::join($this->pathToEnvFiles, $this->envFile));
}

public function putEnvironmentVariable(string $name, string $value): void
{
$this->loadDotEnv()->populate([$name => $value]);
}

private function loadDotEnv(): Dotenv
{
$dotEnv = new Dotenv($this->envKey, $this->debugKey);
$dotEnv->usePutenv();

return $dotEnv;
$dotEnv
->usePutenv()
->loadEnv(
Path::join($this->pathToEnvFiles, $this->envFile)
);
}
}
1 change: 0 additions & 1 deletion source/Internal/Framework/Env/DotenvLoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
interface DotenvLoaderInterface
{
public function loadEnvironmentVariables(): void;
public function putEnvironmentVariable(string $name, string $value): void;
}
2 changes: 1 addition & 1 deletion source/Internal/Transition/Utility/BasicContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getActiveModuleServicesFilePath(int $shopId): string
*/
public function getSourcePath(): string
{
return $this->systemConfiguration->getShopSourceDirectory();
return Path::join($this->getShopRootPath(), 'source');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion source/Setup/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OxidEsales\DatabaseViewsGenerator\ViewsGenerator;
use OxidEsales\DoctrineMigrationWrapper\Migrations;
use OxidEsales\DoctrineMigrationWrapper\MigrationsBuilder;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Framework\Configuration\BootstrapConfigurationFactory;
use OxidEsales\Facts\Facts;
use Symfony\Component\Console\Output\ConsoleOutput;
Expand Down Expand Up @@ -483,7 +484,7 @@ public function getRootDirectory(): string
public function getSqlDirectory(): string
{
return Path::join(
(new BootstrapConfigurationFactory())->create()->getShopSourceDirectory(),
ContainerFacade::getParameter('oxid_shop_source_directory'),
self::SETUP_DIRECTORY,
self::DATABASE_SQL_DIRECTORY
);
Expand Down
4 changes: 3 additions & 1 deletion tests/Codeception/Config/CodeceptionParametersProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OxidEsales\EshopCommunity\Tests\Codeception\Config;

use OxidEsales\Codeception\Module\Database;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Framework\Configuration\BootstrapConfigurationFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Configuration\DataObject\DatabaseConfiguration;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\BootstrapLocator;
Expand All @@ -29,7 +30,8 @@ public function getParameters(): array
$this->dbConfig = (new DatabaseConfiguration($databaseUrl));
return [
'SHOP_URL' => getenv('SHOP_URL') ?: $facts->getShopUrl(),
'SHOP_SOURCE_PATH' => getenv('SHOP_SOURCE_PATH') ?: $systemConfiguration->getShopSourceDirectory(),
'SHOP_SOURCE_PATH' => getenv('SHOP_SOURCE_PATH') ?:
ContainerFacade::getParameter('oxid_shop_source_directory'),
'VENDOR_PATH' => $facts->getVendorPath(),
'DB_NAME' => $this->getDbName(),
'DB_USERNAME' => $this->getDbUser(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function testGetDatabaseConfigurationWillContainSomeDefaults(): void

public function testGetBootstrapParametersWillContainsDefaults(): void
{
$this->assertNotEmpty($this->systemConfiguration->get()->getShopSourceDirectory());
$this->assertNotEmpty($this->systemConfiguration->get()->getCacheDirectory());
}
}
12 changes: 0 additions & 12 deletions tests/Integration/Internal/Framework/Env/EnvLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace OxidEsales\EshopCommunity\Tests\Integration\Internal\Framework\Env;

use OxidEsales\EshopCommunity\Internal\Framework\Configuration\BootstrapConfigurationFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Env\DotenvLoader;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
use OxidEsales\EshopCommunity\Tests\EnvTrait;
use OxidEsales\EshopCommunity\Tests\RequestTrait;
Expand Down Expand Up @@ -83,15 +82,4 @@ public function testJsonDSNsWithSpecialCharactersWillBeParsedAsArray(): void

$this->assertEquals($dsnString, $containerParameter[2]);
}

public function testCanPutEnvironmentVariable(): void
{
$someKey = uniqid('some-key', true);
$someValue = uniqid('some-value', true);

$dotEnvLoader = new DotenvLoader($this->fixtures);
$dotEnvLoader->putEnvironmentVariable($someKey, $someValue);

$this->assertEquals($someValue, getenv($someKey));
}
}
5 changes: 0 additions & 5 deletions tests/Unit/Internal/BasicContextStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,6 @@ public function getShopRootPath(): string
return $this->shopRootPath;
}

public function setShopRootPath(string $shopRootPath): void
{
$this->shopRootPath = $shopRootPath;
}

public function getOutPath(): string
{
return $this->outPath;
Expand Down

0 comments on commit a6c1760

Please sign in to comment.