Skip to content

Commit a450b0e

Browse files
Merge pull request #44 from magento-thunder/MAGECLOUD-1057
MAGECLOUD-1057: Add possibility to change SCD strategy
2 parents c80b772 + 88dba11 commit a450b0e

File tree

32 files changed

+2122
-1134
lines changed

32 files changed

+2122
-1134
lines changed

src/Magento/MagentoCloud/App/Container.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/**
2121
* @inheritdoc
22+
* @codeCoverageIgnore
2223
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2324
*/
2425
class Container extends \Illuminate\Container\Container implements ContainerInterface
@@ -79,7 +80,7 @@ public function __construct(string $root, array $config)
7980
$this->make(BuildProcess\ComposerDumpAutoload::class),
8081
$this->make(BuildProcess\DeployStaticContent::class),
8182
$this->make(BuildProcess\ClearInitDirectory::class),
82-
$this->make(BuildProcess\BackupToInitDirectory::class),
83+
$this->make(BuildProcess\BackupData::class),
8384
],
8485
]);
8586
});
@@ -160,13 +161,22 @@ public function __construct(string $root, array $config)
160161
->give(function () {
161162
return $this->makeWith(ProcessPool::class, [
162163
'processes' => [
163-
$this->get(DeployProcess\DeployStaticContent\GenerateFresh::class),
164+
$this->get(DeployProcess\DeployStaticContent\Generate::class),
164165
],
165166
]);
166167
});
167168
$this->when(\Magento\MagentoCloud\Config\Build::class)
168169
->needs(\Magento\MagentoCloud\Filesystem\Reader\ReaderInterface::class)
169170
->give(\Magento\MagentoCloud\Config\Build\Reader::class);
171+
$this->when(BuildProcess\DeployStaticContent::class)
172+
->needs(ProcessInterface::class)
173+
->give(function () {
174+
return $this->makeWith(ProcessPool::class, [
175+
'processes' => [
176+
$this->get(BuildProcess\DeployStaticContent\Generate::class),
177+
],
178+
]);
179+
});
170180
}
171181

172182
/**

src/Magento/MagentoCloud/Command/ConfigDump.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
class ConfigDump extends Command
1919
{
20+
const NAME = 'dump';
21+
2022
/**
2123
* @var LoggerInterface
2224
*/
@@ -44,7 +46,7 @@ public function __construct(ProcessInterface $process, LoggerInterface $logger)
4446
*/
4547
protected function configure()
4648
{
47-
$this->setName('dump')
49+
$this->setName(static::NAME)
4850
->setDescription('Dump static content');
4951

5052
parent::configure();

src/Magento/MagentoCloud/Config/Build.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
*/
1313
class Build
1414
{
15-
const BUILD_OPT_SCD_EXCLUDE_THEMES = 'exclude_themes';
16-
const BUILD_OPT_SCD_THREADS = 'scd_threads';
17-
const BUILD_OPT_SKIP_SCD = 'skip_scd';
15+
const OPT_SCD_EXCLUDE_THEMES = 'exclude_themes';
16+
const OPT_SCD_THREADS = 'scd_threads';
17+
const OPT_SKIP_SCD = 'skip_scd';
18+
const OPT_SCD_STRATEGY = 'SCD_STRATEGY';
19+
const OPT_VERBOSE_COMMANDS = 'VERBOSE_COMMANDS';
1820

1921
/**
2022
* @var ReaderInterface
@@ -36,8 +38,8 @@ public function __construct(ReaderInterface $reader)
3638

3739
/**
3840
* @param string $key
39-
* @param mixed $default
40-
* @return mixed
41+
* @param string|null $default
42+
* @return string|null
4143
*/
4244
public function get(string $key, $default = null)
4345
{
@@ -53,6 +55,6 @@ public function get(string $key, $default = null)
5355
*/
5456
public function getVerbosityLevel(): string
5557
{
56-
return $this->get('VERBOSE_COMMANDS') === 'enabled' ? ' -vv ' : '';
58+
return $this->get(static::OPT_VERBOSE_COMMANDS) === 'enabled' ? ' -vv ' : '';
5759
}
5860
}

src/Magento/MagentoCloud/Config/Environment.php

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class Environment
2727
const VAL_ENABLED = 'enabled';
2828
const VAL_DISABLED = 'disabled';
2929

30+
/**
31+
* Let's keep variable names same for both phases.
32+
*/
33+
const VAR_SCD_STRATEGY = Build::OPT_SCD_STRATEGY;
34+
3035
/**
3136
* @var LoggerInterface
3237
*/
@@ -42,6 +47,11 @@ class Environment
4247
*/
4348
private $directoryList;
4449

50+
/**
51+
* @var array
52+
*/
53+
private $data = [];
54+
4555
/**
4656
* @param LoggerInterface $logger
4757
* @param File $file
@@ -56,8 +66,8 @@ public function __construct(LoggerInterface $logger, File $file, DirectoryList $
5666

5767
/**
5868
* @param string $key
59-
* @param mixed $default
60-
* @return array
69+
* @param string|int|null $default
70+
* @return array|string|int|null
6171
*/
6272
public function get(string $key, $default = null)
6373
{
@@ -69,19 +79,27 @@ public function get(string $key, $default = null)
6979
*
7080
* @return mixed
7181
*/
72-
public function getRoutes()
82+
public function getRoutes(): array
7383
{
74-
return $this->get('MAGENTO_CLOUD_ROUTES', []);
84+
if (isset($this->data['routes'])) {
85+
return $this->data['routes'];
86+
}
87+
88+
return $this->data['routes'] = $this->get('MAGENTO_CLOUD_ROUTES', []);
7589
}
7690

7791
/**
7892
* Get relationships information from MagentoCloud environment variable.
7993
*
80-
* @return mixed
94+
* @return array
8195
*/
82-
public function getRelationships()
96+
public function getRelationships(): array
8397
{
84-
return $this->get('MAGENTO_CLOUD_RELATIONSHIPS');
98+
if (isset($this->data['relationships'])) {
99+
return $this->data['relationships'];
100+
}
101+
102+
return $this->data['relationships'] = $this->get('MAGENTO_CLOUD_RELATIONSHIPS', []);
85103
}
86104

87105
/**
@@ -100,11 +118,27 @@ public function getRelationship(string $key)
100118
/**
101119
* Get custom variables from MagentoCloud environment variable.
102120
*
121+
* @return array
122+
*/
123+
public function getVariables(): array
124+
{
125+
if (isset($this->data['variables'])) {
126+
return $this->data['variables'];
127+
}
128+
129+
return $this->data['variables'] = $this->get('MAGENTO_CLOUD_VARIABLES', []);
130+
}
131+
132+
/**
133+
* Returns variable value if such variable exists otherwise return $default
134+
*
135+
* @param string $name
136+
* @param mixed $default
103137
* @return mixed
104138
*/
105-
public function getVariables()
139+
public function getVariable($name, $default = null)
106140
{
107-
return $this->get('MAGENTO_CLOUD_VARIABLES');
141+
return $this->getVariables()[$name] ?? $default;
108142
}
109143

110144
/**
@@ -272,7 +306,7 @@ public function doCleanStaticFiles(): bool
272306
*/
273307
public function getStaticDeployExcludeThemes(): string
274308
{
275-
return $this->getVariables()['STATIC_CONTENT_EXCLUDE_THEMES'] ?? '';
309+
return $this->getVariable('STATIC_CONTENT_EXCLUDE_THEMES', '');
276310
}
277311

278312
/**

0 commit comments

Comments
 (0)