Skip to content

Commit 1bcb8d0

Browse files
Merge pull request #33 from magento-thunder/MAGECLOUD-1030
MAGECLOUD-1030: ECE Tools improvements part 2
2 parents 1fad6eb + 651d0d4 commit 1bcb8d0

File tree

75 files changed

+4608
-1127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4608
-1127
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!--- Provide a general summary of the Pull Request in the Title above -->
2+
3+
### Description
4+
<!--- Provide a description of the changes proposed in the pull request -->
5+
6+
### Fixed Issues (if relevant)
7+
<!--- Provide a list of fixed issues, if relevant -->
8+
1. ...
9+
2. ...
10+
11+
### Manual testing scenarios
12+
<!--- Provide a set of unambiguous steps to test the proposed code change -->
13+
1. ...
14+
2. ...
15+
16+
### Contribution checklist
17+
- [ ] Pull request has a meaningful description of its purpose
18+
- [ ] Pull request was approved by architect
19+
- [ ] All commits are accompanied by meaningful commit messages
20+
- [ ] All new or changed code is covered with unit/integration tests (if applicable)
21+
- [ ] All automated tests passed successfully (all builds on Travis CI are green)

src/Magento/MagentoCloud/App/Container.php

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,25 @@ class Container extends \Illuminate\Container\Container implements ContainerInte
2626
/**
2727
* @param string $root
2828
* @param array $config
29+
*
30+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
2931
*/
3032
public function __construct(string $root, array $config)
3133
{
34+
/**
35+
* Instance configuration.
36+
*/
3237
$this->singleton(\Magento\MagentoCloud\Filesystem\DirectoryList::class, function () use ($root, $config) {
3338
return new \Magento\MagentoCloud\Filesystem\DirectoryList($root, $config);
3439
});
40+
$this->singleton(\Composer\Composer::class, function () {
41+
$directoryList = $this->get(\Magento\MagentoCloud\Filesystem\DirectoryList::class);
42+
43+
return \Composer\Factory::create(
44+
new \Composer\IO\BufferIO(),
45+
$directoryList->getMagentoRoot() . '/composer.json'
46+
);
47+
});
3548
/**
3649
* Interface to implementation binding.
3750
*/
@@ -40,20 +53,15 @@ public function __construct(string $root, array $config)
4053
\Magento\MagentoCloud\Shell\Shell::class
4154
);
4255
$this->singleton(\Magento\MagentoCloud\Config\Environment::class);
43-
$this->singleton(\Magento\MagentoCloud\DB\Adapter::class);
4456
$this->singleton(\Magento\MagentoCloud\Config\Build::class);
4557
$this->singleton(\Magento\MagentoCloud\Config\Deploy::class);
4658
$this->singleton(\Psr\Log\LoggerInterface::class, $this->createLogger('default'));
4759
$this->singleton(\Magento\MagentoCloud\Util\ComponentInfo::class);
48-
$this->singleton(\Composer\Composer::class, function () {
49-
$directoryList = $this->get(\Magento\MagentoCloud\Filesystem\DirectoryList::class);
50-
51-
return \Composer\Factory::create(
52-
new \Composer\IO\BufferIO(),
53-
$directoryList->getMagentoRoot() . DIRECTORY_SEPARATOR . 'composer.json'
54-
);
55-
});
56-
60+
$this->singleton(\Magento\MagentoCloud\Util\UrlManager::class);
61+
$this->singleton(
62+
\Magento\MagentoCloud\DB\ConnectionInterface::class,
63+
\Magento\MagentoCloud\DB\Connection::class
64+
);
5765
/**
5866
* Contextual binding.
5967
*/
@@ -88,6 +96,44 @@ public function __construct(string $root, array $config)
8896
],
8997
]);
9098
});
99+
$this->when(DeployProcess\InstallUpdate\Install::class)
100+
->needs(ProcessInterface::class)
101+
->give(function () {
102+
return $this->makeWith(ProcessPool::class, [
103+
'processes' => [
104+
$this->make(DeployProcess\InstallUpdate\Install\Setup::class),
105+
$this->make(DeployProcess\InstallUpdate\Install\SecureAdmin::class),
106+
$this->make(DeployProcess\InstallUpdate\ConfigUpdate::class),
107+
$this->make(DeployProcess\InstallUpdate\Install\ImportDeploymentConfig::class),
108+
],
109+
]);
110+
});
111+
$this->when(DeployProcess\InstallUpdate\Update::class)
112+
->needs(ProcessInterface::class)
113+
->give(function () {
114+
return $this->makeWith(ProcessPool::class, [
115+
'processes' => [
116+
$this->make(DeployProcess\InstallUpdate\ConfigUpdate::class),
117+
$this->make(DeployProcess\InstallUpdate\Update\Setup::class),
118+
$this->make(DeployProcess\InstallUpdate\Update\ClearCache::class),
119+
],
120+
]);
121+
});
122+
$this->when(DeployProcess\InstallUpdate\ConfigUpdate::class)
123+
->needs(ProcessInterface::class)
124+
->give(function () {
125+
return $this->makeWith(ProcessPool::class, [
126+
'processes' => [
127+
$this->make(DeployProcess\InstallUpdate\ConfigUpdate\DbConnection::class),
128+
$this->make(DeployProcess\InstallUpdate\ConfigUpdate\Amqp::class),
129+
$this->make(DeployProcess\InstallUpdate\ConfigUpdate\Redis::class),
130+
$this->make(DeployProcess\InstallUpdate\ConfigUpdate\AdminCredentials::class),
131+
$this->make(DeployProcess\InstallUpdate\ConfigUpdate\SearchEngine::class),
132+
$this->make(DeployProcess\InstallUpdate\ConfigUpdate\Urls::class),
133+
$this->make(DeployProcess\InstallUpdate\ConfigUpdate\EnvConfiguration::class),
134+
],
135+
]);
136+
});
91137
$this->when(ConfigDump::class)
92138
->needs(ProcessInterface::class)
93139
->give(function () {

src/Magento/MagentoCloud/Config/Build/Reader.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ public function __construct(File $file, DirectoryList $directoryList)
3939
*/
4040
public function read(): array
4141
{
42-
$fileName = $this->directoryList->getMagentoRoot() . '/build_options.ini';
42+
$fileName = $this->getPath();
4343

4444
return $this->file->isExists($fileName) ? $this->file->parseIni($fileName) : [];
4545
}
46+
47+
/**
48+
* @return string
49+
*/
50+
public function getPath(): string
51+
{
52+
return $this->directoryList->getMagentoRoot() . '/build_options.ini';
53+
}
4654
}

src/Magento/MagentoCloud/Config/Deploy.php

Lines changed: 38 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,123 +5,87 @@
55
*/
66
namespace Magento\MagentoCloud\Config;
77

8-
use Magento\MagentoCloud\DB\Adapter;
9-
use Magento\MagentoCloud\Filesystem\DirectoryList;
10-
use Magento\MagentoCloud\Filesystem\Driver\File;
11-
use Magento\MagentoCloud\Shell\ShellInterface;
8+
use Magento\MagentoCloud\Config\Deploy\Reader;
9+
use Magento\MagentoCloud\Config\Deploy\Writer;
10+
use Magento\MagentoCloud\DB\ConnectionInterface;
1211
use Psr\Log\LoggerInterface;
1312

1413
/**
1514
* Class Deploy.
1615
*/
1716
class Deploy
1817
{
19-
/**
20-
* @var Environment
21-
*/
22-
private $environment;
23-
2418
/**
2519
* @var LoggerInterface
2620
*/
2721
private $logger;
2822

2923
/**
30-
* @var ShellInterface
24+
* @var ConnectionInterface
3125
*/
32-
private $shell;
26+
private $connection;
3327

3428
/**
35-
* @var Adapter
29+
* @var Reader
3630
*/
37-
private $adapter;
31+
private $reader;
3832

3933
/**
40-
* @var File
34+
* @var Writer
4135
*/
42-
private $file;
36+
private $writer;
4337

4438
/**
45-
* @var DirectoryList
46-
*/
47-
private $directoryList;
48-
49-
/**
50-
* @param Environment $environment
5139
* @param LoggerInterface $logger
52-
* @param ShellInterface $shell
53-
* @param Adapter $adapter
54-
* @param File $file
55-
* @param DirectoryList $directoryList
40+
* @param ConnectionInterface $connection
41+
* @param Reader $reader
42+
* @param Writer $writer
5643
*/
5744
public function __construct(
58-
Environment $environment,
5945
LoggerInterface $logger,
60-
ShellInterface $shell,
61-
Adapter $adapter,
62-
File $file,
63-
DirectoryList $directoryList
46+
ConnectionInterface $connection,
47+
Reader $reader,
48+
Writer $writer
6449
) {
65-
$this->environment = $environment;
6650
$this->logger = $logger;
67-
$this->shell = $shell;
68-
$this->adapter = $adapter;
69-
$this->file = $file;
70-
$this->directoryList = $directoryList;
51+
$this->connection = $connection;
52+
$this->reader = $reader;
53+
$this->writer = $writer;
7154
}
7255

7356
/**
7457
* Verifies is Magento installed based on install date in env.php
7558
*
59+
* 1. from environment variables check if db exists and has tables
60+
* 2. check if core_config_data and setup_module tables exist
61+
* 3. check install date
62+
*
7663
* @return bool
7764
* @throws \Exception
7865
*/
79-
public function isInstalled()
66+
public function isInstalled(): bool
8067
{
81-
$configFile = $this->getConfigFilePath();
82-
$isInstalled = false;
68+
$this->logger->info('Checking if db exists and has tables');
8369

84-
//1. from environment variables check if db exists and has tables
85-
//2. check if core_config_data and setup_module tables exist
86-
//3. check install date
70+
$output = $this->connection->listTables();
8771

88-
$this->logger->info('Checking if db exists and has tables');
89-
$output = $this->adapter->execute('SHOW TABLES');
72+
if (!is_array($output) || count($output) <= 1) {
73+
return false;
74+
}
75+
76+
if (!in_array('core_config_data', $output) || !in_array('setup_module', $output)) {
77+
throw new \Exception('Missing either core_config_data or setup_module table', 5);
78+
}
9079

91-
if (is_array($output) && count($output) > 1) {
92-
if (!in_array('core_config_data', $output) || !in_array('setup_module', $output)) {
93-
throw new \Exception('Missing either core_config_data or setup_module table', 5);
94-
} elseif ($this->file->isExists($configFile)) {
95-
$data = include $configFile;
80+
$data = $this->reader->read();
81+
if (isset($data['install']['date'])) {
82+
$this->logger->info('Magento was installed on ' . $data['install']['date']);
9683

97-
if (isset($data['install']) && isset($data['install']['date'])) {
98-
$this->logger->info('Magento was installed on ' . $data['install']['date']);
99-
$isInstalled = true;
100-
} else {
101-
$config['install']['date'] = date('r');
102-
$updatedConfig = '<?php' . "\n" . 'return ' . var_export($config, true) . ';';
103-
$this->file->filePutContents($configFile, $updatedConfig);
104-
$isInstalled = true;
105-
}
106-
} else {
107-
$this->shell->execute('touch ' . $configFile);
108-
$config['install']['date'] = date('r');
109-
$updatedConfig = '<?php' . "\n" . 'return ' . var_export($config, true) . ';';
110-
$this->file->filePutContents($configFile, $updatedConfig);
111-
$isInstalled = true;
112-
}
84+
return true;
11385
}
11486

115-
return $isInstalled;
116-
}
87+
$this->writer->update(['install' => ['date' => date('r')]]);
11788

118-
/**
119-
* Return full path to environment configuration file.
120-
*
121-
* @return string The path to configuration file
122-
*/
123-
public function getConfigFilePath(): string
124-
{
125-
return $this->directoryList->getMagentoRoot() . '/app/etc/env.php';
89+
return true;
12690
}
12791
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MagentoCloud\Config\Deploy;
7+
8+
use Magento\MagentoCloud\Filesystem\DirectoryList;
9+
use Magento\MagentoCloud\Filesystem\Driver\File;
10+
use Magento\MagentoCloud\Filesystem\Reader\ReaderInterface;
11+
12+
class Reader implements ReaderInterface
13+
{
14+
/**
15+
* @var File
16+
*/
17+
private $file;
18+
19+
/**
20+
* @var DirectoryList
21+
*/
22+
private $directoryList;
23+
24+
/**
25+
* @param File $file
26+
* @param DirectoryList $directoryList
27+
*/
28+
public function __construct(File $file, DirectoryList $directoryList)
29+
{
30+
$this->file = $file;
31+
$this->directoryList = $directoryList;
32+
}
33+
34+
/**
35+
* @return array
36+
*/
37+
public function read(): array
38+
{
39+
$configPath = $this->getPath();
40+
if (!$this->file->isExists($configPath)) {
41+
return [];
42+
}
43+
44+
return include $configPath;
45+
}
46+
47+
/**
48+
* @return string
49+
*/
50+
public function getPath(): string
51+
{
52+
return $this->directoryList->getMagentoRoot() . '/app/etc/env.php';
53+
}
54+
}

0 commit comments

Comments
 (0)