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

26
Drush: using and creating custom commands Использование Drush Successful Development LP

description

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

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

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

Drush: using and creating custom commands

Использование Drush

Successful Development LP

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

Gold Sponsor ofDrupalCamp Kyiv 2011

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

Silver Sponsors ofDrupalCamp Kyiv 2011

Page 4: Pavlenko Sergey. Drush: using and creating custom commands. 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.

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

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)

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

Forgot about php timeout (and some other restrictions of php)

We can hadle have processes Batch processes Using bash scripts

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

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)

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

Automatization (repeating of actions)

Use bash aliases Launching by cron Launching commands queue by 1 command

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

Most interesting ways of using.

Installation in Ubuntu Installation in Unix-like operation systems Installation in MS Windows Main commands in possibilities

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

Installtion in Ubuntu

sudo apt-get install drush Pathes:

/usr/share/drush /etc/drush

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

Installation in Unix-like OS

Unpuck in any required dirrectory Using alias drush='/path/to/drush' Installation some required packages

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

Installation in MS Windows

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

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)\GnuWin32\bin

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

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

Use cases

cache-clear (cc) - Clearing of cache image-flush - Fushes images of image-styles site-install site-upgrade

и т.д.

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

Coding drive development and drush

features-diff features-list features-revert features-update

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

How this work

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

workflow

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

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()

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

Build your drush extention

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

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

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

Implement COMMANDFILE_drush_help()

function sandwich_drush_help($section) {

switch ($section) {

case 'drush:make-me-a-sandwich':

return dt("... brief help summary

goes here ...");

}

}

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

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

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

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);

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

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

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

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

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

Questions

[email protected] Skype: chew1e_serge

Successful Development LP

http://php.sfdev.com