Upload
drupaltour
View
102
Download
4
Embed Size (px)
Citation preview
Drupal shell or just
DruSH
What is Drush?
- drush is a command line interface that allows to
manage your Drupal web sites fast and easy.
- drush is not a module;
- drush = drupal + shell = drupal in the command line;
Why Drush?
- saves your time;
- possibility to use drush in scripts;
- custom drush commands.
- aliases;
The Manual Method The Drush Method
Drush: More Beer, Less Effort
- go to the drupal.org and search
necessary module;- drush dl views -y && drush en views -y
- download module;
- find archive and unzip it;
- copy module to the Drupal repository;
- go to the site, search module and enable it.
- go to beer
Drush commands$ drush <command> [options]
Help!
$ drush
$ drush help <command>
Core drush commands:
● cache-clear (cc)
● core-cron (cron)
● core-status (status, st)
● updatedb (updb)
SQL commands:
● sql-dump
● sql-query (sqlq)
● sql-drop
● sql-create
Project manager commands:
● pm-enable (en)
● pm-disable (dis)
● pm-download (dl)
● pm-update (up)
http://www.drushcommands.com
Aliases- aliases of the sites are shortcuts that point to some
of
the sites for which you want to execute the command- use in our scripts
How to create alias?
- go to the user directore: cd ~<?php
$aliases['example'] = array(
'uri' => 'localhost',
'root' => "/var/www/example.loc",
);
- create file for aliases:
.drush/aliases.drushrc.php
drush @example status
Drush in scripts
// Just some ideas to get the juices flowing.
drush_print_r(user_roles());
drush_print_r($GLOBALS['user']);
drush php-script scratch.php
alan@alan-eMachines-E525:~$ drush php-script
/usr/share/php/drush/commands/core/scratch.php
alan@alan-eMachines-E525:~$
How to create custom script?<?php
$aliases = array('@example', '@example_1', '@example_n');
foreach ($aliases as $alias) {
$status = shell_exec("drush $alias status");
drush_print_r($status);
}
alan@alan-eMachines-E525:~$ drush php-script
/usr/share/php/drush/commands/core/scratch.php
/usr/share/php/drush/commands/core/my-script.php
alan@alan-eMachines-E525:~$
alan@alan-eMachines-E525:~$ sudo drush php-script my-script
Drupal version : 7.26
Site URI : localhost
Database driver : mysql
Database hostname : localhost
Database username : root
...
Custom drush commandsmy_module.drush.inc
/**
* Implements hook_drush_command().
*/
function my_module_drush_command() {
$items = array();
$items['content-info'] = array(
'description' => 'Content info’,
'drupal dependencies' => array('my_module'),
'aliases' => array('ci'),
);
return $items;
}
/**
* Content information.
*/
function drush_my_module_content_info() {
$node_types = node_type_get_types();
foreach ($node_types as $type => $type_info) {
// Get information about nodes.
$info = db_select('node')->condition('type', $type);
$count = $info->countQuery()->execute()->fetchField();
$published = $info->condition('status', TRUE)
->countQuery()->execute()->fetchField();
// Print information.
drush_print_r($type_info->name);
drush_print_r(t('Count: @count', array('@count' => $count)));
drush_print_r(t('Published: @published', array('@published' =>
$published)));
drush_print_r("\n");
}
}
Article
Count: 27
Published: 15
Basic page
Count: 12
Published: 9
$ drush ci
Drush make
$ drush make makefile.make
; Drush Make API version.
api = 2
;Drupal core.
core = 7.x
;Common modules.
projects[admin_menu][subdir] = "contrib"
projects[ctools][subdir] = "contrib"
...
$ make-generate
Questions?