Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit daaf541

Browse files
authored
Remove some cruft from RoleComands, and use wodby/php at CircleCI (#3808)
1 parent 58afda5 commit daaf541

File tree

7 files changed

+54
-70
lines changed

7 files changed

+54
-70
lines changed

.circleci/config.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,29 @@ jobs:
1313
build:
1414
<<: *defaults
1515
docker:
16-
- image: circleci/php:7.1-apache-node
16+
- image: wodby/php:7.1
1717
environment:
1818
- MYSQL_HOST=127.0.0.1
19+
- PHP_SENDMAIL_PATH=/dev/null
1920
- image: circleci/mysql:5.7.24
2021
steps:
2122
- checkout
22-
- run: $HOME/drush/.circleci/setup.sh
23+
- run: cp .docker/zz-php.ini /usr/local/etc/php/conf.d/
2324
- run: composer install
2425
- run: $HOME/drush/.circleci/patch.sh
2526
- run: composer functional
2627

2728
build_highest:
2829
<<: *defaults
2930
docker:
30-
- image: circleci/php:7.2-apache-node
31+
- image: wodby/php:7.2
3132
environment:
3233
- MYSQL_HOST=127.0.0.1
34+
- PHP_SENDMAIL_PATH=/dev/null
3335
- image: circleci/mysql:5.7.24
3436
steps:
3537
- checkout
36-
- run: $HOME/drush/.circleci/setup.sh
38+
- run: cp .docker/zz-php.ini /usr/local/etc/php/conf.d/
3739
- run: composer remove --dev webflo/drupal-core-strict --no-update
3840
- run: composer require --dev drupal/core:8.7.x-dev --no-update
3941
- run: composer config platform.php 7.2
@@ -43,15 +45,14 @@ jobs:
4345
build_56:
4446
<<: *defaults
4547
docker:
46-
# circleci/php:5.6.38-apache-node appears broken.
47-
# Put this back to circleci/php:5.6-apache-node when .37 no longer available
48-
- image: circleci/php:5.6.37-apache-node
48+
- image: wodby/php:5.6
4949
environment:
5050
- MYSQL_HOST=127.0.0.1
51+
- PHP_SENDMAIL_PATH=/dev/null
5152
- image: circleci/mysql:5.7.24
5253
steps:
5354
- checkout
54-
- run: $HOME/drush/.circleci/setup.sh
55+
- run: cp .docker/zz-php.ini /usr/local/etc/php/conf.d/
5556
- run: .scenarios.lock/install php5
5657
- run: $HOME/drush/.circleci/patch.sh
5758
- run: composer functional

.circleci/setup.sh

Lines changed: 0 additions & 38 deletions
This file was deleted.

.docker/zz-php.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[PHP]
22
variables_order = GPCS
3-
error_reporting = E_ALL & ~E_DEPRECATED
3+
error_reporting = E_ALL & ~E_DEPRECATED
4+
date.timezone = "UTC"

src/Commands/core/InitCommands.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class InitCommands extends DrushCommands implements BuilderAwareInterface, IOAwa
3535
*/
3636
public function initializeDrush($options = ['edit' => false, 'add-path' => ''])
3737
{
38-
$home = Drush::config()->home();
38+
$home = $this->getConfig()->home();
3939
$drush_config_dir = $home . "/.drush";
4040
$drush_config_file = $drush_config_dir . "/drush.yml";
4141
$drush_bashrc = $drush_config_dir . "/drush.bashrc";
@@ -45,6 +45,9 @@ public function initializeDrush($options = ['edit' => false, 'add-path' => ''])
4545
$example_bashrc = $examples_dir . "/example.bashrc";
4646
$example_prompt = $examples_dir . "/example.prompt.sh";
4747

48+
/**
49+
* That's right. Robo collections and tasks are usable in Drush.
50+
*/
4851
$collection = $this->collectionBuilder();
4952

5053
// Create a ~/.drush directory if it does not yet exist
@@ -53,6 +56,10 @@ public function initializeDrush($options = ['edit' => false, 'add-path' => ''])
5356
// If there is no ~/.drush/drush.yml, copy example there.
5457
if (!is_file($drush_config_file)) {
5558
$collection->taskWriteToFile($drush_config_file)->textFromFile($example_configuration);
59+
$collection->progressMessage('Copied example.drush.yml to {path}', ['path' => $drush_config_file], LogLevel::OK);
60+
$this->logger()->notice('Copied drush.yml to ' . $drush_config_file);
61+
} else {
62+
$this->logger()->debug($drush_config_file . ' already exists. Skip copy.');
5663
}
5764

5865
// Decide whether we want to add our Bash commands to

src/Drupal/Commands/core/RoleCommands.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
namespace Drush\Drupal\Commands\core;
33

44
use Consolidation\OutputFormatters\Options\FormatterOptions;
5+
use Consolidation\SiteAlias\SiteAliasManagerAwareTrait;
56
use Drupal\user\Entity\Role;
67
use Drush\Commands\DrushCommands;
78
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
9+
use Drush\Drush;
10+
use Drush\SiteAlias\SiteAliasManagerAwareInterface;
11+
use Drush\Utils\StringUtils;
812

9-
class RoleCommands extends DrushCommands
13+
class RoleCommands extends DrushCommands implements SiteAliasManagerAwareInterface
1014
{
15+
use SiteAliasManagerAwareTrait;
16+
1117
/**
1218
* Create a new role.
1319
*
@@ -58,7 +64,6 @@ public function delete($machine_name)
5864
* @validate-permissions permissions
5965
* @param $machine_name The role to modify.
6066
* @param $permissions The list of permission to grant, delimited by commas.
61-
* @option cache-clear Set to 0 to suppress normal cache clearing; the caller should then clear if needed.
6267
* @usage drush role-add-perm anonymous 'post comments'
6368
* Allow anon users to post comments.
6469
* @usage drush role:add-perm anonymous "'post comments','access content'"
@@ -69,10 +74,10 @@ public function delete($machine_name)
6974
*/
7075
public function roleAddPerm($machine_name, $permissions)
7176
{
72-
$perms = _convert_csv_to_array($permissions);
77+
$perms = StringUtils::csvToArray($permissions);
7378
user_role_grant_permissions($machine_name, $perms);
7479
$this->logger()->success(dt('Added "!permissions" to "!role"', ['!permissions' => $permissions, '!role' => $machine_name]));
75-
drush_drupal_cache_clear_all();
80+
Drush::drush($this->siteAliasManager()->getSelf(), 'cache-rebuild');
7681
}
7782

7883
/**
@@ -83,17 +88,16 @@ public function roleAddPerm($machine_name, $permissions)
8388
* @validate-permissions permissions
8489
* @param $machine_name The role to modify.
8590
* @param $permissions The list of permission to grant, delimited by commas.
86-
* @option cache-clear Set to 0 to suppress normal cache clearing; the caller should then clear if needed.
8791
* @usage drush role:remove-perm anonymous 'access content'
8892
* Hide content from anon users.
8993
* @aliases rmp,role-remove-perm
9094
*/
9195
public function roleRemovePerm($machine_name, $permissions)
9296
{
93-
$perms = _convert_csv_to_array($permissions);
97+
$perms = StringUtils::csvToArray($permissions);
9498
user_role_revoke_permissions($machine_name, $perms);
9599
$this->logger()->success(dt('Removed "!permissions" to "!role"', ['!permissions' => $permissions, '!role' => $machine_name]));
96-
drush_drupal_cache_clear_all();
100+
Drush::drush($this->siteAliasManager()->getSelf(), 'cache-rebuild');
97101
}
98102

99103
/**

tests/functional/InitCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public function testInitCommand()
2424

2525
// Next we test to see if there is evidence that those operations worked.
2626
$home = Path::join($this->getSandbox(), 'home');
27-
$this->assertFileExists("$home/.drush/drush.yml");
28-
$this->assertFileExists("$home/.drush/drush.bashrc");
29-
$this->assertFileExists("$home/.bashrc");
27+
$this->assertFileExists("$home/.drush/drush.yml", $this->buildProcessMessage());
28+
$this->assertFileExists("$home/.drush/drush.bashrc", $this->buildProcessMessage());
29+
$this->assertFileExists("$home/.bashrc", $this->buildProcessMessage());
3030

3131
// Check to see if the .bashrc file sources our drush.bashrc file,
3232
// and whether it adds the path to self::getDrush() to the $PATH

tests/unish/CommandUnishTestCase.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function execute($command, $expected_return = self::EXIT_SUCCESS, $cd = n
128128
$return = $this->process->run();
129129
if ($expected_return !== $return) {
130130
$message = 'Unexpected exit code ' . $return . ' (expected ' . $expected_return . ") for command:\n" . $command;
131-
throw new UnishProcessFailedException($message . $this->buildProcessMessage($this->process));
131+
throw new UnishProcessFailedException($message . $this->buildProcessMessage());
132132
}
133133
// Reset timeouts to default.
134134
$this->timeout = $this->defaultTimeout;
@@ -140,24 +140,34 @@ public function execute($command, $expected_return = self::EXIT_SUCCESS, $cd = n
140140
} else {
141141
$message = 'Command had no output for ' . $this->idleTimeout . " seconds:\n" . $command;
142142
}
143-
throw new UnishProcessFailedException($message . $this->buildProcessMessage($this->process));
143+
throw new UnishProcessFailedException($message . $this->buildProcessMessage());
144144
}
145145
}
146146

147147
/**
148-
* @param Process $process
148+
* Borrowed from \Symfony\Component\Process\Exception\ProcessTimedOutException
149+
*
149150
* @return string
150151
*/
151-
public function buildProcessMessage(Process $process)
152+
public function buildProcessMessage()
152153
{
153-
$message = '';
154-
if ($output = $process->getOutput()) {
155-
$message = "\n\nCommand output:\n" . $output;
156-
}
157-
if ($stderr = $process->getErrorOutput()) {
158-
$message = "\n\nCommand stderr:\n" . $stderr;
154+
$error = sprintf(
155+
"%s\n\nExit Code: %s(%s)\n\nWorking directory: %s",
156+
$this->process->getCommandLine(),
157+
$this->process->getExitCode(),
158+
$this->process->getExitCodeText(),
159+
$this->process->getWorkingDirectory()
160+
);
161+
162+
if (!$this->process->isOutputDisabled()) {
163+
$error .= sprintf(
164+
"\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
165+
$this->process->getOutput(),
166+
$this->process->getErrorOutput()
167+
);
159168
}
160-
return $message;
169+
170+
return $error;
161171
}
162172

163173
/**
@@ -252,7 +262,6 @@ public function drush($command, array $args = [], array $options = [], $site_spe
252262
// that tests might cause Drupal to send.
253263

254264
$php_options = (array_key_exists('PHP_OPTIONS', $env)) ? $env['PHP_OPTIONS'] . " " : "";
255-
// @todo The PHP Options below are not yet honored by execute(). See .travis.yml for an alternative way.
256265
$env['PHP_OPTIONS'] = "${php_options}-d sendmail_path='true'";
257266
$cmd = implode(' ', $exec);
258267
$return = $this->execute($cmd, $expected_return, $cd, $env);

0 commit comments

Comments
 (0)