/** * @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 handleConvertProfileFinished(BatchJob $dbBatchJob, kConvertProfileJobData $data) { self::deleteTemporaryFlavors($dbBatchJob->getEntryId()); self::handleLocalFileSyncDeletion($dbBatchJob->getEntryId(), $dbBatchJob->getPartner()); kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob); $entry = $dbBatchJob->getEntry(); if ($entry) { kBusinessConvertDL::checkForPendingLiveClips($entry); } return $dbBatchJob; }
public static function handleFlavorReady(BatchJob $dbBatchJob, $flavorAssetId) { // verifies that flavor asset created if (!$flavorAssetId) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } $currentFlavorAsset = assetPeer::retrieveById($flavorAssetId); // verifies that flavor asset exists if (!$currentFlavorAsset) { throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId); } // if the flavor deleted then it shouldn't be taken into ready calculations if ($currentFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) { return $currentFlavorAsset; } // Remarked because we want the original flavor ready behavior to work the same as other flavors // // $rootBatchJob = $dbBatchJob->getRootJob(); // // // happens in case of post convert on the original (in case of bypass) // if($rootBatchJob && $currentFlavorAsset->getIsOriginal()) // { // kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED); // return $dbBatchJob; // } $sourceMediaInfo = mediaInfoPeer::retrieveOriginalByEntryId($dbBatchJob->getEntryId()); /* * For intermediate source generation, both the source and the asset have the same asset id. * In this case sourceMediaInfo should be retrieved as the first version of source asset mediaInfo */ if (isset($sourceMediaInfo) && $sourceMediaInfo->getFlavorAssetId() == $flavorAssetId) { $productMediaInfo = $sourceMediaInfo; $entry = $dbBatchJob->getEntry(); $operationAttributes = $entry->getOperationAttributes(); // if in clipping operation - take the latest created mediainfo object $ascending = empty($operationAttributes) ? 1 : 0; $sourceMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAssetId, $ascending); KalturaLog::log("Intermediate source generation - assetId(" . $flavorAssetId . "),src MdInf id(" . $sourceMediaInfo->getId() . "),product MdInf id(" . $productMediaInfo->getId()) . ")"; } else { $productMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId()); } $targetFlavor = assetParamsOutputPeer::retrieveByAssetId($currentFlavorAsset->getId()); //Retrieve convert job executing engien $convertEngineType = null; if ($dbBatchJob->getParentJob()) { $dbParentBatchJob = $dbBatchJob->getParentJob(); if ($dbParentBatchJob->getJobType() == BatchJobType::CONVERT) { $convertEngineType = $dbParentBatchJob->getJobSubType(); } } $postConvertData = $dbBatchJob->getData(); $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR; if ($postConvertData instanceof kPostConvertJobData) { $postConvertAssetType = $postConvertData->getPostConvertAssetType(); } // don't validate in case of bypass, in case target flavor or media info are null // or ISM/ISMC manifest assets if ($postConvertAssetType != BatchJob::POSTCONVERT_ASSET_TYPE_BYPASS && $targetFlavor && $productMediaInfo && !$targetFlavor->hasTag(assetParams::TAG_ISM_MANIFEST)) { try { $productFlavor = KDLWrap::CDLValidateProduct($sourceMediaInfo, $targetFlavor, $productMediaInfo, $convertEngineType); } catch (Exception $e) { KalturaLog::err('KDL Error: ' . print_r($e, true)); } $err = kBusinessConvertDL::parseFlavorDescription($productFlavor); KalturaLog::debug("BCDL: job id [" . $dbBatchJob->getId() . "] flavor params output id [" . $targetFlavor->getId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "] desc: {$err}"); if (!$productFlavor->IsValid()) { $description = $currentFlavorAsset->getDescription() . "\n{$err}"; // mark the asset as ready $currentFlavorAsset->setDescription($description); $currentFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $currentFlavorAsset->save(); if (!kConf::get('ignore_cdl_failure')) { kJobsManager::failBatchJob($dbBatchJob, $err); return null; } } } // mark the asset as ready $currentFlavorAsset->setStatusLocalReady(); $currentFlavorAsset->save(); $waitingFlavorAssets = assetPeer::retrieveByEntryIdAndStatus($currentFlavorAsset->getEntryId(), flavorAsset::FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT); $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($currentFlavorAsset->getEntryId()); foreach ($waitingFlavorAssets as $waitingFlavorAsset) { $flavor = assetParamsOutputPeer::retrieveByAsset($waitingFlavorAsset); KalturaLog::debug('Check waiting flavor asset [' . $waitingFlavorAsset->getId() . ']'); if ($dbBatchJob->getParentJob()) { $parentJob = $dbBatchJob->getParentJob(); } else { $parentJob = $dbBatchJob; } kBusinessPreConvertDL::decideFlavorConvert($waitingFlavorAsset, $flavor, $originalFlavorAsset, null, null, $parentJob); } kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $currentFlavorAsset->getFlavorParamsId()); if ($currentFlavorAsset->getIsOriginal()) { $entry = $currentFlavorAsset->getentry(); if ($entry) { kBusinessConvertDL::checkForPendingLiveClips($entry); } } return $currentFlavorAsset; }
public static function handleConvertProfileFinished(BatchJob $dbBatchJob, kConvertProfileJobData $data) { self::deleteTemporaryFlavors($dbBatchJob->getEntryId()); self::handleLocalFileSyncDeletion($dbBatchJob->getEntryId(), $dbBatchJob->getPartner()); kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob); $entry = $dbBatchJob->getEntry(); if ($entry) { kBusinessConvertDL::checkForPendingLiveClips($entry); $clonePendingEntriesArray = $entry->getClonePendingEntries(); foreach ($clonePendingEntriesArray as $pendingEntryId) { $pendingEntry = entryPeer::retrieveByPK($pendingEntryId); if ($pendingEntry) { myEntryUtils::copyEntryData($entry, $pendingEntry); $pendingEntry->setStatus($entry->getStatus()); $pendingEntry->setLengthInMsecs($entry->getLengthInMsecs()); $pendingEntry->save(); } } $entry->setClonePendingEntries(array()); $entry->save(); } return $dbBatchJob; }