Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011


Published on

Drush - это интерфейс командной строки для доступа к вашему сайту на Drupal.
С помощью данного инструмента вы можете выполнять рутинные действия не прибегая к вебинтерфейсу Друпала, что значительно упрощает работу веб-разработчика.
1. Будут рассмотрены основные команды при работе с сайтом на базе Друпал;
2. Установка под Linux и особенности при установке в Windows;
3. Использование при работе с популярными модулями.
4. Возможности использования следуя принципам Coding drive development-а.
5. Drush4 API
6. Пример разработки своих команд для работы с Друпал сайтом.

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011

  1. 1. Drush: using and creating custom commands Использование Drush Successful Development LP
  2. 2. Gold Sponsor ofDrupalCamp Kyiv 2011
  3. 3. Silver Sponsors ofDrupalCamp Kyiv 2011
  4. 4. Scheme Administration of drupal by command line: main benefits. Most interesting ways of using. How this work. Drush_macros: simple drush extention for example.
  5. 5. Administration of drupal by command line: main benefits Drush: More Beer, Less Effort:  Save time  Forgot about php timeout (and some restrictions of php)  Dont need remember all.  Automatization (repeating of actions)
  6. 6. Forgot about php timeout (and some other restrictions of php) We can hadle have processes Batch processes Using bash scripts
  7. 7. Dont need remember all. We can pay more attention on development Forgot about some issues in drupal web- interface using Dont need pay too many attention for file system (locations of some module folder and other)
  8. 8. Automatization (repeating of actions) Use bash aliases Launching by cron Launching commands queue by 1 command
  9. 9. Most interesting ways of using. Installation in Ubuntu Installation in Unix-like operation systems Installation in MS Windows Main commands in possibilities
  10. 10. Installtion in Ubuntu sudo apt-get install drush Pathes:  /usr/share/drush  /etc/drush
  11. 11. Installation in Unix-like OS Unpuck in any required dirrectory Using alias drush=/path/to/drush Installation some required packages
  12. 12. Installation in MS Windows
  13. 13. SolvingInstractions for drush installation in Windows: — Video installation WAMP, Drush & Drupal for Windows 7  Required packages:     Pathes: ;C:php;C:drush;C:Program Files (x86)GnuWin32binWhere is work: Windows server 2008, Windows server 2008, Windows Vista 64-bit Business, Windows Vista 32-bit Business, Windows Vista 32-bit Home Premium, Windows XP SP3 32-bit, Windows 7 Home Premium 32-bit, Windows 7 Enterprise 64-bit
  14. 14. Use cases cache-clear (cc) - Clearing of cache image-flush - Fushes images of image-styles site-install site-upgrade и т.д.
  15. 15. Coding drive development and drush features-diff features-list features-revert features-update
  16. 16. How this work
  17. 17. workflow
  18. 18. Drush API  Hooks: • hook_drush_init() • drush_COMMAND_init() • drush_hook_COMMAND_validate() • drush_hook_pre_COMMAND() • drush_hook_COMMAND() • drush_hook_post_COMMAND() • drush_hook_post_COMMAND_rollback() • drush_hook_COMMAND_rollback() • drush_hook_pre_COMMAND_rollback() • drush_hook_COMMAND_validate_rollback() • hook_drush_exit()
  19. 19. Build your drush extention
  20. 20. Create COMMANDFILE.drush.incDrush searches for commandfiles in the following locations: The "/path/to/drush/commands" folder. Folders listed in the include option (see `drush topic docs-configuration`). The system-wide drush commands folder, e.g. /usr/share/drush/commands The ".drush" folder in the users HOME folder. All modules in the current Drupal installation
  21. 21. ImplementCOMMANDFILE_drush_help()function sandwich_drush_help($section) { switch ($section) { case drush:make-me-a-sandwich: return dt("... brief help summary goes here ..."); }}
  22. 22. ImplementCOMMANDFILE_drush_command() aliases: Provides a list of shorter names for the command. deprecated-aliases: Works just like aliases, but does not appear in help. callback: Name of function to invoke for this command callback arguments: An array of arguments to pass to the callback. description: Description of the command. bootstrap: Drupal bootstrap level. Valid values are:  DRUSH_BOOTSTRAP_DRUSH  DRUSH_BOOTSTRAP_DRUPAL_ROOT  DRUSH_BOOTSTRAP_DRUPAL_SITE  DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION  DRUSH_BOOTSTRAP_DRUPAL_DATABASE  DRUSH_BOOTSTRAP_DRUPAL_FULL  DRUSH_BOOTSTRAP_DRUPAL_LOGIN  DRUSH_BOOTSTRAP_MAX
  23. 23. ImplementCOMMANDFILE_drush_command() Usefull functions:  drush_prompt($prompt, $default = NULL, $required = TRUE);  drush_print($string);  drush_confirm($message);  Example of input: $stdin = fopen("php://stdin","r"); $macros_name = fgetc($stdin); …
  24. 24. Drush_macros: simple drush extention for example. Link for downloading will be later Aim: recording and launching commands by 1 commands, recording drush/bash commands, saving in drush inveronment
  25. 25. Using drush_macros drush cli mstart — start «recording» bash/drush commands mstop — stop «recording» bash/drush commands macros-save — save queue of commands by 1 nameexit — exit from drush cli mode After that we can run queue of commands by 1 command in drush cli
  26. 26. Questions   Skype: chew1e_serge Successful Development LP