Skip to main content

Rules cron based condition code for allowing execution only once

Submitted by amitsedai on
<?php /* * Part of Rules condition code that returns true if the current time during cron is between 6 am and 7 am */ $ji_daily_status = variable_get("ji_daily_report","1"); //Check if the variable is set, if not set it to 1 [First Time] /* * This fragment checks if the time is between 6 and 7, if so enables the flag * If any other time, sets the ji_daily_report so that next time it executes when cron runs between 6 and 7 */ $time = date('H'); // Get the current time /* Any arbitrary time - Checks if the time is not between 6 am and 7 am */ if($time < 6 || $time > 7){

Displaying Errors in Drupal

Submitted by amitsedai on
During testing phase of the system, there are WSOD for whom no logs are available. Devel is one option, but for knowing just what might be the reason, the following changes in the settings.php file will reveal any error that occured. <?php error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); ?>

Drupal Features Update and Revert

Submitted by amitsedai on
Features Update: Update a feature module on your site. This updates the feature module in the site if the components are overriden drush fu
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

Custom Template files for Drupal CCK Forms

Submitted by amitsedai on
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

Submitted by amitsedai on
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

Submitted by amitsedai on
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'

Programmatically Saving File

Submitted by amitsedai on
Get the filename URI path from the dir_name located under public files directory. Save data in the destination. If file exists with the name, replace Get the download link. <?php $dest = file_build_uri('dir_name/'.$filename); $file = file_save_data($data, $dest, FILE_EXISTS_REPLACE); $download_link = file_create_url($file->uri); ?>

Sendmail

Submitted by amitsedai on
You can use the mailq command sendmail -bp command to display a summary of the mail messages queued for future delivery. mailq
OR sendmail -bp
Remove all queued mails from: /var/spool/mqueue cd /var/spool/mqueue/
ls
rm *

-- Source http://www.cyberciti.biz/faq/linux-unix-bsd-clear-sendmail-queue/

Memcache For Drupal in Ubuntu 13.04

Submitted by amitsedai on
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

Submitted by amitsedai on
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 diff -r dir1/ dir2/