private function reconvertEntry($entry_id, $conversion_profile_id, $job_priority) { $entry = entryPeer::retrieveByPK($entry_id); $this->error = ""; if (!$entry) { $error = "Cannot reconvert entry [{$entry_id}]. Might be a deleted entry"; return array($entry_id, null, null, $error); } $flavorAsset = assetPeer::retrieveOriginalByEntryId($entry_id); if (!$flavorAsset) { $flavorAsset = assetPeer::retrieveReadyWebByEntryId($entry_id); if (!$flavorAsset) { $flavorAssets = assetPeer::retrieveFlavorsByEntryId($entry_id); if (!$flavorAssets) { $error = "Cannot find good enough flavor asset to re-convert from"; return array($entry_id, $entry, null, $error); } $flavorAsset = $flavorAssets[0]; // choose the first one } } $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $filePath = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey); if (!$filePath) { $error = "Cannot find a fileSync for the flavorAsset [" . $flavorAsset->getId() . "]"; return array($entry_id, $entry, null, $error); } $dbBatchJob = new BatchJob(); $dbBatchJob->setEntryId($entry_id); $dbBatchJob->setPartnerId($entry->getPartnerId()); $dbBatchJob->setStatus(BatchJob::BATCHJOB_STATUS_PENDING); $dbBatchJob->setDc(kDataCenterMgr::getCurrentDcId()); //$dbBatchJob->setPriority ( $job_priority ); Not supported anymore $dbBatchJob->setObjectId($entry_id); $dbBatchJob->setObjectType(BatchJobObjectType::ENTRY); $dbBatchJob->setJobType(BatchJobType::CONVERT_PROFILE); $dbBatchJob->save(); // creates a convert profile job $convertProfileData = new kConvertProfileJobData(); $convertProfileData->setFlavorAssetId($flavorAsset->getId()); $convertProfileData->setInputFileSyncLocalPath($filePath); kJobsManager::addJob($dbBatchJob, $convertProfileData, BatchJobType::CONVERT_PROFILE); // save again afget the addJob $dbBatchJob->save(); return array($entry_id, $entry, $dbBatchJob, $error); }
/** * @param BatchJob $dbBatchJob * @param kConvertProfileJobData $data * @param BatchJob $twinJob * @return BatchJob */ public static function handleConvertProfilePending(BatchJob $dbBatchJob, kConvertProfileJobData $data, BatchJob $twinJob = null) { KalturaLog::debug("Convert Profile created, with input file: " . $data->getInputFileSyncLocalPath()); if ($data->getExtractMedia()) { // creates extract media job kJobsManager::addExtractMediaJob($dbBatchJob, $data->getInputFileSyncLocalPath(), $data->getFlavorAssetId(), mediaInfo::ASSET_TYPE_ENTRY_INPUT); } else { $conversionsCreated = kBusinessPreConvertDL::decideProfileConvert($dbBatchJob, $dbBatchJob); 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); } } } // mark the job as almost done $dbBatchJob = kJobsManager::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_ALMOST_DONE); return $dbBatchJob; }
/** * @param BatchJob $batchJob * @param entry $entry * @param string $flavorAssetId * @param string $inputFileSyncLocalPath * @return BatchJob */ public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath) { KalturaLog::debug("Parent job [" . ($parentJob ? $parentJob->getId() : 'none') . "] entry [" . $entry->getId() . "] flavor asset [{$flavorAssetId}] input file [{$inputFileSyncLocalPath}]"); if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) { $entry->setStatus(entryStatus::PENDING); $entry->save(); KalturaLog::notice('Entry should not be converted'); return null; } $importingSources = false; // if file size is 0, do not create conversion profile and set entry status as error converting if (!file_exists($inputFileSyncLocalPath) || kFile::fileSize($inputFileSyncLocalPath) == 0) { KalturaLog::debug("Input file [{$inputFileSyncLocalPath}] does not exist"); $partner = $entry->getPartner(); $conversionProfile = myPartnerUtils::getConversionProfile2ForEntry($entry->getId()); // load the asset params to the instance pool $flavorIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($conversionProfile->getId()); assetParamsPeer::retrieveByPKs($flavorIds); $conversionRequired = false; $sourceFileRequiredStorages = array(); $sourceIncludedInProfile = false; $flavorAsset = assetPeer::retrieveById($flavorAssetId); $flavors = flavorParamsConversionProfilePeer::retrieveByConversionProfile($conversionProfile->getId()); KalturaLog::debug("Found flavors [" . count($flavors) . "] in conversion profile [" . $conversionProfile->getId() . "]"); foreach ($flavors as $flavor) { /* @var $flavor flavorParamsConversionProfile */ if ($flavor->getFlavorParamsId() == $flavorAsset->getFlavorParamsId()) { KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] is ingested source"); $sourceIncludedInProfile = true; continue; } $flavorParams = assetParamsPeer::retrieveByPK($flavor->getFlavorParamsId()); if ($flavorParams instanceof liveParams || $flavor->getOrigin() == assetParamsOrigin::INGEST) { KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] should be ingested"); continue; } if ($flavor->getOrigin() == assetParamsOrigin::CONVERT_WHEN_MISSING) { $siblingFlavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor->getFlavorParamsId()); if ($siblingFlavorAsset) { KalturaLog::debug("Flavor [" . $flavor->getFlavorParamsId() . "] already ingested"); continue; } } $sourceFileRequiredStorages[] = $flavorParams->getSourceRemoteStorageProfileId(); $conversionRequired = true; break; } if ($conversionRequired) { foreach ($sourceFileRequiredStorages as $storageId) { if ($storageId == StorageProfile::STORAGE_KALTURA_DC) { $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); list($syncFile, $local) = kFileSyncUtils::getReadyFileSyncForKey($key, true, false); if ($syncFile && $syncFile->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL && $partner && $partner->getImportRemoteSourceForConvert()) { KalturaLog::debug("Creates import job for remote file sync"); $url = $syncFile->getExternalUrl($entry->getId()); kJobsManager::addImportJob($parentJob, $entry->getId(), $partner->getId(), $url, $flavorAsset, null, null, true); $importingSources = true; continue; } } elseif ($flavorAsset->getExternalUrl($storageId)) { continue; } kBatchManager::updateEntry($entry->getId(), entryStatus::ERROR_CONVERTING); $flavorAsset = assetPeer::retrieveById($flavorAssetId); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->setDescription('Entry of size 0 should not be converted'); $flavorAsset->save(); KalturaLog::err('Entry of size 0 should not be converted'); return null; } } else { if ($flavorAsset->getStatus() == asset::FLAVOR_ASSET_STATUS_QUEUED) { if ($sourceIncludedInProfile) { $flavorAsset->setStatusLocalReady(); } else { $flavorAsset->setStatus(asset::FLAVOR_ASSET_STATUS_DELETED); $flavorAsset->setDeletedAt(time()); } $flavorAsset->save(); if ($sourceIncludedInProfile) { kBusinessPostConvertDL::handleConvertFinished(null, $flavorAsset); } } return null; } } if ($entry->getStatus() != entryStatus::READY) { $entry->setStatus(entryStatus::PRECONVERT); } $jobData = new kConvertProfileJobData(); $jobData->setFlavorAssetId($flavorAssetId); $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath); $jobData->setExtractMedia(true); if ($entry->getType() != entryType::MEDIA_CLIP) { $jobData->setExtractMedia(false); $entry->setCreateThumb(false); } $entry->save(); $batchJob = null; if ($parentJob) { $batchJob = $parentJob->createChild(BatchJobType::CONVERT_PROFILE); } else { $batchJob = new BatchJob(); $batchJob->setEntryId($entry->getId()); $batchJob->setPartnerId($entry->getPartnerId()); $batchJob->setUseNewRoot(true); } $batchJob->setObjectId($entry->getId()); $batchJob->setObjectType(BatchJobObjectType::ENTRY); if ($importingSources) { $batchJob->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS); } return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE); }
/** * @param BatchJob $dbBatchJob * @param kConvertProfileJobData $data * @return BatchJob */ public static function handleConvertProfilePending(BatchJob $dbBatchJob, kConvertProfileJobData $data) { if ($data->getExtractMedia()) { // creates extract media job kJobsManager::addExtractMediaJob($dbBatchJob, $data->getInputFileSyncLocalPath(), $data->getFlavorAssetId()); } else { try { $conversionsCreated = kBusinessPreConvertDL::decideProfileConvert($dbBatchJob, $dbBatchJob); } catch (kCoreException $ex) { //This was added so the all the assets prior to reaching the limit would still be created if ($ex->getCode() != kCoreException::MAX_ASSETS_PER_ENTRY) { throw $ex; } KalturaLog::err("Max assets per entry was reached continuing with normal flow"); } if ($conversionsCreated) { // handle the source flavor as if it was converted, makes the entry ready according to ready behavior rules $currentFlavorAsset = assetPeer::retrieveById($data->getFlavorAssetId()); if ($currentFlavorAsset) { $dbBatchJob = kBusinessPostConvertDL::handleConvertFinished($dbBatchJob, $currentFlavorAsset); } } } // mark the job as almost done $dbBatchJob = kJobsManager::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_ALMOST_DONE); return $dbBatchJob; }
/** * @param BatchJob $batchJob * @param entry $entry * @param string $flavorAssetId * @param string $inputFileSyncLocalPath * @return BatchJob */ public static function addConvertProfileJob(BatchJob $parentJob = null, entry $entry, $flavorAssetId, $inputFileSyncLocalPath) { // if file size is 0, do not create conversion profile and set entry status as error converting if (filesize($inputFileSyncLocalPath) == 0) { $entry->setStatus(entryStatus::ERROR_CONVERTING); $entry->save(); $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->setDescription('Entry of size 0 should not be converted'); $flavorAsset->save(); KalturaLog::err('Entry of size 0 should not be converted'); return null; } if ($entry->getConversionQuality() == conversionProfile2::CONVERSION_PROFILE_NONE) { $entry->setStatus(entryStatus::PENDING); $entry->save(); KalturaLog::notice('Entry should not be converted'); return null; } if ($entry->getStatus() != entryStatus::READY) { $entry->setStatus(entryStatus::PRECONVERT); $entry->save(); } $jobData = new kConvertProfileJobData(); $jobData->setFlavorAssetId($flavorAssetId); $jobData->setInputFileSyncLocalPath($inputFileSyncLocalPath); $jobData->setExtractMedia(true); if ($entry->getType() != entryType::MEDIA_CLIP) { $jobData->setExtractMedia(false); $jobData->setCreateThumb(false); } $batchJob = null; if ($parentJob) { $batchJob = $parentJob->createChild(); } else { $batchJob = new BatchJob(); $batchJob->setEntryId($entry->getId()); $batchJob->setPartnerId($entry->getPartnerId()); } return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE); }