Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011
-
Upload
vlad-savitsky -
Category
Technology
-
view
2.409 -
download
2
description
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/1.jpg)
Drush: using and creating custom commands
Использование Drush
Successful Development LP
![Page 2: Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/2.jpg)
Gold Sponsor ofDrupalCamp Kyiv 2011
![Page 3: Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/3.jpg)
Silver Sponsors ofDrupalCamp Kyiv 2011
![Page 4: Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/4.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/5.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/6.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/7.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/8.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/9.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/10.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/12.jpg)
Installation in MS Windows
![Page 13: Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/13.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/14.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/15.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/16.jpg)
How this work
![Page 17: Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/17.jpg)
workflow
![Page 18: Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/18.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/19.jpg)
Build your drush extention
![Page 20: Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/20.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/21.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/22.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/23.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/24.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051412/54b6b2164a7959f01f8b4569/html5/thumbnails/25.jpg)
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