Skip to content

Commit e1d097f

Browse files
committed
Excute all commands within the previous directory and fix destination to be the created config/backup directory
1 parent dbb97f8 commit e1d097f

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

recipes/drupal8.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@
2323

2424
desc('Execute drush config:export to backup previous config');
2525
task('drush:config:backup', function() {
26-
// Skip when there aren't database connection variables.
27-
if (! test('[ -s {{release_or_current_path}}/.env ]')) {
28-
writeln("<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your .env file is empty! Skipping...</>");
29-
return;
30-
}
31-
32-
// Skip when there are no tables in the database.
33-
if (test('[[ -z "$({{release_or_current_path}}/vendor/bin/drush sql:query \'SHOW TABLES\')" ]]')) {
34-
writeln("<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your database is empty! Skipping...</>");
35-
return;
36-
}
37-
3826
$destination = has('previous_release') ? '{{previous_release}}' : '{{release_path}}';
39-
run("mkdir -p $destination/config/backup");
40-
41-
cd('{{release_or_current_path}}');
42-
run("{{release_or_current_path}}/vendor/bin/drush -y config:export --destination=$destination");
43-
writeln('Backup saved to ' . $destination);
27+
// Execute all within the previous release or current release directory.
28+
within($destination, function () use ($destination) {
29+
// Skip when there aren't database connection variables.
30+
if (! test('[ -s ./.env ]')) {
31+
writeln("<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your .env file is empty! Skipping...</>");
32+
return;
33+
}
34+
35+
// Skip when there are no tables in the database.
36+
if (test('[[ -z "$(./vendor/bin/drush sql:query \'SHOW TABLES\')" ]]')) {
37+
writeln("<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your database is empty! Skipping...</>");
38+
return;
39+
}
40+
run("mkdir -p ./config/backup");
41+
run("./vendor/bin/drush -y config:export --destination=$destination/config/backup");
42+
writeln("Backup saved to $destination/config/backup");
43+
});
4444
});
4545
before('deploy:drush', 'drush:config:backup');

0 commit comments

Comments
 (0)