diff --git a/classes/Foreign_user.php b/classes/Foreign_user.php index ec36dc3423..eeaf817876 100644 --- a/classes/Foreign_user.php +++ b/classes/Foreign_user.php @@ -70,33 +70,4 @@ class Foreign_user extends Managed_DataObject return empty($result) ? null : $fuser; } } - - function updateKeys(&$orig) - { - $this->_connect(); - $parts = array(); - foreach (array('id', 'service', 'uri', 'nickname') 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 = $this->tableName(); - if(common_config('db','quote_identifiers')) { - $table = '"' . $table . '"'; - } - $qry = 'UPDATE ' . $table . ' SET ' . $toupdate . - ' WHERE id = ' . $this->id; - $orig->decache(); - $result = $this->query($qry); - if ($result) { - $this->encache(); - } - return $result; - } } diff --git a/classes/Managed_DataObject.php b/classes/Managed_DataObject.php index 531232332d..d20d3cc27e 100644 --- a/classes/Managed_DataObject.php +++ b/classes/Managed_DataObject.php @@ -320,4 +320,35 @@ abstract class Managed_DataObject extends Memcached_DataObject // FIXME: How about forcing to return an int? Or will that overflow eventually? return $this->id; } + + // 'update' won't write key columns, so we have to do it ourselves. + public function updateKeys(&$orig) + { + if (!$orig instanceof $this) { + throw new ServerException('Tried updating a DataObject with a different class than itself.'); + } + + $this->_connect(); + $parts = array(); + foreach ($this->keys() 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 id = ' . $this->getID(); + $orig->decache(); + $result = $this->query($qry); + if ($result !== false) { + $this->encache(); + } + return $result; + } } diff --git a/classes/User.php b/classes/User.php index 242873efe1..060a67411d 100644 --- a/classes/User.php +++ b/classes/User.php @@ -152,34 +152,6 @@ class User extends Managed_DataObject return $this->getProfile()->hasPendingSubscription($other); } - // 'update' won't write key columns, so we have to do it ourselves. - - function updateKeys(&$orig) - { - $this->_connect(); - $parts = array(); - foreach (array('nickname', 'email', 'incomingemail', 'sms', 'carrier', 'smsemail') 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 id = ' . $this->id; - $orig->decache(); - $result = $this->query($qry); - if ($result) { - $this->encache(); - } - return $result; - } - /** * Get the most recent notice posted by this user, if any. *