Skip to content

Commit 049d2a4

Browse files
authored
Deprecate backend.inc in favor of a new site-process library (#3758)
Also bringing in #3759 which was merged into this PR.
1 parent 2354173 commit 049d2a4

File tree

169 files changed

+1123
-1222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+1123
-1222
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,3 @@ workflows:
5959
- build
6060
- build_highest
6161
- build_56
62-

.travis.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ sudo: false
2020
matrix:
2121
include:
2222
- php: 7.2
23-
env: 'SCENARIO=isolation DEPENDENCIES=highest'
23+
env: 'DEPENDENCIES=highest'
2424
- php: 7.2
25-
env: 'SCENARIO=isolation'
2625
- php: 7.0.11
27-
env: 'SCENARIO=isolation'
2826
- php: 5.6
29-
env: 'SCENARIO=isolation-phpunit4 DEPENDENCIES=lowest'
30-
- php: 5.6
31-
env: 'SCENARIO=isolation-phpunit4 DEPENDENCIES=lowest'
27+
env: 'DEPENDENCIES=lowest'
3228

3329
env:
3430
global:
@@ -62,5 +58,3 @@ after_success:
6258
- git config --global user.email $GITHUB_USER_EMAIL
6359
- git config --global user.name "Drush Documentation Bot"
6460
- cd $TRAVIS_BUILD_DIR && build/scripts/publish-api-docs.sh
65-
# Background: https://github.com/drush-ops/drush/pull/1426
66-
#- ${PWD}/tests/testChildren.sh

composer.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"consolidation/filter-via-dot-access-data": "^0.4",
4040
"consolidation/output-formatters": "^3.3.1",
4141
"consolidation/robo": "^1.1.5",
42-
"consolidation/site-alias": "^1.1.5",
42+
"consolidation/site-alias": "^1.1.6|^2",
43+
"consolidation/site-process": "^0.1.13",
4344
"grasmash/yaml-expander": "^1.1.1",
4445
"league/container": "~2",
4546
"psr/log": "~1.0",
@@ -70,13 +71,12 @@
7071
"autoload": {
7172
"psr-4": {
7273
"Drush\\": "src/",
73-
"Drush\\Internal\\": "internal-copy/",
74-
"Unish\\": "tests/"
74+
"Drush\\Internal\\": "src/internal-forks"
7575
}
7676
},
7777
"autoload-dev": {
7878
"psr-4": {
79-
"Drush\\": "isolation/src/"
79+
"Unish\\": "tests/unish"
8080
},
8181
"files": ["tests/load.environment.php"]
8282
},
@@ -107,12 +107,11 @@
107107
"sami-install": "mkdir -p $HOME/bin && curl --output $HOME/bin/sami.phar http://get.sensiolabs.org/sami.phar && chmod +x $HOME/bin/sami.phar",
108108
"scenario": "scenarios/install",
109109
"sut": "./drush --uri=dev",
110-
"sut:si": "./drush site:install testing --uri=dev --sites-subdir=dev --db-url=mysql://root:password@mariadb/unish_dev -v",
111-
"unit": "phpunit --colors=always",
112-
"functional": "phpunit --colors=always --configuration tests",
110+
"sut:si": "./drush site:install testing --uri=dev --sites-subdir=dev --db-url=${UNISH_DB_URL:-mysql://root:password@mariadb}/unish_dev -v",
111+
"unit": "phpunit --colors=always --configuration tests/unit",
112+
"functional": "phpunit --colors=always --configuration tests/functional",
113113
"post-update-cmd": [
114-
"create-scenario isolation --autoload-dir isolation --autoload-dir internal-copy --keep '\\(psr/log\\|consolidation/config\\|site-alias\\|var-dumper\\|symfony/finder\\|drupal-finder\\|path-util\\|vlucas/phpdotenv\\|xhprof\\)' 'phpunit/phpunit:^5.5.4'",
115-
"create-scenario isolation-phpunit4 --base isolation --autoload-dir isolation --autoload-dir internal-copy 'phpunit/phpunit:^4.8.36'"
114+
"create-scenario phpunit4 --autoload-dir internal-copy 'phpunit/phpunit:^4.8.36'"
116115
]
117116
},
118117
"extra": {

examples/Commands/SyncViaHttpCommands.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,28 @@ protected function downloadFile($url, $user = false, $password = false, $destina
6060
{
6161
static $use_wget;
6262
if ($use_wget === null) {
63-
$use_wget = drush_shell_exec('which wget');
63+
$use_wget = drush_which('wget');
6464
}
6565

6666
$destination_tmp = drush_tempnam('download_file');
6767
if ($use_wget) {
68+
$args = ['wget', '-q', '--timeout=30'];
6869
if ($user && $password) {
69-
drush_shell_exec("wget -q --timeout=30 --user=%s --password=%s -O %s %s", $user, $password, $destination_tmp, $url);
70+
$args = array_merge($args, ["--user=$user", "--password=$password", '-O', $destination_tmp, $url]);
7071
} else {
71-
drush_shell_exec("wget -q --timeout=30 -O %s %s", $destination_tmp, $url);
72+
$args = array_merge($args, ['-O', $destination_tmp, $url]);
7273
}
7374
} else {
75+
$args = ['curl', '-s', '-L', '--connect-timeout 30'];
7476
if ($user && $password) {
75-
drush_shell_exec("curl -s -L --connect-timeout 30 --user %s:%s -o %s %s", $user, $password, $destination_tmp, $url);
77+
$args = array_merge($args, ['--user', "$user:$password", '-o', $destination_tmp, $url]);
7678
} else {
77-
drush_shell_exec("curl -s -L --connect-timeout 30 -o %s %s", $destination_tmp, $url);
79+
$args = array_merge($args, ['-o', $destination_tmp, $url]);
7880
}
7981
}
82+
$process = Drush::process($args);
83+
$process->mustRun();
84+
8085
if (!Drush::simulate()) {
8186
if (!drush_file_not_empty($destination_tmp) && $file = @file_get_contents($url)) {
8287
@file_put_contents($destination_tmp, $file);

examples/helloworld.script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $this->output()->writeln(print_r($extra, true));
1818
// there is a bootstrapped site.
1919
//
2020
$self = Drush::aliasManager()->getSelf();;
21-
if (empty($self->root())) {
21+
if (!$self->hasRoot()) {
2222
$this->output()->writeln('No bootstrapped site.');
2323
}
2424
else {

includes/backend.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ function _drush_backend_adjust_options($site_record, $command, $command_options,
622622
* Execute a new local or remote command in a new process.
623623
*
624624
* @deprecated as of Drush 9.4.0 and will be removed in Drush 10. Instead, use
625-
* drush_invoke_process().
625+
* Drush::drush().
626626
*
627627
* @param invocations
628628
* An array of command records to execute. Each record should contain:

includes/batch.inc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* implementations.
2525
*/
2626

27+
use Drush\Drush;
2728
use Drush\Log\LogLevel;
2829

2930
/**
@@ -89,6 +90,9 @@ function drush_backend_batch_process($command = 'batch-process', $args = [], $op
8990
*
9091
* @param int $id
9192
* The batch ID of the batch being processed.
93+
*
94+
* @return bool|array
95+
* A results array.
9296
*/
9397
function drush_batch_command($id) {
9498
include_once(DRUSH_DRUPAL_CORE . '/includes/batch.inc');
@@ -104,6 +108,9 @@ function drush_batch_command($id) {
104108
* @param command
105109
* The command to call to process the batch.
106110
*
111+
* @return array
112+
* A return array. The callers only care about the finished marker and an #abort on an operation.
113+
*
107114
*/
108115
function _drush_backend_batch_process($command = 'batch-process', $args, $options) {
109116
$result = NULL;
@@ -141,8 +148,11 @@ function _drush_backend_batch_process($command = 'batch-process', $args, $option
141148
$finished = FALSE;
142149

143150
while (!$finished) {
144-
$result = drush_invoke_process('@self', $command, $args);
145-
$finished = drush_get_error() || !$result || (isset($result['context']['drush_batch_process_finished']) && $result['context']['drush_batch_process_finished'] == TRUE);
151+
$process = Drush::drush(Drush::aliasManager()->getSelf(), $command, $args);
152+
// Suppress printing stdout since we return a JSON array to the caller there.
153+
$process->run($process->showRealtime()->hideStdout());
154+
$result = $process->getOutputAsJson();
155+
$finished = drush_get_error() || !$process->isSuccessful() || (isset($result['drush_batch_process_finished']) && $result['drush_batch_process_finished'] === TRUE);
146156
}
147157
}
148158

@@ -158,6 +168,9 @@ function _drush_backend_batch_process($command = 'batch-process', $args, $option
158168
*
159169
* @param id
160170
* The batch id of the batch being processed.
171+
*
172+
* @return bool|array
173+
* A results array.
161174
*/
162175
function _drush_batch_command($id) {
163176
$batch =& batch_get();
@@ -234,7 +247,7 @@ function _drush_batch_worker() {
234247
\Drush\Drush::config()->set('runtime.php.halt-on-error', FALSE);
235248
$message = call_user_func_array($function, array_merge($args, [&$batch_context]));
236249
if (!empty($message)) {
237-
drush_print(strip_tags($message), 2);
250+
Drush::logger()->notice($message);
238251
}
239252
\Drush\Drush::config()->set('runtime.php.halt-on-error', $halt_on_error);
240253

@@ -302,6 +315,8 @@ function _drush_batch_worker() {
302315
* End the batch processing:
303316
* Call the 'finished' callbacks to allow custom handling of results,
304317
* and resolve page redirection.
318+
*
319+
* @return array
305320
*/
306321
function _drush_batch_finished() {
307322
$results = [];
@@ -319,7 +334,7 @@ function _drush_batch_finished() {
319334
$queue = _batch_queue($batch_set);
320335
$operations = $queue->getAllItems();
321336
$elapsed = $batch_set['elapsed'] / 1000;
322-
$elapsed = drush_drupal_major_version() >=8 ? \Drupal::service('date.formatter')->formatInterval($elapsed) : format_interval($elapsed);
337+
$elapsed = \Drupal::service('date.formatter')->formatInterval($elapsed);
323338
call_user_func_array($batch_set['finished'], [$batch_set['success'], $batch_set['results'], $operations, $elapsed]);
324339
$results[$id] = $batch_set['results'];
325340
}
@@ -346,6 +361,7 @@ function _drush_batch_finished() {
346361
$_batch = $batch;
347362
$batch = NULL;
348363
drush_set_option('drush_batch_process_finished', TRUE);
364+
$results['drush_batch_process_finished'] = TRUE;
349365

350366
return $results;
351367
}

includes/command.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ use Symfony\Component\Console\Output\ConsoleOutput;
6464
* @see drush_backend_get_result()
6565
*
6666
* Do not change the signature of this function! drush_invoke_process
67-
* is one of the key Drush APIs. See http://drupal.org/node/1152908
67+
* was one of the key Drush APIs. See http://drupal.org/node/1152908
68+
*
69+
* @deprecated See Drush::drush().
6870
*/
6971
function drush_invoke_process($site_alias_record, $command_name, $commandline_args = [], $commandline_options = [], $backend_options = TRUE) {
7072
if ($site_alias_record instanceof AliasRecord) {

includes/context.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,4 +528,4 @@ function drush_unset_option($option, $context = NULL) {
528528
drush_unset_option($option, $context);
529529
}
530530
}
531-
}
531+
}

includes/drupal.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ function drush_drupal_version($drupal_root = NULL) {
3030
return $version;
3131
}
3232

33+
/**
34+
* @deprecated @see Drush::drush()
35+
*/
3336
function drush_drupal_cache_clear_all() {
34-
drush_invoke_process('@self', 'cache-rebuild');
37+
$process = Drush::drush(Drush::aliasManager()->getSelf(), 'cache-rebuild');
38+
$process->mustrun();
3539
}
3640

3741
/**

0 commit comments

Comments
 (0)