5 * Unsubscribe from a WebSub subscription
7 require_once __DIR__ . '/../src/init.php';
9 $cc = new \Console_CommandLine();
10 $cc->description = 'Unsubscribe from a WebSub subscription';
11 $cc->version = '0.0.1';
15 'description' => 'URL to process',
21 } catch (\Exception $e) {
22 $cc->displayError($e->getMessage());
25 $subDb = new Subscriptions();
27 $url = $res->args['url'];
28 $url = Helper::addSchema($url);
29 $urlObj = new \Net_URL2($url);
30 $topic = $urlObj->getNormalizedURL();
33 $sub = $subDb->get($topic);
35 Log::error("No existing subscription for URL");
38 if ($sub->sub_status === 'unsubscribed') {
39 Log::info('Already unsubscribed');
43 $subDb->unsubscribing($sub->sub_id);
45 $callbackUrl = $GLOBALS['phinde']['baseurl'] . 'push-subscription.php'
46 . '?hub.topic=' . urlencode($topic)
47 . '&capkey=' . urlencode($sub->sub_capkey);
48 $req = new HttpRequest($sub->sub_hub, 'POST');
49 $req->addPostParameter('hub.callback', $callbackUrl);
50 $req->addPostParameter('hub.mode', 'unsubscribe');
51 $req->addPostParameter('hub.topic', $topic);
52 $req->addPostParameter('hub.lease_seconds', $sub->sub_lease_seconds);
53 $req->addPostParameter('hub.secret', $sub->sub_secret);
56 if (intval($res->getStatus()) == 202) {
57 Log::info('Unsubscription initiated');
62 'Error: Unsubscription response status code was not 202 but '
65 Log::error($res->getBody());