1 of 33

Drush 9

Moshe Weitzman && Greg Anderson

2 of 33

  • Independant Consultant
    • Drupal Architect for hire
    • CI & Developer Workflow
  • Maintainer:
    • Drush
    • Devel

Moshe Weitzman

3 of 33

  • Pantheon Platform Engineer

  • Maintainer:
    • Drush
    • Robo
    • CGR

Greg Anderson

4 of 33

“Drush is a veritable Swiss Army knife designed to make life easier for those who hack at the command prompt.”

  • Arto Bendiken http://bendiken.net

5 of 33

  • 11 years old!
  • Drush 9 is first ground-up rewrite since 2008
  • Embraces: OO, Symfony, Composer, Drupal 8

About Drush 9

6 of 33

Using Drush9

7 of 33

  • drupal-composer/ drupal-project
  • drush-launcher

Start new project

8 of 33

9 of 33

10 of 33

Migrate existing site

  • drush8 make-convert
  • drush composer-generate
  • Strategy: assemble full codebase via composer install
  • Reason: Dependency mgmt

11 of 33

Familiar friends still kicking

  • pm-enable & pmu
  • uli, rsync, sql-sync
  • config-export & cim
  • drush @foo status
  • drush pml --format=json
  • drush topic

12 of 33

Dearly departed

  • make, archive, qd
  • pm-update, dl
  • -n is --non-interactive
  • Procedural code
  • Drupal 6, Drupal 7
  • Now more maintainable

13 of 33

Departed for now

  • Shell aliases
  • site-set
  • Bash completion

14 of 33

  • Config Split
  • Run commands from project root
  • yml config and aliases
  • drush generate

New friends

15 of 33

Generate code

  • drush generate
  • drush gen module-standard
  • drush gen content-entity
  • drush gen dcf
  • Contrib can add more.
  • @see Drupal Code Generator

16 of 33

Drush9 APIs

17 of 33

Command Authoring

  • Annotated commands
  • OO, DI, Tagged services
  • Drush hooks are also annotated methods
  • Keep Drush8 code in your Contrib modules

18 of 33

Drush with Symfony Console

Drush

Drupal CLI Tool

- Bootstrap - Site Aliases - Remote Execution -

Robo

PHP Task Runner

- Task Collections -

Consolidation

General-Purpose CLI Libraries

- Annotations - Output Formatting - Configuration -

Symfony

PHP Framework Used by Drupal

- Console - Process Execution - Filesystem Utilities -

19 of 33

Two Autoloader Problem

20 of 33

Drush Preflight

  1. Preprocess arguments
  2. Load Config and Aliases
  3. Identify Drupal site
  4. Load Drupal autoloader
  5. Drush Dependency Injection
  6. $application->run()
  7. Comand hooks (e.g. bootstrap)

21 of 33

Code Available During Preflight and Bootstrap

Identify Drupal Site

Load Drupal autoloader

Bootstrap Drupal

Drush sources

Drush vendor

Drupal vendor

Drupal sources

Drush sources

Drush vendor

Drupal vendor

Drupal sources

Drush sources

Drush vendor

Drupal vendor

Drupal sources

Safe code in use

Available code not yet loaded

Code in use that MIGHT conflict

22 of 33

Validate state

Execute

Process Tasks

Format output

@command

@hook

validate

Output formatters

Prepare

to run

Initialize variables

Prompt user

@hook

interact

Validate args & options

@hook

init

@hook

command-event

Bootstrap Sequence in $application->run()

23 of 33

Standard Drush Hooks

Command Event Hooks:

    • Alter options hook (e.g. for output formatters)
    • Inject configuration hook

Init Hooks:

    • Redispatch hook: call remote command if applicable
    • Bootstrap hook: bootstrap Drupal to desired level

24 of 33

Output Formatter Data Preparation

/**

* @field-labels

* first: I

* second: II

* third: III

* @returns RowsOfFields

*/

public function tryFormatters($options = ['format' => 'table', 'fields' => ''])

{

$outputData = [

'en' => [ 'first' => 'One', 'second' => 'Two', 'third' => 'Three' ],

'de' => [ 'first' => 'Eins', 'second' => 'Zwei', 'third' => 'Drei' ],

'jp' => [ 'first' => 'Ichi', 'second' => 'Ni', 'third' => 'San' ],

'es' => [ 'first' => 'Uno', 'second' => 'Dos', 'third' => 'Tres' ],

];

return new RowsOfFields($outputData);

}

25 of 33

Output Format Selection

--format=table

--format=yaml

26 of 33

Output Field Selection

--fields=III,I

--fields=III,I --format=json

27 of 33

Drush Config Now .yml

drushrc.php

$command_specific['site-install'] =

array(

'account-name' => 'alice',

'account-pass' => 'secret'

);

drush.yml

command:

site:

install:

options:

account-name: alice

account-pass: secret

28 of 33

Drush Aliases are also .yml Config

aliases.drushrc.php:

$aliases['anything.at.all.dev'] =

array(

'root' => '/path/to/drupal',

'uri' => 'https://dev.example.com'

);

example.alias.yml:

dev:

root: /path/to/drupal

uri: ‘https://dev.example.com

live:

host: isp.com

root: /srv/www/example

uri: https://example.com

29 of 33

Site Alias Groups

group.aliases.yml:

site-one:

dev:

root: /path/to/drupal

uri: ‘https://site-one.com

site-two:

dev:

root: /path/to/drupal

uri: ‘https://site-two.com

30 of 33

Drush Tests

  • Unish Functional Tests
    • One Site-Under-Test for all tests
  • Isolation tests
    • phpunit tests for preflight classes

31 of 33

JOIN US FOR

CONTRIBUTION SPRINT

Friday, 29 September, 2017

First time

Sprinter Workshop

Mentored

Core Sprint

General Sprint

9:00-12:00

Room: Lehar 1 - Lehar 2

9:00-18:00

Room: Stolz 2

9:00-18:00

Room: Mall

#drupalsprints

32 of 33

WHAT DID YOU THINK?

Locate this session at the DrupalCon Vienna website:

http://vienna2017.drupal.org/schedule

Take the survey!

https://www.surveymonkey.com/r/drupalconvienna

33 of 33

Extra Art