Directory Image
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.

5 Excellent Tips for Drupal Development

Author: Deepa Ranganathan
by Deepa Ranganathan
Posted: Apr 13, 2015

It's normal to have a love-hate relationship with the different development platforms. Drupal is no different, and having a deep relationship with this platform only helps you in creating good designs with excellent backend. When you begin using this platform, you are just starting out. It is your "getting to know" phase where the platform tells you all that you need to know. Once, this phase is over, you move on to having a proper relationship with the platform.

When you are moving between these two phases, it is essential to know the different tricks that might save your day. Here are five such tips that might help you with developing a website using Drupal.

Undefined Index

Most times when you go ahead with installing a distribution and follow it up with a Drupal update, you get an error that reads unidentified index:distribution_name. You can get rid of this error from your Drupal based website in two ways, both of which are given below

Add the below code to includes.inc or install.inc

if (! array_key_exists('distribution_name', $info)) {

$info['distribution_name'] = 'Drupal';

}

The other way to solve the issue, without disturbing the core, is to tackle the database. Once you have solved the issue within the database, you can clear the cache and move on. To make changes in the database, use the following code

UPDATE 'MYDATABASE'.'system' SET 'status' = '1','info' = '' WHERE 'system'.'filename' = 'profiles/MYPROFILE/MYPROFILE.profile';

Database Backup

There are different ways to create a backup for your website, which eventually depends on the size of your website.

In case you have a small website, you can use the backup and migrate module available with Drupal to backup your website.

In case of a large site, this module may not function in a proper manner for you. The best way to create a backup in this case would be to go back to the terminal and use this code

mysqldump -u root -p[root_password] [database_name] | gzip> dumpfilename.sql

In case you don't have the necessary database credentials available, you will need to use drush.

drush sql-dump --gzip --result-file

Drush is known to organize your system files during backup which can be called an advantage for you. You will see that code backups and other backups are organized into their specific directories.

Transferring Files

When you are moving between a server and your local system, your main concern would be broken images. How do you work with files when you need to move back and forth between the server and your local system?

As a regular practice, you upload the content and images to the production server, take a code and features backup and move the database to the local system. Along with the database, you will also need to move the files directory to the local system if you plan on avoiding the broken images. Drush definitely helps in transferring the files easily, but you will eat up a lot of storage space on your system with this method.

So, what is the other available technique to perform this task? Use the stage file proxy module and add the below code to settings.php file

$conf['stage_file_proxy_origin'] = 'http://example.com';

This module transfers the files that you truly need on your local system, thus avoiding unnecessary transfer of files. This module also serves the 301 redirect to your files present on the server. With this mode redirect, you can easily view the files on your local system without creating a local file directory.

Local Settings

The local settings.php file is of importance to those who work in a team development environment. Most files are stored centrally and pulled to local machines only when required. The only file that is not updated across the different systems and environments is the settings.php file. The settings cannot be kept in the central system as that can make the file vulnerable. Secondly, settings required by individual system would be different, and that is the reason it is localized.

To the settings.php file add the following code to create your local settings.php file

@include('local.settings.php');

Now add the local settings file to your central repository's.gitignore

Comparing Modules

When you are asked to make changes in an existing site, you first ensure that you have taken a backup of the database. Once you have done that, you can begin with the changes. There are chances that you may find something amiss when you are updating the website database. How would you know what went wrong- are you missing modules, or is there something wrong with the.gitignore? How will you know that?

First upload the original database, then use the code below and compare the original and modified database with the help of drush.

drush pm-list --status=enabled --type=module --pipe> enabled_modules_now.txt

Now use a diff checker available online to do the comparison check. Diffchecker.com is a great way to compare, and it will give you the details on the modules that were enabled earlier and which are disabled now, in the updated version.

About the Author

Deepa is a technical writer with Semaphore Software.

Rate this Article
Leave a Comment
Author Thumbnail
I Agree:
Comment 
Pictures
Author: Deepa Ranganathan

Deepa Ranganathan

Member since: Mar 29, 2015
Published articles: 42

Related Articles