Memcached_DataObject extensions got their update functions more consistent

This commit is contained in:
Mikael Nordfeldth 2013-10-28 19:36:05 +01:00
parent fa91bc7132
commit 3ba6374b9d
9 changed files with 40 additions and 51 deletions

View File

@ -124,10 +124,10 @@ class Config extends Managed_DataObject
return $result; return $result;
} }
function update($orig=null) function update($dataObject=false)
{ {
$result = parent::update($orig); $result = parent::update($dataObject);
if ($result) { if ($result !== false) {
Config::_blowSettingsCache(); Config::_blowSettingsCache();
} }
return $result; return $result;

View File

@ -388,13 +388,13 @@ class Memcached_DataObject extends Safe_DataObject
return $result; return $result;
} }
function update($orig=null) function update($dataObject=false)
{ {
if (is_object($orig) && $orig instanceof Memcached_DataObject) { if (is_object($dataObject) && $dataObject instanceof Memcached_DataObject) {
$orig->decache(); # might be different keys $dataObject->decache(); # might be different keys
} }
$result = parent::update($orig); $result = parent::update($dataObject);
if ($result) { if ($result !== false) {
$this->fixupTimestamps(); $this->fixupTimestamps();
$this->encache(); $this->encache();
} }

View File

@ -842,12 +842,12 @@ class Profile extends Managed_DataObject
return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit)); return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit));
} }
public function update($orig) function update($dataObject=false)
{ {
if ($this->nickname != $orig->nickname) { if (is_object($dataObject) && $this->nickname != $dataObject->nickname) {
$local = User::getKV('id', $this->id); try {
if ($local instanceof User) { $local = $this->getUser();
common_debug("Updating User ({$this->id}) nickname from {$orig->nickname} to {$this->nickname}"); common_debug("Updating User ({$this->id}) nickname from {$dataObject->nickname} to {$this->nickname}");
$origuser = clone($local); $origuser = clone($local);
$local->nickname = $this->nickname; $local->nickname = $this->nickname;
$result = $local->updateKeys($origuser); $result = $local->updateKeys($origuser);
@ -861,10 +861,12 @@ class Profile extends Managed_DataObject
if ($local->hasRole(Profile_role::OWNER)) { if ($local->hasRole(Profile_role::OWNER)) {
User::blow('user:site_owner'); User::blow('user:site_owner');
} }
} catch (NoSuchUserException $e) {
// Nevermind...
} }
} }
return parent::update($orig); return parent::update($dataObject);
} }
function delete() function delete()

View File

@ -356,23 +356,23 @@ class Profile_list extends Managed_DataObject
* Update a people tag gracefully * Update a people tag gracefully
* also change "tag" fields in profile_tag table * also change "tag" fields in profile_tag table
* *
* @param Profile_list $orig Object's original form * @param Profile_list $dataObject Object's original form
* *
* @return boolean success * @return boolean success
*/ */
function update($orig=null) function update($dataObject=false)
{ {
$result = true; if (!is_object($dataObject) && !$dataObject instanceof Profile_list) {
return parent::update($dataObject);
if (!is_object($orig) && !$orig instanceof Profile_list) {
parent::update($orig);
} }
$result = true;
// if original tag was different // if original tag was different
// check to see if the new tag already exists // check to see if the new tag already exists
// if not, rename the tag correctly // if not, rename the tag correctly
if($orig->tag != $this->tag || $orig->tagger != $this->tagger) { if($dataObject->tag != $this->tag || $dataObject->tagger != $this->tagger) {
$existing = Profile_list::getByTaggerAndTag($this->tagger, $this->tag); $existing = Profile_list::getByTaggerAndTag($this->tagger, $this->tag);
if(!empty($existing)) { if(!empty($existing)) {
// TRANS: Server exception. // TRANS: Server exception.
@ -381,10 +381,9 @@ class Profile_list extends Managed_DataObject
} }
// move the tag // move the tag
// XXX: allow OStatus plugin to send out profile tag // XXX: allow OStatus plugin to send out profile tag
$result = Profile_tag::moveTag($orig, $this); $result = Profile_tag::moveTag($dataObject, $this);
} }
parent::update($orig); return parent::update($dataObject);
return $result;
} }
/** /**

View File

@ -282,11 +282,11 @@ class Profile_tag extends Managed_DataObject
$tags->escape($orig->tag), $tags->escape($orig->tag),
$tags->escape($orig->tagger))); $tags->escape($orig->tagger)));
if (!$result) { if ($result === false) {
common_log_db_error($tags, 'UPDATE', __FILE__); common_log_db_error($tags, 'UPDATE', __FILE__);
return false; throw new Exception('Could not move Profile_tag, see db log for details.');
} }
return true; return $result;
} }
static function blowCaches($tagger, $tagged) { static function blowCaches($tagger, $tagged) {

View File

@ -147,12 +147,12 @@ class Status_network extends Safe_DataObject
} }
} }
function update($orig=null) function update($dataObject=false)
{ {
if (is_object($orig)) { if (is_object($dataObject)) {
$orig->decache(); # might be different keys $dataObject->decache(); # might be different keys
} }
return parent::update($orig); return parent::update($dataObject);
} }
/** /**

View File

@ -389,18 +389,16 @@ class Subscription extends Managed_DataObject
* Because we cache subscriptions, it's useful to flush them * Because we cache subscriptions, it's useful to flush them
* here. * here.
* *
* @param mixed $orig Original version of object * @param mixed $dataObject Original version of object
* *
* @return boolean success flag. * @return boolean success flag.
*/ */
function update($orig=null) function update($dataObject=false)
{ {
$result = parent::update($orig);
self::blow('subscription:by-subscriber:'.$this->subscriber); self::blow('subscription:by-subscriber:'.$this->subscriber);
self::blow('subscription:by-subscribed:'.$this->subscribed); self::blow('subscription:by-subscribed:'.$this->subscribed);
return $result; return parent::update($dataObject);
} }
function getURI() function getURI()

View File

@ -782,14 +782,14 @@ class User_group extends Managed_DataObject
return parent::delete(); return parent::delete();
} }
public function update($orig) public function update($dataObject=false)
{ {
// Whenever the User_group is updated, find the Local_group // Whenever the User_group is updated, find the Local_group
// and updates it nickname too. // and update its nickname too.
if ($this->nickname != $orig->nickname) { if ($this->nickname != $dataObject->nickname) {
$local = Local_group::getKV('group_id', $this->id); $local = Local_group::getKV('group_id', $this->id);
if ($local instanceof Local_group) { if ($local instanceof Local_group) {
common_debug("Updating Local_group ({$this->id}) nickname from {$orig->nickname} to {$this->nickname}"); common_debug("Updating Local_group ({$this->id}) nickname from {$dataObject->nickname} to {$this->nickname}");
$local->setNickname($this->nickname); $local->setNickname($this->nickname);
} }
} }
@ -814,7 +814,7 @@ class User_group extends Managed_DataObject
throw new ServerException(_('Unable to update profile')); throw new ServerException(_('Unable to update profile'));
} }
return parent::update($orig); return parent::update($dataObject);
} }
function isPrivate() function isPrivate()

View File

@ -191,16 +191,6 @@ class HubSub extends Managed_DataObject
return parent::insert(); return parent::insert();
} }
/**
* Update wrapper; transparently update modified column.
* @return boolean success
*/
function update($old=null)
{
$this->modified = common_sql_now();
return parent::update($old);
}
/** /**
* Schedule delivery of a 'fat ping' to the subscriber's callback * Schedule delivery of a 'fat ping' to the subscriber's callback
* endpoint. If queues are disabled, this will run immediately. * endpoint. If queues are disabled, this will run immediately.