Skip to content

Commit 1eeb82b

Browse files
Merge pull request #2 from magento-extensibility/2.0.x-cloud-patches
Port MAGETWO-51592 Make single tenant compiler work when Magento not installed
2 parents 407f321 + 023ea80 commit 1eeb82b

File tree

5 files changed

+219
-156
lines changed

5 files changed

+219
-156
lines changed

setup/src/Magento/Setup/Console/Command/AbstractModuleCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,18 @@ protected function cleanup(InputInterface $input, OutputInterface $output)
8484
/** @var \Magento\Framework\App\State\CleanupFiles $cleanupFiles */
8585
$cleanupFiles = $this->objectManager->get('Magento\Framework\App\State\CleanupFiles');
8686
$cleanupFiles->clearCodeGeneratedClasses();
87-
$output->writeln('<info>Generated classes cleared successfully. Please re-run Magento compile command</info>');
87+
$output->writeln(
88+
"<info>Generated classes cleared successfully. Please run the 'setup:di:compile' command to "
89+
. 'generate classes.</info>'
90+
);
8891
if ($input->getOption(self::INPUT_KEY_CLEAR_STATIC_CONTENT)) {
8992
$cleanupFiles->clearMaterializedViewFiles();
9093
$output->writeln('<info>Generated static view files cleared successfully.</info>');
9194
} else {
9295
$output->writeln(
93-
'<info>Info: Some modules might require static view files to be cleared. Use the optional --' .
94-
self::INPUT_KEY_CLEAR_STATIC_CONTENT . ' option to clear them.</info>'
96+
"<info>Info: Some modules might require static view files to be cleared. To do this, run '"
97+
. $this->getName() . "' with the --" . self::INPUT_KEY_CLEAR_STATIC_CONTENT
98+
. ' option to clear them.</info>'
9599
);
96100
}
97101
}

setup/src/Magento/Setup/Console/Command/AbstractModuleManageCommand.php

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
namespace Magento\Setup\Console\Command;
77

88
use Symfony\Component\Console\Input\InputInterface;
9-
use Symfony\Component\Console\Input\InputOption;
109
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\Console\Input\InputOption;
11+
use Magento\Framework\App\DeploymentConfig;
12+
use Magento\Framework\Module\Status;
1113

1214
abstract class AbstractModuleManageCommand extends AbstractModuleCommand
1315
{
@@ -17,6 +19,11 @@ abstract class AbstractModuleManageCommand extends AbstractModuleCommand
1719
const INPUT_KEY_ALL = 'all';
1820
const INPUT_KEY_FORCE = 'force';
1921

22+
/**
23+
* @var DeploymentConfig
24+
*/
25+
protected $deploymentConfig;
26+
2027
/**
2128
* {@inheritdoc}
2229
*/
@@ -64,20 +71,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
6471
$output->writeln(implode(PHP_EOL, $messages));
6572
return;
6673
}
67-
/**
68-
* @var \Magento\Framework\Module\Status $status
69-
*/
70-
$status = $this->objectManager->get('Magento\Framework\Module\Status');
7174
try {
72-
$modulesToChange = $status->getModulesToChange($isEnable, $modules);
75+
$modulesToChange = $this->getStatus()->getModulesToChange($isEnable, $modules);
7376
} catch (\LogicException $e) {
7477
$output->writeln('<error>' . $e->getMessage() . '</error>');
7578
return;
7679
}
7780
if (!empty($modulesToChange)) {
7881
$force = $input->getOption(self::INPUT_KEY_FORCE);
7982
if (!$force) {
80-
$constraints = $status->checkConstraints($isEnable, $modulesToChange);
83+
$constraints = $this->getStatus()->checkConstraints($isEnable, $modulesToChange);
8184
if ($constraints) {
8285
$output->writeln(
8386
"<error>Unable to change status of modules because of the following constraints:</error>"
@@ -86,20 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8689
return;
8790
}
8891
}
89-
$status->setIsEnabled($isEnable, $modulesToChange);
90-
if ($isEnable) {
91-
$output->writeln('<info>The following modules have been enabled:</info>');
92-
$output->writeln('<info>- ' . implode("\n- ", $modulesToChange) . '</info>');
93-
$output->writeln('');
94-
$output->writeln(
95-
'<info>To make sure that the enabled modules are properly registered,'
96-
. " run 'setup:upgrade'.</info>"
97-
);
98-
} else {
99-
$output->writeln('<info>The following modules have been disabled:</info>');
100-
$output->writeln('<info>- ' . implode("\n- ", $modulesToChange) . '</info>');
101-
$output->writeln('');
102-
}
92+
$this->setIsEnabled($isEnable, $modulesToChange, $output);
10393
$this->cleanup($input, $output);
10494
if ($force) {
10595
$output->writeln(
@@ -112,6 +102,44 @@ protected function execute(InputInterface $input, OutputInterface $output)
112102
}
113103
}
114104

105+
/**
106+
* Enable/disable modules
107+
*
108+
* @param bool $isEnable
109+
* @param string[] $modulesToChange
110+
* @param OutputInterface $output
111+
* @return void
112+
*/
113+
private function setIsEnabled($isEnable, $modulesToChange, $output)
114+
{
115+
$this->getStatus()->setIsEnabled($isEnable, $modulesToChange);
116+
if ($isEnable) {
117+
$output->writeln('<info>The following modules have been enabled:</info>');
118+
$output->writeln('<info>- ' . implode("\n- ", $modulesToChange) . '</info>');
119+
$output->writeln('');
120+
if ($this->getDeploymentConfig()->isAvailable()) {
121+
$output->writeln(
122+
'<info>To make sure that the enabled modules are properly registered,'
123+
. " run 'setup:upgrade'.</info>"
124+
);
125+
}
126+
} else {
127+
$output->writeln('<info>The following modules have been disabled:</info>');
128+
$output->writeln('<info>- ' . implode("\n- ", $modulesToChange) . '</info>');
129+
$output->writeln('');
130+
}
131+
}
132+
133+
/**
134+
* Get module status
135+
*
136+
* @return Status
137+
*/
138+
private function getStatus()
139+
{
140+
return $this->objectManager->get(Status::class);
141+
}
142+
115143
/**
116144
* Validate list of modules and return error messages
117145
*
@@ -134,4 +162,18 @@ protected function validate(array $modules)
134162
* @return bool
135163
*/
136164
abstract protected function isEnable();
165+
166+
/**
167+
* Get deployment config
168+
*
169+
* @return DeploymentConfig
170+
* @deprecated
171+
*/
172+
private function getDeploymentConfig()
173+
{
174+
if (!($this->deploymentConfig instanceof DeploymentConfig)) {
175+
return $this->objectManager->get(DeploymentConfig::class);
176+
}
177+
return $this->deploymentConfig;
178+
}
137179
}

setup/src/Magento/Setup/Console/Command/DiCompileCommand.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
* Copyright © 2016 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Setup\Console\Command;
87

8+
use Magento\Framework\ObjectManagerInterface;
9+
use Magento\Framework\Filesystem\DriverInterface;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Output\OutputInterface;
912
use Magento\Framework\Filesystem;
1013
use Magento\Framework\App\Filesystem\DirectoryList;
11-
use Magento\Framework\Filesystem\DriverInterface;
12-
use Magento\Framework\ObjectManagerInterface;
1314
use Magento\Framework\App\DeploymentConfig;
1415
use Magento\Framework\Component\ComponentRegistrar;
16+
use Magento\Framework\Config\ConfigOptionsListConstants;
1517
use Magento\Setup\Model\ObjectManagerProvider;
1618
use Magento\Setup\Module\Di\App\Task\Manager;
1719
use Magento\Setup\Module\Di\App\Task\OperationFactory;
1820
use Magento\Setup\Module\Di\App\Task\OperationException;
1921
use Magento\Setup\Module\Di\App\Task\OperationInterface;
2022
use Symfony\Component\Console\Command\Command;
2123
use Symfony\Component\Console\Helper\ProgressBar;
22-
use Symfony\Component\Console\Input\InputInterface;
23-
use Symfony\Component\Console\Output\OutputInterface;
2424

2525
/**
2626
* Command to run compile in single-tenant mode
@@ -107,8 +107,10 @@ protected function configure()
107107
private function checkEnvironment()
108108
{
109109
$messages = [];
110-
if (!$this->deploymentConfig->isAvailable()) {
111-
$messages[] = 'You cannot run this command because the Magento application is not installed.';
110+
$config = $this->deploymentConfig->get(ConfigOptionsListConstants::KEY_MODULES);
111+
if (!$config) {
112+
$messages[] = 'You cannot run this command because modules are not enabled. You can enable modules by'
113+
. ' running the \'module:enable --all\' command.';
112114
}
113115

114116
/**

setup/src/Magento/Setup/Test/Unit/Console/Command/DiCompileCommandTest.php

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
1313
{
1414
/** @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject */
15-
private $deploymentConfig;
15+
private $deploymentConfigMock;
1616

1717
/** @var \Magento\Setup\Module\Di\App\Task\Manager|\PHPUnit_Framework_MockObject_MockObject */
18-
private $manager;
18+
private $managerMock;
1919

2020
/** @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
21-
private $objectManager;
21+
private $objectManagerMock;
2222

2323
/** @var DiCompileCommand|\PHPUnit_Framework_MockObject_MockObject */
2424
private $command;
@@ -27,28 +27,28 @@ class DiCompileCommandTest extends \PHPUnit_Framework_TestCase
2727
private $cacheMock;
2828

2929
/** @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject */
30-
private $filesystem;
30+
private $filesystemMock;
3131

32-
/** @var \Magento\Framework\Filesystem\Driver\File | \PHPUnit_Framework_MockObject_MockObject*/
33-
private $fileDriver;
32+
/** @var \Magento\Framework\Filesystem\Driver\File|\PHPUnit_Framework_MockObject_MockObject */
33+
private $fileDriverMock;
3434

35-
/** @var \Magento\Framework\App\Filesystem\DirectoryList | \PHPUnit_Framework_MockObject_MockObject*/
36-
private $directoryList;
35+
/** @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject */
36+
private $directoryListMock;
3737

3838
/** @var \Magento\Framework\Component\ComponentRegistrar|\PHPUnit_Framework_MockObject_MockObject */
39-
private $componentRegistrar;
39+
private $componentRegistrarMock;
4040

4141
public function setUp()
4242
{
43-
$this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
44-
$objectManagerProvider = $this->getMock(
43+
$this->deploymentConfigMock = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false);
44+
$objectManagerProviderMock = $this->getMock(
4545
'Magento\Setup\Model\ObjectManagerProvider',
4646
[],
4747
[],
4848
'',
4949
false
5050
);
51-
$this->objectManager = $this->getMockForAbstractClass(
51+
$this->objectManagerMock = $this->getMockForAbstractClass(
5252
'Magento\Framework\ObjectManagerInterface',
5353
[],
5454
'',
@@ -58,91 +58,87 @@ public function setUp()
5858
->disableOriginalConstructor()
5959
->getMock();
6060

61-
$objectManagerProvider->expects($this->once())
61+
$objectManagerProviderMock->expects($this->once())
6262
->method('get')
63-
->willReturn($this->objectManager);
64-
$this->manager = $this->getMock('Magento\Setup\Module\Di\App\Task\Manager', [], [], '', false);
65-
$this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
66-
$this->filesystem = $this->getMockBuilder('Magento\Framework\Filesystem')
63+
->willReturn($this->objectManagerMock);
64+
$this->managerMock = $this->getMock('Magento\Setup\Module\Di\App\Task\Manager', [], [], '', false);
65+
$this->directoryListMock = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
66+
$this->filesystemMock = $this->getMockBuilder('Magento\Framework\Filesystem')
6767
->disableOriginalConstructor()
6868
->getMock();
6969

70-
$this->fileDriver = $this->getMockBuilder('Magento\Framework\Filesystem\Driver\File')
70+
$this->fileDriverMock = $this->getMockBuilder('Magento\Framework\Filesystem\Driver\File')
7171
->disableOriginalConstructor()
7272
->getMock();
73-
$this->componentRegistrar = $this->getMock(
73+
$this->componentRegistrarMock = $this->getMock(
7474
'\Magento\Framework\Component\ComponentRegistrar',
7575
[],
7676
[],
7777
'',
7878
false
7979
);
80-
$this->componentRegistrar->expects($this->any())->method('getPaths')->willReturnMap([
80+
$this->componentRegistrarMock->expects($this->any())->method('getPaths')->willReturnMap([
8181
[ComponentRegistrar::MODULE, ['/path/to/module/one', '/path/to/module/two']],
8282
[ComponentRegistrar::LIBRARY, ['/path/to/library/one', '/path/to/library/two']],
8383
]);
8484

8585
$this->command = new DiCompileCommand(
86-
$this->deploymentConfig,
87-
$this->directoryList,
88-
$this->manager,
89-
$objectManagerProvider,
90-
$this->filesystem,
91-
$this->fileDriver,
92-
$this->componentRegistrar
86+
$this->deploymentConfigMock,
87+
$this->directoryListMock,
88+
$this->managerMock,
89+
$objectManagerProviderMock,
90+
$this->filesystemMock,
91+
$this->fileDriverMock,
92+
$this->componentRegistrarMock
9393
);
9494
}
9595

96-
public function testExecuteDiExists()
96+
public function testExecuteModulesNotEnabled()
9797
{
98-
$diPath = '/root/magento/var/di';
99-
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
100-
$this->fileDriver->expects($this->atLeastOnce())->method('isExists')->with($diPath)->willReturn(true);
101-
$this->directoryList->expects($this->atLeastOnce())->method('getPath')->willReturn($diPath);
102-
$tester = new CommandTester($this->command);
103-
$tester->execute([]);
104-
$this->assertContains("delete '/root/magento/var/di'", $tester->getDisplay());
105-
}
106-
107-
public function testExecuteNotInstalled()
108-
{
109-
$this->directoryList->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
110-
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(false);
98+
$this->directoryListMock->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
99+
$this->deploymentConfigMock->expects($this->once())
100+
->method('get')
101+
->with(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES)
102+
->willReturn(null);
111103
$tester = new CommandTester($this->command);
112104
$tester->execute([]);
113105
$this->assertEquals(
114-
'You cannot run this command because the Magento application is not installed.' . PHP_EOL,
106+
'You cannot run this command because modules are not enabled. You can enable modules by running the '
107+
. "'module:enable --all' command." . PHP_EOL,
115108
$tester->getDisplay()
116109
);
117110
}
118111

119112
public function testExecute()
120113
{
121-
$this->directoryList->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
122-
$this->objectManager->expects($this->once())
114+
$this->directoryListMock->expects($this->atLeastOnce())->method('getPath')->willReturn(null);
115+
$this->objectManagerMock->expects($this->once())
123116
->method('get')
124117
->with('Magento\Framework\App\Cache')
125118
->willReturn($this->cacheMock);
126119
$this->cacheMock->expects($this->once())->method('clean');
127120
$writeDirectory = $this->getMock('Magento\Framework\Filesystem\Directory\WriteInterface');
128121
$writeDirectory->expects($this->atLeastOnce())->method('delete');
129-
$this->filesystem->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);
122+
$this->filesystemMock->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);
130123

131-
$this->deploymentConfig->expects($this->once())->method('isAvailable')->willReturn(true);
124+
$this->deploymentConfigMock->expects($this->once())
125+
->method('get')
126+
->with(\Magento\Framework\Config\ConfigOptionsListConstants::KEY_MODULES)
127+
->willReturn(['Magento_Catalog' => 1]);
132128
$progressBar = $this->getMockBuilder(
133129
'Symfony\Component\Console\Helper\ProgressBar'
134130
)
135131
->disableOriginalConstructor()
136132
->getMock();
137133

138-
$this->objectManager->expects($this->once())->method('configure');
139-
$this->objectManager
134+
$this->objectManagerMock->expects($this->once())->method('configure');
135+
$this->objectManagerMock
140136
->expects($this->once())
141137
->method('create')
142138
->with('Symfony\Component\Console\Helper\ProgressBar')
143139
->willReturn($progressBar);
144-
$this->manager->expects($this->exactly(7))->method('addOperation');
145-
$this->manager->expects($this->once())->method('process');
140+
$this->managerMock->expects($this->exactly(7))->method('addOperation');
141+
$this->managerMock->expects($this->once())->method('process');
146142
$tester = new CommandTester($this->command);
147143
$tester->execute([]);
148144
$this->assertContains(

0 commit comments

Comments
 (0)