コード例 #1
0
 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;
 }
コード例 #2
0
ファイル: kFlowHelper.php プロジェクト: richhl/kalturaCE
 /**
  * @param BatchJob $dbBatchJob
  * @param kExtractMediaJobData $data
  * @param BatchJob $twinJob
  * @return BatchJob
  */
 public static function handleExtractMediaClosed(BatchJob $dbBatchJob, kExtractMediaJobData $data, BatchJob $twinJob = null)
 {
     KalturaLog::debug("Extract media closed");
     if ($dbBatchJob->getAbort()) {
         return $dbBatchJob;
     }
     $rootBatchJob = $dbBatchJob->getRootJob();
     if (!$rootBatchJob) {
         return $dbBatchJob;
     }
     if ($twinJob) {
         // copy media info
         $twinData = $twinJob->getData();
         if ($twinData->getMediaInfoId()) {
             $twinMediaInfo = mediaInfoPeer::retrieveByPK($twinData->getMediaInfoId());
             if ($twinMediaInfo) {
                 $mediaInfo = $twinMediaInfo->copy();
                 $mediaInfo->setFlavorAssetId($data->getFlavorAssetId());
                 $mediaInfo = kBatchManager::addMediaInfo($mediaInfo);
                 $data->setMediaInfoId($mediaInfo->getId());
                 $dbBatchJob->setData($data);
                 $dbBatchJob->save();
             }
         }
     }
     if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED) {
         $entry = $dbBatchJob->getEntry();
         if ($entry->getStatus() < entryStatus::READY) {
             kBatchManager::updateEntry($dbBatchJob, entryStatus::PRECONVERT);
         }
     }
     switch ($dbBatchJob->getJobSubType()) {
         case mediaInfo::ASSET_TYPE_ENTRY_INPUT:
             if ($rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
                 $conversionsCreated = kBusinessPreConvertDL::decideProfileConvert($dbBatchJob, $rootBatchJob, $data->getMediaInfoId());
                 if ($conversionsCreated) {
                     // handle the source flavor as if it was converted, makes the entry ready according to ready behavior rules
                     $currentFlavorAsset = flavorAssetPeer::retrieveById($data->getFlavorAssetId());
                     if ($currentFlavorAsset) {
                         $dbBatchJob = kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $currentFlavorAsset);
                     }
                 }
             }
             break;
         case mediaInfo::ASSET_TYPE_FLAVOR_INPUT:
             if ($rootBatchJob->getJobType() == BatchJobType::REMOTE_CONVERT) {
                 $remoteConvertData = $rootBatchJob->getData();
                 $errDescription = null;
                 $syncKey = null;
                 // TODO - how to get or create the sync key?
                 $newConvertJob = kBusinessPreConvertDL::decideFlavorConvert($syncKey, $remoteConvertData->getFlavorParamsOutputId(), $errDescription, $remoteConvertData->getMediaInfoId(), $dbBatchJob);
                 if (!$newConvertJob) {
                     kJobsManager::failBatchJob($rootBatchJob);
                 }
             }
             break;
         default:
             // currently do nothing
             break;
     }
     return $dbBatchJob;
 }
コード例 #3
0
ファイル: kFlowHelper.php プロジェクト: GElkayam/server
 /**
  * @param BatchJob $dbBatchJob
  * @param kImportJobData $data
  * @return BatchJob
  */
 public static function handleImportFinished(BatchJob $dbBatchJob, kImportJobData $data)
 {
     if ($dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) {
         return $dbBatchJob;
     }
     if (!file_exists($data->getDestFileLocalPath())) {
         throw new APIException(APIErrors::INVALID_FILE_NAME, $data->getDestFileLocalPath());
     }
     // get entry
     $entryId = $dbBatchJob->getEntryId();
     $dbEntry = entryPeer::retrieveByPKNoFilter($entryId);
     // IMAGE media entries
     if ($dbEntry->getType() == entryType::MEDIA_CLIP && $dbEntry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         //setting the entry's data so it can be used for creating file-syncs' file-path version & extension - in kFileSyncUtils::moveFromFile
         //without saving - the updated entry object exists in the instance pool
         $dbEntry->setData(".jpg");
         $syncKey = $dbEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         try {
             kFileSyncUtils::moveFromFile($data->getDestFileLocalPath(), $syncKey, true, false, $data->getCacheOnly());
         } catch (Exception $e) {
             if ($dbEntry->getStatus() == entryStatus::NO_CONTENT) {
                 $dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
                 $dbEntry->save();
             }
             throw $e;
         }
         $dbEntry->setStatus(entryStatus::READY);
         $dbEntry->save();
         return $dbBatchJob;
     }
     $flavorAsset = null;
     if ($data->getFlavorAssetId()) {
         $flavorAsset = assetPeer::retrieveById($data->getFlavorAssetId());
     }
     $isNewFlavor = false;
     if (!$flavorAsset) {
         $msg = null;
         $flavorAsset = kFlowHelper::createOriginalFlavorAsset($dbBatchJob->getPartnerId(), $dbBatchJob->getEntryId(), $msg);
         if (!$flavorAsset) {
             KalturaLog::err("Flavor asset not created for entry [" . $dbBatchJob->getEntryId() . "]");
             kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::ERROR_CONVERTING);
             $dbBatchJob->setMessage($msg);
             $dbBatchJob->setDescription($dbBatchJob->getDescription() . "\n" . $msg);
             return $dbBatchJob;
         }
         $isNewFlavor = true;
     }
     $isNewContent = true;
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (kFileSyncUtils::fileSync_exists($syncKey)) {
         $isNewContent = false;
     }
     $ext = pathinfo($data->getDestFileLocalPath(), PATHINFO_EXTENSION);
     KalturaLog::info("Imported file extension: {$ext}");
     if (!$flavorAsset->getVersion()) {
         $flavorAsset->incrementVersion();
     }
     if ($ext) {
         $flavorAsset->setFileExt($ext);
     }
     if ($flavorAsset instanceof thumbAsset) {
         list($width, $height, $type, $attr) = getimagesize($data->getDestFileLocalPath());
         $flavorAsset->setWidth($width);
         $flavorAsset->setHeight($height);
         $flavorAsset->setSize(filesize($data->getDestFileLocalPath()));
     }
     $flavorAsset->save();
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     kFileSyncUtils::moveFromFile($data->getDestFileLocalPath(), $syncKey, true, false, $data->getCacheOnly());
     // set the path in the job data
     $localFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     $data->setDestFileLocalPath($localFilePath);
     $data->setFlavorAssetId($flavorAsset->getId());
     $dbBatchJob->setData($data);
     $dbBatchJob->save();
     $convertProfileExist = self::activateConvertProfileJob($dbBatchJob->getEntryId(), $localFilePath);
     if (($isNewContent || $dbEntry->getStatus() == entryStatus::IMPORT) && !$convertProfileExist) {
         // check if status == import for importing file of type url (filesync exists, and we want to raise event for conversion profile to start)
         kEventsManager::raiseEvent(new kObjectAddedEvent($flavorAsset, $dbBatchJob));
     }
     if (!$isNewFlavor) {
         $entryFlavors = assetPeer::retrieveByEntryIdAndStatus($flavorAsset->getEntryId(), flavorAsset::FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT);
         $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($flavorAsset->getEntryId());
         foreach ($entryFlavors as $entryFlavor) {
             /* @var $entryFlavor flavorAsset */
             if ($entryFlavor->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT && $entryFlavor->getFlavorParamsId()) {
                 $flavor = assetParamsOutputPeer::retrieveByAsset($entryFlavor);
                 kBusinessPreConvertDL::decideFlavorConvert($entryFlavor, $flavor, $originalFlavorAsset, null, null, $dbBatchJob);
             }
         }
         $entryThumbnails = assetPeer::retrieveThumbnailsByEntryId($flavorAsset->getEntryId());
         foreach ($entryThumbnails as $entryThumbnail) {
             /* @var $entryThumbnail thumbAsset */
             if ($entryThumbnail->getStatus() != asset::ASSET_STATUS_WAIT_FOR_CONVERT || !$entryThumbnail->getFlavorParamsId()) {
                 continue;
             }
             $thumbParamsOutput = assetParamsOutputPeer::retrieveByAssetId($entryThumbnail->getId());
             /* @var $thumbParamsOutput thumbParamsOutput */
             if ($thumbParamsOutput->getSourceParamsId() != $flavorAsset->getFlavorParamsId()) {
                 continue;
             }
             $srcSyncKey = $flavorAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
             $srcAssetType = $flavorAsset->getType();
             kJobsManager::addCapturaThumbJob($entryThumbnail->getPartnerId(), $entryThumbnail->getEntryId(), $entryThumbnail->getId(), $srcSyncKey, $flavorAsset->getId(), $srcAssetType, $thumbParamsOutput);
         }
     }
     return $dbBatchJob;
 }