/**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @param bool $submitWhenReady
  * @return BatchJob
  */
 public static function submitAddEntryDistribution(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile, $submitWhenReady = true)
 {
     if ($distributionProfile->getStatus() != DistributionProfileStatus::ENABLED || $distributionProfile->getSubmitEnabled() == DistributionProfileActionStatus::DISABLED) {
         KalturaLog::debug("Submission is not enabled");
         return null;
     }
     $validStatus = array(EntryDistributionStatus::ERROR_DELETING, EntryDistributionStatus::ERROR_SUBMITTING, EntryDistributionStatus::ERROR_UPDATING, EntryDistributionStatus::IMPORT_SUBMITTING, EntryDistributionStatus::PENDING, EntryDistributionStatus::QUEUED, EntryDistributionStatus::READY, EntryDistributionStatus::REMOVED);
     if (!in_array($entryDistribution->getStatus(), $validStatus)) {
         KalturaLog::notice("Wrong entry distribution status [" . $entryDistribution->getStatus() . "]");
         return null;
     }
     $returnValue = false;
     $validationErrors = $entryDistribution->getValidationErrors();
     if (!count($validationErrors)) {
         KalturaLog::debug("No validation errors found");
         $returnValue = true;
         $sunrise = $entryDistribution->getSunrise(null);
         if ($sunrise) {
             KalturaLog::debug("Applying sunrise [{$sunrise}]");
             $distributionProvider = $distributionProfile->getProvider();
             if (!$distributionProvider->isScheduleUpdateEnabled() && !$distributionProvider->isAvailabilityUpdateEnabled()) {
                 $sunrise -= $distributionProvider->getJobIntervalBeforeSunrise();
                 if ($sunrise > time()) {
                     KalturaLog::log("Will be sent on exact time [{$sunrise}] for sunrise time [" . $entryDistribution->getSunrise() . "]");
                     $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::SUBMIT_REQUIRED);
                     $entryDistribution->save();
                     $returnValue = null;
                 }
             }
         }
         if ($returnValue) {
             $returnValue = self::addSubmitAddJob($entryDistribution, $distributionProfile);
         }
     }
     if (!$returnValue && $submitWhenReady && $entryDistribution->getStatus() != EntryDistributionStatus::QUEUED) {
         $entryDistribution->setStatus(EntryDistributionStatus::QUEUED);
         $entryDistribution->save();
         KalturaLog::debug("Will be submitted when ready");
     }
     if (!count($validationErrors)) {
         return $returnValue;
     }
     KalturaLog::log("Validation errors found");
     $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId());
     if (!$entry) {
         KalturaLog::err("Entry [" . $entryDistribution->getEntryId() . "] not found");
         return null;
     }
     $autoCreateFlavors = $distributionProfile->getAutoCreateFlavorsArray();
     $autoCreateThumbs = $distributionProfile->getAutoCreateThumbArray();
     foreach ($validationErrors as $validationError) {
         if ($validationError->getErrorType() == DistributionErrorType::MISSING_FLAVOR && in_array($validationError->getData(), $autoCreateFlavors)) {
             $errDescription = null;
             KalturaLog::log("Adding flavor [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]");
             kBusinessPreConvertDL::decideAddEntryFlavor(null, $entryDistribution->getEntryId(), $validationError->getData(), $errDescription);
             if ($errDescription) {
                 KalturaLog::log($errDescription);
             }
         }
         if ($validationError->getErrorType() == DistributionErrorType::MISSING_THUMBNAIL && count($autoCreateThumbs)) {
             list($requiredWidth, $requiredHeight) = explode('x', $validationError->getData());
             $foundThumbParams = false;
             $thumbParamsObjects = assetParamsPeer::retrieveByPKs($autoCreateThumbs);
             foreach ($thumbParamsObjects as $thumbParams) {
                 /* @var $thumbParams thumbParams */
                 if ($thumbParams->getWidth() == intval($requiredWidth) && $thumbParams->getHeight() == intval($requiredHeight)) {
                     $foundThumbParams = true;
                     KalturaLog::log("Adding thumbnail [" . $thumbParams->getId() . "] to entry [" . $entryDistribution->getEntryId() . "]");
                     kBusinessPreConvertDL::decideThumbGenerate($entry, $thumbParams);
                     break;
                 }
             }
             if (!$foundThumbParams) {
                 KalturaLog::err("Required thumbnail params not found [" . $validationError->getData() . "]");
             }
         }
     }
     return null;
 }
コード例 #2
0
ファイル: entry.php プロジェクト: AdiTal/server
 /**
  * @param BatchJob $parentJob
  * @param int $flavorParamsId
  * @param string $puserId
  * @return int job id
  */
 public function createDownloadAsset(BatchJob $parentJob = null, $flavorParamsId, $puserId = null)
 {
     $job = null;
     if ($this->getType() == entryType::MIX) {
         KalturaLog::err("Entry ID [" . $this->getId() . "] is of type mix. The batch job for flattening a mix is no longer supported");
     } else {
         $err = '';
         $job = kBusinessPreConvertDL::decideAddEntryFlavor($parentJob, $this->getId(), $flavorParamsId, $err);
     }
     if ($job) {
         return $job->getId();
     }
     return null;
 }
コード例 #3
0
ファイル: MediaService.php プロジェクト: richhl/kalturaCE
 /**
  * Request a new conversion job, this can be used to convert the media entry to a different format
  * 
  * @action requestConversion
  * @param string $entryId Media entry id
  * @param string $fileFormat Format to convert
  * @return int The queued job id
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  */
 public function requestConversionAction($entryId, $fileFormat)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::MEDIA_CLIP) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     if ($dbEntry->getMediaType() == KalturaMediaType::AUDIO) {
         // for audio - force format flv regardless what the user really asked for
         $fileFormat = "flv";
     }
     //		$job = myBatchDownloadVideoServer::addJob($this->getKuser()->getPuserId(), $dbEntry, null, $fileFormat);
     $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($this->getPartnerId(), $fileFormat);
     $err = null;
     $job = kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParams->getId(), $err);
     if ($job) {
         return $job->getId();
     } else {
         return null;
     }
 }
コード例 #4
0
 /**
  * @param kOperationResource $resource
  * @param entry $dbEntry
  * @param asset $dbAsset
  * @return asset
  */
 protected function attachOperationResource(kOperationResource $resource, entry $dbEntry, asset $dbAsset = null)
 {
     $isNewAsset = false;
     $isSource = false;
     if ($dbAsset) {
         if ($dbAsset instanceof flavorAsset) {
             $isSource = $dbAsset->getIsOriginal();
         }
     } else {
         $isNewAsset = true;
         $isSource = true;
         $dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId());
     }
     if (!$dbAsset && $dbEntry->getStatus() == entryStatus::NO_CONTENT) {
         $dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
         $dbEntry->save();
     }
     $operationAttributes = $resource->getOperationAttributes();
     $internalResource = $resource->getResource();
     if ($internalResource instanceof kLiveEntryResource) {
         $dbEntry->setOperationAttributes($operationAttributes);
         $dbEntry->save();
         return $this->attachLiveEntryResource($internalResource, $dbEntry, $dbAsset, $operationAttributes);
     }
     $dbAsset = $this->attachResource($internalResource, $dbEntry, $dbAsset);
     $sourceType = $resource->getSourceType();
     if ($sourceType) {
         $dbEntry->setSource($sourceType);
         $dbEntry->save();
     }
     $errDescription = '';
     kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $resource->getAssetParamsId(), $errDescription, $dbAsset->getId(), $operationAttributes);
     if ($isNewAsset) {
         kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset));
     }
     kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbAsset));
     if ($isSource && $internalResource instanceof kFileSyncResource) {
         $srcEntryId = $internalResource->getEntryId();
         if ($srcEntryId) {
             $srcEntry = entryPeer::retrieveByPKNoFilter($srcEntryId);
             if ($srcEntry) {
                 $dbEntry->setSourceEntryId($srcEntryId);
                 $dbEntry->setRootEntryId($srcEntry->getRootEntryId(true));
             }
         }
         $dbEntry->setOperationAttributes($operationAttributes);
         $dbEntry->save();
     }
     return $dbAsset;
 }
コード例 #5
0
ファイル: kBusinessConvertDL.php プロジェクト: dozernz/server
 public static function checkForPendingLiveClips(entry $entry)
 {
     if ($entry->getSource() != EntrySourceType::RECORDED_LIVE) {
         KalturaLog::notice("Entry [" . $entry->getId() . "] is not a recorded live");
         return;
     }
     $liveEntry = entryPeer::retrieveByPKNoFilter($entry->getRootEntryId());
     if (!$liveEntry || $liveEntry->getStatus() == entryStatus::DELETED || !$liveEntry instanceof LiveEntry) {
         KalturaLog::notice("Entry root [" . $entry->getRootEntryId() . "] is not a valid live entry");
         return;
     }
     /* @var $liveEntry LiveEntry */
     $pendingMediaEntries = $liveEntry->getAttachedPendingMediaEntries();
     foreach ($pendingMediaEntries as $pendingMediaEntry) {
         /* @var $pendingMediaEntry kPendingMediaEntry */
         if ($pendingMediaEntry->getRequiredDuration() && $pendingMediaEntry->getRequiredDuration() > $entry->getLengthInMsecs()) {
             KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] required duration [" . $pendingMediaEntry->getRequiredDuration() . "] while entry duration [" . $entry->getLengthInMsecs() . "] is too short");
             continue;
         }
         $liveEntry->dettachPendingMediaEntry($pendingMediaEntry->getEntryId());
         $pendingEntry = entryPeer::retrieveByPK($pendingMediaEntry->getEntryId());
         if (!$pendingEntry) {
             KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] not found");
             continue;
         }
         $sourceAsset = assetPeer::retrieveOriginalByEntryId($entry->getId());
         if (!$sourceAsset) {
             $sourceAssets = assetPeer::retrieveReadyFlavorsByEntryId($entry->getId());
             $sourceAsset = array_pop($sourceAssets);
         }
         if (!$sourceAsset) {
             KalturaLog::info("Pending entry [" . $pendingMediaEntry->getEntryId() . "] source asset not found");
             continue;
         }
         /* @var $sourceAsset flavorAsset */
         $operationAttributes = new kClipAttributes();
         $operationAttributes->setOffset($pendingMediaEntry->getOffset());
         $operationAttributes->setDuration($pendingMediaEntry->getDuration());
         $targetAsset = assetPeer::retrieveOriginalByEntryId($pendingMediaEntry->getEntryId());
         if (!$targetAsset) {
             $targetAsset = kFlowHelper::createOriginalFlavorAsset($entry->getPartnerId(), $pendingMediaEntry->getEntryId());
         }
         $targetAsset->setFileExt($sourceAsset->getFileExt());
         $targetAsset->save();
         $sourceSyncKey = $sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         $targetSyncKey = $targetAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         kFileSyncUtils::createSyncFileLinkForKey($targetSyncKey, $sourceSyncKey);
         $errDescription = '';
         kBusinessPreConvertDL::decideAddEntryFlavor(null, $pendingMediaEntry->getEntryId(), $operationAttributes->getAssetParamsId(), $errDescription, $targetAsset->getId(), array($operationAttributes));
     }
     $liveEntry->save();
 }
コード例 #6
0
 /**
  *  request conversion for all entries that doesnt have the required flavor param
  *  returns a comma-separated ids of conversion jobs
  *
  *  @action requestConversion
  *  @param string $feedId
  *  @return string
  */
 public function requestConversionAction($feedId)
 {
     // find entry ids that already converted to the flavor
     $feedRendererWithTheFlavor = new KalturaSyndicationFeedRenderer($feedId);
     $feedRendererWithTheFlavor->addFlavorParamsAttachedFilter();
     $entriesWithTheFlavor = $feedRendererWithTheFlavor->getEntriesIds();
     // create filter of the entries that not converted
     $entryFilter = new entryFilter();
     $entryFilter->setIdNotIn($entriesWithTheFlavor);
     // create feed with the new filter
     $feedRendererToConvert = new KalturaSyndicationFeedRenderer($feedId);
     $feedRendererToConvert->addFilter($entryFilter);
     $createdJobsIds = array();
     $flavorParamsId = $feedRendererToConvert->syndicationFeed->flavorParamId;
     while ($entry = $feedRendererToConvert->getNextEntry()) {
         $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entry->getId());
         if (!is_null($originalFlavorAsset)) {
             $err = "";
             $job = kBusinessPreConvertDL::decideAddEntryFlavor(null, $entry->getId(), $flavorParamsId, $err);
             if ($job && is_object($job)) {
                 $createdJobsIds[] = $job->getId();
             }
         }
     }
     return implode(',', $createdJobsIds);
 }
コード例 #7
0
ファイル: DocumentsService.php プロジェクト: DBezemer/server
 /**
  * This will queue a batch job for converting the document file to swf
  * Returns the URL where the new swf will be available 
  * 
  * @action convertPptToSwf
  * @param string $entryId
  * @return string
  */
 function convertPptToSwf($entryId)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::DOCUMENT) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($flavorAsset) || !$flavorAsset->isLocalReadyStatus()) {
         throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
     }
     $sync_key = null;
     $sync_key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (!kFileSyncUtils::file_exists($sync_key)) {
         // if not found local file - perhaps wasn't created here and wasn't synced yet
         // try to see if remote exists - and proxy the request if it is.
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($sync_key, true, true);
         if (!$local) {
             $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrl($fileSync);
             kFileUtils::dumpApiRequest($remoteDCHost);
         }
         KalturaLog::log("convertPptToSwf sync key doesn't exists");
         return;
     }
     $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($dbEntry->getPartnerId(), flavorParams::CONTAINER_FORMAT_SWF);
     $flavorParamsId = $flavorParams->getId();
     $puserId = $this->getKuser()->getPuserId();
     $err = "";
     kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err);
     $downloadPath = $dbEntry->getDownloadUrl();
     //TODO: once api_v3 will support parameters with '/' instead of '?', we can change this to war with api_v3
     return $downloadPath . '/direct_serve/true/type/download/forceproxy/true/format/swf';
 }
コード例 #8
0
 /**
  * Add and convert new Flavor Asset for Entry with specific Flavor Params
  * 
  * @action convert
  * @param string $entryId
  * @param int $flavorParamsId
  */
 public function convertAction($entryId, $flavorParamsId)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $flavorParamsDb = flavorParamsPeer::retrieveByPK($flavorParamsId);
     flavorParamsPeer::setDefaultCriteriaFilter();
     if (!$flavorParamsDb) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $flavorParamsId);
     }
     $validStatuses = array(entryStatus::ERROR_CONVERTING, entryStatus::PRECONVERT, entryStatus::READY);
     if (!in_array($dbEntry->getStatus(), $validStatuses)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_STATUS);
     }
     $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset) || $originalFlavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
         throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
     }
     $err = "";
     kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err);
 }
コード例 #9
0
ファイル: DocumentsService.php プロジェクト: richhl/kalturaCE
 /**
  * This will queue a batch job for converting the document file to swf
  * Returns the URL where the new swf will be available 
  * 
  * @action convertPptToSwf
  * @param string $entryId
  * @return string
  */
 function convertPptToSwf($entryId)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry || $dbEntry->getType() != KalturaEntryType::DOCUMENT) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     assetPeer::resetInstanceCriteriaFilter();
     $flavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($flavorAsset) || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
         throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
     }
     $sync_key = null;
     $sync_key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (!kFileSyncUtils::file_exists($sync_key)) {
         // if not found local file - perhaps wasn't created here and wasn't synced yet
         // try to see if remote exists - and proxy the request if it is.
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($sync_key, true, true);
         if (!$local) {
             // take input params and add to URL
             $queryArr = array('service' => 'document', 'action' => 'convertPptToSwf', 'entryId' => $entryId, 'format' => $this->params["format"], 'ks' => $this->getKs()->toSecureString());
             $get_query = http_build_query($queryArr, '', '&');
             $remote_url = kDataCenterMgr::getRedirectExternalUrl($fileSync, $_SERVER['REQUEST_URI']);
             $url = strpos($remote_url, '?') === FALSE ? $remote_url . '?' . $get_query : $remote_url . '&' . $get_query;
             // prxoy request to other DC
             KalturaLog::log(__METHOD__ . ": redirecting to [{$url}]");
             kFile::dumpUrl($url);
         }
         KalturaLog::log("convertPptToSwf sync key doesn't exists");
         return;
     }
     $flavorParams = myConversionProfileUtils::getFlavorParamsFromFileFormat($dbEntry->getPartnerId(), flavorParams::CONTAINER_FORMAT_SWF);
     $flavorParamsId = $flavorParams->getId();
     $puserId = $this->getKuser()->getPuserId();
     $err = "";
     kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err);
     $downloadPath = $dbEntry->getDownloadUrl();
     //TODO: once api_v3 will support parameters with '/' instead of '?', we can change this to war with api_v3
     return $downloadPath . '/direct_serve/true/type/download/forceproxy/true/format/swf';
 }
コード例 #10
0
 /**
  * Add and convert new Flavor Asset for Entry with specific Flavor Params
  * 
  * @action convert
  * @param string $entryId
  * @param int $flavorParamsId
  * @param int $priority
  * @validateUser entry entryId edit
  */
 public function convertAction($entryId, $flavorParamsId, $priority = 0)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $flavorParamsDb = assetParamsPeer::retrieveByPK($flavorParamsId);
     assetParamsPeer::setUseCriteriaFilter(false);
     if (!$flavorParamsDb) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $flavorParamsId);
     }
     $validStatuses = array(entryStatus::ERROR_CONVERTING, entryStatus::PRECONVERT, entryStatus::READY);
     if (!in_array($dbEntry->getStatus(), $validStatuses)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_STATUS);
     }
     $conversionProfile = $dbEntry->getconversionProfile2();
     if (!$conversionProfile) {
         throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $dbEntry->getConversionProfileId());
     }
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset) || !$originalFlavorAsset->isLocalReadyStatus()) {
         throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
     }
     $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     // if the file sync isn't local (wasn't synced yet) proxy request to other datacenter
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     /* @var $fileSync FileSync */
     if (!$fileSync) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     }
     if (!$local && $fileSync->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_URL) {
         kFileUtils::dumpApiRequest(kDataCenterMgr::getRemoteDcExternalUrl($fileSync));
     }
     $err = "";
     $dynamicFlavorAttributes = $dbEntry->getDynamicFlavorAttributesForAssetParams($flavorParamsDb->getId());
     kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $flavorParamsId, $err, null, $dynamicFlavorAttributes, $priority);
 }
コード例 #11
0
 /**
  * @param BatchJob $parentJob
  * @param int $flavorParamsId
  * @param string $puserId
  * @return int job id
  */
 public function createDownloadAsset(BatchJob $parentJob = null, $flavorParamsId, $puserId = null)
 {
     $job = null;
     if ($this->getType() == entryType::MIX) {
         // if flavor params == SOURCE, or no format defined for flavor params, default to 'flv'
         $flattenFormat = null;
         if ($flavorParamsId != 0) {
             $flattenFormat = assetParamsPeer::retrieveByPK($flavorParamsId)->getFormat();
         }
         if (!$flattenFormat) {
             $flattenFormat = 'flv';
         }
         $job = myBatchFlattenClient::addJob($puserId, $this, $this->getVersion(), $flattenFormat);
     } else {
         $err = '';
         $job = kBusinessPreConvertDL::decideAddEntryFlavor($parentJob, $this->getId(), $flavorParamsId, $err);
     }
     if ($job) {
         return $job->getId();
     }
     return null;
 }
コード例 #12
0
 /**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @param bool $submitWhenReady
  * @return BatchJob
  */
 public static function submitAddEntryDistribution(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile, $submitWhenReady = true)
 {
     if ($distributionProfile->getStatus() != DistributionProfileStatus::ENABLED || $distributionProfile->getSubmitEnabled() == DistributionProfileActionStatus::DISABLED) {
         return null;
     }
     $validStatus = array(EntryDistributionStatus::ERROR_DELETING, EntryDistributionStatus::ERROR_SUBMITTING, EntryDistributionStatus::ERROR_UPDATING, EntryDistributionStatus::PENDING, EntryDistributionStatus::QUEUED, EntryDistributionStatus::READY, EntryDistributionStatus::REMOVED);
     if (!in_array($entryDistribution->getStatus(), $validStatus)) {
         KalturaLog::notice("wrong entry distribution status [" . $entryDistribution->getStatus() . "]");
         return null;
     }
     if ($submitWhenReady && $entryDistribution->getStatus() != EntryDistributionStatus::QUEUED) {
         $entryDistribution->setStatus(EntryDistributionStatus::QUEUED);
         $entryDistribution->save();
     }
     $validationErrors = $entryDistribution->getValidationErrors();
     if (!count($validationErrors)) {
         $sunrise = $entryDistribution->getSunrise(null);
         if ($sunrise) {
             $distributionProvider = $distributionProfile->getProvider();
             if (!$distributionProvider->isScheduleUpdateEnabled() && !$distributionProvider->isAvailabilityUpdateEnabled()) {
                 $sunrise -= $distributionProvider->getJobIntervalBeforeSunrise();
                 if ($sunrise > time()) {
                     KalturaLog::log("Will be sent on exact time [{$sunrise}] for sunrise time [" . $entryDistribution->getSunrise() . "]");
                     $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::SUBMIT_REQUIRED);
                     $entryDistribution->save();
                     return null;
                 }
             }
         }
         return self::addSubmitAddJob($entryDistribution, $distributionProfile);
     }
     KalturaLog::log("Validation errors found");
     $entry = entryPeer::retrieveByPK($entryDistribution->getEntryId());
     if (!$entry) {
         KalturaLog::err("Entry [" . $entryDistribution->getEntryId() . "] not found");
         return null;
     }
     $autoCreateFlavors = $distributionProfile->getAutoCreateFlavorsArray();
     $autoCreateThumbs = $distributionProfile->getAutoCreateThumbArray();
     foreach ($validationErrors as $validationError) {
         if ($validationError->getErrorType() == DistributionErrorType::MISSING_FLAVOR && in_array($validationError->getData(), $autoCreateFlavors)) {
             $errDescription = null;
             KalturaLog::log("Adding flavor [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]");
             kBusinessPreConvertDL::decideAddEntryFlavor(null, $entryDistribution->getEntryId(), $validationError->getData(), $errDescription);
             if ($errDescription) {
                 KalturaLog::log($errDescription);
             }
         }
         if ($validationError->getErrorType() == DistributionErrorType::MISSING_THUMBNAIL && in_array($validationError->getData(), $autoCreateThumbs)) {
             $destThumbParams = thumbParamsPeer::retrieveByPK($validationError->getData());
             if ($destThumbParams) {
                 KalturaLog::log("Adding thumbnail [" . $validationError->getData() . "] to entry [" . $entryDistribution->getEntryId() . "]");
                 kBusinessPreConvertDL::decideThumbGenerate($entry, $destThumbParams);
             } else {
                 KalturaLog::err("Required thumbnail params not found [" . $validationError->getData() . "]");
             }
         }
     }
     return null;
 }
コード例 #13
0
 /**
  * @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;
 }