/**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @return BatchJob
  */
 protected static function addSubmitAddJob(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile)
 {
     $jobData = new kDistributionSubmitJobData();
     $jobData->setDistributionProfileId($entryDistribution->getDistributionProfileId());
     $jobData->setEntryDistributionId($entryDistribution->getId());
     $jobData->setProviderType($distributionProfile->getProviderType());
     $batchJob = new BatchJob();
     $batchJob->setEntryId($entryDistribution->getEntryId());
     $batchJob->setPartnerId($entryDistribution->getPartnerId());
     $jobType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_SUBMIT);
     $jobSubType = $distributionProfile->getProviderType();
     return kJobsManager::addJob($batchJob, $jobData, $jobType, $jobSubType);
 }
 /**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @return BatchJob
  */
 protected static function addSubmitAddJob(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile)
 {
     if ($entryDistribution->getStatus() == EntryDistributionStatus::SUBMITTING) {
         KalturaLog::debug("Entry distribution [" . $entryDistribution->getId() . "] already submitting");
         return null;
     }
     $entryDistribution->setStatus(EntryDistributionStatus::SUBMITTING);
     $entryDistribution->setDirtyStatus(null);
     if (!$entryDistribution->save()) {
         KalturaLog::err("Unable to save entry distribution [" . $entryDistribution->getId() . "] status");
         return null;
     }
     $dc = $distributionProfile->getRecommendedDcForExecute();
     if (is_null($dc)) {
         $dc = kDataCenterMgr::getCurrentDcId();
     }
     $jobType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_SUBMIT);
     if ($distributionProfile->getProvider()->isLocalFileRequired($jobType)) {
         $readyForSubmit = self::prepareDistributionJob($entryDistribution, $distributionProfile, $dc);
         if (!$readyForSubmit) {
             $entryDistribution->setStatus(EntryDistributionStatus::IMPORT_SUBMITTING);
             $entryDistribution->save();
             return null;
         }
     }
     $jobData = new kDistributionSubmitJobData();
     $jobData->setDistributionProfileId($entryDistribution->getDistributionProfileId());
     $jobData->setEntryDistributionId($entryDistribution->getId());
     $jobData->setProviderType($distributionProfile->getProviderType());
     $batchJob = new BatchJob();
     $batchJob->setDc($dc);
     $batchJob->setEntryId($entryDistribution->getEntryId());
     $batchJob->setPartnerId($entryDistribution->getPartnerId());
     $jobSubType = $distributionProfile->getProviderType();
     return kJobsManager::addJob($batchJob, $jobData, $jobType, $jobSubType);
 }
 /**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @return BatchJob
  */
 protected static function addSubmitAddJob(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile)
 {
     if ($entryDistribution->getStatus() == EntryDistributionStatus::SUBMITTING) {
         KalturaLog::info("Entry distribution [" . $entryDistribution->getId() . "] already submitting");
         return null;
     }
     $entryDistribution->setStatus(EntryDistributionStatus::SUBMITTING);
     if (!$entryDistribution->save()) {
         KalturaLog::err("Unable to save entry distribution [" . $entryDistribution->getId() . "] status");
         $entryDistribution->reload();
         //Reload in case object was chnaged
         return null;
     }
     $entryDistribution->setDirtyStatus(null);
     //Moved down to ensure previous save is done Atomically
     $entryDistribution->save();
     $dc = $distributionProfile->getRecommendedDcForExecute();
     if (is_null($dc)) {
         $dc = kDataCenterMgr::getCurrentDcId();
     }
     $jobType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_SUBMIT);
     if ($distributionProfile->getProvider()->isLocalFileRequired($jobType)) {
         $readyForSubmit = self::prepareDistributionJob($entryDistribution, $distributionProfile, $dc);
         if (!$readyForSubmit) {
             $entryDistribution->setStatus(EntryDistributionStatus::IMPORT_SUBMITTING);
             $entryDistribution->save();
             return null;
         }
     }
     $jobData = new kDistributionSubmitJobData();
     $jobData->setDistributionProfileId($entryDistribution->getDistributionProfileId());
     $jobData->setEntryDistributionId($entryDistribution->getId());
     $jobData->setProviderType($distributionProfile->getProviderType());
     $batchJob = new BatchJob();
     $batchJob->setDc($dc);
     $batchJob->setEntryId($entryDistribution->getEntryId());
     $batchJob->setPartnerId($entryDistribution->getPartnerId());
     $batchJob->setObjectId($entryDistribution->getId());
     $batchJob->setObjectType(kPluginableEnumsManager::apiToCore('BatchJobObjectType', ContentDistributionBatchJobObjectType::ENTRY_DISTRIBUTION));
     $jobSubType = $distributionProfile->getProviderType();
     return kJobsManager::addJob($batchJob, $jobData, $jobType, $jobSubType);
 }