You are here

protected function SubscriptionController::handleSubscribe in Feeds 8.3

Handles a subscribe request.

Parameters

int $subscription_id: The subscription entity id.

string $token: The subscription token.

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

\Symfony\Component\HttpFoundation\Response The response challenge.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException Thrown if anything seems amiss.

1 call to SubscriptionController::handleSubscribe()
SubscriptionController::subscribe in src/Controller/SubscriptionController.php
Handles subscribe/unsubscribe requests.

File

src/Controller/SubscriptionController.php, line 103

Class

SubscriptionController
Returns responses for PuSH module routes.

Namespace

Drupal\feeds\Controller

Code

protected function handleSubscribe($subscription_id, $token, Request $request) {
  if (!($subscription = $this
    ->entityTypeManager()
    ->getStorage('feeds_subscription')
    ->load($subscription_id))) {
    throw new NotFoundHttpException();
  }
  if ($subscription
    ->getToken() !== $token || $subscription
    ->getTopic() !== $request->query
    ->get('hub_topic')) {
    throw new NotFoundHttpException();
  }
  if ($subscription
    ->getState() !== 'subscribing' && $subscription
    ->getState() !== 'subscribed') {
    throw new NotFoundHttpException();
  }
  if ($lease_time = $request->query
    ->get('hub_lease_seconds')) {
    $subscription
      ->setLease($lease_time);
  }
  $subscription
    ->setState('subscribed');
  $subscription
    ->save();
  return new Response(Html::escape($request->query
    ->get('hub_challenge')), 200);
}