Tried out Expression Engine 1.6.8

September 18th, 2009 Posted in Programming | 1 Comment »

I tried the Expression Engine (freely-downloadable Core edition) CMS. I didn’t much care for it; though it might be useful if you want to store many different (complete) HTML pages in a database and have an interface to edit them with. That’s not however exactly what I think a “content management system” should be; that’s more of a markup management system.

I just didn’t find the system inspiring; as a user, it’s hard to pinpoint why, specifically, beyond saying that the administrative interface seemed unintuitive. As a developer and systems administrator I was also pretty disturbed when I looked at the source of the installation script: 4168 lines of PHP, nearly all global-scope code, with MySQL queries, HTML, and CSS interspersed along the way.

Generally, I don’t trust software that I would hate to have to maintain. It goes beyond code simply looking pretty; readability is important. Given The Magical Number Seven, Plus or Minus Two concept, it’s easy to see why 20 line functions with a handful of local variables are much easier to maintain and debug—and to proactively spot bugs in—than something that is essentially a 4000 line function.

The system’s core code looks to be written more modularly, but it’s obviously not as flexible as Drupal. It doesn’t appear to have much database abstraction (it only supports MySQL), nor a form API. Beyond the fact that you can edit the HTML of pages (but not blog entries?) on your site directly in the administrative interface, I’m not sure why this system claims to be the most flexible thing ever.

I told the installer to use no table prefix, but it still prefixed the tables with “exp_”. Apparently it didn’t like a blank prefix, but it didn’t complain, either. There is code to let the system work with a different table prefix, but it’s a dirty hack that involves at least one regular expression to be run for every query. From Expression Engine’s database query function (system/core/db/db.mysql.php):

// Verify table prefix and replace if necessary.

if ($this->prefix != $this->exp_prefix)
{
    $sql = preg_replace("/(\W)".$this->exp_prefix."(\S+?)/", "\\1".$this->prefix."\\2", $sql);

    // If the custom prefix includes 'exp_' the above can sometimes cause partial doubling.
    // This is a quick fix to prevent this from causing errors in 1.x.
    if (strncmp($this->prefix, 'exp_', 4) == 0)
    {
        $sql = str_replace($this->prefix.str_replace('exp_', '', $this->prefix), $this->prefix, $sql);
    }
}

I’m quite curious whether that regex substitution will break database fields with names like “exp_points.”

And, come to think of it, that strncmp() call could be a bug; the comment says “if the prefix includes” but strncmp() only checks the beginning of the string. Shouldn’t it be a call to strpos() instead?

On a more positive note, looking under the hood of other systems, like this one, helps me appreciate Drupal even more. Drupal really sets a high standard; once you’ve worked with it, especially if you’ve looked under the hood or done any module coding, it’s hard not to appreciate its well-thought out design and engineering. The FormAPI has particularly spoiled me rotten.

Installing the PEAR/PECL uploadprogress extension for Drupal 7

September 16th, 2009 Posted in System administration | No Comments »

Trying out the latest development snapshot of Drupal 7, I noticed it supports the uploadprogress PEAR/PECL extension, which apparently lets you see the actual progress (with some kind of Ajaxy widget) while uploading files. Sounds cool to me.

First, I installed PEAR (on my Ubuntu testing server):

$ sudo aptitude install php-pear

and then tried to use PEAR to install uploadprogress:

$ sudo pear install pecl/uploadprogress
downloading uploadprogress-1.0.1.tgz ...
Starting to download uploadprogress-1.0.1.tgz (8,536 bytes)
.....done: 8,536 bytes
4 source files, building
running: phpize
sh: phpize: not found
ERROR: `phpize' failed

PHPize? What’s that? There’s no phpize package; aptitude search phpize gives nothing.

A bit of digging and I found that PHPize is part of the php5-dev package! After installing that, pecl can install a module just fine:

Solution

$ sudo apt-get install php5-dev
$ sudo pear install pecl/uploadprogress

After lots of output, PEAR left a final clue:

configuration option "php_ini" is not set to php.ini location
You should add "extension=uploadprogress.so" to php.ini

So I created /etc/php/conf.d/uploadprogress.ini, containing just this line:

extension=uploadprogress.so

I restarted Apache and now Drupal 7 reports “UPLOAD PROGRESS: Enabled”. Now to try it out….!

Installing the mysql Ruby gem

August 1st, 2009 Posted in System administration | No Comments »

While trying to install this gem on Ubuntu 8.04.3 (Hardy) to run a rails app (Redmine), I encountered the following error:

$ sudo gem install mysql
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
        from extconf.rb:1

There are a bunch of common errors when installing the mysql gem, so Googling for the solution wasn’t instant. Luckily I found this post which showed the missing package: ruby1.8-dev.

Solution

sudo apt-get install ruby1.8-dev

and the MySQL gem installed fine.

gem won’t install Ruby gems on VPS…

July 28th, 2009 Posted in System administration | No Comments »

Having trouble installing Ruby gems on your VPS? Gem was hanging on my Slicehost slice (running Ubuntu Hardy with 256MB of RAM) at “Bulk updating [...]“:

$ gem update
Updating installed gems...
Bulk updating Gem source index for: http://gems.rubyforge.org

It was also gobbling up CPU and memory.

Why does gem hang?

The distro package for Gem is very old, and this old version uses a lot of memory, causing lots of disk thrashing. Since hard disks are, ahem, a bit slower than RAM, this increases gem’s run time by probably a few orders of magnitude.

Solution

Update gem manually:

$ wget http://rubyforge.org/frs/download.php/57642/rubygems-update-1.3.4.gem
$ sudo gem install rubygems-update-1.3.4.gem
$ sudo /var/lib/gems/1.8/bin/update_rubygems
Installing RubyGems 1.3.4
Installing RubyGems
Installing gem executable
Removing old source_cache files
Removing old RubyGems RDoc and ri
Installing rubygems-1.3.4 ri into /usr/lib/ruby/gems/1.8/doc/rubygems-1.3.4/ri
Installing rubygems-1.3.4 rdoc into /usr/lib/ruby/gems/1.8/doc/rubygems-1.3.4/rdoc

RubyGems installed the following executables:
/usr/bin/gem1.8

Looks like everything’s OK, but gem didn’t work anymore:

$ sudo gem install haml
/usr/bin/gem:10: undefined method `manage_gems' for Gem:Module (NoMethodError)

What gives? Notice the path, /usr/bin/gem. Is that still the old version?

$ ls -lah /usr/bin/gem*
-rwxr-xr-x 1 root root 701 Nov 19  2007 /usr/bin/gem
-rwxr-xr-x 1 root root 545 Jul 28 00:15 /usr/bin/gem1.8

Yes. This is what we get for upgrading gem without using Ubuntu’s package system. Well, in for a penny, in for a pound:

sudo mv /usr/bin/gem1.8 /usr/bin/gem

Done. Now to install Haml and Sass….