Renew subscriptions that got no response.
authorChristian Weiske <cweiske@cweiske.de>
Fri, 21 Apr 2017 15:48:14 +0000 (17:48 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 21 Apr 2017 15:48:14 +0000 (17:48 +0200)
May happen if there were network issues or the server phinde is running on
was shut down directly after the subscription request was sent.

Resolves: https://github.com/cweiske/phinde/issues/28

bin/subscribe.php
src/phinde/Subscriptions.php

index 411fa8671cb86dfde43ec9c56eb9494e0f7be122..7d05f79a80af930a4b83b0702391691c3e5e5013 100755 (executable)
@@ -22,17 +22,18 @@ try {
     $cc->displayError($e->getMessage());
 }
 
+$subDb = new Subscriptions();
+
 $url = $res->args['url'];
 $url = Helper::addSchema($url);
 $urlObj = new \Net_URL2($url);
 $url = $urlObj->getNormalizedURL();
 if (!Helper::isUrlAllowed($url)) {
-    Log::error("Domain is not allowed; not crawling");
+    Log::error("Domain is not allowed; not subscribing");
+    $subDb->remove($url);
     exit(2);
 }
 
-$subDb = new Subscriptions();
-
 list($topic, $hub) = $subDb->detectHub($url);
 if ($hub === null) {
     Log::error('No hub URL found for topic');
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();