diff --git a/lib/internal/Magento/Framework/Console/Cli.php b/lib/internal/Magento/Framework/Console/Cli.php index 7fae09c10e5e7..95362a36068ae 100644 --- a/lib/internal/Magento/Framework/Console/Cli.php +++ b/lib/internal/Magento/Framework/Console/Cli.php @@ -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 @@ -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(); @@ -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 */ diff --git a/setup/config/application.config.php b/setup/config/application.config.php index e7efd12023df4..e9362f3af1643 100644 --- a/setup/config/application.config.php +++ b/setup/config/application.config.php @@ -32,5 +32,6 @@ // list of Magento specific required services, like default abstract factory 'required_services' => [ DiAbstractServiceFactory::class - ] + ], + 'document_root' => '' ];