public function BrightcoveSubscriptionController::notificationCallback in Brightcove Video Connect 8
Same name and namespace in other branches
- 8.2 src/Controller/BrightcoveSubscriptionController.php \Drupal\brightcove\Controller\BrightcoveSubscriptionController::notificationCallback()
- 3.x src/Controller/BrightcoveSubscriptionController.php \Drupal\brightcove\Controller\BrightcoveSubscriptionController::notificationCallback()
Menu callback to handle the Brightcove notification callback.
Parameters
\Symfony\Component\HttpFoundation\Request $request: Request object.
Return value
\Symfony\Component\HttpFoundation\Response Redirection response.
Throws
\Exception
File
- src/
Controller/ BrightcoveSubscriptionController.php, line 85
Class
- BrightcoveSubscriptionController
- Provides controller for subscription related callbacks.
Namespace
Drupal\brightcove\ControllerCode
public function notificationCallback(Request $request) {
BrightcoveUtil::runWithSemaphore(function () use ($request) {
$content = Json::decode($request
->getContent());
switch ($content['event']) {
case 'video-change':
// Try to update an existing video or create a new one if not exist.
try {
// Get CMS API.
$api_client = BrightcoveAPIClient::loadByAccountId($content['account_id']);
if (!empty($api_client)) {
$cms = BrightcoveUtil::getCmsApi($api_client
->id());
$video = $cms
->getVideo($content['video']);
BrightcoveVideo::createOrUpdate($video, $this->videoStorage, $api_client
->id());
}
} catch (\Exception $e) {
// Log exception except if it's an APIException and the response
// code was 404.
if ($e instanceof APIException && $e
->getCode() != 404 || !$e instanceof APIException) {
watchdog_exception('brightcove', $e);
}
}
break;
}
});
return new Response();
}