/**
  * @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, $inputFileSyncWamsAssetId = null)
 {
     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;
     }
     if (is_null($inputFileSyncWamsAssetId)) {
         // 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;
                 }
                 if ($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;
                     }
                 }
                 $flavorParams = assetParamsPeer::retrieveByPK($flavor->getFlavorParamsId());
                 $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);
                             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->setInputFileSyncWamsAssetId($inputFileSyncWamsAssetId);
     $jobData->setExtractMedia(true);
     if ($entry->getType() != entryType::MEDIA_CLIP) {
         $jobData->setExtractMedia(false);
         $entry->setCreateThumb(false);
     }
     $entry->save();
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild();
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entry->getId());
         $batchJob->setPartnerId($entry->getPartnerId());
         $batchJob->setUseNewRoot(true);
     }
     return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_PROFILE);
 }