pavlenko sergey. drush: using and creating custom commands. drupalcamp kyiv 2011

Post on 15-Jan-2015

2.408 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

Drush: using and creating custom commands

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

Successful Development LP

Gold Sponsor ofDrupalCamp Kyiv 2011

Silver Sponsors ofDrupalCamp 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)\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

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

top related