Script to update PhpBB 3.0.x to 3.1.x

Recently I had to upgrade a dozen PhpBB boards to the latest version. Previously I would do this by hand, which would take days. This time though, while reading through the update notes, I noticed that it is possible to update the database through the console (I assume this was only introduced in 3.1). That was the necessary prerequisity to be able to automate everything. I ended up with the following script:

#!/usr/bin/env bash
echo "Upgrading PhpBB instal in '$1' to 3.1 with files from '$2'..."

cd $1

echo "Deleting old files..."
shopt -s extglob
rm -r !(config.php|images|files|store)
shopt -u extglob

echo "Copying in 3.1 files..."
rsync -a --exclude='.git' $2/ $1/

echo "Migrating the database..."
php ./bin/phpbbcli.php db:migrate --safe-mode

echo "Removing the install dir..."
rm -r install

echo "Done."

The usage is as follows (assuming you named the script phpbb-update-to-3.1):

phpbb-update-to-3.1 /www/forum-to-update /tmp/phpbb-3.1-files-for-upgrade

The second parameter is the path to where you have prepared your 3.1 files, according to this guide. You should put your custom styles in this folder too.

If you have custom folders or files within your current install, make sure you add those to the rm -r !(config.php|images|files|store) line in the update script. This rm deletes everything except the files within the curly braces.

This saved me a lot of time and prevented mistakes. Enjoy!

Unit testing/Test driven development

…really enjoying it. I have been doing unit testing sparingly for a long time, but just now I am really starting to take it serious. Every new functionality I add to a project/application I am working on I seal with sufficient unit tests. Also it’s much faster to develop and test business logic using tests than testing it trough GUI. I’ve been missing a lot!

CakePHP and WebBaker

Recently I started using this wonderful PHP framework called CakePHP. It really moves the whole web development process to another level. It has got the MVC pattern, great community, good documentation, lots of people writing about it and there is the WebBaker. WebBaker is a PHP script that let’s you easily create all the files you need for your MVC pattern (model, controller, views). This saves you a lot of precious minutes.

Webbaker in action The CakePHP and WebBaker combination is deadly. You can have a functional element in your site like in 1 minute. All you need to do is create a table in the database and use WebBaker to generate appropriate files. At this point when you have written exactly 0 lines of code you have a fully functional interface where you can list, view, edit, add and delete items from database. This is possible due to the excellent scaffold functionality build in Cake. Then you can start writing your own code and smoothly replace the scaffolds. Try it, you’ll never want to go back.