public function objectReplaced(BaseObject $object, BaseObject $replacingObject, BatchJob $raisedJob = null) { KalturaLog::debug("check for DRM key replacement"); try { $replacingDrmKey = $this->getDrmKey($replacingObject); if ($replacingDrmKey) { $newKeyId = $replacingDrmKey->getDrmKey(); KalturaLog::debug("replacing drm key with: " . $newKeyId); $entryDrmKey = $this->getDrmKey($object); if (!$entryDrmKey) { $entryDrmKey = new DrmKey(); $entryDrmKey->setPartnerId($object->getPartnerId()); $entryDrmKey->setObjectId($object->getId()); $entryDrmKey->setObjectType(DrmKeyObjectType::ENTRY); $entryDrmKey->setProvider(PlayReadyPlugin::getPlayReadyProviderCoreValue()); } $entryDrmKey->setDrmKey($newKeyId); $entryDrmKey->save(); $object->putInCustomData(PlayReadyPlugin::ENTRY_CUSTOM_DATA_PLAY_READY_KEY_ID, $newKeyId); $object->save(); } } catch (Exception $e) { KalturaLog::err("Failed to update drm key for entry " . $object->getId()); } return true; }
/** * Get content key and key id for the given entry * * @action getEntryContentKey * @param string $entryId * @param bool $createIfMissing * @return KalturaPlayReadyContentKey $response * */ public function getEntryContentKeyAction($entryId, $createIfMissing = false) { $entry = entryPeer::retrieveByPK($entryId); if (!$entry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $keySeed = $this->getPartnerKeySeed(); $keyId = $this->getEntryKeyId($entry->getId()); if (!$keyId && $createIfMissing) { $drmKey = new DrmKey(); $drmKey->setPartnerId($entry->getPartnerId()); $drmKey->setObjectId($entryId); $drmKey->setObjectType(DrmKeyObjectType::ENTRY); $drmKey->setProvider(PlayReadyPlugin::getPlayReadyProviderCoreValue()); $keyId = kPlayReadyAESContentKeyGenerator::generatePlayReadyKeyId(); $drmKey->setDrmKey($keyId); try { $drmKey->save(); $entry->putInCustomData(PlayReadyPlugin::ENTRY_CUSTOM_DATA_PLAY_READY_KEY_ID, $keyId); $entry->save(); } catch (PropelException $e) { if ($e->getCause() && $e->getCause()->getCode() == self::MYSQL_CODE_DUPLICATE_KEY) { $keyId = $this->getEntryKeyId($entry->getId()); } else { throw $e; // Rethrow the unfamiliar exception } } } if (!$keyId) { throw new KalturaAPIException(KalturaPlayReadyErrors::FAILED_TO_GET_ENTRY_KEY_ID, $entryId); } $contentKey = $this->createContentKeyObject($keySeed, $keyId); $response = new KalturaPlayReadyContentKey(); $response->fromObject($contentKey, $this->getResponseProfile()); return $response; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param DrmKey $value A DrmKey object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(DrmKey $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) { self::$instances[$key] = $obj; kMemoryManager::registerPeer('DrmKeyPeer'); } } }