public static function handleFlavorReady(BatchJob $dbBatchJob, $flavorAssetId)
 {
     // verifies that flavor asset created
     if (!$flavorAssetId) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     $currentFlavorAsset = flavorAssetPeer::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());
     $productMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId());
     $targetFlavor = flavorParamsOutputPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId());
     // don't validate in case of bypass, in case target flavor or media info are null
     if ($dbBatchJob->getJobSubType() != BatchJob::BATCHJOB_SUB_TYPE_POSTCONVERT_BYPASS && $targetFlavor && $productMediaInfo) {
         try {
             $productFlavor = KDLWrap::CDLValidateProduct($sourceMediaInfo, $targetFlavor, $productMediaInfo);
         } 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->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_READY);
     $currentFlavorAsset->save();
     kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $currentFlavorAsset->getFlavorParamsId());
     return $currentFlavorAsset;
 }
Esempio n. 2
0
 public function copyToEntry($entryId = null, $partnerId = null)
 {
     $newFlavorAsset = $this->copy();
     if ($partnerId) {
         $newFlavorAsset->setPartnerId($partnerId);
     }
     if ($entryId) {
         $newFlavorAsset->setEntryId($entryId);
     }
     $newFlavorAsset->save();
     $flavorParamsOutput = flavorParamsOutputPeer::retrieveByFlavorAssetId($this->getId());
     if ($flavorParamsOutput) {
         $newFlavorParamsOutput = $flavorParamsOutput->copy();
         $newFlavorParamsOutput->setPartnerId($newFlavorAsset->getPartnerId());
         $newFlavorParamsOutput->setEntryId($newFlavorAsset->getEntryId());
         $newFlavorParamsOutput->setFlavorAssetId($newFlavorAsset->getId());
         $newFlavorParamsOutput->save();
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($this->getId());
     if ($mediaInfo) {
         $newMediaInfo = $mediaInfo->copy();
         $newMediaInfo->setFlavorAssetId($newFlavorAsset->getId());
         $newMediaInfo->save();
     }
     $assetSyncKey = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $convertLogSyncKey = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     $newAssetSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $newConvertLogSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     if (kFileSyncUtils::file_exists($assetSyncKey, true)) {
         kFileSyncUtils::softCopy($assetSyncKey, $newAssetSyncKey);
     }
     if (kFileSyncUtils::file_exists($convertLogSyncKey, true)) {
         kFileSyncUtils::softCopy($convertLogSyncKey, $newConvertLogSyncKey);
     }
     return $newFlavorAsset;
 }
Esempio n. 3
0
 /**
  * batch decideAddEntryFlavor is the decision layer for adding a single flavor conversion to an entry 
  *
  * @param BatchJob $parentJob
  * @param int $entryId 
  * @param int $flavorParamsId
  * @param string $errDescription
  * @param string $flavorAssetId
  * @return BatchJob 
  */
 public static function decideAddEntryFlavor(BatchJob $parentJob = null, $entryId, $flavorParamsId, &$errDescription)
 {
     KalturaLog::log("entryId [{$entryId}], flavorParamsId [{$flavorParamsId}]");
     $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::log(__METHOD__ . " - " . $errDescription);
         return null;
     }
     if ($originalFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
         $errDescription = 'Original flavor asset not ready';
         KalturaLog::log(__METHOD__ . " - " . $errDescription);
         return null;
     }
     $mediaInfoId = null;
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     if ($mediaInfo) {
         $mediaInfoId = $mediaInfo->getId();
     }
     $flavorParams = flavorParamsPeer::retrieveByPK($flavorParamsId);
     $flavor = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription);
     if (is_null($flavor)) {
         KalturaLog::log(__METHOD__ . " - Failed to validate media info [{$errDescription}]");
         return null;
     }
     if ($parentJob) {
         // prefer the partner id from the parent job, although it should be the same
         $partnerId = $parentJob->getPartnerId();
     } else {
         $partnerId = $originalFlavorAsset->getPartnerId();
     }
     $flavorAssetId = null;
     $flavorAsset = flavorAssetPeer::retrieveByEntryIdAndFlavorParams($entryId, $flavorParamsId);
     if ($flavorAsset) {
         $flavorAssetId = $flavorAsset->getId();
     }
     $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $flavor->_force = true;
     // force to convert the flavor, even if none complied
     $flavor->setReadyBehavior(flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE);
     // should not be taken in completion rules check
     $flavorAsset = kBatchManager::createFlavorAsset($flavor, $partnerId, $entryId, $flavorAssetId);
     if (!$flavorAsset) {
         KalturaLog::err(__METHOD__ . " - Failed to create flavor asset");
         return null;
     }
     $flavorAssetId = $flavorAsset->getId();
     $collectionTag = $flavor->getCollectionTag();
     if ($collectionTag) {
         $entry = entryPeer::retrieveByPK($entryId);
         if (!$entry) {
             throw new APIException(APIErrors::INVALID_ENTRY, $parentJob, $entryId);
         }
         $dbConvertCollectionJob = null;
         if ($parentJob) {
             $dbConvertCollectionJob = $parentJob->createChild(false);
             $dbConvertCollectionJob->setEntryId($entryId);
             $dbConvertCollectionJob->save();
         }
         $flavorAssets = flavorAssetPeer::retrieveByEntryId($entryId);
         $flavorAssets = flavorAssetPeer::filterByTag($flavorAssets, $collectionTag);
         $flavors = array();
         foreach ($flavorAssets as $tagedFlavorAsset) {
             if ($tagedFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE || $tagedFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) {
                 continue;
             }
             $flavorParamsOutput = flavorParamsOutputPeer::retrieveByFlavorAssetId($tagedFlavorAsset->getId());
             if (is_null($flavorParamsOutput)) {
                 KalturaLog::log("Creating flavor params output for asset [" . $tagedFlavorAsset->getId() . "]");
                 $flavorParams = flavorParamsPeer::retrieveByPK($tagedFlavorAsset->getId());
                 $flavorParamsOutput = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription);
                 if (is_null($flavorParamsOutput)) {
                     KalturaLog::log(__METHOD__ . " - Failed to validate media info [{$errDescription}]");
                     continue;
                 }
             }
             if ($flavorParamsOutput) {
                 KalturaLog::log("Adding Collection flavor [" . $flavorParamsOutput->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]");
                 $flavors[$tagedFlavorAsset->getId()] = flavorParamsOutputPeer::retrieveByFlavorAssetId($tagedFlavorAsset->getId());
             }
         }
         if ($flavorAssetId) {
             KalturaLog::log("Updating Collection flavor [" . $flavor->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]");
             $flavors[$flavorAssetId] = $flavor;
         }
         switch ($collectionTag) {
             case flavorParams::TAG_ISM:
                 KalturaLog::log("Calling addConvertIsmCollectionJob with [" . count($flavors) . "] flavor params");
                 return kJobsManager::addConvertIsmCollectionJob($collectionTag, $srcSyncKey, $entry, $parentJob, $flavors, $dbConvertCollectionJob);
             default:
                 KalturaLog::log("Error: Invalid collection tag [{$collectionTag}]");
                 return null;
         }
     }
     $dbConvertFlavorJob = null;
     if ($parentJob) {
         $dbConvertFlavorJob = $parentJob->createChild(false);
         $dbConvertFlavorJob->setEntryId($entryId);
         $dbConvertFlavorJob->save();
     }
     return kJobsManager::addFlavorConvertJob($srcSyncKey, $flavor, $flavorAsset->getId(), $mediaInfoId, $parentJob, null, $dbConvertFlavorJob);
 }