Skip to content

Commit

Permalink
OXDEV-7785 Replace facts get source path
Browse files Browse the repository at this point in the history
  • Loading branch information
AshrafOxid committed May 14, 2024
1 parent 352be9d commit 058ee9a
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 16 deletions.
4 changes: 2 additions & 2 deletions bin/oe-console
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

use OxidEsales\EshopCommunity\Internal\Container\BootstrapContainerFactory;
use OxidEsales\EshopCommunity\Internal\Container\ContainerBuilderFactory;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\BootstrapLocator;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Dao\ShopConfigurationDaoInterface;
use OxidEsales\Facts\Facts;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -50,7 +50,7 @@ if (!isset($shopConfigurations[$shopId])) {

$_POST['shp'] = $shopId;

$bootstrapFilePath = Path::join((new Facts())->getSourcePath(), 'bootstrap.php');
$bootstrapFilePath = Path::join((new BootstrapLocator())->getProjectRoot(), 'source', 'bootstrap.php');
require_once $bootstrapFilePath;

$container = (new ContainerBuilderFactory())->create()->getContainer();
Expand Down
3 changes: 2 additions & 1 deletion source/Application/Model/Manufacturer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\UtilsFile;
use OxidEsales\Eshop\Core\UtilsPic;
use Symfony\Component\Filesystem\Path;

/**
* Manufacturer manager
Expand Down Expand Up @@ -440,7 +441,7 @@ public function deletePicture(string $pictureName, string $pictureType, string $

$utilsPic->safePictureDelete(
$pictureName,
$pictureDirectory . $utilsFile->getImageDirByType($pictureType),
Path::join($pictureDirectory, $utilsFile->getImageDirByType($pictureType)),
'oxmanufacturers',
$pictureFieldName
);
Expand Down
6 changes: 5 additions & 1 deletion source/Core/UtilsFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Str;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Framework\Configuration\BootstrapConfigurationFactory;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\Bridge\MasterImageHandlerBridgeInterface;
use OxidEsales\Facts\Facts;
use Symfony\Component\Filesystem\Path;
Expand Down Expand Up @@ -670,6 +671,9 @@ private function addErrorMessageToDisplay($message): void
*/
private function makePathRelativeToShopSource(string $path): string
{
return Path::makeRelative($path, (new Facts())->getSourcePath());
return Path::makeRelative(
$path,
Path::join((new BootstrapConfigurationFactory())->create()->getShopDirectory(), 'source')
);
}
}
8 changes: 6 additions & 2 deletions source/Core/UtilsPic.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use OxidEsales\Eshop\Core\Exception\ExceptionToDisplay;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Framework\Configuration\BootstrapConfigurationFactory;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\Bridge\MasterImageHandlerBridgeInterface;
use OxidEsales\Facts\Facts;
use OxidEsales\Eshop\Core\Registry;
Expand Down Expand Up @@ -84,7 +85,7 @@ protected function deletePicture($filename, $masterImagePath)

if (!Registry::getConfig()->getConfigParam('sAltImageUrl')) {
$generatedImagePath = str_replace('/master/', '/generated/', $masterImagePath);
$files = glob("{$generatedImagePath}*/{$filename}");
$files = glob(Path::join($generatedImagePath,'*',$filename));
if (\is_array($files)) {
foreach ($files as $file) {
$removed = unlink($file);
Expand Down Expand Up @@ -285,6 +286,9 @@ private function removeMasterFile(string $filepath): bool
*/
private function makePathRelativeToShopSource(string $path): string
{
return Path::makeRelative($path, (new Facts())->getSourcePath());
return Path::makeRelative(
$path,
Path::join((new BootstrapConfigurationFactory())->create()->getShopDirectory())
);
}
}
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\Internal\Framework\Configuration\BootstrapConfigurationFactory;
use OxidEsales\Facts\Facts;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Filesystem\Path;
Expand Down Expand Up @@ -482,7 +483,7 @@ public function getRootDirectory(): string
public function getSqlDirectory(): string
{
return Path::join(
(new Facts())->getSourcePath(),
Path::join((new BootstrapConfigurationFactory())->create()->getShopDirectory(), 'source'),
self::SETUP_DIRECTORY,
self::DATABASE_SQL_DIRECTORY
);
Expand Down
3 changes: 2 additions & 1 deletion tests/Codeception/Acceptance/CheckoutProcessCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OxidEsales\Codeception\Page\Checkout\UserCheckout;
use OxidEsales\Codeception\Step\Basket;
use OxidEsales\Codeception\Step\UserRegistrationInCheckout;
use OxidEsales\EshopCommunity\Internal\Framework\Configuration\BootstrapConfigurationFactory;
use OxidEsales\EshopCommunity\Tests\Codeception\Support\AcceptanceTester;
use OxidEsales\Facts\Facts;

Expand Down Expand Up @@ -444,7 +445,7 @@ public function checkNoSessionCookiesCheckout(AcceptanceTester $I): void
$I->updateConfigInDatabase('blShowBirthdayFields', true, 'bool');

file_put_contents(
(new Facts())->getShopRootPath() . '/cust_config.inc.php',
(new BootstrapConfigurationFactory())->create()->getShopDirectory() . '/cust_config.inc.php',
'<?php $this->blSessionUseCookies = false;'
);

Expand Down
7 changes: 4 additions & 3 deletions tests/Codeception/Config/CodeceptionParametersProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ public function getParameters(): array
{

$facts = new Facts();
$databaseUrl = getenv('OXID_DB_URL') ?: (new BootstrapConfigurationFactory())->create()->getDatabaseUrl();
$systemConfiguration = (new BootstrapConfigurationFactory())->create();
$databaseUrl = getenv('OXID_DB_URL') ?: $systemConfiguration->getDatabaseUrl();
$this->dbConfig = (new DatabaseConfiguration($databaseUrl));
return [
'SHOP_URL' => getenv('SHOP_URL') ?: $facts->getShopUrl(),
'SHOP_SOURCE_PATH' => getenv('SHOP_SOURCE_PATH') ?: $facts->getSourcePath(),
'SHOP_SOURCE_PATH' => getenv('SHOP_SOURCE_PATH') ?: $systemConfiguration->getShopDirectory(),
'VENDOR_PATH' => $facts->getVendorPath(),
'DB_NAME' => $this->getDbName(),
'DB_USERNAME' => $this->getDbUser(),
Expand Down Expand Up @@ -77,7 +78,7 @@ private function getShopSuitePath(Facts $facts): string
{
$testSuitePath = (string)getenv('TEST_SUITE');
if ($testSuitePath === '' || $testSuitePath === '0') {
$testSuitePath = $facts->getShopRootPath() . '/tests';
$testSuitePath = (new BootstrapConfigurationFactory())->create()->getShopDirectory() . '/tests';
}
return $testSuitePath;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ConsoleRunnerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace OxidEsales\EshopCommunity\Tests;

use OxidEsales\Facts\Facts;
use OxidEsales\EshopCommunity\Internal\Framework\FileSystem\BootstrapLocator;
use RuntimeException;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -43,7 +43,7 @@ public function runInConsoleAndAssertSuccess(string $command): Process
private function getPathToConsoleScript(): string
{
$scriptPath = 'bin/oe-console';
$shopRootPath = (new Facts())->getShopRootPath();
$shopRootPath = (new BootstrapLocator())->getProjectRoot();
if (is_file("$shopRootPath/vendor/$scriptPath")) {
return "$shopRootPath/vendor/$scriptPath";
}
Expand Down
3 changes: 2 additions & 1 deletion tests/FilesystemTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OxidEsales\EshopCommunity\Tests;

use OxidEsales\EshopCommunity\Internal\Framework\Configuration\BootstrapConfigurationFactory;
use OxidEsales\Facts\Facts;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
Expand All @@ -34,7 +35,7 @@ public function restoreVarDirectory(): void

private function init(): void
{
$shopRootPath = (new Facts())->getShopRootPath();
$shopRootPath = (new BootstrapConfigurationFactory())->create()->getShopDirectory();
$this->filesystem = new Filesystem();
$this->varPath = Path::join($shopRootPath, 'var');
$this->varBackupPath = Path::join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Composer\Package\Package;
use OxidEsales\ComposerPlugin\Installer\Package\ComponentInstaller;
use OxidEsales\EshopCommunity\Internal\Container\BootstrapContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Configuration\BootstrapConfigurationFactory;
use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Service\ProjectYamlImportServiceInterface;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface;
use OxidEsales\EshopCommunity\Tests\ContainerTrait;
Expand Down Expand Up @@ -54,7 +55,7 @@ private function createInstaller(): ComponentInstaller

return new ComponentInstaller(
new NullIO(),
(new Facts())->getShopRootPath(),
(new BootstrapConfigurationFactory())->create()->getShopDirectory(),
$packageStub
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Container\ContainerBuilderFactory;
use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface;
use OxidEsales\Facts\Config\ConfigFile;
use PHPUnit\Framework\TestCase;

final class ContextTest extends TestCase
Expand Down

0 comments on commit 058ee9a

Please sign in to comment.