aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/renew-subscriptions.php16
-rwxr-xr-xbin/subscribe.php14
2 files changed, 25 insertions, 5 deletions
diff --git a/bin/renew-subscriptions.php b/bin/renew-subscriptions.php
new file mode 100755
index 0000000..16bc11b
--- /dev/null
+++ b/bin/renew-subscriptions.php
@@ -0,0 +1,16 @@
+#!/usr/bin/env php
+<?php
+namespace phinde;
+/**
+ * Renew subscriptions
+ * Call this once a day with cron.
+ */
+require_once __DIR__ . '/../src/init.php';
+
+chdir(__DIR__);
+$subDb = new Subscriptions();
+foreach ($subDb->getExpiring() as $sub) {
+ Log::info('Expires soon: ' . $sub['sub_topic']);
+ passthru('./subscribe.php ' . escapeshellarg($sub['sub_topic']));
+}
+?>
diff --git a/bin/subscribe.php b/bin/subscribe.php
index 768ee10..411fa86 100755
--- a/bin/subscribe.php
+++ b/bin/subscribe.php
@@ -43,12 +43,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'