Esempio n. 1
0
 /**
  * 
  * Starts the bulk upload
  * @param KalturaBatchJob $job
  */
 private function startBulkUpload(KalturaBatchJob $job)
 {
     KalturaLog::info("Start bulk upload ({$job->id})");
     //Gets the right Engine instance
     $engine = KBulkUploadEngine::getEngine($job->jobSubType, $job);
     if (is_null($engine)) {
         throw new KalturaException("Unable to find bulk upload engine", KalturaBatchJobAppErrors::ENGINE_NOT_FOUND);
     }
     $job = $this->updateJob($job, 'Parsing file [' . $engine->getName() . ']', KalturaBatchJobStatus::QUEUED, $engine->getData());
     $engine->setJob($job);
     $engine->setData($job->data);
     $engine->handleBulkUpload();
     $job = $engine->getJob();
     $data = $engine->getData();
     $countObjects = $this->countCreatedObjects($job->id, $job->data->bulkUploadObjectType);
     $countHandledObjects = $countObjects[0];
     $countErrorObjects = $countObjects[1];
     if (!$countHandledObjects && !$engine->shouldRetry() && $countErrorObjects) {
         throw new KalturaBatchException("None of the uploaded items were processed succsessfuly", KalturaBatchJobAppErrors::BULK_NO_ENTRIES_HANDLED, $engine->getData());
     }
     if ($engine->shouldRetry()) {
         self::$kClient->batch->resetJobExecutionAttempts($job->id, $this->getExclusiveLockKey(), $job->jobType);
         return $this->closeJob($job, null, null, "Retrying: " . $countHandledObjects . " " . $engine->getObjectTypeTitle() . " objects were handled untill now", KalturaBatchJobStatus::RETRY);
     }
     return $this->closeJob($job, null, null, 'Waiting for objects closure', KalturaBatchJobStatus::ALMOST_DONE, $data);
 }
 /**
  * 
  * Starts the bulk upload
  * @param KalturaBatchJob $job
  */
 private function startBulkUpload(KalturaBatchJob $job)
 {
     KalturaLog::debug("startBulkUpload({$job->id})");
     //Gets the right Engine instance
     $engine = KBulkUploadEngine::getEngine($job->jobSubType, $this->taskConfig, $this->kClient, $job);
     if (is_null($engine)) {
         throw new KalturaException("Unable to find bulk upload engine", KalturaBatchJobAppErrors::ENGINE_NOT_FOUND);
     }
     $this->updateJob($job, 'Parsing file [' . $engine->getName() . ']', KalturaBatchJobStatus::QUEUED, 1);
     $openedEntries = $this->kClient->batch->updateBulkUploadResults($job->id);
     if ($openedEntries) {
         KalturaLog::debug("There are open objects on the job so we wait for them");
         $this->kClient->batch->resetJobExecutionAttempts($job->id, $this->getExclusiveLockKey(), $job->jobType);
         return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::RETRY);
     }
     $engine->handleBulkUpload();
     $job = $engine->getJob();
     $data = $engine->getData();
     $countHandledObjects = $this->countCreatedObjects($job->id, $job->data->bulkUploadObjectType);
     if (!$countHandledObjects) {
         throw new KalturaBatchException("None of the uploaded items were processed succsessfuly", KalturaBatchJobAppErrors::BULK_NO_ENTRIES_HANDLED);
     }
     if ($engine->shouldRetry()) {
         $handledObjectsTypeName = $this->getBulkUploadObectTypeName($job->data->bulkUploadObjectType);
         KalturaLog::debug("Set the job to retry");
         $this->kClient->batch->resetJobExecutionAttempts($job->id, $this->getExclusiveLockKey(), $job->jobType);
         return $this->closeJob($job, null, null, "Retrying: [{$countHandledObjects}] {$handledObjectsTypeName} objects were handled untill now", KalturaBatchJobStatus::RETRY);
     }
     return $this->closeJob($job, null, null, 'Waiting for objects closure', KalturaBatchJobStatus::ALMOST_DONE, $data);
 }
Esempio n. 3
0
 /**
  * (non-PHPdoc)
  * @see KBulkUploadEngine::addBulkUploadResult()
  */
 protected function addBulkUploadResult(KalturaBulkUploadResult $bulkUploadResult)
 {
     parent::addBulkUploadResult($bulkUploadResult);
     $this->handledRecordsThisRun++;
     //adds one to the count of handled records
 }
 protected function addBulkUploadResult(KalturaBulkUploadResult $bulkUploadResult)
 {
     parent::addBulkUploadResult($bulkUploadResult);
 }
 /**
  * Update widevine asset properties
  * If flavorAssetId is not set find asset by entryID and flavorParamsId
  * 
  * @param string $entryId
  * @param SimpleXMLElement $widevineAssetElm
  */
 private function handleWidevineAsset($entryId, SimpleXMLElement $widevineAssetElm)
 {
     $widevineAsset = new KalturaWidevineFlavorAsset();
     $widevineAsset->widevineAssetId = $widevineAssetElm->widevineAssetId;
     if ($widevineAssetElm->widevineDistributionStartDate) {
         $widevineAsset->widevineDistributionStartDate = KBulkUploadEngine::parseFormatedDate((string) $widevineAssetElm->widevineDistributionStartDate);
     }
     if ($widevineAssetElm->widevineDistributionEndDate) {
         $widevineAsset->widevineDistributionEndDate = KBulkUploadEngine::parseFormatedDate((string) $widevineAssetElm->widevineDistributionEndDate);
     }
     $flavorAssetId = null;
     if (isset($widevineAssetElm['flavorAssetId'])) {
         $flavorAssetId = $widevineAssetElm['flavorAssetId'];
     }
     if (!$flavorAssetId) {
         $flavorParamsId = $widevineAssetElm->flavorParamsId;
         $filter = new KalturaAssetFilter();
         $filter->entryIdEqual = $entryId;
         $flavorAssetList = KBatchBase::$kClient->flavorAsset->listAction($filter);
         if ($flavorAssetList->objects) {
             foreach ($flavorAssetList->objects as $flavorAsset) {
                 if ($flavorAsset->flavorParamsId == $flavorParamsId) {
                     $flavorAssetId = $flavorAsset->id;
                 }
             }
         }
     }
     if ($flavorAssetId) {
         KalturaLog::debug("updating flavor asset: " . $flavorAssetId);
         KBatchBase::$kClient->flavorAsset->update($flavorAssetId, $widevineAsset);
     }
 }
 public function handleDistribution($entryId, SimpleXMLElement $distribution)
 {
     $distributionProfileId = null;
     if (!empty($distribution->distributionProfileId)) {
         $distributionProfileId = (int) $distribution->distributionProfileId;
     }
     if (!$distributionProfileId && (!empty($distribution->distributionProfile) || !empty($distribution->distributionProvider))) {
         $distributionProfileId = $this->getDistributionProfileId($distribution->distributionProfile, $distribution->distributionProvider);
     }
     if (!$distributionProfileId) {
         throw new KalturaBatchException("Missing custom data distributionProfile attribute", KalturaBatchJobAppErrors::BULK_MISSING_MANDATORY_PARAMETER);
     }
     $distributionPlugin = KalturaContentDistributionClientPlugin::get($this->xmlBulkUploadEngine->getClient());
     $entryDistributionFilter = new KalturaEntryDistributionFilter();
     $entryDistributionFilter->distributionProfileIdEqual = $distributionProfileId;
     $entryDistributionFilter->entryIdEqual = $entryId;
     $pager = new KalturaFilterPager();
     $pager->pageSize = 1;
     $entryDistributionResponse = $distributionPlugin->entryDistribution->listAction($entryDistributionFilter, $pager);
     $entryDistribution = new KalturaEntryDistribution();
     $entryDistributionId = null;
     if (is_array($entryDistributionResponse->objects) && count($entryDistributionResponse->objects) > 0) {
         $existingEntryDistribution = reset($entryDistributionResponse->objects);
         $entryDistributionId = $existingEntryDistribution->id;
     } else {
         $entryDistribution->entryId = $entryId;
         $entryDistribution->distributionProfileId = $distributionProfileId;
     }
     if (!empty($distribution->sunrise) && KBulkUploadEngine::isFormatedDate($distribution->sunrise)) {
         $entryDistribution->sunrise = KBulkUploadEngine::parseFormatedDate($distribution->sunrise);
     }
     if (!empty($distribution->sunset) && KBulkUploadEngine::isFormatedDate($distribution->sunset)) {
         $entryDistribution->sunset = KBulkUploadEngine::parseFormatedDate($distribution->sunset);
     }
     if (!empty($distribution->flavorAssetIds)) {
         $entryDistribution->flavorAssetIds = $distribution->flavorAssetIds;
     }
     if (!empty($distribution->thumbAssetIds)) {
         $entryDistribution->thumbAssetIds = $distribution->thumbAssetIds;
     }
     $submitWhenReady = false;
     if ($distribution['submitWhenReady']) {
         $submitWhenReady = true;
     }
     $this->xmlBulkUploadEngine->impersonate();
     if ($entryDistributionId) {
         $updatedEntryDistribution = $distributionPlugin->entryDistribution->update($entryDistributionId, $entryDistribution);
         if ($submitWhenReady && $updatedEntryDistribution->dirtyStatus == KalturaEntryDistributionFlag::UPDATE_REQUIRED) {
             $distributionPlugin->entryDistribution->submitUpdate($entryDistributionId);
         }
     } else {
         $createdEntryDistribution = $distributionPlugin->entryDistribution->add($entryDistribution);
         $distributionPlugin->entryDistribution->submitAdd($createdEntryDistribution->id, $submitWhenReady);
     }
     $this->xmlBulkUploadEngine->unimpersonate();
 }