Do not use STDOUT and STDERR constants
[phinde.git] / bin / subscribe.php
index 411fa8671cb86dfde43ec9c56eb9494e0f7be122..9df5b08c484307c6bc692a003aa111ab971e0de3 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');
@@ -44,7 +45,7 @@ if ($topic != $url) {
 
 $sub = $subDb->get($topic);
 if ($sub === false) {
-    $subDb->create($topic);
+    $subDb->create($topic, $hub);
 } else {
     Log::info(
         'Topic exists already in subscription table with status '
@@ -52,6 +53,7 @@ if ($sub === false) {
     );
     Log::info('Renewing subscription...');
     $subDb->renew($sub->sub_id);
+    $hub = $sub->sub_hub;
 }
 $sub = $subDb->get($topic);