Drupal Features Update and Revert

Features Update: Update a feature module on your site. This updates the feature module in the site if the components are overriden

drush fu <feature-module-name>

Features Revert: Revert a feature module on your site. Reverts the basic configuration in the module onto the site removing any custom configurations made at the database end.

drush fr <feature-module-name>

Custom Template files for Drupal CCK Forms

To render a Drupal CCK form in a template file, add the following lines in the currently enabled theme. Assuming the enabled theme to be footheme

For a cck form called external_exam, the theme function can be used to provide a template file called external_exam_form.tpl.php under templates directory.

<?php
function footheme_theme() {
  return array(
   
'external_exam_node_form' => array(
     
'arguments' => array('form' => NULL),
     
'template' => 'templates/external_exam_form',
     
'render element' => 'form'
   
),
  );
}
?>

Rendering a CCK field programmatically

Sometimes we need to render a field when we have a node object containing field values.

field_view_value is a Drupal API that allows us to render any field. Example: Display the Invoice Description Field in a Node Object. The display would take care of any input filter that is applied in the field

<?php
$invoice_description
= field_get_items('node', $node, 'field_invoice_description');
print
render(field_view_value('node', $node, 'field_invoice_description',$invoice_description[0]));
?>

The other way to display the label and data completely rendered by Drupal.

<?php

Find the Largest Table in a MySQL Database


SELECT CONCAT(table_schema, '.', table_name),
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
WHERE table_schema='database_name'

Memcache For Drupal in Ubuntu 13.04

Installation and Configuration of Memcached Daemon and PECL Memcache in Ubuntu for Drupal 7

Steps:

1. Install memcached in the server

sudo apt-get install memcached libmemcached-tools
sudo apt-get install php5-dev php-pear make
sudo pecl install memcache

Latest dev Version of Memcache can be installed via.

# If you haven't already installed PECL memcache
pecl install memcache-beta
# If you wish to "upgrade" to a beta release
pecl upgrade memcache-beta

2. Add memcache.ini in PHP conf.d directory

Handy Linux Commands

Technologies: 

Split: Split a text file in half (or any percentage) on Ubuntu Linux

The following command splits access.log files into multiple files with 6000 lines each

split -l 6000 access.log

Split files into size of 5M each

split --bytes 5M --numeric-suffixes --suffix-length=3 foo.mysql  last_part.mysql

Diff : Get Difference between files and folders
Following command provides recursive difference

Displaying Graph Using HighCharts

HighCharts is a charting library tool made freely available for non commercial usage. Drupal HighCharts 2.x has no other module dependency except that HighCharts library needs to be downloaded from here. There are a huge variety of options made available in HighCharts API which can be used for manipulation and for additional info.

The example below is a Line Chart uses Drupal HighCharts version 2.x

<?php
/* Render Line Charts using Drupal Highcharts 2.x */
function jicustom_chart_render($chart_arr){

$options = new stdClass();

jQuery Mobile Page Load Issue

Technologies: 

Sometimes when we visit a link, specially on mobile, there is a situation when we place a link and reaching a page clicking that link leads to a situation where the jQuery library is not loaded into the browser. This could affect conditional fields and other jQuery widgets.

The solution is to add  rel="external" to the link.

--
Source
http://stackoverflow.com/questions/10389751/jquery-mobile-page-load-issue