11
Drupal shell or just DruSH

DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

Embed Size (px)

Citation preview

Page 1: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

Drupal shell or just

DruSH

Page 2: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

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;

Page 3: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

Why Drush?

- saves your time;

- possibility to use drush in scripts;

- custom drush commands.

- aliases;

Page 4: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

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

Page 5: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

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

Page 6: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

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

Page 7: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

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:~$

Page 8: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

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

...

Page 9: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

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

Page 10: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

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

Page 11: DrupalTour. Ternopil — Drupal shell or just Drush (Serhii Puchkovskii, InternetDevels)

Questions?