X-Git-Url: https://git.cweiske.de/phinde.git/blobdiff_plain/dd3e0698a71ca2746166f006135aeace83dfeb20..acf02a1269b9c191a66a7ea476f11d53d4ad0c08:/src/phinde/Subscriptions.php diff --git a/src/phinde/Subscriptions.php b/src/phinde/Subscriptions.php index 5aac9b2..87119c8 100644 --- a/src/phinde/Subscriptions.php +++ b/src/phinde/Subscriptions.php @@ -59,6 +59,23 @@ class Subscriptions return $res; } + /** + * Get all topics that either expired or expire soon + * + * @return \PDOStatement Result iterator + */ + public function getExpiring() + { + $stmt = $this->db->prepare( + 'SELECT * FROM subscriptions' + . ' WHERE sub_status IN ("active", "expired")' + . ' AND DATEDIFF(sub_expires, NOW()) <= 2' + ); + $stmt->execute(); + + return $stmt; + } + /** * Create a new subscription entry in database. * Automatically generates secret, capkey and lease seconds. @@ -94,6 +111,23 @@ class Subscriptions ); } + /** + * Renew a subscription: Set its status to "subscribing" + * + * @param integer $subId Subscription ID + * + * @return void + */ + public function renew($subId) + { + $this->db->prepare( + 'UPDATE subscriptions' + . ' SET sub_status = "subscribing"' + . ' , sub_updated = NOW()' + . ' WHERE sub_id = :id' + )->execute([':id' => $subId]); + } + /** * A subscription has been confirmed by the hub - mark it as active. * @@ -137,6 +171,14 @@ class Subscriptions )->execute([':id' => $subId]); } + /** + * Subscription has been cancelled/denied for some reason + * + * @param integer $subId Subscription ID + * @param string $reason Cancellation reason + * + * @return void + */ public function denied($subId, $reason) { $this->db->prepare( @@ -148,6 +190,13 @@ class Subscriptions )->execute([':id' => $subId, ':reason' => $reason]); } + /** + * Topic update notification has been received + * + * @param integer $subId Subscription ID + * + * @return void + */ public function pinged($subId) { $this->db->prepare(