Use the new onUpdateKeys in dataobject for tasks on-update of keys

sets the hashkey column of the row to sha1(topic + '|' + callback)
This commit is contained in:
Mikael Nordfeldth 2016-03-23 15:22:34 +01:00
parent f83b81b8c4
commit 0767bf487e

View File

@ -17,9 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
/** /**
* PuSH feed subscription record * PuSH feed subscription record
@ -202,16 +200,25 @@ class HubSub extends Managed_DataObject
} }
} }
/** // set the hashkey automagically on insert
* Insert wrapper; transparently set the hash key from topic and callback columns. protected function onInsert()
* @return mixed success
*/
function insert()
{ {
$this->hashkey = self::hashkey($this->getTopic(), $this->callback); $this->setHashkey();
$this->created = common_sql_now(); $this->created = common_sql_now();
$this->modified = common_sql_now(); $this->modified = common_sql_now();
return parent::insert(); }
// update the hashkey automagically if needed
protected function onUpdateKeys(Managed_DataObject $orig)
{
if ($this->topic !== $orig->topic || $this->callback !== $orig->callback) {
$this->setHashkey();
}
}
protected function setHashkey()
{
$this->hashkey = self::hashkey($this->topic, $this->callback);
} }
/** /**
@ -322,7 +329,7 @@ class HubSub extends Managed_DataObject
if ($response->isOk()) { if ($response->isOk()) {
$orig = clone($this); $orig = clone($this);
$this->callback = $httpscallback; $this->callback = $httpscallback;
$this->hashkey = self::hashkey($this->getTopic(), $this->callback); // NOTE: hashkey will be set in $this->onUpdateKeys($orig) through updateWithKeys
$this->updateWithKeys($orig); $this->updateWithKeys($orig);
return true; return true;
} }