Wednesday, January 11, 2012

Drush : Set password, watchdog entries and run sql-query

The more you learn about Drush, the more you will love it. Generally most of the developers use Drush only for download modules, install modules and clear cache. But there is more to Drush than that.

1. You have a Drupal instance and you don't remember the password for the admin.

drush user-password admin  --password="IamNotadmin$123"

converting the password to MD5 and storing it in DB drush will take care :)

2. Recently I had an instance of Drupal to which I was not able to login. I wanted to check out the watchdog entries, but as I was not able to login I had to check it from db. I thought drush may help me out and it did.


drush watchdog-show  

You can also use watchdog-list which will give you more control. This throws up a set of options like cc does and you can select what you want
drush watchdog-list 

3. If you are drupal developer and you are using, it's a safe bet to assume that you are using sql-cli. But the pain with that is that you need to remove the braces from the table names to actuall run the query.


drush sql-query "SELECT u.name, u.status from {users} u where uid = 1"



And you can see the result of the query ;) Saves a  lot of time. Doesn't it?

Tuesday, January 3, 2012

Drupal 6 : PHP snipper to get a list of all the content types with respective fields.

Here is small snippet of php code that will help you get a list of all Content types in an instance along with the fields within the content type. It came handy to me when I wanted to give a list of conent types with fields to one of my clients for remapping them to the new structure that they wanted to build.

  
  $content_types = node_get_types();
  $output = '';
  foreach($content_types as $content_type => $content_type_object) {
    $output .= "" . $content_type_object->name . "";
    $output .= '
';
    $fields = _content_type_info();
    $fields = $fields['content types'][$content_type]['fields'];
    $ouput = '';
    foreach ($fields as $field_name=>$field) {
      $output .= $field['widget']['label'];
      $output .= '
';
    }
  }