Keep filter when clicking pager links
[phinde.git] / bin / subscribe.php
index 768ee102a0182967c2fd8856de9f6a460d2b45b4..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');
@@ -43,12 +44,16 @@ if ($topic != $url) {
 }
 
 $sub = $subDb->get($topic);
-if ($sub !== false) {
-    Log::error('Topic exists already in subscription table');
-    Log::info('Current status: ' . $sub->sub_status);
-    exit(3);
+if ($sub === false) {
+    $subDb->create($topic);
+} else {
+    Log::info(
+        'Topic exists already in subscription table with status '
+        . $sub->sub_status
+    );
+    Log::info('Renewing subscription...');
+    $subDb->renew($sub->sub_id);
 }
-$subDb->create($topic);
 $sub = $subDb->get($topic);
 
 $callbackUrl = $GLOBALS['phinde']['baseurl'] . 'push-subscription.php'