Category Archives: Drupal 7

Make your Drupal 7 faster by removing all revisions

Maybe you were in the same case as me. I got a big database full of revision rows in every revision table with their usefulnessofmeter beyond zero. In fact, I’m pretty sure revisions are not needed in 99.999% Drupal installation.

So, I tried to remove them by disabling the create a revision default option in my content type settings but it didn’t change anything. When you check the database manually, you can see every field has it’s own revision table. If you install the field_collection module, every collections and their fields have a revision table too. I got millions of revisions in some tables for just a few nodes. It was hell. Read More →

Drupal 7 Optimizations, Make it faster in one single line !

I just discovered something today that should interest lots of people :P Did you know Drupal saves each notice and error in his report logs ? If you have a custom script that generates for example 1000 notices, Drupal does 1000 notice database inserts before you get results. The script execution will never fail and you won’t be warned of these. Read More →

How to deal with translated nodes programmatically

I had to import four different languages nodes into my Drupal 7 installation programmatically. It’s easy when you know where to begin with.

First, you have to enable different languages you will use into your Drupal administration. For example, I used

How to create a user programmatically in Drupal ?

Why would you need to load or create a Drupal user from your PHP script ? Because you can associate processes and node importations with a user to identify them quickly into the Drupal content administration ! Then, it’s faster to create it programmatically if it doesn’t exist.

If you want to create or retrieve a Drupal user from your PHP Script, pretty simple: Read More →

How to use Drupal into a custom PHP Script ?

I had to make a Drupal data importation script in PHP to be processed every day. You have to follow a few steps to succeed.

First I had to remove PHP time out and memory limits to avoid failures. Drupal script can take a long time to execute, so many tables, queries, caches and joins every where… Read More →

How to deal with your custom module updates ?

At first, it can be hard to maintain and update your custom module but when you understand how it works, it’s pretty easy.

In your module.install file you will create a function for each update you want to make, for example, you forgot to add an agenda field in your content type : Read More →

Remove all nodes for a content type

If you want to clean your Drupal installation and remove everything that belongs to a content type, it is better to use a Drupal query. You shouldn’t try to remove them directly from a custom SQL Query. Here is how you can use Drupal db_query function: Read More →

How quickly send a mail with a Drupal module ?

You made a PHP script associated to a Drupal module and you want to be alerted of custom special events or big fails

In your module file, just implement the hook_mail() like this : Read More →

Create a node content type programmatically

If you’re a new Drupal user, you may have already created a fresh content type manually to organize your site correctly. But what happens if you want to create this content type with your module installation and don’t want to do it manually each type you install it on a new website ?. Here is how to create a content type programmatically with Drupal 7.  Read More →

Add taxonomy with custom fields programmatically

Taxonomies are very useful in Drupal when you need to organize your content but sometimes the default and available fields are not enough. Here is an example how you can add some to you taxonomy vocabulary.

If you want to create a taxonomy from a PHP script, here is what you could do: Read More →