function getAssetsByLanguage($entryId, array $assetTypes, $spokenLanguage, $returnSingleObject = false) { $objects = $returnSingleObject ? null : array(); $statuses = array(asset::ASSET_STATUS_QUEUED, asset::ASSET_STATUS_READY); $resultArray = assetPeer::retrieveByEntryId($entryId, $assetTypes, $statuses); foreach ($resultArray as $object) { if ($object->getLanguage() == $spokenLanguage) { if ($returnSingleObject) { return $object; } $objects[$object->getContainerFormat()] = $object; } } return $objects; }
/** * Adds new live stream entry. * The entry will be queued for provision. * * @action add * @param KalturaLiveStreamEntry $liveStreamEntry Live stream entry metadata * @param KalturaSourceType $sourceType Live stream source type * @return KalturaLiveStreamEntry The new live stream entry * * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL */ function addAction(KalturaLiveStreamEntry $liveStreamEntry, $sourceType = null) { if ($sourceType) { $liveStreamEntry->sourceType = $sourceType; } elseif (is_null($liveStreamEntry->sourceType)) { // default sourceType is AKAMAI_LIVE $liveStreamEntry->sourceType = kPluginableEnumsManager::coreToApi('EntrySourceType', $this->getPartner()->getDefaultLiveStreamEntrySourceType()); } $dbEntry = $this->prepareEntryForInsert($liveStreamEntry); $dbEntry->save(); $te = new TrackEntry(); $te->setEntryId($dbEntry->getId()); $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY); $te->setDescription(__METHOD__ . ":" . __LINE__ . "::" . $dbEntry->getSource()); TrackEntry::addTrackEntry($te); //If a jobData can be created for entry sourceType, add provision job. Otherwise, just save the entry. $jobData = kProvisionJobData::getInstance($dbEntry->getSource()); if ($jobData) { /* @var $data kProvisionJobData */ $jobData->populateFromPartner($dbEntry->getPartner()); $jobData->populateFromEntry($dbEntry); kJobsManager::addProvisionProvideJob(null, $dbEntry, $jobData); } else { $dbEntry->setStatus(entryStatus::READY); $dbEntry->save(); $liveAssets = assetPeer::retrieveByEntryId($dbEntry->getId(), array(assetType::LIVE)); foreach ($liveAssets as $liveAsset) { /* @var $liveAsset liveAsset */ $liveAsset->setStatus(asset::ASSET_STATUS_READY); $liveAsset->save(); } } myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry, $this->getPartnerId(), null, null, null, $dbEntry->getId()); $liveStreamEntry->fromObject($dbEntry, $this->getResponseProfile()); return $liveStreamEntry; }
public function contribute(BaseObject $object, SimpleXMLElement $mrss, kMrssParameters $mrssParams = null) { if (!$object instanceof entry) { return; } $types = KalturaPluginManager::getExtendedTypes(assetPeer::OM_CLASS, AttachmentPlugin::getAssetTypeCoreValue(AttachmentAssetType::ATTACHMENT)); $attachmentAssets = assetPeer::retrieveByEntryId($object->getId(), $types); foreach ($attachmentAssets as $attachmentAsset) { $this->contributeAttachmentAssets($attachmentAsset, $mrss); } }
/** * @param entry $entry * @param entry $tempEntry */ public static function replaceEntry(entry $entry, entry $tempEntry = null) { if (!$tempEntry) { $tempEntry = entryPeer::retrieveByPK($entry->getReplacingEntryId()); } if (!$tempEntry) { KalturaLog::err("Temp entry id [" . $entry->getReplacingEntryId() . "] not found"); return; } //Extract all assets of the temp entry $tempAssets = assetPeer::retrieveByEntryId($tempEntry->getId()); //Extract all assets of the existing entry $oldAssets = assetPeer::retrieveByEntryId($entry->getId()); $newAssets = array(); //Loop which creates a mapping between the new assets' paramsId and their type to the asset itself foreach ($tempAssets as $newAsset) { if ($newAsset->getStatus() != asset::FLAVOR_ASSET_STATUS_READY) { KalturaLog::info("Do not add new asset [" . $newAsset->getId() . "] to flavor [" . $newAsset->getFlavorParamsId() . "] status [" . $newAsset->getStatus() . "]"); continue; } //If doesn't exist - create a new array for the current asset's type. if (!isset($newAssets[$newAsset->getType()])) { $newAssets[$newAsset->getType()] = array(); } if ($newAsset->getFlavorParamsId() || $newAsset instanceof flavorAsset) { $newAssets[$newAsset->getType()][$newAsset->getFlavorParamsId()] = $newAsset; KalturaLog::info("Added new asset [" . $newAsset->getId() . "] for asset params [" . $newAsset->getFlavorParamsId() . "]"); } else { $newAssets[$newAsset->getType()]['asset_' . count($newAssets[$newAsset->getType()])] = $newAsset; KalturaLog::info("Added new asset [" . $newAsset->getId() . "] with no asset params"); } } $defaultThumbAssetNew = null; $defaultThumbAssetOld = null; foreach ($oldAssets as $oldAsset) { /* @var $oldAsset asset */ //If the newAssets map contains an asset of the same type and paramsId as the current old asset, // re-link the old asset to the new asset. if (isset($newAssets[$oldAsset->getType()]) && isset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()])) { $newAsset = $newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]; if ($oldAsset->hasTag(assetParams::TAG_RECORDING_ANCHOR)) { $newAsset->addTags(array(assetParams::TAG_RECORDING_ANCHOR)); } /* @var $newAsset asset */ KalturaLog::info("Create link from new asset [" . $newAsset->getId() . "] to old asset [" . $oldAsset->getId() . "] for flavor [" . $oldAsset->getFlavorParamsId() . "]"); $oldAsset->linkFromAsset($newAsset); $oldAsset->save(); self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_ISM); self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_ISMC); self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_MPD); $newFlavorMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($newAsset->getId()); if ($newFlavorMediaInfo) { $oldFlavorNewMediaInfo = $newFlavorMediaInfo->copy(); $oldFlavorNewMediaInfo->setFlavorAssetId($oldAsset->getId()); $oldFlavorNewMediaInfo->setFlavorAssetVersion($oldAsset->getVersion()); $oldFlavorNewMediaInfo->save(); } unset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]); if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $defaultThumbAssetNew = $oldAsset; KalturaLog::info("Nominating ThumbAsset [" . $oldAsset->getId() . "] as the default ThumbAsset after replacent"); } } elseif ($oldAsset instanceof flavorAsset || $oldAsset instanceof thumbAsset) { if ($oldAsset instanceof thumbAsset && $oldAsset->keepOnEntryReplacement()) { KalturaLog::info("KeepManualThumbnails ind is set, manual thumbnail is not deleted [" . $oldAsset->getId() . "]"); if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $defaultThumbAssetOld = $oldAsset; } } else { KalturaLog::info("Delete old asset [" . $oldAsset->getId() . "] for paramsId [" . $oldAsset->getFlavorParamsId() . "]"); $oldAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED); $oldAsset->setDeletedAt(time()); $oldAsset->save(); } } } foreach ($newAssets as $newAssetsByTypes) { foreach ($newAssetsByTypes as $newAsset) { $createdAsset = $newAsset->copyToEntry($entry->getId(), $entry->getPartnerId()); KalturaLog::info("Copied from new asset [" . $newAsset->getId() . "] to copied asset [" . $createdAsset->getId() . "] for flavor [" . $newAsset->getFlavorParamsId() . "]"); if ($createdAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $defaultThumbAssetNew = $newAsset; KalturaLog::info("Nominating ThumbAsset [" . $newAsset->getId() . "] as the default ThumbAsset after replacent"); } } } if ($defaultThumbAssetOld) { KalturaLog::info("Kepping ThumbAsset [" . $defaultThumbAssetOld->getId() . "] as the default ThumbAsset"); } elseif ($defaultThumbAssetNew) { kBusinessConvertDL::setAsDefaultThumbAsset($defaultThumbAssetNew); KalturaLog::info("Setting ThumbAsset [" . $defaultThumbAssetNew->getId() . "] as the default ThumbAsset"); } else { KalturaLog::info("No default ThumbAsset found for replacing entry [" . $tempEntry->getId() . "]"); $entry->setThumbnail(".jpg"); // thumbnailversion++ $entry->save(); $tempEntrySyncKey = $tempEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); $realEntrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); kFileSyncUtils::createSyncFileLinkForKey($realEntrySyncKey, $tempEntrySyncKey); } self::createIsmManifestFileSyncLinkFromReplacingEntry($tempEntry, $entry); $entry->setDimensions($tempEntry->getWidth(), $tempEntry->getHeight()); $entry->setLengthInMsecs($tempEntry->getLengthInMsecs()); $entry->setConversionProfileId($tempEntry->getConversionProfileId()); $entry->setConversionQuality($tempEntry->getConversionQuality()); $entry->setReplacingEntryId(null); $entry->setReplacementStatus(entryReplacementStatus::NONE); $entry->setReplacementOptions(null); $entry->setStatus($tempEntry->getStatus()); $entry->save(); //flush deffered events to re-index sphinx before temp entry deletion kEventsManager::flushEvents(); kBusinessConvertDL::checkForPendingLiveClips($entry); kEventsManager::raiseEvent(new kObjectReplacedEvent($entry, $tempEntry)); myEntryUtils::deleteEntry($tempEntry, null, true); $te = new TrackEntry(); $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_REPLACED_ENTRY); $te->setEntryId($entry->getId()); $te->setParam1Str($tempEntry->getId()); $te->setDescription(__METHOD__ . "[" . __LINE__ . "]"); TrackEntry::addTrackEntry($te); }
public static function copyEntryData(entry $entry, entry $targetEntry) { // for any type that does not require assets: $shouldCopyDataForNonClip = true; if ($entry->getType() == entryType::MEDIA_CLIP) { $shouldCopyDataForNonClip = false; } if ($entry->getType() == entryType::PLAYLIST) { $shouldCopyDataForNonClip = false; } $shouldCopyDataForClip = false; // only images get their data copied if ($entry->getType() == entryType::MEDIA_CLIP) { if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) { $shouldCopyDataForClip = true; } } if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) { // copy the data $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath $to = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]"); kFileSyncUtils::softCopy($from, $to); } $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); if (kFileSyncUtils::fileSync_exists($ismFrom)) { $ismTo = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]"); kFileSyncUtils::softCopy($ismFrom, $ismTo); } $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); if (kFileSyncUtils::fileSync_exists($ismcFrom)) { $ismcTo = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]"); kFileSyncUtils::softCopy($ismcFrom, $ismcTo); } $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); // replaced__getThumbnailPath $considerCopyThumb = true; // if entry is image - data is thumbnail, and it was copied if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $considerCopyThumb = false; } // if entry is not clip, and there is no file in both DCs - nothing to copy if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) { $considerCopyThumb = false; } if ($considerCopyThumb) { $skipThumb = false; // don't attempt to copy a thumbnail for images - it's the same as the data which was just created if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) { // check if audio entry has real thumb, if not - don't copy thumb. $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false); if (!$originalFileSync) { $skipThumb = true; } } if (!$skipThumb) { $to = $targetEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); // replaced__getThumbnailPath KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]"); kFileSyncUtils::softCopy($from, $to); } } // added by Tan-Tan 12/01/2010 to support falvors copy $sourceAssets = assetPeer::retrieveByEntryId($entry->getId()); foreach ($sourceAssets as $sourceAsset) { $sourceAsset->copyToEntry($targetEntry->getId(), $targetEntry->getPartnerId()); } }
/** * * @param string $entryId * @return array<flavorAsset> */ public static function retrieveByEntryId($entryId) { self::getInstance(); return parent::retrieveByEntryId($entryId); }
/** * Markss the caption as default and removes that mark from all other caption assets of the entry. * * @action setAsDefault * @param string $captionAssetId * @throws KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND * @validateUser asset::entry captionAssetId edit */ public function setAsDefaultAction($captionAssetId) { $captionAsset = assetPeer::retrieveById($captionAssetId); if (!$captionAsset || !$captionAsset instanceof CaptionAsset) { throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND, $captionAssetId); } $entry = $captionAsset->getentry(); if (!$entry || !in_array($entry->getType(), $this->mediaTypes) || !in_array($entry->getMediaType(), array(KalturaMediaType::VIDEO, KalturaMediaType::AUDIO))) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $captionAsset->getEntryId()); } $entryKuserId = $entry->getKuserId(); $thisKuserId = $this->getKuser()->getId(); $isNotAdmin = !kCurrentContext::$ks_object->isAdmin(); KalturaLog::debug("entryKuserId [{$entryKuserId}], thisKuserId [{$thisKuserId}], isNotAdmin [{$isNotAdmin} ]"); if (!$entry || $isNotAdmin && !is_null($entryKuserId) && $entryKuserId != $thisKuserId) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $captionAsset->getEntryId()); } $entryCaptionAssets = assetPeer::retrieveByEntryId($captionAsset->getEntryId(), array(CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION))); foreach ($entryCaptionAssets as $entryCaptionAsset) { if ($entryCaptionAsset->getId() == $captionAsset->getId()) { $entryCaptionAsset->setDefault(true); } else { $entryCaptionAsset->setDefault(false); } $entryCaptionAsset->save(); } }
public static function getCaptionSearchData(entry $entry) { $captionAssets = assetPeer::retrieveByEntryId($entry->getId(), array(CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION))); if (!$captionAssets || !count($captionAssets)) { return null; } $data = array(); foreach ($captionAssets as $captionAsset) { /* @var $captionAsset CaptionAsset */ $syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $content = kFileSyncUtils::file_get_contents($syncKey, true, false); if (!$content) { continue; } $captionsContentManager = kCaptionsContentManager::getCoreContentManager($captionAsset->getContainerFormat()); if (!$captionsContentManager) { KalturaLog::err("Captions content manager not found for format [" . $captionAsset->getContainerFormat() . "]"); continue; } $content = $captionsContentManager->getContent($content); if (!$content) { continue; } $data[] = $captionAsset->getId() . " ca_prefix {$content} ca_sufix"; } $dataField = CaptionSearchPlugin::getSearchFieldName(CaptionSearchPlugin::SEARCH_FIELD_DATA); $searchValues = array($dataField => CaptionSearchPlugin::PLUGIN_NAME . ' ' . implode(' ', $data) . ' ' . CaptionSearchPlugin::SEARCH_TEXT_SUFFIX); return $searchValues; }
/** * @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; }
public static function handleProvisionProvideFinished(BatchJob $dbBatchJob, kProvisionJobData $data) { kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::READY); $entry = $dbBatchJob->getEntry(); if (!$entry) { return $dbBatchJob; } $data->populateEntryFromData($entry); $liveAssets = assetPeer::retrieveByEntryId($entry->getId(), array(assetType::LIVE)); foreach ($liveAssets as $liveAsset) { /* @var $liveAsset liveAsset */ $liveAsset->setStatus(asset::ASSET_STATUS_READY); $liveAsset->save(); } $entry->save(); return $dbBatchJob; }
public static function copyEntry(entry $entry, Partner $toPartner = null, $dontCopyUsers = false) { KalturaLog::log("copyEntry - Copying entry [" . $entry->getId() . "] to partner [" . $toPartner->getId() . "]"); $newEntry = $entry->copy(); $newEntry->setIntId(null); $newEntry->setCategories(null); $newEntry->setCategoriesIds(null); if ($toPartner instanceof Partner) { $newEntry->setPartnerId($toPartner->getId()); $newEntry->setSubpId($toPartner->getId() * 100); $newEntry->setAccessControlId($toPartner->getDefaultAccessControlId()); } $newKuser = null; if (!$dontCopyUsers) { // copy the kuser (if the same puser id exists its kuser will be used) kuserPeer::setUseCriteriaFilter(false); $kuser = $entry->getKuser(); $newKuser = kuserPeer::createKuserForPartner($newEntry->getPartnerId(), $kuser->getPuserId()); $newEntry->setKuserId($newKuser->getId()); $newEntry->setCreatorKuserId($newKuser->getId()); kuserPeer::setUseCriteriaFilter(true); } // copy the kshow kshowPeer::setUseCriteriaFilter(false); $kshow = $entry->getKshow(); if ($kshow) { $newKshow = $kshow->copy(); $newKshow->setIntId(null); $newKshow->setPartnerId($toPartner->getId()); $newKshow->setSubpId($toPartner->getId() * 100); if ($newKuser) { $newKshow->setProducerId($newKuser->getId()); } $newKshow->save(); $newEntry->setKshowId($newKshow->getId()); } kshowPeer::setUseCriteriaFilter(true); // reset the statistics myEntryUtils::resetEntryStatistics($newEntry); // set the new partner id into the default category criteria filter $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter(); $oldPartnerId = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID); $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID); $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId()); // save the entry $newEntry->save(); // restore the original partner id in the default category criteria filter $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID); $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerId); KalturaLog::log("copyEntry - New entry [" . $newEntry->getId() . "] was created"); // for any type that does not require assets: $shouldCopyDataForNonClip = true; if ($entry->getType() == entryType::MEDIA_CLIP) { $shouldCopyDataForNonClip = false; } if ($entry->getType() == entryType::PLAYLIST) { $shouldCopyDataForNonClip = false; } $shouldCopyDataForClip = false; // only images get their data copied if ($entry->getType() == entryType::MEDIA_CLIP) { if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) { $shouldCopyDataForClip = true; } } //if entry is a static playlist, link between it and its new child entries if ($entry->getType() == entryType::PLAYLIST) { switch ($entry->getMediaType()) { case entry::ENTRY_MEDIA_TYPE_TEXT: $from = $entry->getDataContent(); KalturaLog::debug("Entries to copy from source static playlist: [{$from}]"); $fromEntryIds = explode(",", $from); $toEntryIds = array(); foreach ($fromEntryIds as $fromEntryId) { $toEntryIds[] = kObjectCopyHandler::getMappedId(entryPeer::OM_CLASS, $fromEntryId); } $newEntry->setDataContent(implode(",", $toEntryIds)); break; case entry::ENTRY_MEDIA_TYPE_XML: list($totalResults, $fromFiltersList) = myPlaylistUtils::getPlaylistFilterListStruct($entry->getDataContent()); $toPlaylistXml = new SimpleXMLElement("<playlist/>"); $toPlaylistXml->addChild("total_results", $totalResults); $toFiltersXml = $toPlaylistXml->addChild("filters"); foreach ($fromFiltersList as $filterXML) { $entryFilter = new entryFilter(); $entryFilter->fillObjectFromXml($filterXML, "_"); if (isset($entryFilter->fields["_matchand_categories_ids"])) { $categoriesIds = explode(",", $entryFilter->fields["_matchand_categories_ids"]); $newCategoriesIds = array(); foreach ($categoriesIds as $categoryId) { $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId); } $entryFilter->fields["_matchand_categories_ids"] = implode(",", $newCategoriesIds); } if (isset($entryFilter->fields["_matchor_categories_ids"])) { $categoriesIds = explode(",", $entryFilter->fields["_matchor_categories_ids"]); $newCategoriesIds = array(); foreach ($categoriesIds as $categoryId) { $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId); } $entryFilter->fields["_matchor_categories_ids"] = implode(",", $newCategoriesIds); } if (isset($entryFilter->fields["_in_category_ancestor_id"])) { $categoriesIds = explode(",", $entryFilter->fields["_in_category_ancestor_id"]); $newCategoriesIds = array(); foreach ($categoriesIds as $categoryId) { $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId); } $entryFilter->fields["_in_category_ancestor_id"] = implode(",", $newCategoriesIds); } $toEntryFilterXML = $toFiltersXml->addChild("filter"); $toEntryFilterXML = $entryFilter->toXml($toEntryFilterXML); } $newEntry->setDataContent($toPlaylistXml->asXML()); break; } } if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) { // copy the data $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA); // replaced__getDataPath KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]"); kFileSyncUtils::softCopy($from, $to); } $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); if (kFileSyncUtils::fileSync_exists($ismFrom)) { $ismTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM); KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]"); kFileSyncUtils::softCopy($ismFrom, $ismTo); } $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); if (kFileSyncUtils::fileSync_exists($ismcFrom)) { $ismcTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC); KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]"); kFileSyncUtils::softCopy($ismcFrom, $ismcTo); } $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); // replaced__getThumbnailPath $considerCopyThumb = true; // if entry is image - data is thumbnail, and it was copied if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) { $considerCopyThumb = false; } // if entry is not clip, and there is no file in both DCs - nothing to copy if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) { $considerCopyThumb = false; } if ($considerCopyThumb) { $skipThumb = false; // don't attempt to copy a thumbnail for images - it's the same as the data which was just created if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) { // check if audio entry has real thumb, if not - don't copy thumb. $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false); if (!$originalFileSync) { $skipThumb = true; } } if (!$skipThumb) { $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); // replaced__getThumbnailPath KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]"); kFileSyncUtils::softCopy($from, $to); } } // added by Tan-Tan 12/01/2010 to support falvors copy $sourceAssets = assetPeer::retrieveByEntryId($entry->getId()); foreach ($sourceAssets as $sourceAsset) { $sourceAsset->copyToEntry($newEntry->getId(), $newEntry->getPartnerId()); } // copy relationships to categories KalturaLog::debug('Copy relationships to categories from entry [' . $entry->getId() . '] to entry [' . $newEntry->getId() . ']'); $c = KalturaCriteria::create(categoryEntryPeer::OM_CLASS); $c->addAnd(categoryEntryPeer::ENTRY_ID, $entry->getId()); $c->addAnd(categoryEntryPeer::STATUS, CategoryEntryStatus::ACTIVE, Criteria::EQUAL); $c->addAnd(categoryEntryPeer::PARTNER_ID, $entry->getPartnerId()); categoryEntryPeer::setUseCriteriaFilter(false); $categoryEntries = categoryEntryPeer::doSelect($c); categoryEntryPeer::setUseCriteriaFilter(true); // Create srcCategoryIdToDstCategoryIdMap - a map of source partner category ids -> dst. partner category ids // // Build src category IDs set $srcCategoryIdSet = array(); foreach ($categoryEntries as $categoryEntry) { $srcCategoryIdSet[] = $categoryEntry->getCategoryId(); } $illegalCategoryStatus = array(CategoryStatus::DELETED, CategoryStatus::PURGED); // Get src category objects $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $c->add(categoryPeer::ID, $srcCategoryIdSet, Criteria::IN); $c->addAnd(categoryPeer::PARTNER_ID, $entry->getPartnerId()); $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN); categoryPeer::setUseCriteriaFilter(false); $srcCategories = categoryPeer::doSelect($c); categoryPeer::setUseCriteriaFilter(true); // Map the category names to their IDs $fullNamesToSrcCategoryIdMap = array(); foreach ($srcCategories as $category) { $fullNamesToSrcCategoryIdMap[$category->getFullName()] = $category->getId(); } // Get dst. partner categories based on src. category full-names $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $c->add(categoryPeer::FULL_NAME, array_keys($fullNamesToSrcCategoryIdMap), KalturaCriteria::IN); $c->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId()); $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN); categoryPeer::setUseCriteriaFilter(false); $dstCategories = categoryPeer::doSelect($c); categoryPeer::setUseCriteriaFilter(true); $srcCategoryIdToDstCategoryIdMap = array(); foreach ($dstCategories as $dstCategory) { $fullName = $dstCategory->getFullName(); if (array_key_exists($fullName, $fullNamesToSrcCategoryIdMap)) { $srcCategoryId = $fullNamesToSrcCategoryIdMap[$fullName]; $srcCategoryIdToDstCategoryIdMap[$srcCategoryId] = $dstCategory->getId(); } } foreach ($categoryEntries as $categoryEntry) { /* @var $categoryEntry categoryEntry */ $newCategoryEntry = $categoryEntry->copy(); $newCategoryEntry->setPartnerId($newEntry->getPartnerId()); $newCategoryEntry->setEntryId($newEntry->getId()); $srcCategoryId = $categoryEntry->getCategoryId(); if (!array_key_exists($srcCategoryId, $srcCategoryIdToDstCategoryIdMap)) { continue; // Skip the category_entry's creation } $dstCategoryId = $srcCategoryIdToDstCategoryIdMap[$srcCategoryId]; $newCategoryEntry->setCategoryId($dstCategoryId); categoryPeer::setUseCriteriaFilter(false); entryPeer::setUseCriteriaFilter(false); $newCategoryEntry->save(); entryPeer::setUseCriteriaFilter(true); categoryPeer::setUseCriteriaFilter(true); } return $newEntry; }
/** * @param entry $entry * @param entry $tempEntry */ public static function replaceEntry(entry $entry, entry $tempEntry = null) { KalturaLog::debug("in replaceEntry"); if (!$tempEntry) { $tempEntry = entryPeer::retrieveByPK($entry->getReplacingEntryId()); } if (!$tempEntry) { KalturaLog::err("Temp entry id [" . $entry->getReplacingEntryId() . "] not found"); return; } //Extract all assets of the temp entry $tempAssets = assetPeer::retrieveByEntryId($tempEntry->getId()); //Extract all assets of the existing entry $oldAssets = assetPeer::retrieveByEntryId($entry->getId()); KalturaLog::debug("num of old assets: " . count($oldAssets)); $newAssets = array(); //Loop which creates a mapping between the new assets' paramsId and their type to the asset itself foreach ($tempAssets as $newAsset) { if ($newAsset->getStatus() != asset::FLAVOR_ASSET_STATUS_READY) { KalturaLog::debug("Do not add new asset [" . $newAsset->getId() . "] to flavor [" . $newAsset->getFlavorParamsId() . "] status [" . $newAsset->getStatus() . "]"); continue; } //If doesn't exist - create a new array for the current asset's type. if (!isset($newAssets[$newAsset->getType()])) { $newAssets[$newAsset->getType()] = array(); } if ($newAsset->getFlavorParamsId() || $newAsset instanceof flavorAsset) { $newAssets[$newAsset->getType()][$newAsset->getFlavorParamsId()] = $newAsset; KalturaLog::debug("Added new asset [" . $newAsset->getId() . "] for asset params [" . $newAsset->getFlavorParamsId() . "]"); } else { $newAssets[$newAsset->getType()]['asset_' . count($newAssets[$newAsset->getType()])] = $newAsset; KalturaLog::debug("Added new asset [" . $newAsset->getId() . "] with no asset params"); } } $saveEntry = false; $defaultThumbAssetNew = null; foreach ($oldAssets as $oldAsset) { /* @var $oldAsset asset */ kFileSyncUtils::clearWAMSDataForKey($oldAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET)); //If the newAssets map contains an asset of the same type and paramsId as the current old asset, // re-link the old asset to the new asset. if (isset($newAssets[$oldAsset->getType()]) && isset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()])) { $newAsset = $newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]; /* @var $newAsset asset */ KalturaLog::debug("Create link from new asset [" . $newAsset->getId() . "] to old asset [" . $oldAsset->getId() . "] for flavor [" . $oldAsset->getFlavorParamsId() . "]"); if ($oldAsset instanceof flavorAsset) { $oldAsset->setBitrate($newAsset->getBitrate()); $oldAsset->setFrameRate($newAsset->getFrameRate()); $oldAsset->setVideoCodecId($newAsset->getVideoCodecId()); } $oldAsset->setWidth($newAsset->getWidth()); $oldAsset->setHeight($newAsset->getHeight()); $oldAsset->setContainerFormat($newAsset->getContainerFormat()); $oldAsset->setSize($newAsset->getSize()); $oldAsset->setFileExt($newAsset->getFileExt()); $oldAsset->setTags($newAsset->getTags()); $oldAsset->setDescription($newAsset->getDescription()); $oldAsset->incrementVersion(); $oldAsset->setStatusLocalReady(); $oldAsset->save(); $oldFileSync = $oldAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $newFileSync = $newAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::createSyncFileLinkForKey($oldFileSync, $newFileSync); $newFlavorMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($newAsset->getId()); if ($newFlavorMediaInfo) { $oldFlavorNewMediaInfo = $newFlavorMediaInfo->copy(); $oldFlavorNewMediaInfo->setFlavorAssetId($oldAsset->getId()); $oldFlavorNewMediaInfo->setFlavorAssetVersion($oldAsset->getVersion()); $oldFlavorNewMediaInfo->save(); } unset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]); if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $defaultThumbAssetNew = $oldAsset; KalturaLog::debug("Nominating ThumbAsset [" . $oldAsset->getId() . "] as the default ThumbAsset after replacent"); } } elseif ($oldAsset instanceof flavorAsset || $oldAsset instanceof thumbAsset) { KalturaLog::debug("Delete old asset [" . $oldAsset->getId() . "] for paramsId [" . $oldAsset->getFlavorParamsId() . "]"); $oldAsset->setStatus(flavorAsset::ASSET_STATUS_DELETED); $oldAsset->setDeletedAt(time()); $oldAsset->save(); $entry->removeFlavorParamsId($oldAsset->getFlavorParamsId()); $saveEntry = true; } } foreach ($newAssets as $newAssetsByTypes) { foreach ($newAssetsByTypes as $newAsset) { $createdAsset = $newAsset->copyToEntry($entry->getId(), $entry->getPartnerId()); KalturaLog::debug("Copied from new asset [" . $newAsset->getId() . "] to copied asset [" . $createdAsset->getId() . "] for flavor [" . $newAsset->getFlavorParamsId() . "]"); if ($createdAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $defaultThumbAssetNew = $newAsset; KalturaLog::debug("Nominating ThumbAsset [" . $newAsset->getId() . "] as the default ThumbAsset after replacent"); } } } if ($defaultThumbAssetNew) { kBusinessConvertDL::setAsDefaultThumbAsset($defaultThumbAssetNew); kalturalog::debug("Setting ThumbAsset [" . $defaultThumbAssetNew->getId() . "] as the default ThumbAsset"); } else { kalturalog::debug("No default ThumbAsset found for replacing entry [" . $tempEntry->getId() . "]"); $entry->setThumbnail(".jpg"); // thumbnailversion++ $entry->save(); $tempEntrySyncKey = $tempEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); $realEntrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); kFileSyncUtils::createSyncFileLinkForKey($realEntrySyncKey, $tempEntrySyncKey); } $entry->setDimensions($tempEntry->getWidth(), $tempEntry->getHeight()); $entry->setLengthInMsecs($tempEntry->getLengthInMsecs()); $entry->setConversionProfileId($tempEntry->getConversionProfileId()); $entry->setConversionQuality($tempEntry->getConversionQuality()); $entry->setReplacingEntryId(null); $entry->setReplacementStatus(entryReplacementStatus::NONE); $entry->setStatus($tempEntry->getStatus()); $entry->save(); myEntryUtils::deleteEntry($tempEntry, null, true); $te = new TrackEntry(); $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_REPLACED_ENTRY); $te->setEntryId($entry->getId()); $te->setParam1Str($tempEntry->getId()); $te->setDescription(__METHOD__ . "[" . __LINE__ . "]"); TrackEntry::addTrackEntry($te); }
public function populateFromEntry(LiveStreamEntry $entry) { $this->setStreamName($entry->getStreamName()); $liveAssets = assetPeer::retrieveByEntryId($entry->getId(), array(assetType::LIVE)); $playbackProtocols = array(); $this->provisioningParams = array(); foreach ($liveAssets as $liveAsset) { /* @var $liveAsset liveAsset */ $tags = explode(',', $liveAsset->getTags()); foreach ($tags as $tag) { if (isset($this->provisioningParams[$tag])) { $bitrates = $this->provisioningParams[$tag]; $bitrates = explode(',', $bitrates); $bitrates[] = $liveAsset->getBitrate(); $this->provisioningParams[$tag] = implode(',', $bitrates); } else { $this->provisioningParams[$tag] = $liveAsset->getBitrate(); } } } }