public function BrightcoveSubscriptionController::notificationCallback in Brightcove Video Connect 8.2
Same name and namespace in other branches
- 8 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 97
Class
- BrightcoveSubscriptionController
- Provides controller for subscription related callbacks.
Namespace
Drupal\brightcove\ControllerCode
public function notificationCallback(Request $request) {
$status = 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 (APIException $e) {
// In case of 404 we have nothing to do.
if ($e
->getCode() != 404) {
watchdog_exception('brightcove', $e, $e
->getMessage());
return FALSE;
}
}
break;
}
return TRUE;
}, $this->lock);
// Return 409 only if the status is FALSE, in any other case such as TRUE or
// NULL return 200.
return new Response('', $status === FALSE ? 409 : 200);
}