- // fetch the old subscription if it exists
- $r = q("SELECT * FROM `push_subscriber` WHERE `callback_url` = '%s'",
- dbesc($hub_callback));
-
- // delete old subscription if it exists
- dba::delete('push_subscriber', ['callback_url' => $hub_callback]);
-
- if ($subscribe) {
- $last_update = DateTimeFormat::utcNow();
- $push_flag = 0;
-
- // if we are just updating an old subscription, keep the
- // old values for push and last_update
- if (DBM::is_result($r)) {
- $last_update = $r[0]['last_update'];
- $push_flag = $r[0]['push'];
- }
-
- // subscribe means adding the row to the table
- q("INSERT INTO `push_subscriber` (`uid`, `callback_url`, " .
- "`topic`, `nickname`, `push`, `last_update`, `secret`) values " .
- "(%d, '%s', '%s', '%s', %d, '%s', '%s')",
- intval($owner['uid']),
- dbesc($hub_callback),
- dbesc($hub_topic),
- dbesc($nick),
- intval($push_flag),
- dbesc($last_update),
- dbesc($hub_secret));
- logger("pubsubhubbub: successfully subscribed [$hub_callback].");
- } else {
- logger("pubsubhubbub: successfully unsubscribed [$hub_callback].");
- // we do nothing here, since the row was already deleted
- }
- System::httpExit(202);
- }
+ PushSubscriber::renew($owner['uid'], $nick, $subscribe, $hub_callback, $hub_topic, $hub_secret);