SlideShare a Scribd company logo
Drush: using and creating
   custom commands

    Использование Drush
           Successful Development LP
Gold Sponsor of
DrupalCamp Kyiv 2011
Silver Sponsors of
DrupalCamp Kyiv 2011
Scheme

    Administration of drupal by command line:
    main benefits.

    Most interesting ways of using.

    How this work.

    Drush_macros: simple drush extention for
    example.
Administration of drupal by
     command line: main benefits

    Drush: More Beer, Less Effort:
       
           Save time
       
           Forgot about php timeout (and some restrictions of php)
       
           Don't need remember all.
       
           Automatization (repeating of actions)
Forgot about php timeout (and
     some other restrictions of php)

    We can hadle have processes

    Batch processes

    Using bash scripts
Don't need remember all.

    We can pay more attention on development

     Forgot about some issues in drupal web-
    interface using

     Don't need pay too many attention for file
    system (locations of some module folder and
    other)
Automatization (repeating of
                actions)

    Use bash aliases

    Launching by cron

    Launching commands queue by 1 command
Most interesting ways of using.

    Installation in Ubuntu

    Installation in Unix-like operation systems

    Installation in MS Windows

    Main commands in possibilities
Installtion in Ubuntu

    sudo apt-get install drush

    Pathes:
      
          /usr/share/drush
      
          /etc/drush
Installation in Unix-like OS

    Unpuck in any required dirrectory

    Using alias drush='/path/to/drush'

    Installation some required packages
Installation in MS Windows
Solving
Instractions for drush installation in Windows:


     http://drupal.org/node/594744


    http://www.starbowconsulting.com/node/103


    http://vimeo.com/15371661 — Video installation WAMP, Drush & Drupal for Windows 7

             
                     Required packages:
                           
                                  http://gnuwin32.sourceforge.net/packages/libarchive.htm
                           
                                  http://gnuwin32.sourceforge.net/packages/gzip.htm
                           
                                  http://gnuwin32.sourceforge.net/packages/wget.htm
                           
                                  http://gnuwin32.sourceforge.net/packages/gtar.htm
Environment Pathes: ;C:php;C:drush;C:Program Files (x86)GnuWin32bin

Where 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
Use cases

    cache-clear (cc) - Clearing of cache

    image-flush - Fushes images of image-styles

    site-install

    site-upgrade
    и т.д.
Coding drive development
              and drush

    features-diff

    features-list

    features-revert

    features-update
How this work
workflow
Drush API

    http://drupalcontrib.org/api/drupal/contributions--drush--docs--drush.api.php/7
     
         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()
Build your drush
    extention
Create COMMANDFILE.drush.inc
Drush 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 user's HOME folder.

      All modules in the current Drupal installation
Implement
COMMANDFILE_drush_help()
function sandwich_drush_help($section) {
    switch ($section) {
        case 'drush:make-me-a-sandwich':
         return dt("... brief help summary
                    goes here ...");
    }
}
Implement
COMMANDFILE_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
Implement
COMMANDFILE_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);
      …
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
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
         name
exit — exit from drush cli mode

     After that we can run queue of commands by 1
    command in drush cli
Questions
        chewie@sfdev.com
        Skype: chew1e_serge


     Successful Development LP
     http://php.sfdev.com

More Related Content

PDF
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
PPT
Drush. Why should it be used?
PDF
Dennis Povshedny.Mediamosa intro.DrupalCamp Kyiv 2011
PPT
Intro to Drush
PDF
PDF
2011 - DDU - Intro to Drush
ODP
Travis Carden/Drupal Nebraks: Drush Presentation
DOCX
Hadoop installation
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
Drush. Why should it be used?
Dennis Povshedny.Mediamosa intro.DrupalCamp Kyiv 2011
Intro to Drush
2011 - DDU - Intro to Drush
Travis Carden/Drupal Nebraks: Drush Presentation
Hadoop installation

What's hot (20)

PDF
Contribuir a Drupal - Entorno
DOCX
Run wordcount job (hadoop)
PPTX
Hadoop installation on windows
PDF
TP2 Big Data HBase
PPT
Drupal Camp Atlanta 2011 - Drupal Security
PDF
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
ODP
Drush Presentation
PPTX
Dc kyiv2010 jun_08
ODP
Drush - More Beer, Less Effort
PDF
Beginning Jquery In Drupal Theming
PDF
mapserver_install_linux
PDF
Red hat lvm cheatsheet
PDF
Linux con europe_2014_f
ODP
Asian Spirit 3 Day Dba On Ubl
PPTX
Drupal from scratch
PDF
Drupal Pilipinas Apprentice: LAMP Administration, CSS, and Vagrant
PDF
Alfredo-PUMEX
PPT
101 4.3 control mounting and unmounting of filesystems
PDF
55 best linux tips, tricks and command lines
PDF
Refcard en-a4
Contribuir a Drupal - Entorno
Run wordcount job (hadoop)
Hadoop installation on windows
TP2 Big Data HBase
Drupal Camp Atlanta 2011 - Drupal Security
PuppetConf. 2016: Puppet Best Practices: Roles & Profiles – Gary Larizza, Puppet
Drush Presentation
Dc kyiv2010 jun_08
Drush - More Beer, Less Effort
Beginning Jquery In Drupal Theming
mapserver_install_linux
Red hat lvm cheatsheet
Linux con europe_2014_f
Asian Spirit 3 Day Dba On Ubl
Drupal from scratch
Drupal Pilipinas Apprentice: LAMP Administration, CSS, and Vagrant
Alfredo-PUMEX
101 4.3 control mounting and unmounting of filesystems
55 best linux tips, tricks and command lines
Refcard en-a4
Ad

Similar to Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011 (20)

PDF
A Drush Primer - DrupalCamp Chattanooga 2013
PPTX
DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, Intern...
PDF
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
PPTX
Drush for drupal website builder
PDF
Drush deploy presentation by Goruachev Mikhail
ODP
Drush A beginners guide to a advanced tool.
PPT
Drush and drupal. администрирование. Волчек Михаил
PDF
How to Use the Command Line to Increase Speed of Development
PDF
DevOps: Cooking Drupal Deployment
PPT
Drush and drupal. администрирование волчек михаил
PPT
Drush&drupal. administration
PDF
Face your fears: Drush and Aegir
PPTX
Dcp'14 drush
PPTX
Exploring composer in drupal 8 with drupal project - salva molina
PPTX
Managing Drupal on Windows with Drush
PDF
Drush in the Composer Era
KEY
Drupal on your laptop
PDF
Development Setup of B-Translator
PDF
drush_multi @ DrupalDevDays 2010
PPTX
Intro to Drush
A Drush Primer - DrupalCamp Chattanooga 2013
DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, Intern...
Drush 5.0 (DrupalCamp LA 2012) - Chris Charlton
Drush for drupal website builder
Drush deploy presentation by Goruachev Mikhail
Drush A beginners guide to a advanced tool.
Drush and drupal. администрирование. Волчек Михаил
How to Use the Command Line to Increase Speed of Development
DevOps: Cooking Drupal Deployment
Drush and drupal. администрирование волчек михаил
Drush&drupal. administration
Face your fears: Drush and Aegir
Dcp'14 drush
Exploring composer in drupal 8 with drupal project - salva molina
Managing Drupal on Windows with Drush
Drush in the Composer Era
Drupal on your laptop
Development Setup of B-Translator
drush_multi @ DrupalDevDays 2010
Intro to Drush
Ad

More from Vlad Savitsky (18)

PDF
Looking for Vulnerable Code. Vlad Savitsky
PDF
Art of Estimation. Vlad Savitsky
PDF
Varnish and Drupal.
PDF
Chapter18
PDF
Css Intro. Vlad Savitsky
PDF
HTML. Быстрое погружение. Влад Савицкий
PDF
How to be a believer online. Vlad Savitsky. Novomedia forum 2011
PPT
Vlad savitsky. Church Site in 15 minutes
PDF
Dmitry Drozdik. how to make friendship between drupal and content manager. dr...
PDF
Alexey Kostin. Increase site ctr in serp using google rich snippets. DrupalCa...
PDF
Oleg Natalushko. Drupal server anatomy. DrupalCamp Kyiv 2011
PDF
Dennis popov. scrum for drupal. drupal camp kyiv 2011
PDF
Andriy Kushnarov. BOND: a giant drupal in a huge company. DrupalCamp Kyiv 2011
PDF
Danilenko Alexander. Drupal 7 theming on Omega. DrupalCamp Kyiv 2011
PDF
Evgeniy Karelin. Mongo DB integration example solving performance and high lo...
PDF
Oleksandr Masovets. Forms in Drupal. Drupal Camp Kyiv 2011
PDF
Yuriy Gerasimov. Drupal Services. Integration with third party applications. ...
PDF
Оптимизация JavaScript в Drupal
Looking for Vulnerable Code. Vlad Savitsky
Art of Estimation. Vlad Savitsky
Varnish and Drupal.
Chapter18
Css Intro. Vlad Savitsky
HTML. Быстрое погружение. Влад Савицкий
How to be a believer online. Vlad Savitsky. Novomedia forum 2011
Vlad savitsky. Church Site in 15 minutes
Dmitry Drozdik. how to make friendship between drupal and content manager. dr...
Alexey Kostin. Increase site ctr in serp using google rich snippets. DrupalCa...
Oleg Natalushko. Drupal server anatomy. DrupalCamp Kyiv 2011
Dennis popov. scrum for drupal. drupal camp kyiv 2011
Andriy Kushnarov. BOND: a giant drupal in a huge company. DrupalCamp Kyiv 2011
Danilenko Alexander. Drupal 7 theming on Omega. DrupalCamp Kyiv 2011
Evgeniy Karelin. Mongo DB integration example solving performance and high lo...
Oleksandr Masovets. Forms in Drupal. Drupal Camp Kyiv 2011
Yuriy Gerasimov. Drupal Services. Integration with third party applications. ...
Оптимизация JavaScript в Drupal

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Modernizing your data center with Dell and AMD
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Modernizing your data center with Dell and AMD
Per capita expenditure prediction using model stacking based on satellite ima...
Big Data Technologies - Introduction.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
“AI and Expert System Decision Support & Business Intelligence Systems”
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Building Integrated photovoltaic BIPV_UPV.pdf

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

  • 1. Drush: using and creating custom commands Использование Drush Successful Development LP
  • 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. Administration of drupal by command line: main benefits  Drush: More Beer, Less Effort:  Save time  Forgot about php timeout (and some restrictions of php)  Don't need remember all.  Automatization (repeating of actions)
  • 6. Forgot about php timeout (and some other restrictions of php)  We can hadle have processes  Batch processes  Using bash scripts
  • 7. Don't need remember all.  We can pay more attention on development  Forgot about some issues in drupal web- interface using  Don't need pay too many attention for file system (locations of some module folder and other)
  • 8. Automatization (repeating of actions)  Use bash aliases  Launching by cron  Launching commands queue by 1 command
  • 9. Most interesting ways of using.  Installation in Ubuntu  Installation in Unix-like operation systems  Installation in MS Windows  Main commands in possibilities
  • 10. Installtion in Ubuntu  sudo apt-get install drush  Pathes:  /usr/share/drush  /etc/drush
  • 11. Installation in Unix-like OS  Unpuck in any required dirrectory  Using alias drush='/path/to/drush'  Installation some required packages
  • 13. Solving Instractions for drush installation in Windows:  http://drupal.org/node/594744  http://www.starbowconsulting.com/node/103  http://vimeo.com/15371661 — Video installation WAMP, Drush & Drupal for Windows 7  Required packages:  http://gnuwin32.sourceforge.net/packages/libarchive.htm  http://gnuwin32.sourceforge.net/packages/gzip.htm  http://gnuwin32.sourceforge.net/packages/wget.htm  http://gnuwin32.sourceforge.net/packages/gtar.htm Environment Pathes: ;C:php;C:drush;C:Program Files (x86)GnuWin32bin Where 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. Use cases  cache-clear (cc) - Clearing of cache  image-flush - Fushes images of image-styles  site-install  site-upgrade и т.д.
  • 15. Coding drive development and drush  features-diff  features-list  features-revert  features-update
  • 18. Drush API  http://drupalcontrib.org/api/drupal/contributions--drush--docs--drush.api.php/7  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. Build your drush extention
  • 20. Create COMMANDFILE.drush.inc Drush 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 user's HOME folder.  All modules in the current Drupal installation
  • 21. Implement COMMANDFILE_drush_help() function sandwich_drush_help($section) { switch ($section) { case 'drush:make-me-a-sandwich': return dt("... brief help summary goes here ..."); } }
  • 22. Implement COMMANDFILE_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. Implement COMMANDFILE_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. 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. 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 name exit — exit from drush cli mode  After that we can run queue of commands by 1 command in drush cli
  • 26. Questions  chewie@sfdev.com  Skype: chew1e_serge Successful Development LP http://php.sfdev.com