Php

1 minute read Published:

CakePHP beforeSave() gotcha: need to set $this->__exists to true if setting a primary key

I added an update to CakePHP Book: beforeSave() Also, if you add a primary key which would turn an “insert” into an “update” within beforeSave() you’ll need to set $this->__exists = true;… the call to $this->exists(); happens in model.php before the callback to beforeSave(). function beforeSave() { if (!isset($this->data[$this->name]['id']) && isset($this->data[$this->name]['unique_field'])) { $found = $this->find("first",array( "recursive" => -1, "fields" => array("id"), "conditions" => array("unique_field" => $this->data[$this->name]['unique_field']))); if (!empty($found) && isset($found[$this->name]['id'])) { $this->id = $this->data[$this->name]['id'] = $found[$this->name]['id']; $this->__exists = true; } } return parent::beforeSave(); } That’s been confusing me a bit recently – setting the ID of a row within beforesave() should change the save to an update, but it was trying to insert with a specified ID and thus, failing… glad to have a simple solution that makes sense… hope that helps someone else…

1 minute read Published:

MySQL Master/Slave Replication Monitoring PHP Script

I’m a bit proud of myself on this one… I setup a simple, but clean and configurable, MySQL Master/Slave Replication Monitoring PHP Script: http://code.google.com/p/php-mysql-master-slave-replication-monitor/ (docs) It’s Open Source and free, I welcome comments, suggestions, and questions. I think this will be quite useful for anyone who is setting up a pair of MySQL servers as master/slave and want to be sure their replication works as it should.

4 minute read Published:

SVN Merge, making sure a branch is updated from trunk, then merging back to trunk

So I’ve just fought a battle w/ SVN merge and thought I’d post the solution in case others might find it… Scenario Our stable code is in trunk svn://svn.domain.tld/repository/trunk I’ve got a branch of trunk svn://svn.domain.tld/repository/branches/dev Changes have been made to my branch and changes have been made to trunk, since I branched. I’m ready to merge my branch back into trunk. Approach / Overview Basically, to be safe, I need to first update my branch with the changes from trunk and resolve any conflicts.

1 minute read Published:

repost: If programming languages were religions

A very funny post for the programming nerds out there: If programming languages were religions… By amz – Monday, December 15, 2008 at 14:52 PHP would be Cafeteria Christianity – Fights with Java for the web market. It draws a few concepts from C and Java, but only those that it really likes. Maybe it’s not as coherent as other languages, but at least it leaves you with much more freedom and ostensibly keeps the core idea of the whole thing.

1 minute read Published:

Mantis to Basecamp to-do(s)

I just created a handy little script to create todos in basecamp for unresovled tickets in mantis. You can see the open sourced code/project: http://code.google.com/p/mantis2basecamp-todo/. This is something we found useful, if you use both tools, you might find it useful as well.