Deploy last Git tag from a capistrano deloyment script

We are using capistrano and git to deploy our application. Sometimes we need to deploy specific git branch or a git tag in our application.

To tag a release using git is very simple.

git tag -a production-release-28-08-2013 -m "falgunapp release 1"

It will create an annotated tag with name “production-release-28-08-2013″

To see available tag list. you can use

git tag

After tagging your release you have to push it to remote server.To push a single tag use

git push origin production-release-28-08-2013

If you have a lot of tags that you want to push up at once, you can also use the --tags option to the git push command. This will transfer all of your tags to the remote server that are not already there.

git push origin --tags

if you want to know more about git tag then check out the link below

And now to deploy most recent tag you have to change at deployment script. At deploy.rb file you have a line

set :branch, 'develop' #which will deploy "develop" branch.

You have change it to deploy recent tagging release

set :branch do
    default_tag = "production"
    last_tag = `git tag`.split("\n").last
    last_tag = default_tag if last_tag.empty?

This will deploy the last tagging release. If don’t find any tag then it deploy production branch by default.

1 Hour Crash Course To Develop A Website Using Drupal 7

What Is Drupal

Drupal is an open source content management platform powering millions of websites and applications. It’s built, used, and supported by an active and diverse community of people around the world.

You can check it from

Why Choose Drupal?

Use Drupal to build everything from personal blogs to custom web applications. Thousands of add-on modules and designs let you build any site you can imagine. Drupal is free, flexible, robust and constantly being improved by hundreds of thousands of passionate people from all over the world.

Installing Drupal 7

Before beginning to install Drupal 7, you will need a web server running the PHP and Apache. You can also use IIS on Microsoft Windows, but the Apache server is preferred and you will be able to obtain support from the community more easily if you use the Apache.

To install Drupal check out this link

Installation Complete

If you have installed drupal successfully then please check this link We are going to make this site using Drupal 7.

Here goes our Website Mindmap :-

Our challenges while building this website :-

We don’t have too much challenges here to build this website. We are going to develop some specific module where contributed modules fulfil our most of the needs.

Content Slide Show has a lot of modules that can create image and content slide show easily. Here I will develop our own content slide show using CCK, VIEWS and Jquery so you can understand how VIEWS, CCK works.

Twitter Widget Module has a lot of modules that can help you to use twitter widget. But I will develop this module to show you how to develop a custom module.

Data Architecture :-

The site uses one content type SlideShow. Drupal Block system use to make Intro and Contact Block. For twitter widget we will develop a custom module. And Menus, Header and Footer will be developed using Drupal Basic settings.

You can check the link below to know what is Content Type and Block in Drupal.

1. Block

2. Content Type

Module Used :-

A large number of modules built by the Drupal community. I have given some key modules which I use to develop this website.








You have to download ckeditor library to use ckeditor module. You have to create a library folder at /sites/all/modules/ and keep the ckeditor library into that folder.

Some stuff we built ourselves :-


Our Approach :-

First of all I will develop our theme using static html content. After that I will replace our html content using Dynamic content. Here goes our approach

Step 1

Develop theme named ‘Personal’.

Step 2

Change Website Header and Slogan of this site.

Step 3

Create our top and primary menu

Step 4

Develop our Content Slide show

Step 5

Create Intro Block

Step 6

Create Contact Block

Step 7

Develop TwitterWidget Block

Step 8

Change Footer Info.

Step 9

Enjoy and treat me a ice cream or chocolate :) I love it

Ok take a break and drink a cup of coffee, lets start……..

Step 1: Develop Our Own theme named ‘Personal’

If you are new to Drupal theme please take a look here first I think I will waste my time if I have to explain it to you. This link describes all the things about Drupal theme structure and file system. So Let’s start to develop our theme.

First of all Download the HTML template from

Unzip the folder and then copy the folder to sites/all/themes/

Now rename the folder to  “personal” .

Browse the personal folder and create a file named ‘‘.

Open the file and paste the code below and saved.

name = Personal
description = A personal Drupal theme made by Community
package = Core
version = VERSION
core = 7.x

stylesheets[all][] = css/style.css

scripts[] = js/easyslider1.5.js

regions[header] = Header
regions[content] = Content
regions[content_slide_show] = Content Slide Show
regions[intro_block] = Intro Block
regions[twitter_block] = Twitter Block
regions[contact_block] = Contact Block
regions[footer] = Footer

Create a folder named “templates
Cut the file index.php and paste the file into templates folder
Rename the file page.tpl.php
Open the page.tpl.php file and just keep body’s inner part and delete all the things.

Okay, our theme is ready to install and next we will change the theme during development.
So we are going with an iterative process where design and development run with simultaneously.

Go to your Drupal Admin panel and click on the tab Appearance.
You will see a theme named “personal”. enable and set default the theme.
Browse home page and you will see our webpage with html content.

Okay we have finished our step 1.
Lets move to step 2.

Step 2: Change Website Header and Slogan of this site

Goto admin panel and click on tab configuration and then site information. You have a page, as shown in screen shot.

Change the site name “Raju Mazumder

Change the site slogan as “TDD, Agile and Open Source Enthusiastic” and saved the configuration.

Open the file page.tpl.php from sites/all/personal/templates and change the line like as below.

<div id="blogTitle">
   <h1><a href="#" title="title"><?php echo $site_name;?></a></h1>
   <h2><?php echo $site_slogan; ?></h2>

And Save the file.
Okay we have finished step 2.

Let’s move to step 3.

Step 3: Create Top and Primary Menu

Go to the admin panel and click on structure tab and then click on menus. Here we will use Main menu. Click on list links and you can see that there is Home links available. So We don’t have to create Home menu link.

Create a menu link named ‘My Contribution‘ and give menu path ‘<front>‘ and we will change the menu path when we will create My Contribution Page.

Create another one link named ‘Blog‘ and give the menu path a external ‘‘ and saved the menu.

We have created our menu.

Now we have to create My Contribution page. Go to the admin panel, click on content tab and then click on add content link. Give a title, description.

Click on url path settings and give url alias named ‘my-contribution‘ and click on publishing option and uncheck the promoted to front page and saved.

Go to main menu’s my contribution menu link and change menu path to ‘my-contribution‘ and saved.

Now we have to change the theme file. Open the file page.tpl.php and change the html line using below the line.

<ul id="navigation">
   <li><a href="index.php">Home</a></li>
  <li><a href="/blog/my-contribution/">My Contribution</a></li>
  <li><a href="/blog">Blog</a></li>

repalce with below code

<?php print theme('links__system_main_menu', array(
          'links' => $main_menu,
          'attributes' => array(
           'id' => 'navigation',
)); ?>

Browse the site and you will see the menu links there.

But If you click on the My Contribution Link then you didn’t see any content. Because We didn’t set the template variable content at template file. Here we have to change the template when some one going to a page except home page. We should remove the intro, contact and twitter block from the template. So we can do it easily using “$is_front” variable. It will return true if it is home page.

So change the template file to add the condtion into your template file.

see the below

<?php if($is_front):?>
         //block goes here
      <?php else:?>
         <?php echo render($page['content']); ?>
      <?php endif;?>

Change it later when theme is ready.
Okay we have completed our step 3.

Now Let’s move to the step 4

Step 4: Develop our Content Slide show

First of all we will make a content type for our content slide show. Then we will make view to get content list and  then using template file and view we will make our content slide show.

Let’s create a new slide show content type by navigating to Structure ->Content Types and clicking the “Add content type” link on the “Content types” page. See the screen shot below.

Creating a new content type is relatively simple—enter the appropriate values for the name of the content type (in our
example case, the name is Content Slide Show) and a short description of the content type, and optionally override the label assigned to the title of the Content Slide Show node. In the example, I changed the label from just Title to Coding Tips Title (see the below screen shot).

Click the “Publishing options” tab and uncheck the “Promoted to front page” option, which by default is checked.
On the “Display settings” form, uncheck the box that triggers author information display when an Content Slide Show displayed.
The “Comment settings” form set the “Default comment setting for new content” to Closed.
On the “Menu settings” form, uncheck the “Main menu” check box.

Drupal takes you to the page where you can begin to add new fields to the Content Slide Show content type. See the screen shot below.

Add new text field “Content Tips By” where we will reference book name of coding tips.

I now have all of the required fields for the Content Slide Show content type and
can begin to create using the node creation form, as shown in screen shot.

Add some content using that form.

Create a view to get Content Slide Listing:

Let’s create a view by navigating to Structure ->Views and clicking the “Add new view” link on the “Views” page.

This brings up a basic dialog that can be used to create the general settings for this view, as shown in the following screen shot:

Write “content_slide_show” as name of view and add a brief description on this page.Towards the bottom of this page, select “Node” as view type.

Click on the Next button to bring up the familiar views editing interface:

Note that, at present, we have a blank Defaults display and nothing else. We’re going to work on the Defaults display in this section and after completing view we will create block display for our content slide show.

First things we should tell view about filters. By looking at the Node group in the Filters dialog,In this case, we need to use the Node: Type option so that we can specify Content Slide Show entry. Check this option, and click on the Add button to bring up the following configuration dialog:

Click on the Update button to complete the configuration of this filter .

From the Style settings select style:Html list, Rowstyle: Node and save the view. If everything is going well then you can see the live preview.

Add a block display from the right side menu, give a named ‘slideshow_block‘ and save the view. See the screen shot below.

Our view is ready to go.

By navigating to Structure -> Blocks, you will see a block “content_slide_view: Block”. From the right side drop down, set this block to Content Slide Show region and save the settings.

Go to sites/all/themes/personal/templates and create a file named ‘views-view-list—content-slide-view.tpl‘ and saved.

Copy and paste the line below.

<?php print $wrapper_prefix; ?>
  <?php if (!empty($title)) : ?>
    <h3><?php print $title; ?></h3>
  <?php endif; ?>
  <div id="slider">
  <?php print $list_type_prefix; ?>

    <?php foreach ($rows as $id => $row): ?>
      <li style="position: relative;" id="feature" class="banner"><?php print $row; ?></li>
    <?php endforeach; ?>
  <?php print $list_type_suffix; ?>
<?php print $wrapper_suffix; ?>

And open the page.tpl.php file and replace the “<div id=’slider’>…” to “<?php echo render($page['content_slide_show']); ?>” and saved the file.

Okay our slide show is ready to go.

Step 5: Create Intro Block

By navigating Structure->Blocks and Clicking the “Add Block” link, you have a screenmshot like that.

Set Description, Body and regions “Intro Block” and saved.

Open the file page.tpl.php and replace the “<div id=”columnleft”>…” to “<?php echo render($page['intro_block']); ?>”.

Okay you have a dynamic intro block.

Step 6: Create a Contact Block

By navigating Structure->Blocks and Clicking the “Add Block” link, you have a screen shot like that.

Set Description, Body and regions “Contact Block” and saved.

Open the file page.tpl.php and replace the “<div id=”columnright”>…” to “<?php echo render($page['contact_block']); ?>”.

Okay you have a dynamic contact block.

Step 7: Develop a Twitter Widget Block

Here we will develop a basic module to show a twitter widget. You can customize it more. I just take the username from admin but you can add more settings like color, height,width etc. So Let’s Start.

Navigate to sites/all/modules/custom and create a folder called “twitterwidget”.

Create a file into that directory.

Copy and paste the below code into that file.

name = TwitterWidget
description = "Allows you to setup a twitter widget."
package = Socialization
core = 7.x
files[] = twitterwidget.module
files[] = twitterwidget.install
files[] =

Now we’re ready to create the actual module. Create a file named twitterwidget.module inside your
sites/all/modules/custom/twitterwidget subdirectory.

The first hook that we will implement is the hook_menu() function. We’ll use this function to add two menu items to the administrative menu on our site. We will add a new “twitterwidget” menu item off to the main admin/config menu and a submenu item under “twitterwidget” named “settings,” which when clicked will launch the twitter widget configuration settings page. The values of our menu items are arrays consisting of keys and values describing what Drupal should do when this path is requested. We name the call to hook_menu “twitterwidget_menu”—replacing “hook” with the name of our module. This is consistent across all hooks—

you always replace the word “hook” with the name of your module.

 * Implementation of hook_menu().
function twitterwidget_menu() {

	$items['admin/config/twitterwidget'] = array(
		'title' => 'Twitter Widget',
		'description' => 'Twitter Widget.',
		'position' => 'right',
		'weight' => -5,
		'page callback' => 'system_admin_menu_block_page',
		'access arguments' => array('administer site configuration'),
		'file' => '',
		'file path' => drupal_get_path('module', 'system'),

	$items['admin/config/twitterwidget/settings'] = array(
		'title' => 'Twitter Widget settings',
		'description' => 'To display a twitter widget.',
		'page callback' => 'drupal_get_form',
		'page arguments' => array('twitterwidget_admin_settings'),
		'access arguments' => array('administer site configuration'),
		'type' => MENU_NORMAL_ITEM,
		'file' => '',

	return $items;

Let’s add our hook_block_info so our block appears in the list of blocks on the block administration page I’ll define the title that appears for the block through the info attribute, the status set to True so that it is automatically enabled, region set to twitter_block, weight set to 0, and visibility set to 1 (visible).

* Implements hook_block_info().
function twitterwidget_block_info() {

$blocks['twitterwidget_block'] = array(
'info'=> t('Twitter Widget'),
'status' => TRUE,
'region' => 'twitter_block',
'weight' => 0,
'visibility' => 1,
return $blocks;

Finally, add the view operation using hook_block_view and a custom function that returns twitter widget javascript code when the block is viewed:

* Implements hook_block_view().
function twitterwidget_block_view($delta = '') {

	$block['content'] = twitterwidget_block_contents($delta);
	return $block;


function twitterwidget_block_contents($delta)
    $twitterUserName = variable_get('twitter_username');

    $data = '<h2>twittering..</h2>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        new TWTR.Widget({
            version: 2,
            type: "profile",
            rpp: 5,
            interval: 6000,
            width: 250,
            height: 300,
            theme: {
                shell: {
                    background: "#ffffff",
                    color: "#000000"
                tweets: {
                    background: "#ffffff",
                    color: "#000000",
                    links: "#e32614"
            features: {
                scrollbar: false,
                loop: false,
                live: false,
                hashtags: true,
                timestamp: true,
                avatars: true,
                behavior: "all"
        }).render().setUser("'. $twitterUserName. '").start();

	return $data;

Create another one file named “” into twitterwidget directory. Open the file and write the code below. This code responsible to show settings form. I just add an one field twitter username but you can get more settings by this hook.

 * Form builder. Configure Twitter Widget.
 * @ingroup forms
 * @see system_settings_form().
function twitterwidget_admin_settings() {

	$twitterUserName = variable_get('twitter_username');
	$defaultValue = empty($twitterUserName) ? 'rajuniit' : $twitterUserName;
	$form['twitter_username'] = array(
	'#type' => 'textfield',
	'#title' => t('Twitter User Name'),
	'#default_value' => $defaultValue,
	'#size' => 25

	$form['#submit'][] = 'twitterwidget_admin_settings_submit';
	return system_settings_form($form);

function twitterwidget_admin_settings_submit($form, $form_state)
	$data = $form_state['values'];
	variable_set('twitter_username', $data['twitter_username']);


Navigate to Configuration->Twitter Widget Settings and change the twitter username what you want and saved.

Open the sites/all/themes/personal/page.tpl.php and replace the “

..” to “”.

Okay step 7 complete.

Step 8: Change Footer Information

In Drupal 7 Footer is also a block. So Create a Block to change footer information.By navigating Structure->Blocks and Clicking the “Add Block” link.

Set Description, Body and regions “Footer Block” and saved.

Open the file page.tpl.php and insert ths code “<?php print render($page['footer']); ?>”  into “<div id=”footer”>…”.

Okay you have a dynamic footer block.

Step 9: Treat me a ice cream or chocolate

This is your responsibility how can you complete this step. If you can’t complete this request then you can’t see the complete website.


You can Download the complete website from


Here is some links which I think really a good resource of Drupal related things.


Pro Drupal Development 3rd Edition.

I love this book.

and of course  Its also a good resource to learn Drupal.

RESTful API for Orange HRM

OrangeHRM aims to be the world’s leading open source HRM solution for small and medium sized enterprises (SMEs) by providing a flexible and easy to use HRM system affordable for any company worldwide.

You can checkout orange hrm from

Recently I have worked with a project where I use Orange HRM. My Application use Zend Framework and Doctrine 2. So to integrate Orange HRM into my project I have to build REST API for Orange HRM because they have no official REST API to integrate with third party software.

So Lets see how can you use it with orange hrm.

Steps 1

  1. You can check the documentation from here.
  2. Download the API folder from here.
  3. You can find a example folder where I have written a script how to call this API.

Steps 2

  1. Copy the API folder into your orange hrm root folder
  2. Change the Config file to assign authentication key and secret key
  3. If your base url or local.orangehrm.tld then the API endpoint will be http://local.orangehrm.tld/api/
  4. Thats all. Your API is ready to use.

Here I have created only Two Resources Employee and Location. If you need any other resource you can implement it for you.
Also I have created only GET request. I didn’t implement POST, PUT and DELETE.

How it works


Each REST request against the Orange HRM system requires the inclusion of a specific
authorization API HTTP x-header defined as X-Auth-Key and X-Auth-Secret.


In order to authenticate, you must supply your API access key in the X-Auth-Key and X-Auth-Secret respectively.

Sample Request

GET /api/ HTTP/1.1
Host: local.orangehrm.tld
X-Auth-Key: a86850deb2742ec3cb41518e26aa2d89
X-Auth-Secret: a86850deb2742ec3cb41518e26aa2d89

Sample Response

HTTP/1.1 204
Content-Length: 0
Content-Type: text/plain; charset=UTF-8

Request/Response Types

The Orange HRM API supports JSON data serialization formats. The request format is specified using the Content-Type header and is required for operations that have a request body. If no response format is specified,JSON is the default.

Format          Accept Header        Default
JSON             application/json       Yes

Sample JSON Request with Headers

GET /employee/ HTTP/1.1
Host: api.orangehrm.tld
Content-Type: application/json
Accept: application/json
X-Auth-Key: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb
X-Auth-Secret: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb

Sample JSON Response with Headers

HTTP/1.1 200
Content-Length: 185
Content-Type: application/json; charset=UTF-8
         "empFullName":"raju mazumder",


When an error occurs the system will return an HTTP error response code denoting the type of error.
The system will also return additional information about the fault in the body of the response.
Sample JSON Response

    "serviceUnavailable" : {
    "code" : 503,
    "message" : "Service Unavailable"

The error code is returned in the body of the response for convenience. The message section
returns a human readable message that is appropriate for display to the end user. The root element of the fault (e.g. serviceUnavailable) may change depending on the type of error.

The following is a list of possible elements along with their associated error codes.

Fault Element Associated Error Codes

serviceUnavailable            503
unauthorized                       401
badRequest                          400
itemNotFound                     404

Sample Json Error Response

"itemNotFound" : {
"code" : 404,
"message" : "Item Not Found. Sorry this resource is not available in our system"

I would like to thanks to gen-x-design for his nice post REST API design.

I get some idea from his blog post

You can google it to learn how to design REST API. For your interest I have given here some link


Disclaimer: This is not orange hrm official API  and Documentation. I publish it here for interested developers to improve it.

Hello world!

Hello Everybody!

I have been blogging into stylephp for two years. But I have been thinking for a another domain to share, test and explore my works and experience on an unique web identity. In order to fulfill my desire, I have chosen this site and this domain:!

It’s been 4+ years since I am working with PHP and I am proud to say that I am a PHP dev. But I also love to work ASP.NET(C#) and Ruby. Because I am not strict with one language. I also use JavaScript, CSS, AJAX, and XML. Some of the PHP frameworks I’ve worked with are: CodeIgniter, Zend FrameworkSympony and Javascript library: prototype, jquery. Besides, I’ve been making a few social applications in Facebook and up to now, I love it !

So friends, here I will share what i know and what i want to know from you. My blog is here so that I can know from you and to share my experience with you.

Thats all for now. See you soon with new post :)

Raju Mazumder

FireStats icon Powered by FireStats