|
23 | 23 |
|
24 | 24 | desc('Execute drush config:export to backup previous config');
|
25 | 25 | 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 |
| - |
38 | 26 | $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 | + }); |
44 | 44 | });
|
45 | 45 | before('deploy:drush', 'drush:config:backup');
|
0 commit comments