Blogs

First steps migrating to Drupal 8: drush

There we go. First steps in upgrading (or should I say migrating?) to Drupal 8. Drush is an incredible valuable tool, so this will be basically my first step.

Install the last version of drush, at least Drush 7 which includes support for Drupal8. If you already have drush and don't want to play with current versions, you can download drush 7 via git, and place it in /usr/local/drush-7, for example. Then, create a symlink like that:

ln -s /usr/local/drush/drush /usr/local/bin/drush7

This will create a second version to play safely. Now you also need to install composer:

curl -sS https://getcomposer.org/installer | php

and then, run install inside the new drush folder.

More information about next steps can be found here (basically information about Migrate module, which I will need to study in order to achieve the next steps):

The last steps will be... starting to develop in Drupal 8 :-):

 

Migrating to Drupal 7 (and Drupal 8)

Well, that's it. ProgramadoresWeb is now in Drupal 7. I have been also experimenting in D8, as probably in a very few time I'll be upgrading to D8.

Why migrating to D8? Basically this site is quite simple, there are not too much modules installed and I can afford to migrate some of them or help to migrate them into D8. Of course the main reason is less altruistic: knowledge :-)

categorias: 

Changing Short project name in a Drupal.org project

Typical problem, you have just gained your full project permissions role in Drupal.org, and you make your first mess... you have promoted your so loved first project without changing the Short project name.

Well, you have a problem, but not too big. Drupal.org will not allow you to rename your Short project name, so you will have to create a new one if you don't want to have an ugly url like that: https://drupal.org/project/2062343

Fortunately git can help. You will simply have to:

  • Create a new project, sandbox or not,
  • Go to the "Version control tab" and get the url of your new git project, something like: programadoresweb@git.drupal.org:project/2062343.git
  • Go to the folder of your old sandbox, the project in which you cannot change the Short name, and change the remote for this folder. For my url example, the command will be: git remote set-url origin programadoresweb@git.drupal.org:project/2062343.git
  • Nearly finished. You probably have to merge, as you will have to make your first commit in the new project: git pull
  • And finally, git push origin master will get the job done.
  • Remember to create a new branch, like 6.x-1.x and commit to that one to create a new official, downlodable release of your module. Congratulations :-).

 

Next time, take it easy cowboy ;-).

 

More information:

 

Drupal form api select elements returning integers instead of string

I always have the same problem when using select forms, and I always forget the solution.

Instead of returning an array, like: return $competitions; you have to return a drupal_map_assoc, like this: return drupal_map_assoc($competitions);

Otherwise, when selecting the form in hook_submit you will get a number, instead of a human readable string.

categorias: 

Customize a webform with

categorias: 

Convert dates from UNIXTIME in mysql

Reading a date in mysql can be frustrating, unless your brain is able to convert Dates from UNIXTIME formats. Let's see for example this scenario in Drupal:

SELECT * FROM `node` ORDER BY `node`.`created` DESC LIMIT 0 , 30

If you need to fetch, for example, when it was the last time that a node was created, this format doesn't help too much.

The solution is quite simple, FROM_UNIXTIME( field_with_date )

For example:

SELECT * , FROM_UNIXTIME( created ) FROM `node` ORDER BY `node`.`created` DESC LIMIT 0 , 30

categorias: 

Restart vhost conf without restarting Apache

Changing your vhost.conf and working with plesk? There is no need to restart your whole Apache server and bother your users:

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

Tip of the weekend :-)

 

categorias: 

Using git in bitbucket without password

Look mom, without hands...

First, change this in your .git/config:

old url:

 url = https://USER@bitbucket.org/hispamedios/PROJECT.git

new one:

url = ssh://USER.bitbucket.org/hispamedios/PROJECT.git

 

Edit your .ssh/config, in your local directory, and add this:

 cat .ssh/config
Host YOURUSER.bitbucket.org 
HostName bitbucket.org 
User git
IdentityFile ~/.ssh/bitbucket

The last line is important, so you are indicating your identity file. Now create this file:

ssh-keygen -f .ssh/bitbucket -C "YOURUSER"

And now test it. Go to your local repository, do smart changes in your code and commit them or simply do a "git pull". It should not ask you for password anymore.

categorias: 

Deploying Drupal projects: git + capistrano

 

removing some folders from git, file .gitignore with these contents:

 

# Ignore paths that contain generated content.

cache/

files/

sites/*/files

sites/*/private

 

 

 

Using symbolic links for /files directory:

 

 

namespace:custom do

    task:symlink do

      run "ln -s /var/www/crucerista/sites/crucerista.net/files/ /var/www/crsta/current/sites/crucerista.net/"

      run "echo 'finished'"

    end

end

after "deploy","custom:symlink"

 

 

Related links:

Similar technique, but aplied to Rails apps: http://www.practicalecommerce.com/blogs/post/468-Creating-Symlinks-When-Deploying-a-Rails-Application

Another idea, File Transfer actions in Capistrano: http://www.simonecarletti.com/blog/2009/02/capistrano-uploads-folder/

 

Optimizing a Drupal database: improving the performance

That is what you have when you don't optimize and maintenance properly your Drupal projects. A 4GB database which hits hugely the server performance. Just a couple of "magic tricks" and .... 194MB.

Magic? Not at all. If you have a problem with your server, with hangs up and things going very sloooow, check the cache. sessions and watchdog tables, and clear them.

It works like a charm :-)