Skip to content

Commit 3a740d3

Browse files
authored
[#1667] Fixed installer not removing the demo header. (#1692)
1 parent f24fb5b commit 3a740d3

16 files changed

Lines changed: 279 additions & 191 deletions

File tree

.vortex/installer/composer.lock

Lines changed: 135 additions & 121 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.vortex/installer/src/Command/InstallCommand.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ protected function resolveOptions(array $arguments, array $options): void {
233233

234234
// Internal flag to enforce DEMO mode. If not set, the demo mode will be
235235
// discovered automatically.
236-
if (!is_null(Env::get(Config::IS_DEMO_MODE))) {
237-
$this->config->set(Config::IS_DEMO_MODE, (bool) Env::get(Config::IS_DEMO_MODE));
236+
if (!is_null(Env::get(Config::IS_DEMO))) {
237+
$this->config->set(Config::IS_DEMO, (bool) Env::get(Config::IS_DEMO));
238238
}
239239

240240
// Internal flag to skip processing of the demo mode.
241-
$this->config->set(Config::DEMO_MODE_SKIP, (bool) Env::get(Config::DEMO_MODE_SKIP, FALSE));
241+
$this->config->set(Config::IS_DEMO_DB_DOWNLOAD_SKIP, (bool) Env::get(Config::IS_DEMO_DB_DOWNLOAD_SKIP, FALSE));
242242
}
243243

244244
protected function prepareDestination(): array {
@@ -308,35 +308,40 @@ protected function copyFiles(): void {
308308
}
309309

310310
protected function handleDemo(): array|string {
311-
if (empty($this->config->get(Config::IS_DEMO_MODE)) || !empty($this->config->get(Config::DEMO_MODE_SKIP))) {
312-
return ['Skipping demo database download.'];
311+
if (empty($this->config->get(Config::IS_DEMO))) {
312+
return 'Not a demo mode.';
313+
}
314+
315+
if (!empty($this->config->get(Config::IS_DEMO_DB_DOWNLOAD_SKIP))) {
316+
return sprintf('%s is set. Skipping demo database download.', Config::IS_DEMO_DB_DOWNLOAD_SKIP);
313317
}
314318

315319
// Reload variables from destination's .env.
316320
Env::putFromDotenv($this->config->getDst() . '/.env');
317321

318322
$url = Env::get('VORTEX_DB_DOWNLOAD_URL');
319323
if (empty($url)) {
320-
return ['No database download URL provided. Skipping demo database download.'];
324+
return 'No database download URL provided. Skipping demo database download.';
321325
}
322326

323327
$data_dir = $this->config->getDst() . DIRECTORY_SEPARATOR . Env::get('VORTEX_DB_DIR', './.data');
324-
$file = Env::get('VORTEX_DB_FILE', 'db.sql');
328+
$db_file = Env::get('VORTEX_DB_FILE', 'db.sql');
325329

326-
if (file_exists($data_dir . DIRECTORY_SEPARATOR . $file)) {
327-
return ['Database dump file already exists. Skipping download.'];
330+
if (file_exists($data_dir . DIRECTORY_SEPARATOR . $db_file)) {
331+
return 'Database dump file already exists. Skipping demo database download.';
328332
}
329333

330334
$messages = [];
331335
if (!file_exists($data_dir)) {
332336
$data_dir = File::mkdir($data_dir);
333337
$messages[] = sprintf('Created data directory "%s".', $data_dir);
334338
}
335-
$command = sprintf('curl -s -L "%s" -o "%s/%s"', $url, $data_dir, $file);
336339

340+
$command = sprintf('curl -s -L "%s" -o "%s/%s"', $url, $data_dir, $db_file);
337341
if (passthru($command) === FALSE) {
338-
throw new \RuntimeException(sprintf('Unable to download demo database from "%s".', $url));
342+
throw new \RuntimeException(sprintf('Unable to download demo database from %s.', $url));
339343
}
344+
340345
$messages[] = sprintf('No database dump file was found in "%s" directory.', $data_dir);
341346
$messages[] = sprintf('Downloaded demo database from %s.', $url);
342347

.vortex/installer/src/Prompts/Handlers/Internal.php

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,38 +81,48 @@ public function process(): void {
8181
}
8282

8383
protected function processDemoMode(array $responses, string $dir): void {
84-
if (is_null($is_demo_mode = $this->config->get(Config::IS_DEMO_MODE))) {
84+
$is_demo = $this->config->get(Config::IS_DEMO);
85+
86+
// If demo mode is not set, check if it should be enabled based on
87+
// provision type and database download source.
88+
if (is_null($is_demo)) {
8589
if ($responses[ProvisionType::id()] === ProvisionType::DATABASE) {
86-
$download_source = $responses[DatabaseDownloadSource::id()];
87-
$db_file = Env::get('VORTEX_DB_DIR', './.data') . DIRECTORY_SEPARATOR . Env::get('VORTEX_DB_FILE', 'db.sql');
90+
$db_file_exists = file_exists(Env::get('VORTEX_DB_DIR', './.data') . DIRECTORY_SEPARATOR . Env::get('VORTEX_DB_FILE', 'db.sql'));
8891
$has_comment = File::contains($this->dstDir . '/.env', 'Override project-specific values for demonstration purposes');
8992

90-
// Enable Vortex demo mode if download source is file AND
91-
// there is no downloaded file present OR if there is a demo comment in
92-
// destination .env file.
93-
if ($download_source !== DatabaseDownloadSource::CONTAINER_REGISTRY) {
94-
if ($has_comment || !file_exists($db_file)) {
95-
$this->config->set(Config::IS_DEMO_MODE, TRUE);
96-
}
97-
else {
98-
$this->config->set(Config::IS_DEMO_MODE, FALSE);
99-
}
93+
// Demo mode can only be used if the user selected a URL or a container
94+
// registry download source. This is because the demo mode would not
95+
// have access to integrations with providers to pull the database
96+
// from.
97+
if ($responses[DatabaseDownloadSource::id()] === DatabaseDownloadSource::URL) {
98+
// For a downloading from URL, demo mode is enabled if the database
99+
// file does not exist or if there is an explicit comment in the
100+
// destination .env file that indicates that this is a demo mode.
101+
$is_demo = !$db_file_exists || $has_comment;
100102
}
101-
elseif ($has_comment) {
102-
$this->config->set(Config::IS_DEMO_MODE, TRUE);
103+
elseif ($responses[DatabaseDownloadSource::id()] === DatabaseDownloadSource::CONTAINER_REGISTRY) {
104+
// For a downloading from container registry, demo mode is enabled if
105+
// there is an explicit comment in the destination .env file that
106+
// indicates that this is a demo mode.
107+
$is_demo = $has_comment;
103108
}
104109
else {
105-
$this->config->set(Config::IS_DEMO_MODE, FALSE);
110+
// For any other download source, demo mode is not applicable.
111+
$is_demo = FALSE;
106112
}
107113
}
108114
else {
109-
$this->config->set(Config::IS_DEMO_MODE, FALSE);
115+
// Not a database-driven provision type (a profile-driven), so demo is
116+
// not applicable.
117+
$is_demo = FALSE;
110118
}
111119
}
112120

113-
if (!$this->config->get(Config::IS_DEMO_MODE)) {
121+
if (!$is_demo) {
114122
File::removeTokenAsync('DEMO');
115123
}
124+
125+
$this->config->set(Config::IS_DEMO, $is_demo);
116126
}
117127

118128
}

.vortex/installer/src/Utils/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ final class Config {
2525

2626
const PROCEED = 'VORTEX_INSTALL_PROCEED';
2727

28-
const IS_DEMO_MODE = 'VORTEX_INSTALL_IS_DEMO_MODE';
28+
const IS_DEMO = 'VORTEX_INSTALL_IS_DEMO';
2929

30-
const DEMO_MODE_SKIP = 'VORTEX_INSTALL_DEMO_SKIP';
30+
const IS_DEMO_DB_DOWNLOAD_SKIP = 'VORTEX_INSTALL_IS_DEMO_DB_DOWNLOAD_SKIP';
3131

3232
const IS_VORTEX_PROJECT = 'VORTEX_INSTALL_IS_VORTEX_PROJECT';
3333

.vortex/installer/tests/Fixtures/install/db_download_source_acquia/.env

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@
1313
# Environment to download the database from.
1414
#
1515
# Applies to hosting environments.
16-
@@ -177,7 +172,4 @@
17-
# Remove this section after completing database download integration. #
18-
# #
19-
################################################################################
16+
@@ -166,18 +161,4 @@
17+
# with optional names in the format "email|name".
18+
# Example: "to1@example.com|Jane Doe, to2@example.com|John Doe"
19+
VORTEX_NOTIFY_EMAIL_RECIPIENTS="webmaster@star-wars-domain.example"
20+
-
21+
-################################################################################
22+
-# DEMO #
23+
-################################################################################
24+
-# #
25+
-# Override project-specific values for demonstration purposes. #
26+
-# Used to showcase Vortex without asking users to perform additional steps. #
27+
-# #
28+
-# Remove this section after completing database download integration. #
29+
-# #
30+
-################################################################################
2031
-
2132
-# URL of the database used for demonstration with URL database download type.
2233
-VORTEX_DB_DOWNLOAD_URL=https://github.com/drevops/vortex/releases/download/25.4.0/db_d11.demo.sql

.vortex/installer/tests/Fixtures/install/db_download_source_ftp/.env

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@
2323
# Environment to download the database from.
2424
#
2525
# Applies to hosting environments.
26-
@@ -177,7 +183,4 @@
27-
# Remove this section after completing database download integration. #
28-
# #
29-
################################################################################
26+
@@ -166,18 +172,4 @@
27+
# with optional names in the format "email|name".
28+
# Example: "to1@example.com|Jane Doe, to2@example.com|John Doe"
29+
VORTEX_NOTIFY_EMAIL_RECIPIENTS="webmaster@star-wars-domain.example"
30+
-
31+
-################################################################################
32+
-# DEMO #
33+
-################################################################################
34+
-# #
35+
-# Override project-specific values for demonstration purposes. #
36+
-# Used to showcase Vortex without asking users to perform additional steps. #
37+
-# #
38+
-# Remove this section after completing database download integration. #
39+
-# #
40+
-################################################################################
3041
-
3142
-# URL of the database used for demonstration with URL database download type.
3243
-VORTEX_DB_DOWNLOAD_URL=https://github.com/drevops/vortex/releases/download/25.4.0/db_d11.demo.sql

.vortex/installer/tests/Fixtures/install/db_download_source_lagoon/.env

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@
1313
# Environment to download the database from.
1414
#
1515
# Applies to hosting environments.
16-
@@ -177,7 +172,4 @@
17-
# Remove this section after completing database download integration. #
18-
# #
19-
################################################################################
16+
@@ -166,18 +161,4 @@
17+
# with optional names in the format "email|name".
18+
# Example: "to1@example.com|Jane Doe, to2@example.com|John Doe"
19+
VORTEX_NOTIFY_EMAIL_RECIPIENTS="webmaster@star-wars-domain.example"
20+
-
21+
-################################################################################
22+
-# DEMO #
23+
-################################################################################
24+
-# #
25+
-# Override project-specific values for demonstration purposes. #
26+
-# Used to showcase Vortex without asking users to perform additional steps. #
27+
-# #
28+
-# Remove this section after completing database download integration. #
29+
-# #
30+
-################################################################################
2031
-
2132
-# URL of the database used for demonstration with URL database download type.
2233
-VORTEX_DB_DOWNLOAD_URL=https://github.com/drevops/vortex/releases/download/25.4.0/db_d11.demo.sql

.vortex/installer/tests/Fixtures/install/hosting_acquia/.env

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,21 @@
5555

5656
################################################################################
5757
# NOTIFICATIONS #
58-
@@ -177,7 +182,4 @@
59-
# Remove this section after completing database download integration. #
60-
# #
61-
################################################################################
58+
@@ -166,18 +171,4 @@
59+
# with optional names in the format "email|name".
60+
# Example: "to1@example.com|Jane Doe, to2@example.com|John Doe"
61+
VORTEX_NOTIFY_EMAIL_RECIPIENTS="webmaster@star-wars-domain.example"
62+
-
63+
-################################################################################
64+
-# DEMO #
65+
-################################################################################
66+
-# #
67+
-# Override project-specific values for demonstration purposes. #
68+
-# Used to showcase Vortex without asking users to perform additional steps. #
69+
-# #
70+
-# Remove this section after completing database download integration. #
71+
-# #
72+
-################################################################################
6273
-
6374
-# URL of the database used for demonstration with URL database download type.
6475
-VORTEX_DB_DOWNLOAD_URL=https://github.com/drevops/vortex/releases/download/25.4.0/db_d11.demo.sql

.vortex/installer/tests/Fixtures/install/hosting_lagoon/.env

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,21 @@
3939

4040
################################################################################
4141
# NOTIFICATIONS #
42-
@@ -177,7 +182,4 @@
43-
# Remove this section after completing database download integration. #
44-
# #
45-
################################################################################
42+
@@ -166,18 +171,4 @@
43+
# with optional names in the format "email|name".
44+
# Example: "to1@example.com|Jane Doe, to2@example.com|John Doe"
45+
VORTEX_NOTIFY_EMAIL_RECIPIENTS="webmaster@star-wars-domain.example"
46+
-
47+
-################################################################################
48+
-# DEMO #
49+
-################################################################################
50+
-# #
51+
-# Override project-specific values for demonstration purposes. #
52+
-# Used to showcase Vortex without asking users to perform additional steps. #
53+
-# #
54+
-# Remove this section after completing database download integration. #
55+
-# #
56+
-################################################################################
4657
-
4758
-# URL of the database used for demonstration with URL database download type.
4859
-VORTEX_DB_DOWNLOAD_URL=https://github.com/drevops/vortex/releases/download/25.4.0/db_d11.demo.sql

.vortex/installer/tests/Functional/FunctionalTestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ protected function runNonInteractiveInstall(?string $dst = NULL, array $options
107107
$args['--' . $option] = $value;
108108
}
109109

110-
Env::put(Config::DEMO_MODE_SKIP, '1');
110+
// Skip the database download in demo mode as it is not needed for the
111+
// installer's tests.
112+
Env::put(Config::IS_DEMO_DB_DOWNLOAD_SKIP, '1');
111113

112114
$this->applicationRun($args, [], $expect_fail);
113115
}

0 commit comments

Comments
 (0)