protected function attachRemoteAssetResource(entry $entry, kDistributionSubmitJobData $data) { $distributionProfile = DistributionProfilePeer::retrieveByPK($data->getDistributionProfileId()); /* @var $distributionProfile UnicornDistributionProfile */ $domainGuid = $distributionProfile->getDomainGuid(); $applicationGuid = $distributionProfile->getAdFreeApplicationGuid(); $assetParamsId = $distributionProfile->getRemoteAssetParamsId(); $mediaItemGuid = $data->getRemoteId(); $url = "{$domainGuid}/{$applicationGuid}/{$mediaItemGuid}/content.m3u8"; $entry->setSource(KalturaSourceType::URL); $entry->save(); $isNewAsset = false; $asset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $assetParamsId); if (!$asset) { $isNewAsset = true; $assetParams = assetParamsPeer::retrieveByPK($assetParamsId); $asset = assetPeer::getNewAsset($assetParams->getType()); $asset->setPartnerId($entry->getPartnerId()); $asset->setEntryId($entry->getId()); $asset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED); $asset->setFlavorParamsId($assetParamsId); $asset->setFromAssetParams($assetParams); if ($assetParams->hasTag(assetParams::TAG_SOURCE)) { $asset->setIsOriginal(true); } } $asset->incrementVersion(); $asset->setFileExt('m3u8'); $asset->setStatus(asset::FLAVOR_ASSET_STATUS_READY); $asset->save(); $syncKey = $asset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $storageProfile = StorageProfilePeer::retrieveByPK($distributionProfile->getStorageProfileId()); $fileSync = kFileSyncUtils::createReadyExternalSyncFileForKey($syncKey, $url, $storageProfile); if ($isNewAsset) { kEventsManager::raiseEvent(new kObjectAddedEvent($asset)); } kEventsManager::raiseEvent(new kObjectDataChangedEvent($asset)); kBusinessPostConvertDL::handleConvertFinished(null, $asset); }
/** * @param BatchJob $dbBatchJob * @param kDistributionSubmitJobData $data * @param BatchJob $twinJob * @return BatchJob */ public static function onDistributionSubmitJobUpdated(BatchJob $dbBatchJob, kDistributionSubmitJobData $data, BatchJob $twinJob = null) { if ($data->getRemoteId() || $data->getResults() || $data->getSentData() || $data->getMediaFiles()) { $entryDistribution = EntryDistributionPeer::retrieveByPK($data->getEntryDistributionId()); if (!$entryDistribution) { KalturaLog::err("Entry distribution [" . $data->getEntryDistributionId() . "] not found"); return $dbBatchJob; } if ($data->getResults()) { $entryDistribution->incrementSubmitResultsVersion(); } if ($data->getSentData()) { $entryDistribution->incrementSubmitDataVersion(); } if ($data->getRemoteId()) { $entryDistribution->setRemoteId($data->getRemoteId()); } if ($data->getMediaFiles()) { $entryDistribution->setMediaFiles($data->getMediaFiles()); } $entryDistribution->save(); if ($data->getResults()) { $key = $entryDistribution->getSyncKey(EntryDistribution::FILE_SYNC_ENTRY_DISTRIBUTION_SUBMIT_RESULTS); kFileSyncUtils::file_put_contents($key, $data->getResults()); $data->setResults(null); } if ($data->getSentData()) { $key = $entryDistribution->getSyncKey(EntryDistribution::FILE_SYNC_ENTRY_DISTRIBUTION_SUBMIT_DATA); kFileSyncUtils::file_put_contents($key, $data->getSentData()); $data->setSentData(null); } $dbBatchJob->setData($data); $dbBatchJob->save(); } switch ($dbBatchJob->getStatus()) { case BatchJob::BATCHJOB_STATUS_PENDING: return self::onDistributionSubmitJobPending($dbBatchJob, $data, $twinJob); case BatchJob::BATCHJOB_STATUS_FINISHED: return self::onDistributionSubmitJobFinished($dbBatchJob, $data, $twinJob); case BatchJob::BATCHJOB_STATUS_FAILED: case BatchJob::BATCHJOB_STATUS_FATAL: return self::onDistributionSubmitJobFailed($dbBatchJob, $data, $twinJob); default: return $dbBatchJob; } }