Skip to content

Commit

Permalink
OXDEV-7785 Replace sShopDir with container parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
AshrafOxid committed Apr 24, 2024
1 parent 342c962 commit 3638954
Show file tree
Hide file tree
Showing 32 changed files with 135 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use OxidEsales\Eshop\Core\Field;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\ShopVersion;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use Symfony\Component\Filesystem\Path;

class AdminDetailsController extends \OxidEsales\Eshop\Application\Controller\Admin\AdminController
{
Expand All @@ -21,7 +23,7 @@ public function render()

// generate help link
$myConfig = Registry::getConfig();
$sDir = $myConfig->getConfigParam('sShopDir') . '/documentation/admin';
$sDir = Path::join(ContainerFacade::getParameter('oxid_shop_directory'), 'documentation', 'admin');
if (is_dir($sDir)) {
$sDir = $myConfig->getConfigParam('sShopURL') . 'documentation/admin';
} else {
Expand Down
2 changes: 1 addition & 1 deletion source/Application/Controller/Admin/DiagnosticsMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function __construct()
{
parent::__construct();

$this->_sShopDir = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sShopDir');
$this->_sShopDir = ContainerFacade::getParameter('oxid_shop_directory');
$this->_oOutput = oxNew(\OxidEsales\Eshop\Application\Model\DiagnosticsOutput::class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
namespace OxidEsales\EshopCommunity\Application\Controller\Admin;

use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use stdClass;
use OxidEsales\Eshop\Core\Str;
use OxidEsales\Eshop\Core\TableViewNameGenerator;
use Symfony\Component\Filesystem\Path;

/**
* Error constants
Expand Down Expand Up @@ -120,7 +122,12 @@ public function __construct()
parent::__construct();

// set generic frame template
$this->_sFilePath = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sShopDir') . "/" . $this->sExportPath . $this->sExportFileName . "." . $this->sExportFileType;
$this->_sFilePath = Path::join(
ContainerFacade::getParameter('oxid_shop_directory'),
$this->sExportPath,
$this->sExportFileName,
$this->sExportFileType
);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions source/Application/Controller/Admin/GenericImportMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace OxidEsales\EshopCommunity\Application\Controller\Admin;

use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use Symfony\Component\Filesystem\Path;

/**
* Admin general export manager.
Expand Down
5 changes: 3 additions & 2 deletions source/Application/Controller/Admin/NavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OxidEsales\Eshop\Core\ShopVersion;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\Facts\Facts;
use Symfony\Component\Filesystem\Path;

/**
* Administrator GUI navigation manager class.
Expand Down Expand Up @@ -179,12 +180,12 @@ protected function doStartUpChecks()


// check if setup dir is deleted
if (file_exists(Registry::getConfig()->getConfigParam('sShopDir') . '/Setup/index.php')) {
if (file_exists(Path::join(ContainerFacade::getParameter('oxid_shop_directory'), 'Setup', 'index.php'))) {
$messages['warning'] .= ((!empty($messages['warning'])) ? "<br>" : '') . Registry::getLang()->translateString('SETUP_DIRNOTDELETED_WARNING');
}

// check if config file is writable
$sConfPath = Registry::getConfig()->getConfigParam('sShopDir') . "/config.inc.php";
$sConfPath = Path::join(ContainerFacade::getParameter('oxid_shop_directory'), 'config.inc.php');
if (!is_readable($sConfPath) || is_writable($sConfPath)) {
$messages['warning'] .= ((!empty($messages['warning'])) ? "<br>" : '') . Registry::getLang()->translateString('SETUP_CONFIGPERMISSIONS_WARNING');
}
Expand Down
8 changes: 7 additions & 1 deletion source/Application/Controller/Admin/VoucherSerieExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace OxidEsales\EshopCommunity\Application\Controller\Admin;

use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use Symfony\Component\Filesystem\Path;

/**
* General export class.
Expand Down Expand Up @@ -100,7 +102,11 @@ protected function getExportFileName()
*/
protected function getExportFilePath()
{
return \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sShopDir') . "/export/" . $this->getExportFileName();
return Path::join(
ContainerFacade::getParameter('oxid_shop_directory'),
'export',
$this->getExportFileName()
);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions source/Application/Model/MediaUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace OxidEsales\EshopCommunity\Application\Model;

use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use Symfony\Component\Filesystem\Path;

class MediaUrl extends \OxidEsales\Eshop\Core\Model\MultiLanguageModel
{
protected $_sClassName = 'oxmediaurls';
Expand Down Expand Up @@ -89,8 +92,12 @@ public function getObjectId()
*/
public function delete($sOXID = null)
{
$sFilePath = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sShopDir') . "/out/media/" .
basename($this->oxmediaurls__oxurl->value);
$sFilePath = Path::join(
ContainerFacade::getParameter('oxid_shop_directory'),
'out',
'media',
basename($this->oxmediaurls__oxurl->value)
);

if ($this->oxmediaurls__oxisuploaded->value) {
if (file_exists($sFilePath)) {
Expand Down
41 changes: 16 additions & 25 deletions source/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\EshopCommunity\Internal\Framework\Config\Event\ShopConfigurationChangedEvent;
use OxidEsales\EshopCommunity\Internal\Framework\Theme\Event\ThemeSettingChangedEvent;
use Symfony\Component\Filesystem\Path;

//max integer
define('MAX_64BIT_INTEGER', '18446744073709551615');
Expand Down Expand Up @@ -86,13 +87,6 @@ class Config extends \OxidEsales\Eshop\Core\Base
*/
protected $sAdminSSLURL = null;

/**
* Shops install directory
*
* @var string
*/
protected $sShopDir = null;

/**
* Shops compile directory
*
Expand Down Expand Up @@ -461,7 +455,6 @@ protected function loadVarsFromFile()

//adding trailing slashes
$fileUtils = Registry::getUtilsFile();
$this->sShopDir = $fileUtils->normalizeDir($this->sShopDir);
$this->sCompileDir = $fileUtils->normalizeDir($this->sCompileDir);
$this->sShopURL = $fileUtils->normalizeDir($this->sShopURL);
$this->sSSLShopURL = $fileUtils->normalizeDir($this->sSSLShopURL);
Expand Down Expand Up @@ -1064,9 +1057,12 @@ public function setActShopCurrency($cur)
public function getOutDir($absolute = true)
{
if ($absolute) {
return $this->getConfigParam('sShopDir') . $this->_sOutDir . '/';

return Path::join(ContainerFacade::getParameter('oxid_shop_directory'), $this->_sOutDir)
. DIRECTORY_SEPARATOR;
} else {
return $this->_sOutDir . '/';

return $this->_sOutDir . DIRECTORY_SEPARATOR;
}
}

Expand All @@ -1079,11 +1075,7 @@ public function getOutDir($absolute = true)
*/
public function getViewsDir($absolute = true)
{
if ($absolute) {
return $this->getConfigParam('sShopDir') . 'Application/views/';
} else {
return 'Application/views/';
}
return Path::join($this->getAppDir($absolute), 'views') . DIRECTORY_SEPARATOR;
}

/**
Expand All @@ -1097,13 +1089,9 @@ public function getViewsDir($absolute = true)
*/
public function getTranslationsDir($file, $dir, $absolute = true)
{
$path = $absolute ? $this->getConfigParam('sShopDir') : '';
$path .= 'Application/translations/';
if (is_readable($path . $dir . '/' . $file)) {
return $path . $dir . '/' . $file;
}
$path = Path::join($this->getAppDir($absolute), 'translations', $dir, $file);

return false;
return is_readable($path) ? $path : false;
}

/**
Expand All @@ -1116,9 +1104,12 @@ public function getTranslationsDir($file, $dir, $absolute = true)
public function getAppDir($absolute = true)
{
if ($absolute) {
return $this->getConfigParam('sShopDir') . 'Application/';

return Path::join(ContainerFacade::getParameter('oxid_shop_directory'), 'Application')
. DIRECTORY_SEPARATOR;
} else {
return 'Application/';

return 'Application' . DIRECTORY_SEPARATOR;
}
}

Expand Down Expand Up @@ -1627,7 +1618,7 @@ public function getFullEdition()
*/
public function getPackageInfo()
{
$fileName = $this->getConfigParam('sShopDir') . "/pkg.info";
$fileName = Path::join(ContainerFacade::getParameter('oxid_shop_directory'), 'pkg.info');
$rev = @file_get_contents($fileName);
$rev = str_replace("\n", "<br>", $rev);

Expand Down Expand Up @@ -1939,7 +1930,7 @@ public function getActiveViewsIds()
*/
public function getLogsDir()
{
return $this->getConfigParam('sShopDir') . 'log/';
return Path::join(ContainerFacade::getParameter('oxid_shop_directory'), 'log');
}

/**
Expand Down
4 changes: 3 additions & 1 deletion source/Core/DynamicImageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function includeImageUtils()

use OxidEsales\Eshop\Core\Exception\SystemComponentException;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use Symfony\Component\Filesystem\Path;

/**
* Image generator class
Expand Down Expand Up @@ -174,7 +176,7 @@ public function __call($method, $arguments)
*/
protected function getShopBasePath()
{
return Registry::getConfig()->getConfigParam("sShopDir");
return ContainerFacade::getParameter('oxid_shop_directory') . DIRECTORY_SEPARATOR;
}

/**
Expand Down
1 change: 1 addition & 0 deletions source/Core/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use OxidEsales\Eshop\Core\ConfigFile;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;

/**
* Cache for storing module variables selected from database.
Expand Down
8 changes: 7 additions & 1 deletion source/Core/ShopControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use ReflectionMethod;
use OxidEsales\EshopCommunity\Internal\Transition\ShopEvents\ViewRenderedEvent;
use OxidEsales\EshopCommunity\Internal\Transition\ShopEvents\BeforeHeadersSendEvent;
use Symfony\Component\Filesystem\Path;

class ShopControl extends \OxidEsales\Eshop\Core\Base
{
Expand Down Expand Up @@ -521,7 +522,12 @@ protected function runOnce()
$runOnceExecuted = Registry::getSession()->getVariable('blRunOnceExecuted');
if (!$runOnceExecuted && !$this->isAdmin() && $config->isProductiveMode()) {
// check if setup is still there
if (file_exists($config->getConfigParam('sShopDir') . '/Setup/index.php')) {
$setupIndexFile = Path::join(
ContainerFacade::getParameter('oxid_shop_directory'),
'Setup',
'index.php'
);
if (file_exists($setupIndexFile)) {
$tpl = 'message/err_setup';
$activeView = oxNew(\OxidEsales\Eshop\Application\Controller\FrontendController::class);
$context = [
Expand Down
1 change: 1 addition & 0 deletions source/Core/SystemRequirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use OxidEsales\Eshop\Core\DatabaseProvider as DatabaseConnectionProvider;
use OxidEsales\Eshop\Core\Exception\SystemComponentException;
use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Internal\Framework\SystemRequirements\SystemSecurityChecker;

/**
Expand Down
1 change: 1 addition & 0 deletions source/Core/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OxidEsales\EshopCommunity\Internal\Transition\ShopEvents\ApplicationExitEvent;
use stdClass;
use OxidEsales\Eshop\Core\Registry;
use Symfony\Component\Filesystem\Path;

/**
* General utils class
Expand Down
8 changes: 4 additions & 4 deletions source/Core/UtilsFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public function urlValidate($url)
* Process uploaded files. Returns unique file name, on fail false
*
* @param string $sFileName form file item name
* @param string $sUploadPath RELATIVE (to config sShopDir parameter) path for uploaded file to be copied
* @param string $sUploadPath RELATIVE (to container parameter oxid_shop_directory) path for uploaded file to be copied
*
* @throws \OxidEsales\Eshop\Core\Exception\StandardException if file is not valid
*
Expand All @@ -476,7 +476,7 @@ public function processFile($sFileName, $sUploadPath)
{
$aFileInfo = $_FILES[$sFileName];

$sBasePath = Registry::getConfig()->getConfigParam('sShopDir');
$absoluteUploadPath = Path::join(ContainerFacade::getParameter('oxid_shop_directory'), $sUploadPath);

//checking params
if (!isset($aFileInfo['name']) || !isset($aFileInfo['tmp_name'])) {
Expand Down Expand Up @@ -505,9 +505,9 @@ public function processFile($sFileName, $sUploadPath)
throw oxNew(\OxidEsales\Eshop\Core\Exception\StandardException::class, 'EXCEPTION_NOTALLOWEDTYPE');
}

$sFileName = $this->getUniqueFileName($sBasePath . $sUploadPath, $sFileName, $sExt);
$sFileName = $this->getUniqueFileName($absoluteUploadPath, $sFileName, $sExt);

$destination = Path::join($sBasePath, $sUploadPath, $sFileName);
$destination = Path::join($absoluteUploadPath, $sFileName);
if ($this->uploadMasterImage($aFileInfo['tmp_name'], $destination)) {
return $sFileName;
}
Expand Down
2 changes: 1 addition & 1 deletion source/Core/ViewConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ public function getModuleUrl($sModule, $sFile = '')
$config = Registry::getConfig();

$moduleUrl = str_replace(
rtrim($config->getConfigParam('sShopDir'), '/'),
rtrim(ContainerFacade::getParameter('oxid_shop_directory'), '/'),
rtrim($config->getCurrentShopUrl(false), '/'),
$this->getModulePath($sModule, $sFile)
);
Expand Down
3 changes: 2 additions & 1 deletion source/Core/ViewHelper/BaseRegistrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OxidEsales\EshopCommunity\Core\ViewHelper;

use OxidEsales\EshopCommunity\Core\Di\ContainerFacade;
use OxidEsales\EshopCommunity\Core\Registry;

/**
Expand Down Expand Up @@ -104,7 +105,7 @@ protected function getPathByUrl($url)
$config = Registry::getConfig();
return str_replace(
rtrim($config->getCurrentShopUrl(false), '/'),
rtrim($config->getConfigParam('sShopDir'), '/'),
rtrim(ContainerFacade::getParameter('oxid_shop_directory'), '/'),
$url
);
}
Expand Down
5 changes: 5 additions & 0 deletions source/Internal/Container/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function getContainer(): ContainerInterface
return $this->symfonyContainer;
}

public function setContainer(ContainerInterface $symfonyContainer): void
{
$this->symfonyContainer = $symfonyContainer;
}

/**
* Loads container from cache if available, otherwise
* create the container from scratch.
Expand Down
5 changes: 5 additions & 0 deletions source/Internal/Container/services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
imports:
- { resource: bootstrap-services.yaml }

parameters:
oxid_shop_directory: '%env(OXID_SHOP_DIRECTORY)%'
oxid_compilation_directory: '%env(OXID_COMPILATION_DIRECTORY)%'

services:
_defaults:
autowire: true
Expand Down
Loading

0 comments on commit 3638954

Please sign in to comment.