Skip to content

Commit

Permalink
Excute all commands within the previous directory and fix destination…
Browse files Browse the repository at this point in the history
… to be the created config/backup directory
  • Loading branch information
joelpittet committed Nov 28, 2024
1 parent dbb97f8 commit e1d097f
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions recipes/drupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@

desc('Execute drush config:export to backup previous config');
task('drush:config:backup', function() {
// Skip when there aren't database connection variables.
if (! test('[ -s {{release_or_current_path}}/.env ]')) {
writeln("<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your .env file is empty! Skipping...</>");
return;
}

// Skip when there are no tables in the database.
if (test('[[ -z "$({{release_or_current_path}}/vendor/bin/drush sql:query \'SHOW TABLES\')" ]]')) {
writeln("<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your database is empty! Skipping...</>");
return;
}

$destination = has('previous_release') ? '{{previous_release}}' : '{{release_path}}';
run("mkdir -p $destination/config/backup");

cd('{{release_or_current_path}}');
run("{{release_or_current_path}}/vendor/bin/drush -y config:export --destination=$destination");
writeln('Backup saved to ' . $destination);
// Execute all within the previous release or current release directory.
within($destination, function () use ($destination) {
// Skip when there aren't database connection variables.
if (! test('[ -s ./.env ]')) {
writeln("<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your .env file is empty! Skipping...</>");
return;
}

// Skip when there are no tables in the database.
if (test('[[ -z "$(./vendor/bin/drush sql:query \'SHOW TABLES\')" ]]')) {
writeln("<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your database is empty! Skipping...</>");
return;
}
run("mkdir -p ./config/backup");
run("./vendor/bin/drush -y config:export --destination=$destination/config/backup");
writeln("Backup saved to $destination/config/backup");
});
});
before('deploy:drush', 'drush:config:backup');

0 comments on commit e1d097f

Please sign in to comment.