Content management systems, meh.

Anytime I take on a project that involves the possibility of using a CMS, I feel conflicted. In my experience as a web developer, I have typically found that any CMS I provide my clients with never quite meets their needs. Most find the administrative interfaces confusing and end up asking me to just make the updates or add content. From a technical perspective, a CMS also means a lot more code to maintain. Yuck.

Looking back at the content management systems I’ve worked with, one stands out: it’s one I developed from scratch that specifically targeted what the client needed: uploading PDFs of meeting minutes, adding phone numbers to a directory, updating content on specific pages, etc. It seems that the more generic and flexible a CMS, the harder it is for the average user to grasp. I’ve actually found that teaching a semi-technical client some basic HTML so that he could add news items to his site was better than integrating an entire CMS. He even thought it was fun! Non of my clients using WordPress found the administrative interface to be “fun”. Obviously, asking non-technical users to hand-edit HTML is not an option. However, it is an option for the ones who are capable.

If an average CMS user wants to add a new page to their site they won’t typically consider it from the perspective that a web developer would (which is from a site visitor’s perspective). Even when it comes to simply adding content, most CMS user’s don’t properly use headings where headings should be used or lists where lists should be used. In my opinion, you’re better off letting a web developer make the updates. It will be done properly the first time around, rather than paying them to come in and fix things when they’re broken.

How Do I Choose Whether or Not to Use a CMS?

  • Is the client semi-technical? If yes, then give them a mini-training session on HTML and a quick crash course on semantic markup.
  • If the client is not semi-technical then consider using a framework and developing only the specific updating abilities the client needs.
  • Is the client insisting on a CMS even after you’ve explained the benefits of not having one? Then looks like you’re going with a CMS! Choose wisely.

Passing a Table or Field Name Containing Spaces as a Parameter to a MySQL Procedure

The Solution

delimiter //
CREATE PROCEDURE my_proc (table_name VARCHAR(200))
BEGIN
    SET @sql =  CONCAT('INSERT INTO My_Table(field1, field2) SELECT field1, field2 FROM `', table_name, '`');
PREPARE stmt FROM @sql;
EXECUTE stmt;
END //
delimiter ;

And calling it:

CALL my_proc('A Table Name with Spaces');

Curious to know if there’s a better way, like variable interpolation.

Resources

MySQL: Passing procedure params to EXECUTE USING statement Re: Query about variable interpolation in stored procedures

ERROR 2003 (HY000): Can’t connect to MySQL server on ‘a.a.a.a’ (61)

A quick Google search for ‘mysql remote connections” provides one with plenty of “how to” articles on getting MySQL setup for remote connections. Even after carefully following all instructions to change settings in my.cnf, add the appropriate rules to iptables and grant proper privileges I could not remotely connect to MySQL.

Finally, after troubleshooting the problem for quite some time, I figured out the issue. It was the ordering of my iptables rule.

Issuing the following command to insert the rule on line 6, before the REJECT rule, solved my problem:

 iptables -I INPUT 6 -p tcp -m tcp --dport 3306 -j ACCEPT

Tips for troubleshooting a remote connection to a MySQL server:

  • nmap -sT -O <ip address> OR netstat -an | grep 3306' to verify the MySQL server is listening on port 3306 (or whatever port you’ve specified in my.cnf)
  • iptables -L to verify appropriate rule exists for accepting tcp connections on port 3306
  • iptables -L INPUT --line-numbers to view line numbers so you determine the appropriate line to insert your rule for allowing tcp on port 3306
  • telnet <ip address> 3306 from client to verify connection from client to server

N.B. I’m no server admin, so take everything in this post with a grain of salt!

Recursive Wildcard SVN Commit and Ignore *.orig Files

Okay, so the title is actually a little misleading. As far as I know, in SVN, there is no way to actually do a recursive wildcard commit in one command without a little extra effort. Initially I expected that the following would work (it didn’t):

Ideal Solution (that doesn’t actually work)

% svn rm *.orig
% svn propset svn:ignore '*.orig' .
% svn ci -m "Remove all orig files from version control" *.orig

So back to the title…I’m using it because it’s what I used myself as a search phrase when hunting for an answer. I spent a good bit of time trying figuring it all out, so in hopes of saving time for others, here’s what ended up working for me:

Requirements

  • Remove all .orig files from version control
  • Figure out how to commit an svn propset svn:ignore *.orig on the repository root without committing all the other pending changes!

Actual Solution

Store the list of all .orig files so we can pass it to the commit later:

% find ./ -name *.orig > /tmp/origfiles

Remove the .orig files from version control:

% find ./ -name *.orig | xargs svn rm --force

Commit only the orig files:

% svn ci --targets /tmp/origfiles -m "Unversion orig files"

Tell SVN to ignore all .orig files:

% svn propset svn:ignore '*.orig' .

Commit only the property changes:

% svn ci --depth . -m "Ignore all .orig files"

Helpful Resources

Tags: subversion

Installing PHP’s mailparse Extension on Mac OS X from Source

Note to self: don’t forget to `make clean’ when compiling!

It seems whenever I’m compiling something from source it NEVER fails that I run into issues, usually related to file architecture.

Today, I wanted to hack around with PHP’s mailparse extension. So I

pecl install mailparse

‘Sweet!’ I said out loud when it installed without a hitch. I proceeded to update my php.ini with

extension=mailparse.so

Easy enough. Then,

$ php ~/Scratch/mail_parse.php
PHP Warning:  PHP Startup: Unable to load dynamic library  
'/usr/local/lib/php/extensions/no-debug-non-zts-20060613/mailparse.so' - (null) 
in Unknown on line 0

*sigh*

At this point, I had no idea why it was failing, so I tried all sorts of variations of extension=....

Finally, after no progress, I decided to stop my wild goose chase, take a deep breath and really try to understand what the PHP Warning was telling me.

PHP Warning:  PHP Startup: Unable to load dynamic library  
'/usr/local/lib/php/extensions/no-debug-non-zts-20060613/mailparse.so' - (null) 
in Unknown on line 0

Not much. However, at some point, a light went on in my head and I decided to check the architecture.

$ file /usr/local/lib/php/extensions/no-debug-non-zts-20060613/mailparse.so 
/usr/local/lib/php/extensions/no-debug-non-zts-20060613/mailparse.so: Mach-O 
64-bit bundle x86_64

Ah, ha! And, let’s just see…

$ file /usr/local/bin/php
/usr/local/bin/php: Mach-O executable i386

AH, HA! Mixing 32-bit PHP with a 64-bit extension, probably won’t work. Luckily, I try to post problems like this one on here so I can use it as a reference for later (if it helps others out in the process, then it’s a win-win). Sure enough, I had a previous post about mixing architectures.

Assuming that the architecture difference was the culprit, I went on to figure out how to compile the mailparse extension as 32-bit, which ended up taking quite a while.

I finally came across an article, Compiling PHP extensions on Snow Leopard with XAMPP, which had the answer:

$ phpize
$ CFLAGS=-m32 CPPFLAGS=-m32 CCASFLAGS=-m32 ./configure
$ make
$ sudo make install

However, at this point it failed. Another previous post I had made about compiling popped into my head: don’t forget to make clean, which I had NOT been doing. After a make clean and the above commands…

$ file /usr/local/lib/php/extensions/no-debug-non-zts-20060613/mailparse.so 
/usr/local/lib/php/extensions/no-debug-non-zts-20060613/mailparse.so: Mach-O bundle i386

And I tried out my script, it worked. Perfect!

I have a love/hate relationship with compiling. My guess is that it’s mostly my fault because I don’t have a solid understanding of the basics. I’m learning though. Always learning.

Two New Functions I Learned While Creating Alphabetized Paging Links

PHP’s range() function:

foreach (range('a', 'z') as $letter)
    echo $letter;

MySQL’s LEFT() function:

SELECT * FROM customers WHERE LEFT(customer_name, 1) = 'A'

Setting the Default DB Adapter in a Zend Framework ControllerTestCase

Following the section in the Zend Framework manual for Integrating Database Testing with the ControllerTestCase, I encountered a Zend_Db_Table_Exception: when running the tests:

No adapter found for Model_DbTable_SurveyElements

The solution was to set the default adapter:

public function setupDatabase()
{
    ...
    // Set default adapter
    Zend_Db_Table_Abstract::setDefaultAdapter(
        $connection->getConnection()
    );
}

Fixing Uncaught exception ‘Zend_Application_Bootstrap_Exception’ with message ‘Resource matching “db” not found’

While running tests with PHPUnit within the Zend Framework, I started receiving an uncaught exception during the point when PHPUnit attempts to generate the code coverage report.

After Googling that didn’t lead anywhere I decided to dive into the PHPUnit source. I didn’t get very far when I realized, by actually looking at the stack trace, that I had created some new directories containing database scripts for generating schema, seed data, etc.

Excluding these directories in test/phpunit.xml fixed the issue.

Hope this helps someone else.

Converting an XML Hierarchy Into a Nested HTML Ordered List

Given

<?xml version="1.0" encoding="UTF-8"?>
<tree>
    <branch heading="some heading">
        <leaf>some text</leaf>
        <branch heading="some heading">
            <branch heading="some heading">
                <branch heading="some heading">
                    <leaf>some text</leaf>
                    <leaf>some text</leaf>
                    <leaf>some text</leaf>
                    <leaf>some text</leaf>
                </branch>
                <branch heading="some heading">
                    <leaf>some text</leaf>
                    <leaf>some text</leaf>
                </branch>
            </branch>
        </branch>
    </branch>
</tree>

and

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <title>Tree</title>
            </head>
            <body>
                <ol>
                    <xsl:apply-templates select="tree" />
                </ol>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="branch">
        <li>
            <xsl:value-of select="@heading" />
            <ol><xsl:apply-templates /></ol>
        </li>
    </xsl:template>

    <xsl:template match="leaf">
        <li>
            <xsl:value-of select="." />
        </li>
    </xsl:template>

</xsl:stylesheet>

should output a properly nested HTML ordered list.

Resources I found helpful:

I hope it helps someone; took me quite a while to figure it out.