/** * Replace content associated with the media entry. * * @action updateContent * @param string $entryId Media entry id to update * @param KalturaResource $resource Resource to be used to replace entry media content * @param int $conversionProfileId The conversion profile id to be used on the entry * @param KalturaEntryReplacementOptions $advancedOptions Additional update content options * @return KalturaMediaEntry The updated media entry * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaErrors::ENTRY_REPLACEMENT_ALREADY_EXISTS * @throws KalturaErrors::INVALID_OBJECT_ID * @validateUser entry entryId edit */ function updateContentAction($entryId, KalturaResource $resource, $conversionProfileId = null, $advancedOptions = null) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::MEDIA_CLIP) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } //calling replaceResource only if no lock or we grabbed it $lock = kLock::create("media_updateContent_{$entryId}"); if ($lock && !$lock->lock(self::KLOCK_MEDIA_UPDATECONTENT_GRAB_TIMEOUT, self::KLOCK_MEDIA_UPDATECONTENT_HOLD_TIMEOUT)) { throw new KalturaAPIException(KalturaErrors::ENTRY_REPLACEMENT_ALREADY_EXISTS); } try { $this->replaceResource($resource, $dbEntry, $conversionProfileId, $advancedOptions); } catch (Exception $e) { if ($lock) { $lock->unlock(); } throw $e; } if ($lock) { $lock->unlock(); } return $this->getEntry($entryId); }
/** * @param LiveEntry $dbEntry * @return entry */ private function createRecordedEntry(LiveEntry $dbEntry, $mediaServerIndex) { $lock = kLock::create("live_record_" . $dbEntry->getId()); if ($lock && !$lock->lock(self::KLOCK_CREATE_RECORDED_ENTRY_GRAB_TIMEOUT, self::KLOCK_CREATE_RECORDED_ENTRY_HOLD_TIMEOUT)) { return; } // If while we were waiting for the lock, someone has updated the recorded entry id - we should use it. $dbEntry->reload(); if ($dbEntry->getRecordStatus() != RecordStatus::PER_SESSION && $dbEntry->getRecordedEntryId()) { $lock->unlock(); $recordedEntry = entryPeer::retrieveByPK($dbEntry->getRecordedEntryId()); return $recordedEntry; } $recordedEntry = null; try { $recordedEntryName = $dbEntry->getName(); if ($dbEntry->getRecordStatus() == RecordStatus::PER_SESSION) { $recordedEntryName .= ' ' . ($dbEntry->getRecordedEntryIndex() + 1); } $recordedEntry = new entry(); $recordedEntry->setType(entryType::MEDIA_CLIP); $recordedEntry->setMediaType(entry::ENTRY_MEDIA_TYPE_VIDEO); $recordedEntry->setRootEntryId($dbEntry->getId()); $recordedEntry->setName($recordedEntryName); $recordedEntry->setDescription($dbEntry->getDescription()); $recordedEntry->setSourceType(EntrySourceType::RECORDED_LIVE); $recordedEntry->setAccessControlId($dbEntry->getAccessControlId()); $recordedEntry->setConversionProfileId($dbEntry->getConversionProfileId()); $recordedEntry->setKuserId($dbEntry->getKuserId()); $recordedEntry->setPartnerId($dbEntry->getPartnerId()); $recordedEntry->setModerationStatus($dbEntry->getModerationStatus()); $recordedEntry->setIsRecordedEntry(true); $recordedEntry->setTags($dbEntry->getTags()); $recordedEntry->save(); $dbEntry->setRecordedEntryId($recordedEntry->getId()); $dbEntry->save(); $assets = assetPeer::retrieveByEntryId($dbEntry->getId(), array(assetType::LIVE)); foreach ($assets as $asset) { /* @var $asset liveAsset */ $asset->incLiveSegmentVersion($mediaServerIndex); $asset->save(); } } catch (Exception $e) { $lock->unlock(); throw $e; } $lock->unlock(); return $recordedEntry; }