Skip to content

MAGETWO-84709 - Respect Magento document root in CLI #14334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions lib/internal/Magento/Framework/Console/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class Cli extends Console\Application
*/
private $objectManager;

/**
* @var array
*/
private $configuration;

/**
* @param string $name the application name
* @param string $version the application version
Expand All @@ -67,9 +72,9 @@ class Cli extends Console\Application
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
{
try {
$configuration = require BP . '/setup/config/application.config.php';
$this->configuration = require BP . '/setup/config/application.config.php';
$bootstrapApplication = new Application();
$application = $bootstrapApplication->bootstrap($configuration);
$application = $bootstrapApplication->bootstrap($this->configuration);
$this->serviceManager = $application->getServiceManager();

$this->assertCompilerPreparation();
Expand Down Expand Up @@ -159,6 +164,21 @@ private function initObjectManager()
$params = (new ComplexParameter(self::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER);
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;

/**
* Workaround for CLI not respecting pub document root described in MAGETWO-84709
*/
if (isset($this->configuration['document_root'])
&& $this->configuration['document_root'] === \Magento\Framework\App\Filesystem\DirectoryList::PUB) {

$params[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] = [
DirectoryList::PUB => [DirectoryList::URL_PATH => ''],
DirectoryList::MEDIA => [DirectoryList::URL_PATH => 'media'],
DirectoryList::STATIC_VIEW => [DirectoryList::URL_PATH => 'static'],
DirectoryList::UPLOAD => [DirectoryList::URL_PATH => 'media/upload'],
];

}

$this->objectManager = Bootstrap::create(BP, $params)->getObjectManager();

/** @var ObjectManagerProvider $omProvider */
Expand Down
3 changes: 2 additions & 1 deletion setup/config/application.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
// list of Magento specific required services, like default abstract factory
'required_services' => [
DiAbstractServiceFactory::class
]
],
'document_root' => ''
];