You are here

public function SubscriptionController::receive in Feeds 8.3

Receives a notification.

Parameters

\Drupal\feeds\SubscriptionInterface $feeds_subscription: The subscription entity.

string $feeds_push_token: The subscription token.

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

Return value

Symfony\Component\HttpFoundation\Response The response object.

Throws

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

1 string reference to 'SubscriptionController::receive'
feeds.routing.yml in ./feeds.routing.yml
feeds.routing.yml

File

src/Controller/SubscriptionController.php, line 173

Class

SubscriptionController
Returns responses for PuSH module routes.

Namespace

Drupal\feeds\Controller

Code

public function receive(SubscriptionInterface $feeds_subscription, $feeds_push_token, Request $request) {
  if ($feeds_subscription
    ->getToken() !== $feeds_push_token) {
    throw new NotFoundHttpException();
  }

  // X-Hub-Signature is in the format sha1=signature.
  parse_str($request->headers
    ->get('X-Hub-Signature'), $result);
  if (empty($result['sha1']) || !$feeds_subscription
    ->checkSignature($result['sha1'], $request
    ->getContent())) {
    throw new NotFoundHttpException();
  }
  $feed = $this
    ->entityTypeManager()
    ->getStorage('feeds_feed')
    ->load($feeds_subscription
    ->id());
  try {
    $feed
      ->pushImport($request
      ->getContent());
  } catch (\Exception $e) {
    return new Response('', 500);
  }
  return new Response('', 200);
}