"We needed technical guidance and support and thanks to the team at Three Rock we now have streamlined processes and can manage the project with ease."

Steve Sherlock: Managing Director 'Oodles' car hire comparison web site

Today's Tech News

Warning: Creating default object from empty value in /var/www/threerock/modules/mod_newsticker/helper.php on line 50
Microsoft Inks UC Deal With Polycom
Under a multi-year agreement unveiled Monday, Polycom will begin shipping...
IT Earnings Way Up at Job Site Elance
Google App Engine, HTML5, search engine optimization and social media...
Google, Verizon Posit Net Neutrality Accord
The two Internet and communications giants have put aside their...
Tech Stocks Gain Despite HP's Plunge
HP investors had a bad day, but the rest of...
New Federal Data Breach Bill Debuts in Senate
The new bill is getting early support from prominent Democrats...
Technical Tips
Virtuemart States for Australia

Modifying an out of the box installation of Virtuemart for the Australian market where addresses have a two and three character state code ie QLD, NSW, TAS, WA, SA, NT etc.

This is a fairly simple fix and works a treat for Virtuemart 1.14

Three simple changes require. One change each for the following two file



In each file search for the first occurrance of the word 'state'.

You will find the default is using state_2_code

In each file, change it to state_3_code

The next file to update is


Again, all occurrances of state_2_code need to be changed to state_3_code 

Another little fix I used is where no City value is entered, an ugly looking comma is displayed. To stop this, come a few lines above the state change you've just made. Find the line that has the text

echo $db->f("city");

Underneath it you'll find the culprit, a line that just blindly outputs a comma

echo ', ';

Just above the comma culprit place the following 'if' condition.

if($db->f("city") != "")

so your code should look like this:

if($db->f("city") != "")
echo ', ';

 The address section of the file now looks something like the following

<td nowrap="nowrap" width="10%" align="right"><?php echo $VM_LANG->_('PHPSHOP_ADDRESS') ?>: </td>
           <td width="90%">
            if($db->f("address_2") != ""){
                 echo "<br />";
           <td nowrap="nowrap" width="10%" align="right"> </td>
           <td width="90%">

                echo  $db->f("city");
                echo "<br />";
             // for state, can be used: state_name, state_2_code, state_3_code
             if($db->f("state_3_code") != ""){
                echo " ";
                echo "<br />";
             // for country, can be used: country_name, country_2_code, country_3_code
Now you've updated the code, your 3 letter states will be listed with three letters.

But hang on!! What about NT, SA and WA?

Unfortunately they get changed to NOT SOA and WEA. Not what we want.

To fix this, log into your Virtuemart site as an administrator.

Select the 'Admin' menu option, then List Countries.

Click the '[List States]' suboption against the country name.

n here you can enter the correct values for the 3 character value for each state.

Capistrano without root privileges

Given a user with sudo (but not root) access on a remote box, the following deploy.rb script will perform a capistrano deploy of a ruby application:


1. You're using 'git'. Although svn can be used, the script targets a git setup.

2. You're using mongrel_cluster. Change the script accordingly if using passenger etc.

3. The application being deployed is dropped into a subfolder/subdirectory on the remote server. You can remove the task :recreate_public_link if you're deploying to the root of a virtual directory.

4. A user and group called 'mongrel' has been created on the remote server. This owns the running mongrel_cluster processes. Relevant permissions are set by the script.

# deploy.rb - controls deployment setup/configuration
# using the capistrano or 'cap' deployment utility.
# requires mongrel_cluster recipes to allow restart of mongrel cluster
require 'mongrel_cluster/recipes'

set :application, "rentmanager"
set :user, "peter"
set :web_user, "apache"
set :location, ""

# If you are using Passenger mod_rails uncomment this:
# if you're still using the script/reapear helper you will need
# these http://github.com/rails/irs_process_scripts

# namespace :deploy do
#   task :start do ; end
#   task :stop do ; end
#   task :restart, :roles => :app, :except => { :no_release => true } do
#     run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
#   end
# end

ssh_options[:forward_agent] = true

default_run_options[:pty] = true
set :scm, "git"
set :scm_user, "git"
set :repository,  "#{scm_user}@#{location}:/usr/local/share/gitrepos/#{application}.git"
set :scm_passphrase, "your password" #This is your custom users password
set :git_shallow_clone, 1
set :deploy_via, :remote_cache
set :branch, "master"
set :use_sudo, true
set :site_root, "app/rentmanager"
role :app, location
role :web, location
role :db, location, :primary=>true
set :deploy_to, "/var/www/html/test.threerock.com/#{application}"

#mongrel details
set :mongrel_conf, "#{deploy_to}/current/config/mongrel_cluster.yml"
set :mongrel_user, "mongrel"
set :mongrel_group, "mongrel"
set :runner, nil
set :mongrel_clean, true  # helps keep mongrel pid files clean

# migration parameters
set :rake, "rake"
set :rails_env, "production"
set :migrate_env, ""
set :migrate_target, :latest

before "deploy:update_code", "custom:set_permissions_for_checkout"

before "deploy:migrate", "custom:set_permissions_pre_schema_dump"
after "deploy:migrate", "custom:set_permissions_post_schema_dump"

before "deploy:migrations", "custom:set_permissions_pre_schema_dump"
after "deploy:migrations", "custom:set_permissions_post_schema_dump", "deploy:cleanup"

before "deploy:symlink", "custom:get_current_ownership"

after "deploy:symlink", "custom:update_application_controller",

namespace(:deploy) do

  desc "Restart the Mongrel processes on the app server."
  task :restart, :roles => :app do
    sleep 2.5


namespace(:custom) do

  desc "Change ownership of target folders and files to current user"
  task :set_permissions_for_checkout, :except => { :no_release => true } do
    #chown of files to current user
    sudo "chown -R #{scm_user}:#{scm_user} #{deploy_to}"

  desc "Change ownership of target folders and files to current user"
  task :set_permissions_for_runtime, :except => { :no_release => true } do
    #chown of files to current user
    sudo "chown -R #{web_user}:#{web_user} #{deploy_to}"
    sudo "chown #{mongrel_user}.#{mongrel_group} -R #{deploy_to}/current/tmp/pids"
    sudo "chown #{mongrel_user}.#{mongrel_group} -R #{deploy_to}/current/log"
    sudo "chown #{mongrel_user}.#{mongrel_group} -R #{shared_path}/pids"

  desc "Recreate link to serve public folders when hosting within subfolder"
  task :recreate_public_link do
    run <<-CMD
      cd #{deploy_to}/current/public && sudo ln -s . #{application}

  desc "Take temporary ownership of current folder to allow symlink updates"
  task :get_current_ownership do
    sudo "chown #{user}:#{user} #{release_path}"

  desc "Take temporary ownership of current folder to allow symlink updates"
  task :yield_current_ownership do
    sudo "chown -R #{web_user}:#{web_user} #{release_path}"

  desc "Change ownership of db folders and files to current user"
  task :set_permissions_pre_schema_dump, :except => { :no_release => true } do
    #chown of files to current user
    sudo "chown -R #{user}:#{user} #{release_path}/db"

  desc "Change ownership of db folders and files to current user"
  task :set_permissions_post_schema_dump, :except => { :no_release => true } do
    #chown of files to current user
    sudo "chown -R #{web_user}:#{web_user} #{release_path}/db"

  desc "Update application.rb to application_controller.rb"
  task :update_application_controller, :roles => :app do
    run <<-CMD
      cd #{deploy_to}/current/ && sudo rake rails:update:application_controller
  task :config, :roles => :app do
    run <<-CMD
      sudo ln -nfs #{shared_path}/system/database.yml #{release_path}/config/database.yml

  desc "Creating symbolic link (custom namespace)"
  task :symlink, :roles => :app do
    run <<-CMD
      sudo ln -nfs #{shared_path}/system/uploads #{release_path}/public/uploads



</end of article>

Setup Git Local and Remote repositories

Here at Three Rock, we like to encourage remote working among our developers. This involves a level of discipline in terms of source control. We use both subversion and Git as our tools of choice but we're finding Git is becoming more the norm. The rationale behind this is the subject of many on-line debates. The purpose of this article is to take a developer through the steps needed to set up a repository oh a local machine, do the same on the dev server (a centrally shared resource) and get the two repositories talking to each other.

Configuring Git project in Three Rock environment


A Git server has been set up on a box called bluelight. This box is available to the network as git.threerock.com.

A git user has ben created on the server called 'git'. This user has access to the folder where the git repositories are stored.

The Steps: 

1.On your dev machine create your code project using whatever tools you need.

2.Initialise this working project under the git version control system

$ cd ~/projects/[myprojectname]
$ git init
peter@peter-desktop:~/Projects/rentmanager$ git init
Initialized empty Git repository in /home/peter/Projects/rentmanager/.git/

3.Add whatever work you've done to the repository

$ git add app/
$ git add docs/

4.Check the files you want added have been added

$ git status
# On branch master
# Initial commit
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#    new file: app/rentmanager/,

5.Open a SSH session to bluelight – (the central git repository server)

$ sudo mkdir /usr/local/share/gitrepos/[myprojectname].git

6.Obviously substitute your real projectname and don't forget to leave the .git extenstion
7.Initialise the repository under the new folder

$cd /usr/local/share/gitrepos/[myprojectname].git

[peter@bluelight myprojectname.git]$ sudo git init
Initialized empty Git repository in /usr/local/share/gitrepos/myprojectname.git/.git/

8.Change ownership of the repository to the system git user

$cd ..; sudo chown git.git -R /usr/local/share/gitrepos/[myprojectname].git

9.Return back to the local dev machine and add reference to the new 'remote' repository from the base directory of the project.

$ git remote add remote ssh://git at git.threerock.com/usr/local/share/gitrepos/myprojectname].git

10.Here the 'git remote add' part says add a reference to a remote repository. The second 'remote' is the friendly name I want to use when referring to the repository on the git server

11.Now commit the local files to the local repository – Note: Step 3 was only an add, not a commit.  When you commit you'll be prompted (or you can enter it as a-m option) to enter a message to be used as a comment.

peter@peter-desktop:~/Projects/myprojectname$ git commit
Created initial commit 633fd3c: initial checkin of project core and data migration files

12.It's time to test the new remote repository by 'pushing your local repository info up to it. This is done using git push

peter@peter-desktop:~/Projects/myprojectname$ git push –dry-run –all --repo=remote
fatal: 'origin': unable to chdir or not a git archive
fatal: The remote end hung up unexpectedly

Didn't quite go to plan – so let's see what's wrong

peter@peter-desktop:~/Projects/myprojectname$ git remote show remote
The authenticity of host 'git.threerock.com (' can't be established.
RSA key fingerprint is 5a:ce:6e:a4:78:d5:01:50:36:2b:bb:12:67:e1:be:53.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'git.threerock.com' (RSA) to the list of known hosts.
git at git.threerock.com's password: 
* remote remote
  URL: ssh://git at git.threerock.com/usr/local/share/gitrepos/myprojectname.git

let's try again

$ git push –dry-run –all –repo=remote
git at git.threerock.com's password: 
To ssh://git at git.threerock.com/usr/local/share/gitrepos/myprojectname.git
[new branch]      master -> master

looks like it will work so remove the dry-run parameter

$ git push –all –repo=remote

</end of article>