Skip to content

Commit 30032a0

Browse files
Merge pull request #695 from magento-fearless-kiwis/MAGETWO-62400-Cli-pre-install
MAGETWO-62400 - Cli pre install
2 parents 717ba2b + fad45f4 commit 30032a0

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Console;
7+
8+
use Magento\Framework\ObjectManagerInterface;
9+
10+
/**
11+
* This class groups and instantiates a list of deploy commands in order to be used separately before install
12+
*/
13+
class CommandList implements \Magento\Framework\Console\CommandListInterface
14+
{
15+
/**
16+
* Object Manager
17+
*
18+
* @var ObjectManagerInterface
19+
*/
20+
private $objectManager;
21+
22+
/**
23+
* @param ObjectManagerInterface $objectManager
24+
*/
25+
public function __construct(ObjectManagerInterface $objectManager)
26+
{
27+
$this->objectManager = $objectManager;
28+
}
29+
30+
/**
31+
* Gets list of command classes
32+
*
33+
* @return string[]
34+
*/
35+
protected function getCommandsClasses()
36+
{
37+
return [
38+
\Magento\Deploy\Console\Command\DeployStaticContentCommand::class
39+
];
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function getCommands()
46+
{
47+
$commands = [];
48+
foreach ($this->getCommandsClasses() as $class) {
49+
if (class_exists($class)) {
50+
$commands[] = $this->objectManager->get($class);
51+
} else {
52+
throw new \Exception('Class ' . $class . ' does not exist');
53+
}
54+
}
55+
return $commands;
56+
}
57+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
if (PHP_SAPI == 'cli') {
8+
\Magento\Framework\Console\CommandLocator::register('Magento\Deploy\Console\CommandList');
9+
}

app/code/Magento/Deploy/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
],
1717
"autoload": {
1818
"files": [
19+
"cli_commands.php",
1920
"registration.php"
2021
],
2122
"psr-4": {

lib/internal/Magento/Framework/Console/Cli.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,21 @@ protected function getApplicationCommands()
126126
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
127127
$bootstrap = Bootstrap::create(BP, $params);
128128
$objectManager = $bootstrap->getObjectManager();
129-
/** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */
130-
$omProvider = $this->serviceManager->get('Magento\Setup\Model\ObjectManagerProvider');
131-
$omProvider->setObjectManager($objectManager);
132129

133-
if (class_exists('Magento\Setup\Console\CommandList')) {
130+
// Specialized setup command list available before and after M2 install
131+
if (class_exists('Magento\Setup\Console\CommandList')
132+
&& class_exists('Magento\Setup\Model\ObjectManagerProvider')
133+
) {
134+
/** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */
135+
$omProvider = $this->serviceManager->get(\Magento\Setup\Model\ObjectManagerProvider::class);
136+
$omProvider->setObjectManager($objectManager);
134137
$setupCommandList = new \Magento\Setup\Console\CommandList($this->serviceManager);
135138
$commands = array_merge($commands, $setupCommandList->getCommands());
136139
}
137140

138-
if (count($objectManager->get(\Magento\Framework\App\DeploymentConfig::class)->get('modules'))) {
139-
/** @var \Magento\Framework\Console\CommandListInterface */
141+
// Allowing instances of all modular commands only after M2 install
142+
if ($objectManager->get(\Magento\Framework\App\DeploymentConfig::class)->isAvailable()) {
143+
/** @var \Magento\Framework\Console\CommandListInterface $commandList */
140144
$commandList = $objectManager->create(\Magento\Framework\Console\CommandListInterface::class);
141145
$commands = array_merge($commands, $commandList->getCommands());
142146
}

0 commit comments

Comments
 (0)