Drupal Dump

Drupal Snippets, Hacks and more....

GIT - checking status of master and differences

Before final git pull to LIVE site, it is a good idea to check what is going to be pulled. So to do that

Git fetch
git diff master origin/master

or 

git diff --name-only master origin/master

This should give you more insight on what is going to be pulled in the end, as this marks differences between current master branch on LIVE site and master on github.

Debugging ajax calls/requests

In case ajax calls are making a trouble and developer needs more information about what is happening regarding:

Dumping drupal DB without cache tables

If you want to dump DB from production or develop servers and not include cahce table values for faster importing you can use below script. You need to change site_name variable and DUMPDIR to match what you have and also user/password of DB

Bash script for cloning database on server

If you need to copy DB, lets say from production to develop you can use this script and call it like "develclone.sh original_db cloned_db"
For faster cloning it will exclude cache tables data.

Messages api, make message programmatically for orders

I wanted to add a message to orders when I did some auto approving of orders. To add some trace of that you need to load user which will be the one that did that. Send $values that will be used for token replacement in message and also select which message type you are going to use. In here I made a clone of default message "commerce_order_admin_comment" and used that.

How to style elements that change ids when ajax actions replace them

In drupal, when you have ajax refreshing some content, elements get new ids when they refresh. So some input element that was "edit-get-score"  becomes "edit-get-score-2" then ""edit-get-score-3" etc.
So to match them properly by ID you can use this. Which is CSS attribute selector using sort of a wildcard

Life of a view and what and where to hook or alter

Often I have a need to alter a bit output of a view, either the markup or just query, it's important to know where to hook in a life of a view, here is the list of hooks and alters.
 

Get list of all the hooks your site currently uses

In includes/module.inc, find the module_implements() function (around line 715 in Drupal 7). At the top of the function, just add this below and you will get huge output of all the hooks that are called.

 

function module_implements($hook, $sort = FALSE, $reset = FALSE) {
  drupal_set_message("hook_$hook");
  ......