Posts Tagged ‘Drupal’

Updating Price PHP print statements in Ubercart

Recently, I updated an Ubercart shopping cart system on Drupal that was very out of date.

After the upgrade, the list price on the product pages had too many zeros. It looked like this.

MSRP $ 49.99000

After a bit of research, I learned that Ubercart has been updated to include more decimal places to accommodate more International currencies.

I took a look at the node-product.tpl.php template and found that the print statement for the list price was using the out of date print statement.

The old print statement looked like:

list_price ?>

The new print statement looks like this:

list_price); ?>

Now all is fine.

MSRP $ 49.99

Theming fields in Drupal 6

I needed to figure out how to theme a field in Drupal 6. The use case was that I wanted to field to be a URL. This is pretty simple and straightforward by using the CCK Link module, which is a sub-module of CCK.

I was able to input my URL, such as http://www.symetrikdesign.com with no problem, and the CCK display options are pretty good. However, I wanted to strip the “http://” part on the output display, but have the link remain the legitimate link of http://www.symetrikdesign.com

CCK Link Display field

Though, there are several options for outputting the display in the Admin/Content Type//Display fields, there is nothing that handles stripping some characters from the title.

So I figured that I needed to theme the custom field. I searched drupal.org and google.com far and wide and found that though the documentation was present, there wasn’t much of it and it wasn’t that clear.

Here’s what I did.

My field name was called artistwebsite, so I needed to make sure that there was a standard content-field.tpl.php in my theme’s directory and then copy/clone that and call the new file content-field-field_artistwebsite.tpl.php. This works like other types of Drupal entity template files, but the tricky part is that you need to find content-field.tpl.php into your theme’s directory, because it probably isn’t there by default, depending on your theme.

I now have the following in my theme directory, and a field called field_artistwebsite in my content type.
content-field.tpl.php
content-field-field_artistwebsite.tpl.php

I was able to re-write the output of a CCK Link field so that it removes the “http://” on the display title on the node.

I did this by adding the following lines of code in place of the commented out print statement below:

".$item['display_title']."";
         
/* Here is the original PHP print statement line in the stock/default content-field.tpl.php
*  file that I commented out and replaced with what is above.
* 
*/
?>

Session Expiration in Drupal

I’ve spent a significant amount of time researching session expiration in Drupal.

It turns out that by default Drupal sessions a session of 23 days. You can configure the session to expire at a shorter interval and you can configure Drupal to expire the session when the browser closes.

In addition, there is a module called Session_Expire, which pushes the cleanup of the sessions table in the database to the core Drupal cron job instead of relying on PHP garbage collection of your particular operating system which can vary.

Here’s the details of what I changed in one Drupal 6 setup. There is a whole section on sessions which are stored in /sites/default/settings.php.

/* ini_set('session.cookie_lifetime',  2000000); default 23 days */ 
/* expire session on browser close */
ini_set('session.cookie_lifetime',  0);

/* ini_set('session.gc_maxlifetime',   200000); default 23 days */
/* session expires after 1 hour (without closing browser) */
ini_set('session.gc_maxlifetime',   3600);

/* The following two lines collect garbage, this is done with 
session_expire module.  In Drupal 7 they will be handled here
ini_set('session.gc_probability',   1);
ini_set('session.gc_divisor',   1);
*/

It doesn’t seem that there is much information out there on how this works, so I thought I would share my findings.

Also, as noted in the last comment I included from my settings.php, this is handled better in Drupal 7.

Review of publicly available Drupal stack Amazon AMIs

Until Pantheon Mercury 1.1 or 1.2 comes out publicly, I wanted to setup a plain vanilla Drupal server for development on Amazon’s EC2 environment.

I wanted the server to have:

  • Ubuntu 10.04
  • Apache
  • MySQL
  • PHP
  • Drupal
  • Drush
  • Webmin
  • PhpMyAdmin

There are a ton of AMIs out there, so I wanted to find one that was already available and easy to spin up and configure with my server name and database name/users.

NOTE: The preferred method for me, is still going to be to use Pantheon. I was only looking for a short term, temporary image for a development server while we wait for Pantheon to go public/live.

The final result for me was that I spun up a Ubuntu 10.04 LTS server. The latest official Canonical Ubuntu AMIs are are all listed at http://alestic.com for each region. The list is automatically updated with the latest images.
From there, I installed LAMP all in one go with one command, then added Mail servers, PhpMyAdmin, Webmin, Drupal, and finally Drush.

It actually wouldn’t have taken me less time to just do that instead of going out and looking for other AMIs and trying out the ones I found.

Here’s the command to get you started:

$ sudo tasksel install lamp-server

I found 3 main public AMIs for Drupal. Here’s what I thought about each one of them.


Bitnami (http://bitnami.org)

I tried spinning up one of the free Bitnami AMIs on a micro instance. I decided that it was not a viable solution due to poor documentation and non-standard, non-Ubuntu way software is installed such as Apache and Drupal.

If you run on the Bitnami cloud, it’s easy to spin up an instance and backup your instance. There is a flat fee for using their system. For a single server, it’s not worth it ($49/month up to 3 servers, on top of Amazon charges) – http://bitnami.org/cloud/pricing

PROS:

  • Up-to-date versions of Drupal 6.20 and 7 available.
  • Can run on micro instance.
  • AMIs are EBS boot.
  • Have a free AMI that you can use in addition to the cloud hosted version with a backup that is similar to Turnkey Linux’s Hub setup.

CONS:

  • I found the Bitnami stack unusuable because of the customized installation of Apache.
  • It is installed in /opt/bitnami/apache2
  • sudo service apache2 restart didn’t work – there is a bitnami specific command to restart it
  • Drupal was installed in a non-tradtional way /opt/bitnami/apps/drupal
  • By defualt apache was setup such that www.example.com was a bitnami splash page, whereas to get to Drupal, I had to go to http://www.example.com/drupal.
  • Changing the default apache root was not-inuitive (I couldn’t figure it out).
  • No username/password supplied for PhpMyAdmin.
  • Poor documentation

Turnkey Linux(http://www.turnkeylinux.org)

I run another, non-Drupal turnkey linux appliance and it works pretty well, so I was familiar with how their AMIs and general setup works. Their software images are open source and you can download and install on your own hardware. They do not offer a free public Amazon AMI. If you use their Amazon AMI, you kick it off from their Hub. After logging into hub.turnkeylinux.org, you can spin up an instance, and configure automatic backups, similar to Bitnami’s cloud backup feature. They charge 10% on top of the Amazon charges, so it’s pretty affordable for a single server.

I decided against the Drupal AMI without installing it because of the following two cons.

CONS:

  • No free AMI version to try like Bitnami has.
  • The AMI is an instance boot.
  • The AMIs do not support micro instance, so you have to run a small instance at a minimum.
  • The AMI was built on a much older version of Drupal 6.16 (not really a big issue).
  • The following statement is on their page: http://www.turnkeylinux.org/drupal6

Note: Drupal 6 includes a built-in update status module.
* When enabled could produce confusing/annoying version notifications.
* This is due to drupal6 being installed and updated via the APT package manager, instead of manually from the upstream source code.

I didn’t want to deal with having Ubuntu’s apt-get manage my Drupal updates, I would rather use Drush.


Jumpbox (http://www.jumpbox.com)

They didn’t have a free version to try, so I didn’t try their service. It looks similar in setup and price to Bitnami.
http://www.jumpbox.com/pricing

Quick Drupal install on Ubuntu 10.04 server

Here’s some instructions for doing a really quick Drupal install on Ubuntu server 10.04.

This assumes that you are well versed with Drupal and have already created your database and database user and given the rights to the DB user to access the DB.

Step 1 download, extract, and copy the files into the /var/www root

$ cd /
$ sudo wget http://ftp.drupal.org/files/projects/drupal-6.20.tar.gz
$ sudo tar xvzf drupal-6.20.tar.gz
$ sudo mv drupal-6.20/* drupal-6.20/.htaccess /var/www
$ sudo rm -rf drupal-6.20.tar.gz
$ sudo rm -rf drupal-6.20

Create the files directory and give it the proper ownership

$ sudo mkdir /var/www/sites/default/files
$ sudo chown www-data:www-data /var/www/sites/default/files

Copy default settings.php file to settings.php so that you can enter your own server and database details

$ sudo cp /var/www/sites/default/default.settings.php /var/www/sites/default/settings.php
$ sudo chown www-data:www-data /var/www/sites/default/settings.php

From here you would need to edit /var/www/sites/default/settings.php and enter in our server, database, and database user details.

I would also like to note that you can also install Drupal with aptitude on Ubuntu, but I would much prefer to install Drupal manually and use Drush to update drupal whenever I want to have it updated.

I only want Drupal updated when I say so and with what versions that I decide on.

$ sudo apt-get install drupal6

Installing Drush (at the time of this writing 4.2 is the latest version)

$ sudo apt-get install php5-cli
$ cd /usr/local/
$ sudo wget http://ftp.drupal.org/files/projects/drush-All-versions-4.2.tar.gz
$ sudo tar zxvf drush-All-versions-4.2.tar.gz
$ sudo rm -rf drush-All-versions-4.2.tar.gz (remove downloaded and extracted tar file)
$ cd drush (to make sure the files are there)
$ sudo chmod 555 drush

Create symbolik link
$ cd /usr/local/bin
$ sudo ln -s /usr/local/drush/drush drush
Consulting

I'm currently available
for Lotus Notes / Domino consulting engagements.

LinkedIn

Connect with me:

LinkedIn

Advertisement
Advertisement
Categories