Reorganize Subversion Repository

I’ve restructured the repository to use the standard layout:
/oldsite
/oldsite/trunk
/oldsite/branches
/oldsite/tags
/newsite
/newsite/trunk
/newsite/branches
/newsite/tags

I’ve put all the existing code into /oldsite/trunk and created a new Zend Framework project in /newsite/trunk.

This is evidently confusing Zend Studio 7, because now it won’t add a new project to the repository. I’ve tried cleaning things up, retrying, etc. but I still end up with red exclamation marks next to all the files, and nothing has been added to the repository.

Doing some google searching, it appears that a lot of folks are having problems with the SVN support in ZS. Several mention that due to these and other bugs in ZS they have opted to use Aptana instead. Since Aptana is free, I’m going to give it a try and see how hard it is to setup my project and SVN connection.

Debugging the Debugging Environment

It can be pretty frustrating to sit down to do some web coding, only to find that the development IDE or server isn’t working correctly. One then spends the time planned for development on simply debugging the development environment instead.

This often happens to me due to the following things:

1. I’ve deleted a project’s folder without removing the vhosts reference to it. This will cause the Apache server to fail to start.

2. I’ve made changes to the httpd.conf or httpd-vhost.conf file without restarting Apache right away to confirm that the settings work correctly.

The easiest way to debug this is to look in the Apache log files. Apache can also be manually started using apache2/bin/httpd and may generate messages.

1. Try to launch the ZendServer control panel. Sometimes this fails if the system is still starting up, so wait until boot up is complete.

2. Check the Apache error_log.

3. Try manually starting using apache2/bin/httpd.

Trouble with debugging

I apparently have screwed up my Zend Studio 7 debug settings. I can launch the debugger ok from within Zend Studio 7, but any breakpoints that I’ve set on subsequent pages don’t ever trigger. I can also see the browser output indicating that the code all ran.

At this point I’m getting so frustrated that I think I’m going to start with a fresh install of Zend Studio 7, ensure the debug example works, recreate my project, and see if all works then.

Everything is backed up on Time Machine, so here we go.

Installing Zend Server CE

Zend Server CE is a package containing Apache, PHP, MySQL, and the Zend Debugger. It is a great way to quickly install the full environment needed for PHP development. It is also free.

Installation is pretty simple, mostly download and run.

After installing, you’ll probably want to setup multiple virtual hosts. This requires editing two Zend Server files (conf/httpd.conf and conf/extra/httpd-vhosts.conf) and /private/etc/hosts.

The ZendServer control panel is accessed through the default localhost documentroot folder, so its probably best to leave localhost where it is. Alternatively it may work to copy the ZendServer link that is in /usr/local/zend/apache2/htdocs to whereever localhost gets moved to.

Create new vhosts by uncommenting the vhosts file include in httpd.conf. Then create as many vhost sections as needed. Be careful that any specified log files are within folders with permissions enabled. Also be sure to copy the localhost permissions section in httpd.conf for the location of the vhosts folders (eg. Sites). Remember to setup localhost or the Zend Server control panel will be broken.

MySQL Backup/Restore

I’ve been working with MySQL databases years. Since most of my projects have been fairly small, I’ve managed backups and schema updates manually using phpMyAdmin. Typically I will setup 3 separate server environments and databases: dev, test, and live.

User Scenarios

The scenarios that I would like to implement are:

  1. Create ‘dev’ database, tables, and optionally initial content.
  2. Optionally import existing content from ‘live’ to ‘dev’.
  3. Develop and test code using the ‘dev’ environment and database.
  4. Copy the ‘dev’ database to the ‘test’ database
  5. Optionally import existing content from ‘live’ to ‘test’
  6. Test using the ‘test’ environment
  7. Lock the ‘live’ database
  8. Backup the ‘live’ database
  9. Copy the ‘test’ database to the ‘live’ database
  10. Restore the ‘live’ content
  11. Unlock the ‘live’ database

MySQL supports doing all of these things.

Creating the Database and (optionally) Initial Content

Creating the database is done using CREATE TABLE. Using a PHP function to do this works well because then the structure of the table is documented and can be checked into the SCM.

Importing Existing Content

Development on the ‘dev’ site is easier if the ‘dev’ database contains valid data. If the ‘live’ and ‘dev’ databases reside on the same server then the content from the ‘live’ database can easily be copied into the ‘dev’ database using ‘INSERT INTO dbname.tablename (cols) SELECT cols FROM dbname.tablename’. If not, then the ‘live’ database will need to be unloaded to a file, then the file loaded into the ‘dev’ database as described for backup below.

Copying the Dev Database to Test

Once new code is developed and tested in the ‘dev’ environment it needs to be copied as-is to the ‘test’ environment. This is easily done using ‘CREATE TABLE dbname.tablename AS (SELECT * FROM dbname.tablename)’. Updated content can be copied from ‘live’ to ‘test’ as described above for copying data into ‘dev’.

Lock the Live Database

Although MySQL provides a locking mechanism, this is probably not the best approach in this case. A better approach might be to set a flag in the user login or identification code. I call this setting a ‘service mode’. Other users that try to interact with the site will be told that the site is down for service, and to try again later.

Backup the Live Database Content

MySQL provides a BACKUP and RESTORE commands, but these are marked as ‘deprecated’. Since the structure of the database is recorded in the code which creates the database, only the content needs to be backed up. This can be done using what MySQL calls ‘unloading’ and ‘loading’: “SELECT * FROM table INTO OUTFILE filename FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘”‘ ” and “LOAD DATA INFILE ‘filename’ INTO TABLE table FIELDS TERMINATED BY ‘,'”

Recreate the Live Database

Use the same code that was used to create the ‘dev’ tables to recreate the ‘live’ tables.

Restore the Live Database Content

As stated above, MySQL provides a RESTORE command but it is marked as ‘deprecated’. Since the structure of the database was recreated in the previous step, load the content using “LOAD DATA INFILE ‘filename’ INTO TABLE table FIELDS TERMINATED BY ‘,'”

Unlock the Live Database

This is done by turning off ‘service mode’.

Keyboard Mapping

I’ve been doing a lot of web programming using Eclipse on both my work Windows machine and my personal Macbook Pro. I’m finding the difference in the “Start of line” and “End of line” keys to be extremely annoying. So I’m looking to remap the Mac keystrokes on the external keyboard I use with the Macbook Pro to match those of my office Windows machine.
This post appears to provide the info I need to do this: http://www.erasetotheleft.com/post/mac-os-x-key-bindings
I may look a bit more though, and see about remapping the Windows keyboard to match the Macbook Pro instead 🙂

BorderContainer disappears when height=100%

I ran into a snag getting the tab container to work when specifying height and widths of 100%.

Solution: I eventually discovered that all 3 html, body, and the BorderContainer div must be set to 100%. I had not specified anything for html and body, and when I set the div tag to 100% the whole thing just went blank.

In addition, the BorderContainer will updating the size of its child divs (those marked with “region=”. It won’t however update any additional divs that are children of those. This tripped me up because I was trying to put an AccordionContainer within the left region div of a BorderContainer. The AccordionContainer height wasn’t being updated and was not working when setting the AccordionContainer to 100%. The solution was to eliminate the left region div, and set “region=’left'” in the AccordionContainer itself.

Now we know.

Starting Dojo Drag and Drop

Last night I began creating a lineup edit page. I’m hoping to use Dojo’s drag-and-drop functionality to make creating each week’s song lineup very easy:

On the left side I will display a list of song positions and names (Intro, 1st congregational, offertory, etc). Next to each item will be the song name.

On the right side I will display all of the songs in the database, and a link to add a new song.

The user will then drag songs from the list on the left onto the lineup position. Any positions not needed can be dragged out of the list, and will appear at the bottom in an ‘unused’ section. They can thus be dragged back if needed. Individual items can be dragged to rearrange the order.

The list of songs will include an MP3 link to allow previewing the song.

Last night I added the code for the lists, and a few lines of Dojo to enable dnd and the result was immediately impressive. With just a few additional statements added to the lists, I can now drag between the lists and within the lists to reorder.

I found a very helpful link which I’m working through: http://www.sitepen.com/blog/2008/06/10/dojo-drag-and-drop-1/

I’ll need to clean up the way it works though. I don’t want the songs to be removed from the song list when dragged onto the lineup. Sometimes the same song may be played twice. There is also some formatting problems due to different columns being displayed in the lineup and songs lists (tables). And there is no functionality yet. DND operations modify the appearance of the form, but don’t get written to the DB yet.

Subversion + Eclipse is wonderful

Ok, I initially had one small problem where I couldn’t commit a couple files. Other files worked just file. So I simply deleted and recreated the 2 files. All is working great now.

I also had created a small problem by adding Subclipse. I’m using Zend Studio for Eclipse 6.1, and it comes bundles with Subversive. So adding Subclipse caused ‘SVN’ to appear twice everywhere. I uninstalled Subclipse and the confusion is gone.

Having worked extensively with both ClearCase and Accurev at work, I wasn’t sure what to expect from Subversion, or how well it would integrate into the Eclipse environment. I must say that I am very impressed. This setup is working way better than what I’m used to at work, which is just standalone AccuRev. The Subversion integration with Eclipse (via the bundled Subversive) is very efficient. The ‘compare’ functions are very helpful, allowing quick selection of previous versions to help me remember what I’ve changed and when on a file-by-file basis.

I know that things can get difficult when managing merging of multiple programmers changes. Since I’m the only one updating this code, I haven’t had to try out Subversions functions for doing this.

Further Development on TheRockBand site

Having made great progress this week setting up subversion, I was anxious to get started this morning, only to have all kinds of weird failures.

It turned out that I had created a new directory when I checked out the code, but hadn’t switched the vhosts paths to point to it, nor the ZSE path info. So it took me awhile to figure that out.

Next I implemented the Song Add/Edit/Delete actions. Delete had a bug caused by the dependent table info not being correct. In this case I used the table name instead of the table class. I determined this by tracing down into the ZF code. When a Zend_Db_Table_Row is deleted, it automatically performs a delete of any dependent tables. This is cool, but means that if I specify dependentTables and referenceMaps then they better be correct.

I’ve been reading up on the Dojo drag-and-drop support, and will be using this for editing lineups. I’ll display a list of the possible lineup items (eg. Special, 1st congregational, etc), and song, and allow them to be dragged into a blank lineup matirx.

But first I will get based pages working so we can get the site back online this weekend.