From 1d26fedf12491dae42260c54bf504fed4167c947 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 13 Jan 2016 19:45:20 +0100 Subject: [PATCH] Don't store lease seconds, just sub start and end The seconds can always be calculated from the dates! --- plugins/OStatus/classes/HubSub.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/OStatus/classes/HubSub.php b/plugins/OStatus/classes/HubSub.php index 54949c6113..2e3fde6243 100644 --- a/plugins/OStatus/classes/HubSub.php +++ b/plugins/OStatus/classes/HubSub.php @@ -34,7 +34,6 @@ class HubSub extends Managed_DataObject public $topic; // varchar(191) not 255 because utf8mb4 takes more space public $callback; // varchar(191) not 255 because utf8mb4 takes more space public $secret; - public $lease; public $sub_start; public $sub_end; public $created; @@ -58,7 +57,6 @@ class HubSub extends Managed_DataObject 'topic' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'HubSub topic'), 'callback' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'HubSub callback'), 'secret' => array('type' => 'text', 'description' => 'HubSub stored secret'), - 'lease' => array('type' => 'int', 'description' => 'HubSub leasetime'), 'sub_start' => array('type' => 'datetime', 'description' => 'subscription start'), 'sub_end' => array('type' => 'datetime', 'description' => 'subscription end'), 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'), @@ -97,11 +95,28 @@ class HubSub extends Managed_DataObject } common_debug('PuSH hub after sanitation: lease_seconds=='._ve($length)); - $this->lease = $length; $this->sub_start = common_sql_now(); $this->sub_end = common_sql_date(time() + $length); } + function getLease() + { + if (empty($this->sub_start) || empty($this->sub_end)) { + return null; + } + $length = strtotime($this->sub_end) - strtotime($this->sub_start); + assert($length > 0); + return $length; + } + + function getLeaseRemaining() + { + if (empty($this->sub_end)) { + return null; + } + return strtotime($this->sub_end) - time(); + } + /** * Schedule a future verification ping to the subscriber. * If queues are disabled, will be immediate. @@ -144,7 +159,7 @@ class HubSub extends Managed_DataObject 'hub.topic' => $this->getTopic(), 'hub.challenge' => $challenge); if ($mode == 'subscribe') { - $params['hub.lease_seconds'] = $this->lease; + $params['hub.lease_seconds'] = $this->getLease(); } if ($token !== null) { // TODO: deprecated in PuSH 0.4 $params['hub.verify_token'] = $token; // let's put it in there if remote uses PuSH <0.4 -- 2.39.5