aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2017-04-21 17:48:14 +0200
committerChristian Weiske <cweiske@cweiske.de>2017-04-21 17:48:14 +0200
commitc38abf3b8de60ec1012f0fdf6e65658b97b3a13b (patch)
tree1f25f418e4bd923491fd7056865a84015dd895b0
parent85d12ec744c29a53acd22f6476994cd16ccc16bf (diff)
downloadphinde-c38abf3b8de60ec1012f0fdf6e65658b97b3a13b.tar.gz
phinde-c38abf3b8de60ec1012f0fdf6e65658b97b3a13b.zip
Renew subscriptions that got no response.
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
-rwxr-xr-xbin/subscribe.php7
-rw-r--r--src/phinde/Subscriptions.php28
2 files changed, 30 insertions, 5 deletions
diff --git a/bin/subscribe.php b/bin/subscribe.php
index 411fa86..7d05f79 100755
--- a/bin/subscribe.php
+++ b/bin/subscribe.php
@@ -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');
diff --git a/src/phinde/Subscriptions.php b/src/phinde/Subscriptions.php
index 87119c8..e49e817 100644
--- a/src/phinde/Subscriptions.php
+++ b/src/phinde/Subscriptions.php
@@ -38,6 +38,22 @@ class Subscriptions
}
/**
+ * 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
*
* @return array Array of keys with different status, number as value
@@ -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();