Showing posts with label drush. Show all posts
Showing posts with label drush. Show all posts

Tuesday, January 27, 2015

Using coder.module to auto-format your code with drush

Coder  is a one of the best Drupal module to format / clean your Drupal codes.

Find more details about it here

After installed coder module, got to http://your-site/admin/config/development/coder

Select module / theme which is needs to be cleaned and click RUN REVIEWS.

You will get report as listed below.



you can automate this process by one line Drush command (drush coder-format ../path/to/your/module).

// download coder module
drush dl coder
// enable this module
drush en coder // drush en coder -y (Yes by default)
// auto format Or clean code
drush coder-format sites/all/modules/custom/your-module - path to your module

Note: Its cleaning inc,tpl,module,install files. Not cleaning js & css files.
Link to original post.

Tuesday, August 19, 2014

Drush custom command - Drush in our custom module

Drush is a very powerful command line tool to manage Drupal site.

Other than core Drush command, we can also write our own custom drush command to perform some task like cron setup, etc, ...

we can do it by using below 3 steps.

Steps :
1) Write hook_drush_help.
2) Write hook_drush_command.
3) Write drush_hook_command.

1) hook_drush_help.
/**
 * Implements hook_drush_help().
 */
function my_module_drush_help($command) {
  switch ($command) {
    case 'drush:test-import':
     return dt('Import test contents.');
  }
}

2) hook_drush_command.
/**
 * Implements hook_drush_command().
 */
function my_module_drush_command() {
  $items = array();
  $items['test-import'] = array(
    'description' => dt('Import test contents.'),
    'arguments'   => array(
      'arg1'    => dt('An optional example argument'),
    ),
    'examples' => array(
      'Standard example' => 'drush test-import',
      'Argument example' => 'drush test-import 5',
    ),
    'aliases' => array('ti'),
  );
  return $items;
}

3) drush_hook_command.
/**
 * Implements drush_hook_command().
 */
function drush_my_module_test_import($arg = NULL) {
  // print arg if any.
  if (isset($arg)) {
   drush_print($arg);
  } 
  drush_log('importing test contents...', 'ok');
}

Now Goto drush command line interface and try > drush test-import or > drush ti

Friday, October 25, 2013

Drupal backup and restore using Drush

 

Drush is a very poweful command line tool to manage Drupal efficiently.

You can manage your drupal site very well using this tool. 

Starting from Drupal installation, you can 

1) Download themes and modules
2) Enable themes and modules
3) Disable themes and modules
4) uninstall modules
5) Clearing cache
6) Backup root files & database
7) Restore them to new site

Some useful drush commands :

Before running the command, first go to desired directory.

Ex: If you want to enable commerce module, first go to /var/www/docroot/sites/all/modules/contrib
drush dl commerce  - will download the commerce module.
drush en commerce - will enable it
drush uninstall commerce - will uninstall it
drush dis commerce - will disable it&nbsp
drush cc all - will clear all cache&nbsp

Backup and restore :

Backup:

As i said before go to your root directory before running below command.
drush archive-dump --destination=/var/back_up/yoursite_today.com.tar.gz

( or )

drush ard --destination=/var/back_up/yoursite_today.com.tar.gz



 Restore :

drush archive-restore /var/back_up/yoursite_today.com.tar.gz --destination=/var/www/new_site.com

( or )

drush arr /var/back_up/yoursite_today.com.tar.gz --destination=/var/www/new_site.com

When you go to your backup directory, there will be one MANIFEST.ini which will contain backup details as in below.

[Global]
datestamp = "1382704323"
formatversion = "1.0"
generator = "Drush archive-dump"
generatorversion = "6.0-beta1"
archiveformat = "platform"

[default]
docroot = "/var/www/beta_bbd"
sitedir = "sites/default"
files-public = "sites/default/files"
database-default-file = "beta_bbd.sql"
database-default-driver = "mysql"
 
Click here to see more about Drush . Another useful link.


Friday, April 12, 2013

Install drush on windows

 

Drush is a command line shell and scripting interface for Drupal. More

 

How to install (click here to see more) drush on windows ?


Steps to install :


Very simple steps to install drush on windows.

1) http://drupal.org/node/594744

2) See this image for more help

install drush
You can use the above link to see more


after completing these steps goto step # 3

3) open cmd - goto xamp /htdocs - > drush dl drupal (Will down load drupal package)

4) move to specified path where do you : xamp / htdocs / drupal

5) goto xamp /htdocs/drupal -> drupal si --help

si(site install)

Ex:
drush site-install
--db-url=mysql://root:pass@localhost:port/dbname

6) Example code :

C:\xampp\htdocs\drupal-7.20>drush si standard --db-url=mysql://root:""@localhost
:port/kali --db-su=root --site-name ="kalidas site"

Note : kali is my db name

thats it. Drupal will be installed in your machine.

7) see below image for more help 


install drush on windows
Install drush on windows