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());
     $productMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId());
     $targetFlavor = assetParamsOutputPeer::retrieveByAssetId($currentFlavorAsset->getId());
     $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
     if ($postConvertAssetType != BatchJob::POSTCONVERT_ASSET_TYPE_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->setStatusLocalReady();
     $currentFlavorAsset->save();
     kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $currentFlavorAsset->getFlavorParamsId());
     return $currentFlavorAsset;
 }
 /**
  * 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
  * @param array<kOperationAttributes> $dynamicAttributes
  * @return BatchJob 
  */
 public static function decideAddEntryFlavor(BatchJob $parentJob = null, $entryId, $flavorParamsId, &$errDescription, $flavorAssetId = null, array $dynamicAttributes = array())
 {
     KalturaLog::log("entryId [{$entryId}], flavorParamsId [{$flavorParamsId}]");
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::err($errDescription);
         return null;
     }
     if ($originalFlavorAsset->getId() != $flavorAssetId && !$originalFlavorAsset->isLocalReadyStatus()) {
         $errDescription = 'Original flavor asset not ready';
         KalturaLog::err($errDescription);
         return null;
     }
     // TODO - if source flavor is remote storage, create import job and mark the flavor as FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT
     $mediaInfoId = null;
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     if ($mediaInfo) {
         $mediaInfoId = $mediaInfo->getId();
     }
     $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
     if (!$flavorParams) {
         KalturaLog::err("Flavor Params Id [{$flavorParamsId}] not found");
         return null;
     }
     $flavorParams->setDynamicAttributes($dynamicAttributes);
     $flavor = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription);
     if (is_null($flavor)) {
         KalturaLog::err("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();
     }
     if (is_null($flavorAssetId)) {
         $flavorAsset = assetPeer::retrieveByEntryIdAndParams($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
     $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if ($conversionProfile) {
         $flavorParamsConversionProfile = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($flavor->getFlavorParamsId(), $conversionProfile->getId());
         if ($flavorParamsConversionProfile) {
             $flavor->setReadyBehavior($flavorParamsConversionProfile->getReadyBehavior());
         }
     }
     $flavorAsset = kBatchManager::createFlavorAsset($flavor, $partnerId, $entryId, $flavorAssetId);
     if (!$flavorAsset) {
         KalturaLog::err("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 = assetPeer::retrieveFlavorsByEntryId($entryId);
         $flavorAssets = assetPeer::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 = assetParamsOutputPeer::retrieveByAssetId($tagedFlavorAsset->getId());
             if (is_null($flavorParamsOutput)) {
                 KalturaLog::log("Creating flavor params output for asset [" . $tagedFlavorAsset->getId() . "]");
                 $flavorParams = assetParamsPeer::retrieveByPK($tagedFlavorAsset->getId());
                 $flavorParamsOutput = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription);
                 if (is_null($flavorParamsOutput)) {
                     KalturaLog::err("Failed to validate media info [{$errDescription}]");
                     continue;
                 }
             }
             if ($flavorParamsOutput) {
                 KalturaLog::log("Adding Collection flavor [" . $flavorParamsOutput->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]");
                 $flavors[$tagedFlavorAsset->getId()] = assetParamsOutputPeer::retrieveByAssetId($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);
 }
 /**
  * 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
  * @param array<kOperationAttributes> $dynamicAttributes
  * @return BatchJob
  */
 public static function decideAddEntryFlavor(BatchJob $parentJob = null, $entryId, $flavorParamsId, &$errDescription, $flavorAssetId = null, array $dynamicAttributes = array(), $priority = 0)
 {
     KalturaLog::log("entryId [{$entryId}], flavorParamsId [{$flavorParamsId}]");
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::err($errDescription);
         return null;
     }
     if ($originalFlavorAsset->getId() != $flavorAssetId && !$originalFlavorAsset->isLocalReadyStatus()) {
         $errDescription = 'Original flavor asset not ready';
         KalturaLog::err($errDescription);
         return null;
     }
     // TODO - if source flavor is remote storage, create import job and mark the flavor as FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT
     $mediaInfoId = null;
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     if ($mediaInfo) {
         $mediaInfoId = $mediaInfo->getId();
     }
     $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
     if (!$flavorParams) {
         KalturaLog::err("Flavor Params Id [{$flavorParamsId}] not found");
         return null;
     }
     $flavorParams->setDynamicAttributes($dynamicAttributes);
     self::adjustAssetParams($entryId, array($flavorParams));
     $flavor = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription);
     if (is_null($flavor)) {
         KalturaLog::err("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();
     }
     if (is_null($flavorAssetId)) {
         $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavorParamsId);
         if ($flavorAsset) {
             $flavorAssetId = $flavorAsset->getId();
         }
     }
     $flavor->_force = true;
     // force to convert the flavor, even if none complied
     $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if ($conversionProfile) {
         $flavorParamsConversionProfile = flavorParamsConversionProfilePeer::retrieveByFlavorParamsAndConversionProfile($flavor->getFlavorParamsId(), $conversionProfile->getId());
         if ($flavorParamsConversionProfile) {
             $flavor->setReadyBehavior($flavorParamsConversionProfile->getReadyBehavior());
         }
     }
     $flavorAsset = kBatchManager::createFlavorAsset($flavor, $partnerId, $entryId, $flavorAssetId);
     if (!$flavorAsset) {
         return null;
     }
     if (!$flavorAsset->getIsOriginal()) {
         $flavor->setReadyBehavior(flavorParamsConversionProfile::READY_BEHAVIOR_IGNORE);
     }
     // should not be taken in completion rules check
     $flavorAssetId = $flavorAsset->getId();
     $collectionTag = $flavor->getCollectionTag();
     /*
      * CHANGE: collection porcessing only for ExpressionEncoder jobs
      * to allow FFmpeg/ISMV processing
      */
     KalturaLog::log("Check for collection case - asset(" . $flavorAssetId . "),engines(" . $flavor->getConversionEngines() . ")");
     if ($collectionTag && $flavor->getConversionEngines() == conversionEngineType::EXPRESSION_ENCODER3) {
         $entry = entryPeer::retrieveByPK($entryId);
         if (!$entry) {
             throw new APIException(APIErrors::INVALID_ENTRY, $parentJob, $entryId);
         }
         $flavorAssets = assetPeer::retrieveFlavorsByEntryId($entryId);
         $flavorAssets = assetPeer::filterByTag($flavorAssets, $collectionTag);
         $flavors = array();
         foreach ($flavorAssets as $tagedFlavorAsset) {
             $errDescription = null;
             if ($tagedFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE || $tagedFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) {
                 continue;
             }
             $flavorParamsOutput = assetParamsOutputPeer::retrieveByAssetId($tagedFlavorAsset->getId());
             if (is_null($flavorParamsOutput)) {
                 KalturaLog::log("Creating flavor params output for asset [" . $tagedFlavorAsset->getId() . "]");
                 $flavorParams = assetParamsPeer::retrieveByPK($tagedFlavorAsset->getId());
                 self::adjustAssetParams($entryId, array($flavorParams));
                 $flavorParamsOutput = self::validateFlavorAndMediaInfo($flavorParams, $mediaInfo, $errDescription);
                 if (is_null($flavorParamsOutput)) {
                     KalturaLog::err("Failed to validate media info [{$errDescription}]");
                     continue;
                 }
             }
             if ($flavorParamsOutput) {
                 KalturaLog::log("Adding Collection flavor [" . $flavorParamsOutput->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]");
                 $flavors[$tagedFlavorAsset->getId()] = assetParamsOutputPeer::retrieveByAssetId($tagedFlavorAsset->getId());
             }
         }
         if ($flavorAssetId) {
             KalturaLog::log("Updating Collection flavor [" . $flavor->getId() . "] for asset [" . $tagedFlavorAsset->getId() . "]");
             $flavors[$flavorAssetId] = $flavor;
         }
         return self::decideCollectionConvert($collectionTag, $originalFlavorAsset, $entry, $parentJob, $flavors);
     } else {
         return self::decideFlavorConvert($flavorAsset, $flavor, $originalFlavorAsset, $conversionProfile->getId(), $mediaInfoId, $parentJob, null, false, $priority);
     }
 }
Beispiel #4
0
 public function copyToEntry($entryId = null, $partnerId = null)
 {
     $newFlavorAsset = $this->copy();
     //this is the first version of the new asset.
     $newFlavorAsset->incrementVersion();
     if ($partnerId) {
         $newFlavorAsset->setPartnerId($partnerId);
     }
     if ($entryId) {
         $newFlavorAsset->setEntryId($entryId);
     }
     $newFlavorAsset->save();
     $flavorParamsOutput = assetParamsOutputPeer::retrieveByAssetId($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->setFlavorAssetVersion($newFlavorAsset->getVersion());
         $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);
     $ismSyncKey = $this->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISM);
     $ismcSyncKey = $this->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
     $newAssetSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $newConvertLogSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     $newIsmSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISM);
     $newIsmcSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($assetSyncKey)) {
         kFileSyncUtils::softCopy($assetSyncKey, $newAssetSyncKey);
     }
     if (kFileSyncUtils::fileSync_exists($convertLogSyncKey)) {
         kFileSyncUtils::softCopy($convertLogSyncKey, $newConvertLogSyncKey);
     }
     if (kFileSyncUtils::fileSync_exists($ismSyncKey)) {
         kFileSyncUtils::softCopy($ismSyncKey, $newIsmSyncKey);
     }
     if (kFileSyncUtils::fileSync_exists($ismcSyncKey)) {
         kFileSyncUtils::softCopy($ismcSyncKey, $newIsmcSyncKey);
     }
     kEventsManager::raiseEvent(new kObjectAddedEvent($newFlavorAsset));
     return $newFlavorAsset;
 }
 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;
 }
Beispiel #6
0
 /**
  * @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;
 }
 /**
  * @param BatchJob $dbBatchJob
  * @param kImportJobData $data
  * @param BatchJob $twinJob
  * @return BatchJob
  */
 public static function handleImportFinished(BatchJob $dbBatchJob, kImportJobData $data, BatchJob $twinJob = null)
 {
     KalturaLog::debug("Import finished, with file: " . $data->getDestFileLocalPath());
     if ($dbBatchJob->getAbort()) {
         return $dbBatchJob;
     }
     if (!$twinJob) {
         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) {
         $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;
     }
     if ($twinJob) {
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         // copy file sync
         $twinData = $twinJob->getData();
         if ($twinData instanceof kImportJobData) {
             $twinFlavorAsset = assetPeer::retrieveById($twinData->getFlavorAssetId());
             if ($twinFlavorAsset) {
                 $twinSyncKey = $twinFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                 if ($twinSyncKey && kFileSyncUtils::file_exists($twinSyncKey)) {
                     kFileSyncUtils::softCopy($twinSyncKey, $syncKey);
                 }
             }
         }
     } else {
         $ext = pathinfo($data->getDestFileLocalPath(), PATHINFO_EXTENSION);
         KalturaLog::info("Imported file extension: {$ext}");
         if (!$flavorAsset->getVersion()) {
             $flavorAsset->incrementVersion();
         }
         $flavorAsset->setFileExt($ext);
         $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();
     if ($isNewContent || $dbEntry->getStatus() == entryStatus::IMPORT) {
         // 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 && $flavorAsset->getIsOriginal()) {
         $entryFlavors = assetPeer::retrieveFlavorsByEntryId($flavorAsset->getEntryId());
         foreach ($entryFlavors as $entryFlavor) {
             /* @var $entryFlavor flavorAsset */
             if ($entryFlavor->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT && $entryFlavor->getFlavorParamsId()) {
                 kBusinessPreConvertDL::decideAddEntryFlavor($dbBatchJob, $flavorAsset->getEntryId(), $entryFlavor->getFlavorParamsId());
             }
         }
         $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;
 }