29
Drush. Why should it be used?

Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Embed Size (px)

Citation preview

Page 1: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Drush. Why should it be used?

Page 2: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Gold Sponsor ofDrupalCamp Kyiv 2011

Page 3: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Silver Sponsors ofDrupalCamp Kyiv 2011

Page 4: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

What will be described?

1. Drush. What is this? Common information.

2. What features does Drush have “from the box”?

3. Features which Drush may have with extensions.

4. Examples of how Drush helps during development process.

Page 5: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

What won't be described?

1. Aliases of sites.

2. Synchronization of code and databases.

3. Development of extensions.

4. Upgrade of Drupal code, modules and themes.

5. Many other helpful Drush commands and features which I don't know about.

Page 6: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Part 1

Common information.

Page 7: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Common information

1. Drush == drupal shell == command line.

2. Installation of Drush – README helps us!

3. What's next? Ask Drush to show you what it can to do!

4. So many commands, how could I use them? Ask Help for help!

5. How to use commands? It's simple:

«drush [options] [command]»

Page 8: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

First Drush response

Execute a drush command. Run `drush help [command]` to view command

specific help. Run `drush topic` to read even more documentation.

Global options (see `drush topic core-global-options` for the full list): …options…

Core drush commands: (core) …commands…

Field commands: (field) …commands…

SQL commands: (sql) …commands…

User commands: (user) …commands…

Page 9: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Help message

ss81@laptop:~$ drush help cc

Clear a specific cache, or all drupal caches.

Arguments:

type The particular cache to clear. Omit

this argument to choose from

available caches.

Aliases: cc

Page 10: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Clear cache and enable module

ss81@laptop:~$ drush cc all

'all' cache was cleared [success]

ss81@laptop:~$ drush en -y forum

The following extensions will be enabled: taxonomy, forum

Do you really want to continue? (y/n): y

forum was enabled successfully. [ok]

taxonomy was enabled successfully. [ok]

Page 11: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Part 2

Extend Drush features with other modules.

Page 12: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Groups of commands

1. Core rush commands (28 commands).

2. Field commands (5 commands).

3. Project manager commands (11 commands).

4. SQL commands (6 commands).

5. User commands (9 commands).

TOTAL: 59.

Page 13: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Modules, which I like

1. Devel.

2. Drush Make.

3. Module Builder.

4. Drush Cleanup.

5. Backup and Migrate.

Page 14: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

DevelAll commands in devel: (devel)

devel-reinstall (dre) Disable, Uninstall, and Install a list of projects.

...

fn-view (fnv) Show the source of specified function or method.

All commands in devel_generate: (devel_generate)

generate-content (genc) Create content.

...

Page 15: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Drush Make

1. Projects: drupal, pressflow, modules, themes. Could be downloaded from repository, by direct link, by name.

2. Libraries: any files you need to use.

Page 16: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Example of Drush Make file

projects[] = drupal

projects[] = apachesolr

libraries[SolrPhpClient][download][type] = "get"

libraries[SolrPhpClient][download][url] = "http://solr-php-client.googlecode.com/files/SolrPhpClient.r22.2009-11-09.tgz"

libraries[SolrPhpClient][destination] = "modules/apachesolr"

Page 17: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Module Builder

Examples:

drush mb my_module menu cron nodeapi

drush mb my_module menu cron --write --name="My module" --dep="forum views"

drush mb my_module menu cron --add

Page 18: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Backup and Migrate

All commands in backup_migrate: (backup_migrate)

bam-backup (bb) Backup the site's database with Backup and Migrate.

bam-backups Get a list of previously created backup files.

bam-destinations Get a list of available destinations.

bam-profiles Get a list of available settings profiles.

bam-restore Restore the site's database with Backup and Migrate.

bam-sources Get a list of available sources.

Page 19: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Part 3

How Drush helps during development process.

Page 20: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Base facts

1. Site URL is http://example.dev.

2. Version of Drupal – 7.

3. Additional modules: admin_menu, pathauto, views.

4. Custom modules: one module with some features will be created. It will use database.

PS: no Drush Make because it's not interesting.

Page 21: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Step 1

ss81@laptop:~/session$ drush dl drupal

Project drupal (7.2) downloaded to /home/ss81/session/drupal-7.2. [success]

Project drupal contains: [success]

- 3 profiles: minimal, testing, standard

- 4 themes: bartik, seven, garland, stark

- 47 modules: drupal_system_listing_compatible_test, ...

Page 22: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Step 2

ss81@laptop:~/session$ mv drupal-7.2/* ./

ss81@laptop:~/session$ mv drupal-7.2/.htaccess ./

ss81@laptop:~/session$ ls

authorize.php cron.php index.php install.php LICENSE.txt modules robots.txt themes web.config

CHANGELOG.txt drupal-7.2 INSTALL.mysql.txt

ss81@laptop:~/session$ rm -r drupal-7.2/

Page 23: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Step 3

ss81@laptop:~/session$ drush si

--db-url=mysql://root:111@localhost/session

--account-name=ss81 --account-pass=qwerty

You are about to create a sites/default/files directory and create

a sites/default/settings.php file and DROP your 'session' database

and then CREATE a new one. Do you want to continue? (y/n): y

Starting Drupal installation. This takes a few seconds ... [ok]

Page 24: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Step 4

ss81@laptop:~/session$ drush dl admin_menu views pathauto token

ss81@laptop:~/session$ drush en -y admin_menu views pathauto token

The following projects have unmet dependencies:

views requires ctools

Would you like to download them? (y/n): y

Project ctools (7.x-1.0-alpha4) downloaded to /home/ss81/session/sites/all/modules/ctools. [success]

...

That's all. We installed a site! Let's create a custom module.

Page 25: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Step 5

ss81@laptop:~/session$ drush mbdl

Hook files have been downloaded to public://hooks and processed.

We need to download hooks definitions before we can generate a module. There are 33 files with

different hooks, so this could be used as a good manual.

Page 26: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Step 6

ss81@laptop:~/session$ drush mb my_module menu permission

user_load --write --name="My module" --desc="My test module“

--pachage="test" --noi

Proposed my_module.module:

…code of the module...

Proposed my_module.info:

…code of the info file...

Page 27: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Helpful commands

drush dre -y my_module

drush sql-dump > dump.sql

drush -y sql-drop

drush -y sql-cli < dump.sql

drush cc all

drush scr test.php

Page 28: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Helpful links

http://drupal.org/project/drush

http://drush.ws

http://groups.drupal.org/drush

http://drupal.org/taxonomy/term/4654

http://drush.ws/resources

Page 29: Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011

Questions

Email: [email protected]

Skype: sergei.stryukov

Drupal: http://drupal.org/user/228065