public static function BrightcoveUtil::checkUpdatedVersion in Brightcove Video Connect 3.x
Same name and namespace in other branches
- 8.2 src/BrightcoveUtil.php \Drupal\brightcove\BrightcoveUtil::checkUpdatedVersion()
- 8 src/BrightcoveUtil.php \Drupal\brightcove\BrightcoveUtil::checkUpdatedVersion()
Check updated version of the CMS entity.
If the checked CMS entity has a newer version of it on Brightcove then show a message about it with a link to be able to update the local version.
Parameters
\Drupal\brightcove\BrightcoveCMSEntityInterface $entity: Brightcove CMS Entity, can be BrightcoveVideo or BrightcovePlaylist. Player is currently not supported.
Throws
\Exception If the version for the given entity is cannot be checked.
1 call to BrightcoveUtil::checkUpdatedVersion()
- BrightcoveVideoPlaylistForm::buildForm in src/
Form/ BrightcoveVideoPlaylistForm.php - Form constructor.
File
- src/
BrightcoveUtil.php, line 173
Class
- BrightcoveUtil
- Utility class for Brightcove.
Namespace
Drupal\brightcoveCode
public static function checkUpdatedVersion(BrightcoveCMSEntityInterface $entity) {
$client = self::getClient($entity
->getApiClient());
if (!is_null($client)) {
$cms = self::getCmsApi($entity
->getApiClient());
$entity_type = '';
try {
if ($entity instanceof BrightcoveVideo) {
$entity_type = 'video';
$cms_entity = $cms
->getVideo($entity
->getBrightcoveId());
}
elseif ($entity instanceof BrightcovePlaylist) {
$entity_type = 'playlist';
$cms_entity = $cms
->getPlaylist($entity
->getBrightcoveId());
}
else {
throw new \Exception(t("Can't check version for :entity_type entity.", [
':entity_type' => get_class($entity),
]));
}
if (isset($cms_entity)) {
if ($entity
->getChangedTime() < strtotime($cms_entity
->getUpdatedAt())) {
$url = Url::fromRoute("brightcove_manual_update_{$entity_type}", [
'entity_id' => $entity
->id(),
], [
'query' => [
'token' => \Drupal::getContainer()
->get('csrf_token')
->get("brightcove_{$entity_type}/{$entity->id()}/update"),
],
]);
drupal_set_message(t("There is a newer version of this :type on Brightcove, you may want to <a href=':url'>update the local version</a> before editing it.", [
':type' => $entity_type,
':url' => $url
->toString(),
]), 'warning');
}
}
} catch (APIException $e) {
if (!empty($entity_type)) {
$url = Url::fromRoute("entity.brightcove_{$entity_type}.delete_form", [
"brightcove_{$entity_type}" => $entity
->id(),
]);
drupal_set_message(t("This :type no longer exists on Brightcove. You may want to <a href=':url'>delete the local version</a> too.", [
':type' => $entity_type,
':url' => $url
->toString(),
]), 'error');
}
else {
drupal_set_message($e
->getMessage(), 'error');
}
}
}
else {
drupal_set_message(t('Brightcove API connection error: :error', [
':error' => self::getApiClient($entity
->getApiClient())
->getClientStatusMessage(),
]), 'error');
}
}