Drush Presentation

3,138 views

Published on

This is a presentation that I will be giving at the Cape Town Drupal meet-up.

Published in: Technology
1 Comment
3 Likes
Statistics
Notes
  • Just the facts!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
3,138
On SlideShare
0
From Embeds
0
Number of Embeds
29
Actions
Shares
0
Downloads
0
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Drush Presentation

  1. 1. DRUSH (and extending it to do your bidding) (at the speed of light) Perceptum Thought Squad Perceptum Thought Squad develops, integrates and "mashes up" concepts and technologies to solve puzzles and problems in innovative ways. Aiming to master concepts and insights in as short a time as possible, we try not to neglect conceptual clarity of underlying principles. http://www.perceptum.biz/ http://www.drupaler.co.za/ [email_address]
  2. 2. Drupal + Shell Scripting = DRUSH <ul><li>“DRUSH is a command line shell and Unix scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt.” </li></ul>
  3. 3. Drupal + Shell Scripting = DRUSH ? <ul><li>For those coming from a Microsoft backgroun – the shell is basically the UNIX version of cmd.exe
  4. 4. DRUSH provides a way of executing commands and scripts on a Drupal installation – without the need for the web browser </li></ul>
  5. 5. Drupal + Shell Scripting = DRUSH ? <ul>Why DRUSH? <li>Saves you time
  6. 6. Automates repetitive tasks
  7. 7. Gives you a quick and easy overview of your installation
  8. 8. BUT MAINLY....
  9. 9. IT IS EXTENSIBLE!
  10. 10. (more on this in a bit)
  11. 11. (But will it make the coffee??) </li></ul>
  12. 12. Drupal + Shell Scripting = DRUSH <ul>Installing DRUSH (for Unixy OS) <li>Download from http://drupal.org/projects/drush
  13. 13. Untar the tarball into a folder outside of your web site (We use /opt/drush)
  14. 14. Make sure you have the php-cli (command line interface) package installed
  15. 15. chmod u+x /opt/drush/drush (add executable permission)
  16. 16. (optional) ln -s /opt/drush/drush /usr/bin/
  17. 17. (this lets you run drush without the full path) </li></ul>Installing DRUSH (for Windows) <ul><li>Download and install Ubuntu
  18. 18. OR
  19. 19. Unpack the tarball to a directory, and use the drush.bat script
  20. 20. Whenever the documentation or the help text refers to drush [option] <command>' or something similar, 'drush' has to be replaced by 'drush.bat'.
  21. 21. If drush.bat is not working for you, either add the directory in which your php.exe resides to your PATH or edit drush.bat to point to your php.exe </li></ul>
  22. 22. Drupal + Shell Scripting = DRUSH <ul>Most used features (from within a Drupal Installation) <li>drush status
  23. 23. drush cron
  24. 24. drush dl <project>
  25. 25. drush pm-enable <project>
  26. 26. drush pm-disable <project>
  27. 27. drush pm-uninstall <project>
  28. 28. drush pm-info <project>
  29. 29. drush sql-cli
  30. 30. variable-get (vget)
  31. 31. variable-set (vset)
  32. 32. … and much more (drush help will reveal all) </li></ul>
  33. 33. Drupal + Shell Scripting = DRUSH <ul>Running arbitrary php script from drush is easy!! <li>Create a php file (test.php)
  34. 34. Run drush --user=1 scr test
  35. 35. Remember – you are in the drupal environment now
  36. 36. You can call all functions like db_query() … variable_get().... node_load()... user_load() ...etc
  37. 37. When??
  38. 38. Use this when you have a once off script to run </li></ul>
  39. 39. Drupal + Shell Scripting = DRUSH <ul>Building drush plugins is easy!! (kinda) <li>First you need a module (drush_demo)
  40. 40. Install drush module_builder
  41. 41. drush dl module_builder
  42. 42. drush pm-enable module_builder
  43. 43. Create a module
  44. 44. drush mb drush_demo init --write --name=&quot;Drush Demo&quot;
  45. 45. drush pm-enable drush_demo
  46. 46. Add your drush_demo.drush.inc
  47. 47. When??
  48. 48. Use this when you have to write functionality that will be used repetitively </li></ul>
  49. 49. Drupal + Shell Scripting = DRUSH <ul>Drush plugin anatomy 1 <li>The file name is important! drush_demo .drush.inc
  50. 50. 3 hook functions are required </li></ul>function drush_demo _drush_command() { $items = array(); $items[' drush_demo - makenode '] = array( 'description' => &quot;This plugin makes a node!&quot;, ); return $items; }
  51. 51. Drupal + Shell Scripting = DRUSH <ul>Drush plugin anatomy 2 <li>The file name is important! drush_demo .drush.inc </li></ul>function drush_demo _drush_help($section) { switch ($section) { case 'drush: drush_demo - makenode ': return dt(&quot;You need help??? Its easy ... just give me the title and the body... I'll do the rest. Usage: drush drush_demo-makenode 'Node Title' 'Node Body'&quot;); } }
  52. 52. Drupal + Shell Scripting = DRUSH <ul>Drush plugin anatomy 3 <li>The file name is important! drush_demo .drush.inc </li></ul>function drush_ drush_demo _ makenode () { $args = func_get_args(); if(count($args) != 2) { return; } global $user; $node = new stdClass(); $node->title = $args[0]; $node->teaser = substr($args[1],0,10); $node->type = 'page'; $node->uid = $user->uid; $node->published = 1; $node->promote = 1; node_save($node); drush_print(print_r($node, true)); }
  53. 53. DRUSH ?> thanks for listening :) <?php

×