CakePHP and Subversion

A Quick How-To about properly setting up a svn for your cake app.

First of all, we need to drop a "trunk" folder into our svn:
/trunk

inside this trunk, we now add
/app (actual app)
/vendors (global vendors)
/cake (cake core)

Now, before committing the first time, we want to make sure that only non-transient files are actually under svn. That means, we need to exclude temporary files as well as all config files containing passwords and other private settings.

a) database.php
You will need to exclude this file in the properties of the parent folder "/trunk/app/config/".

With tortoise, its as easy as right-clicking on the folder and adding
svn:ignore database.php
But under linux it shouldn’t be that much harder.

b) tmp folder
Exclude all subfolders and files within "/trunk/app/tmp" with
svn:ignore *
But don’t forget to manually add the subfolders like "cache" as well their subfolders (for cache: "persistant", "models", "views").
Now apply the same ignore property on those subfolders, too.

The Result:
/tmp
/tmp/cache
/tmp/logs
/tmp/cache/persistant
/tmp/cache/models
/tmp/cache/views
are all under svn – but any tmp file (either in /tmp directly or in one of the subfolders) will be not.

c) configs – the probably most difficult part

It is never a good idea to submit keys (Akismet, SMTP, FacebookAPI, …) to svn.
so we need to find a solution for this.
This is my advice:

Include both "config.php" and "config_private.php" in exact this order in your bootstrap (with file_exists() in order to prevent errors!). Now all settings in the private config override the public one.

One example:

# config.php
$config['Email'] = array(
    'use_smtp' => 0,
    'smtp_port' => 25,
    'smtp_timeout' => 20,
    'smtp_host' => '',
    'smtp_username' => '',
    'smtp_password' => '',
);
 
# config_private.php
Configure::write('Email.smtp_password', '123');
//...

This way every developer can use his own private keys and settings without publishing them in the svn.

Hot tips

With Tortoise you can export your properties and easily import it for other upcoming projects (for each folder separately). I save my /config/ exlusions in "config.svnprops" for example.

The same properties can be applied to multiple folders at once by selecting all folders and then right-click on them. This helps to quickly ignore any files in the 3 tmp-subfolders.

Outlook

Soon I will talk about how to manage several apps with the same libraries (like cake and vendors folder).

0.00 avg. rating (0% score) - 0 votes

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.