The Joys of Inheriting an Old Web Site

Recently I’ve been helping out a buddy of mine with a website he’s recently taken over. I’ve taken on hosting it and I’m helping getting some “best practices” into their development process. I’m no veteran of open source but I’m a long time spectator (some would say a lurker) so I figured it would be a good learning experience for the both of us.

When we took over the code was pretty much just dumped on our laps. We got a tar ball of the code (well the whole site really), a database dump, and a pat on the back. No install script, no documentation, just 53000 lines of PHP, some HTML and some users … great. We didn’t even know how much PHP code there was beyond a file count till I wrote a little script to count the number of lines of code in the PHP files. This script probably gives an inflated sense of code size since it doesn’t account for comments, whitespace or in line HTML. It’s probably safe to say the line count is a few thousand lines heavy but it’s a good estimate (better than what we started with).

find ./ -name '*.php' | 
  while read FILE; do
    SUM=$((SUM+$(cat $FILE | wc -l)));
    echo $SUM;

Simple right? But pretty useful. I had initially tried to replace the cat $FILE | wc -l with just a wc -l $FILE but I guess wc prints the file name after the line count and I couldn’t figure out how to turn this off. Meh, take the file name away from wc and all is well.

So this how it all started. I’ll be posting periodically as interesting things happen with this project. I’ll post useful scripts, whatever interesting PHP stuff I pick up along the way and anything else that may be interesting. The code is pretty old (dates on some files go back to 2003) so this should be interesting. I’ve even spotted a few frames on the site … yeah.

I’ll try to be constructive as much as possible but I can’t guarantee that I won’t post a few WTFs as I go through the code and find ’em … bad coding makes for good comedy (to the right audience or course).

Stay tuned.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s