From b66709215309126969104ad114874360785f3d57 Mon Sep 17 00:00:00 2001 From: James Walker Date: Thu, 17 Jun 2010 13:44:17 -0400 Subject: adding a Status_network::updateKeys() method, since DB_DataObject update doesn't do keys. --- classes/Status_network.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/classes/Status_network.php b/classes/Status_network.php index 4a1f2c374..64016dd79 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -144,6 +144,35 @@ class Status_network extends Safe_DataObject return parent::update($orig); } + /** + * DB_DataObject doesn't allow updating keys (even non-primary) + */ + function updateKeys(&$orig) + { + $this->_connect(); + foreach (array('hostname', 'pathname') as $k) { + if (strcmp($this->$k, $orig->$k) != 0) { + $parts[] = $k . ' = ' . $this->_quote($this->$k); + } + } + if (count($parts) == 0) { + // No changes + return true; + } + + $toupdate = implode(', ', $parts); + + $table = common_database_tablename($this->tableName()); + $qry = 'UPDATE ' . $table . ' SET ' . $toupdate . + ' WHERE nickname = ' . $this->_quote($this->nickname); + $orig->decache(); + $result = $this->query($qry); + if ($result) { + $this->encache(); + } + return $result; + } + function delete() { $this->decache(); # while we still have the values! -- cgit v1.2.3-54-g00ecf