CUSTOM DRUSH COMMANDS
HOW TO BUILD YOUR OWN CUSTOM DRUSH COMMANDS
Created by /Mike Bell @mikebell_
WHO?
Mike Bell
Twitter -
Drupal.org -
Where - CTI Digital - Drupal Technical Architect
@mikebell_
digital006
WHAT IS DRUSH?
Command line utility for Drupal
Used by most Drupal developers, an insanely powerful tool
drupal.org/projec...
ALIAS UP
THE PROBLEM:
Updating aliases across multiple multiple dev machines
without the user having to go out of their wa...
CAVEAT
Insecure, Demo, Use at own risk!
THE TOOLS
Drush...
Composer
Symfony YAML
COMPOSER
WHAT IS IT?
Dependency manager for PHP.
WHY?
Used for grabbing Symfony components and creating an
autoloader for ...
COMPOSER EXAMPLE
{
"name": "drush/alias_up",
"description": "Provide a method to automatically upgrade a user's aliases.
"...
SYMFONY/YAML
Used for parsing Yaml files into arrays.
Also used in Drupal 8 core for all config files.
EXAMPLE CONFIG FILE
type: git (git/http/https)
source: http://mikebell.io/alias.php
updatefreq: 1 (days)
THE HOOKS
Symfony Autoload
hook_drush_help()
hook_drush_command()
aliasup_init()
aliasup()
aliasup_download()
hook_drush_i...
SYMFONY AUTOLOAD
Auto load the YAML component
require 'vendor/autoload.php';
use SymfonyComponentYamlYaml;
HOOK_DRUSH_HELP()
Define standard help for the command
HOOK_DRUSH_COMMAND()
Define your command and the short commands for running
$items['aliasup'] = array(
'description' => 'U...
INSTALL
1. Clone Repository
2. composer.phar install
3. cp example.config.yml
../aliasup.config.yml
4. Configure
5. Create...
USAGE
drush au
Updates the alias file from the remote server
UNINSTALL
drush auuni
Removes all the code from the install.
LIVE DEMO
What could go wrong?
ANY QUESTIONS?
RESOURCES
Presentation resources:
- Used for presentation
- HTML shorthand
Drush API File
Drupal Answers
Reveal.js
Zen Cod...
Upcoming SlideShare
Loading in …5
×

Custom Drush Commands - Drupal Yorkshire

2,372 views
2,314 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,372
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Custom Drush Commands - Drupal Yorkshire

  1. 1. CUSTOM DRUSH COMMANDS HOW TO BUILD YOUR OWN CUSTOM DRUSH COMMANDS Created by /Mike Bell @mikebell_
  2. 2. WHO? Mike Bell Twitter - Drupal.org - Where - CTI Digital - Drupal Technical Architect @mikebell_ digital006
  3. 3. WHAT IS DRUSH? Command line utility for Drupal Used by most Drupal developers, an insanely powerful tool drupal.org/project/drush
  4. 4. ALIAS UP THE PROBLEM: Updating aliases across multiple multiple dev machines without the user having to go out of their way. THE SOLUTION: Drush command to keep aliases in sync. Prompt user for download when using Drush.
  5. 5. CAVEAT Insecure, Demo, Use at own risk!
  6. 6. THE TOOLS Drush... Composer Symfony YAML
  7. 7. COMPOSER WHAT IS IT? Dependency manager for PHP. WHY? Used for grabbing Symfony components and creating an autoloader for them.
  8. 8. COMPOSER EXAMPLE { "name": "drush/alias_up", "description": "Provide a method to automatically upgrade a user's aliases. "license": "GPL-2.0+", "require": { "symfony/yaml": "2.3.*" } }
  9. 9. SYMFONY/YAML Used for parsing Yaml files into arrays. Also used in Drupal 8 core for all config files.
  10. 10. EXAMPLE CONFIG FILE type: git (git/http/https) source: http://mikebell.io/alias.php updatefreq: 1 (days)
  11. 11. THE HOOKS Symfony Autoload hook_drush_help() hook_drush_command() aliasup_init() aliasup() aliasup_download() hook_drush_init() aliasup_uninstall()
  12. 12. SYMFONY AUTOLOAD Auto load the YAML component require 'vendor/autoload.php'; use SymfonyComponentYamlYaml;
  13. 13. HOOK_DRUSH_HELP() Define standard help for the command
  14. 14. HOOK_DRUSH_COMMAND() Define your command and the short commands for running $items['aliasup'] = array( 'description' => 'Update aliases from central server', 'callback' => 'aliasup', 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, 'examples' => array( 'drush aliasup' => 'Update aliases' ), 'aliases' => array('au') );
  15. 15. INSTALL 1. Clone Repository 2. composer.phar install 3. cp example.config.yml ../aliasup.config.yml 4. Configure 5. Create aliases.drush.php 6. drush aui 7. drush sa --table
  16. 16. USAGE drush au Updates the alias file from the remote server
  17. 17. UNINSTALL drush auuni Removes all the code from the install.
  18. 18. LIVE DEMO What could go wrong?
  19. 19. ANY QUESTIONS?
  20. 20. RESOURCES Presentation resources: - Used for presentation - HTML shorthand Drush API File Drupal Answers Reveal.js Zen Coding Reveal and Zen Coding Blog Post

×