Alex Moreno

A Drupal Developer in London

get current drupal theme

very simple:

        global $theme_key;

      echo $theme_key;


if we need more information, we can use this:

       $themes = list_themes();

       $theme_object = $themes[$theme_key];


        // print all the object fields




changing vhost.conf without restarting apache

Sometimes you need to change some parameters to your apache virtual host. Then, when you need to check the changes, in plesk you'd probably will have to execute the next command to see the changes:

/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain

Otherwise, restarting apache (/etc/init/apache2 restart) could not make the trick.

I allways forgot this little trick... never more, because Programadores Web will remind it me :-).


Programadores drupal y php en España

De verdad que España me parece cada vez más lejana. Estoy viendo una oferta de trabajo y de verdad que los sueldos son "tercermundistas".

El país no va a salir de la economía agro-inmobiliaria en la que se ha basado hasta ahora si se está ofreciendo por un senior lo que en Londres se ofrece para un junior de cualquier tecnología. Menciono Londres por poner un ejemplo que conozco bien (porque vivo y trabajo en Londres), pero en el resto de Europa ocurre exactamente igual.

Muchos podréis argumentar que el coste de la vida aquí es muy superior... sin embargo no es así. Proporcionalmente la carne, la leche, el periódico, ... las cosas básicas cuestan lo mismo que en España... la vivienda tres cuartos de lo mismo, si quieres vivir en el centro de Madrid no vas a pagar mucho menos de lo que pagarías por el equivalente en Londres.

Así pues, ofreciendo 25 a 30 mil euros a un senior, nada menos que un senior, como va España a atraer talento? Ese mismo rol en uk se está pagando entre 45 y 60k libras, podéis hacer el cambio a euros.

Lo más sangrante es cuando se lee en las ofertas de trabajo, título mínimo fp. Pero vamos a ver, si necesitas un ingeniero de software no necesitas un arquitecto de bases de datos... si estás buscando alquien que sea capaz de resolver cualquier problema, y que salga barato, posiblemente esa persona no vaya a poder centrarse en desarrollar productos de calidad (sino en escribir código todo lo rápido que se pueda y en resolver problema tras problema).

No es el camino mi vieja, querida (y cada vez más lejana) España :-(.


Apache Solr + Drupal

Download the apachesolr module from, and put it in sites/all/modules:

download solr-php-client, version 22

and uncompress it in the apachesolr module directory.

Ready to activate the module, but we will did not installed the Apache server, so the module will not work.

Now, as you guessed, it's time to install the apache solr server. Download one of the latests releases:

Remember to download the binary files, not the src directory. You'll know that you have the correct tar if you have an example directory with a .jar file.


Now, time to move all these files to a .bak version in conf directory



  • schema.xml,
  • solrconfig.xml,
  • protwords.xml


then, copy these files from your drupal module directory.







paging results in Drupal

Paginating the results in Drupal is incredible incredible easy. You just have to remember the two "magic functions":


  • pager_query($sql, $count);
  • theme('pager',10);


pager_query substitutes the typical db_query. Just something like that: 


  • // $resource = db_query($sql);  // -> old sentence without pager
  • $resource = pager_query($sql, $count); // -> pager


Then, we simple come back to the function that is called by our hook_menu, and we change:

  • return theme('list_products')


  • return theme('list_products') . theme('pager',10);


It couldn't be easier, could it? :-). In fact it is harder to undertand the documentation and the different howtos and tutorials which you can find than the process itself.

archlinux and vbox: sharing folders

This days i'm discovering a new Linux flavour, which it remembers me a lot to another old friend: Gentoo. It has a really similar way of installing, it's very very customizable like Gentoo, and it's quite minimalistic. I'm speaking about Archlinux.

I have to say that this days I was thinking in changing from more than 3 or 4 idilic years with Debian/Ubuntu to a more customizable system. I really don't like the last change which Ubuntu has made on the Desktop, and I really loved when I had the possibility of using last releases of software when using Gentoo (5 or 6 years ago).

So, the possibilities were mainly Gentoo... and my recent Archlinux discovery. Anyway, this is another story.

The fact is that I thought that working with Arhclinux was going to be more harder. Far from the reality. The installation is faster and not too much complicated, unlike Slackware, it has a powerfull package system with dependency resolution, and it is very customizable, so I can build it as fast as I want or as heavy and nice graphic looking as i prefer.

An example of how easy it is to do some things is shaing a folder with the vbox, (something that a fully advice against, unless you have no choice).

In the guest / Arhclinux side it was as simple as installing the module and activating:

  • pacman -S virtualbox-guest-modules
  • pacman -S virtualbox-guest-utils
And finally:
  • modprobe -a vboxguest vboxsf vboxvideo
  • systemctl start vboxservice.service
Enjoy :-)

ERROR 2013 (HY000): Lost connection to MySQL server

Have you ever had a big (and when i say big I mean BIG) database which you need to import in a sql file?

If so, you'll probably have found this issue (or even you are having the problem just now and you are reading this looking for a solution):

ERROR 2013 (HY000): Lost connection to MySQL server

This uses to happen when trying to import the dump with the mysql -u command:

mysql -u root -p database < databasetoimport.sql

You can try to play with the my.ini settings, but a best secure solution is just to do the import from the mysql own console. How? easy.

1. go to the place where your sql is. Then log in mysql:

mysql -uroot -p

2. create the database if needed:

create database mynewdb

3. Change to it:

use mynewdb;

4. and finally, import it:

source databasetoimport.sql

Wait and hopefully the problem will not appear again.

The reason is simple. Mysql is designed to have this behabiour of closing the connection dealing with external scripts, like php or the own mysql command. If you are executing the import from inside the console, the problem will not appear.

Installing capistrano in Centos

Very very easy in CentOS, just like it would be in a Debian system:

# yum install ruby -y

# yum install rubygems -y

# gem install capistrano

Really, it couldn't be easier. Next step, just having fun with Capistrano :-)


Upgrading two git repositories automatically

There is a simple way of upgrading or executing a command immediatly after a push has been done.

We just need to go to the server repository (the one which is going to receive the push), and enter in hooks (.git/hooks or hooks if it's a bare repository).

Then, we rename the post-receive.sample to post-receive, without extension, and add this content:

echo "********************"

echo "Post receive hook: Updating User Staging"

echo "********************"

cd ../live


git pull origin master

echo "********************"

echo "Post receive hook: Updating User Staging"

echo "********************"

You'll just have to change the ../live path with the place where your live git code lives, and the next time you make a commit, the live directory will be automatically updated with a git pull.

It is not the perfect way of going live, is my case this is a staging server, so it's fine. If you need to go to "real" live, Capistrano is what you are looking for. We'll speak about it next weeks.


Capistrano config.rb

set :application, "bounty app"

#set :repository,  "localhost:/var/www/git/bountyrepo"

set :repository,  "localhost:/var/www/git/blessed"

set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names

# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`


default_run_options[:pty] = true

set :use_sudo, false

#role :web, "localhost"                          # Your HTTP server, Apache/etc

#role :app, "localhost"                          # This may be the same as your `Web` server

#role :db,  "your primary db-server here", :primary => true # This is where Rails migrations will run

#role :db,  "your slave db-server here"


#set :deploy_to, "/var/www/html/staging"

task :staging do

  role :web, "localhost"

  set :deploy_to, "/var/www/html/staging"

  #set :deploy_via, :remote_cache

  #after('deploy:symlink', 'cache:clear')


task :live do
  role :web, "localhost"
  set :deploy_to, "/var/www/html/live"
  #set :deploy_via, :remote_cache
  #after('deploy:symlink', 'cache:clear')
task :live2 do
  role :web, "localhost"
  set :deploy_to, "/var/www/html/live2"
  #set :deploy_via, :remote_cache
  #after('deploy:symlink', 'cache:clear')
# if you're still using the script/reaper helper you will need
# If you are using Passenger mod_rails uncomment this:
# 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
namespace:deploy do
    task:start do
    task:stop do
    task:finalize_update do
        run "chmod -R g+w #{release_path}"
    task:restart do
 after "deploy:restart" do
   #add any tasks in here that you want to run after the project is deployed
     run "rm -rf #{release_path}.git"