Renew subscriptions that got no response.
[phinde.git] / src / phinde / Subscriptions.php
index 87119c8b2cb2e9bc73e1d74256255d66e98688dc..e49e817549d811981fcfa362584e18129e0a68c5 100644 (file)
@@ -37,6 +37,22 @@ class Subscriptions
         return $stmt->fetchObject();
     }
 
+    /**
+     * Remove a topic
+     *
+     * @param string $topic Topic URL
+     *
+     * @return void
+     */
+    public function remove($topic)
+    {
+        $stmt = $this->db->prepare(
+            'DELETE FROM subscriptions'
+            . ' WHERE sub_topic = :topic'
+        );
+        $stmt->execute([':topic' => $topic]);
+    }
+
     /**
      * Count number of subscriptions
      *
@@ -68,8 +84,16 @@ class Subscriptions
     {
         $stmt = $this->db->prepare(
             'SELECT * FROM subscriptions'
-            . ' WHERE sub_status IN ("active", "expired")'
-            . ' AND DATEDIFF(sub_expires, NOW()) <= 2'
+            . ' WHERE'
+            . '('
+            //expire soon
+            . '  sub_status IN ("active", "expired")'
+            . '  AND DATEDIFF(sub_expires, NOW()) <= 2'
+            . ') OR ('
+            //no reaction to subscription within 10 minutes
+            . '  sub_status = "subscribing"'
+            . '  AND TIMEDIFF(NOW(), sub_created) > "00:10:00"'
+            . ')'
         );
         $stmt->execute();