return $stmt->fetchObject();
}
+ /**
+ * Count number of subscriptions
+ *
+ * @return array Array of keys with different status, number as value
+ */
+ public function count()
+ {
+ $stmt = $this->db->prepare(
+ 'SELECT COUNT(*) as count, sub_status FROM subscriptions'
+ . ' GROUP BY sub_status'
+ . ' ORDER BY sub_status'
+ );
+ $stmt->execute();
+
+ $res = [];
+ foreach ($stmt as $row) {
+ $res[$row['sub_status']] = $row['count'];
+ }
+
+ 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.
);
}
+ /**
+ * 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.
*
)->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(
)->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(