Note: This post is over two years old and so the information contained here might be out of date. If you do spot something please leave a comment and we will endeavour to correct.
24th November 2009 - 5 minutes read time
The other day I needed to copy a Drupal project from my source folder to another folder, so rather than manually copy the files I decided to create a Phing script that would do it for me in one go. This Phing script will export your Drupal project into another directory, change the database credentials and create zip and tar files of the project. The first thing to do is create a properties, here is the contents of that file.
Just save this file as build.properties and change the properties to your needed settings.
The build file part of the the contains a fileset to include all of the needed files and then some targets to do things with those files. Those of you used to Phing and Drupal will notice that we are including a lot of files but we are missing one called settings.php. This is deliberate for the reason that trying to match the parameters in our build.properties file into the database settings in the settings.php file is going to be tricky. So rather than enter multiple database parameters we can just use the destination parameters, the default.settings.php file (which we will know the format) and a small amount of regular expression replacing in order to create a new settings.php file for our destination. Here is the contents of the build file.
That's pretty insane. You've not taken into account any support for multiple sites, you're migrating Drupal core as well as just the necessary site files, and you're not looking at creating Apache Vhosts or migrating databases or creating databases.
It was a good start though, and has inspired me to create a phing build script which does all these things.
Running complex tasks in Phing can mean running out of memory, especially when altering or changing lots of files. I was recently working on a image sorting Phing project that sorted images based on EXIF information.
Providing a Phing build file along with a project is a good way of allowing automation of certain aspects of the project. The only trouble is that users won't know what's in the build file unless they open it or just run it.
Phing has a few different tasks and elements that allow you to select paths of code execution depending on what you need to happen in a build file. These are limited to loops and if statements, but a lot of functionality can be covered with just a couple of lines of XML.
The other day I was experimenting with Git hooks. These are scripts that you can execute before certain actions are run in Git. For example, you might want to ensure that forced updates are not run, ensuring respository files have the correct permissions after merging, or that the files have ASCII standard names before being committed.
I use Phing for a lot of different tasks, it helps me to automate things that I would otherwise mess up if left to my own devices. Prime candidates for Phing scripts are things that I don't do that much and forget how to do them, or that have a number of complex steps.
Checking Syntax Errors In PHP And JavaScript Using Phing
Running a simple syntax check over your files is a good way to save time. This can be when testing code but best practice is to not to even commit code that contains syntax errors.
Comments
Submitted by forex robot on Wed, 12/09/2009 - 06:52
PermalinkSubmitted by Forex on Wed, 03/17/2010 - 12:39
PermalinkSubmitted by Anonymous on Sun, 08/22/2010 - 20:08
PermalinkSubmitted by Wim Mostrey on Wed, 09/01/2010 - 12:27
PermalinkAdd new comment