public function handleItemUpdated(KalturaObjectBase $object, SimpleXMLElement $item)
 {
     if (!$object instanceof KalturaBaseEntry) {
         return;
     }
     if (empty($item->scenes)) {
         return;
     }
     $action = KBulkUploadEngine::$actionsMap[KalturaBulkUploadAction::UPDATE];
     if (isset($item->scenes->action)) {
         $action = strtolower($item->scenes->action);
     }
     switch ($action) {
         case KBulkUploadEngine::$actionsMap[KalturaBulkUploadAction::UPDATE]:
             break;
         default:
             throw new KalturaBatchException("scenes->action: {$action} is not supported", KalturaBatchJobAppErrors::BULK_ACTION_NOT_SUPPORTED);
     }
     $this->entryId = $object->id;
     $this->cuePointPlugin = KalturaCuePointClientPlugin::get($this->xmlBulkUploadEngine->getClient());
     $this->xmlBulkUploadEngine->impersonate();
     $this->getExistingCuePointsBySystemName($this->entryId);
     $this->xmlBulkUploadEngine->getClient()->startMultiRequest();
     $items = array();
     foreach ($item->scenes->children() as $scene) {
         if ($this->updateCuePoint($scene)) {
             $items[] = $scene;
         }
     }
     $results = $this->xmlBulkUploadEngine->getClient()->doMultiRequest();
     $this->xmlBulkUploadEngine->unimpersonate();
     if (is_array($results) && is_array($items)) {
         $this->handleResults($results, $items);
     }
 }
 public function handleItemAdded(KalturaObjectBase $object, SimpleXMLElement $item)
 {
     if (!$object instanceof $this->objectClass) {
         return;
     }
     $metadataItems = $item;
     if ($this->containerName) {
         $containerName = $this->containerName;
         if (empty($item->{$containerName})) {
             return;
         }
         $metadataItems = $item->{$containerName};
     }
     $nodeName = $this->nodeName;
     if (empty($metadataItems->{$nodeName})) {
         // if there is no costum data then we exit
         return;
     }
     KalturaLog::debug("Handles custom metadata for object type [{$this->objectType}] class [{$this->objectClass}] id [{$object->id}] partner id [{$object->partnerId}]");
     $this->xmlBulkUploadEngine->impersonate();
     $pluginsErrorResults = array();
     foreach ($metadataItems->{$nodeName} as $customData) {
         try {
             $this->handleCustomData($object->id, $customData);
         } catch (Exception $e) {
             KalturaLog::err($this->getContainerName() . ' failed: ' . $e->getMessage());
             $pluginsErrorResults[] = $e->getMessage();
         }
     }
     if (count($pluginsErrorResults)) {
         throw new Exception(implode(', ', $pluginsErrorResults));
     }
     $this->xmlBulkUploadEngine->unimpersonate();
 }
 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();
 }
 private function handleCaptionAsset($entryId, $conversionProfileId, SimpleXMLElement $caption)
 {
     $captionAssetPlugin = KalturaCaptionClientPlugin::get($this->xmlBulkUploadEngine->getClient());
     $captionAsset = new KalturaCaptionAsset();
     $captionAsset->tags = $this->xmlBulkUploadEngine->implodeChildElements($caption->tags);
     $this->xmlBulkUploadEngine->impersonate();
     //needed since $this->xmlBulkUploadEngine->getAssetParamsId calles to unimpersonate
     if (isset($caption->captionAssetId)) {
         $captionAsset->id = $caption->captionAssetId;
     }
     if (isset($caption['captionParamsId']) || isset($caption['captionParams'])) {
         $captionAsset->captionParamsId = $this->xmlBulkUploadEngine->getAssetParamsId($caption, $conversionProfileId, true, 'caption');
     }
     if (isset($caption['isDefault'])) {
         if (strtolower($caption['isDefault']) == 'true') {
             $captionAsset->isDefault = KalturaNullableBoolean::TRUE_VALUE;
         } else {
             $captionAsset->isDefault = KalturaNullableBoolean::FALSE_VALUE;
         }
     }
     if (isset($caption['format'])) {
         $captionAsset->format = $caption['format'];
     }
     if (isset($caption['lang'])) {
         $captionAsset->language = $caption['lang'];
     }
     $captionAssetId = null;
     if (isset($caption['captionAssetId'])) {
         $captionAssetId = $caption['captionAssetId'];
     } elseif (isset($captionAsset->captionParamsId)) {
         if (isset($this->currentCaptionAssets[$captionAsset->captionParamsId])) {
             $captionAssetId = $this->currentCaptionAssets[$captionAsset->captionParamsId];
         }
     }
     if ($captionAssetId) {
         $captionAssetPlugin->captionAsset->update($captionAssetId, $captionAsset);
     } else {
         $captionAsset = $captionAssetPlugin->captionAsset->add($entryId, $captionAsset);
         $captionAssetId = $captionAsset->id;
     }
     $captionAssetResource = $this->xmlBulkUploadEngine->getResource($caption, $conversionProfileId);
     if ($captionAssetResource) {
         $captionAssetPlugin->captionAsset->setContent($captionAssetId, $captionAssetResource);
     }
 }
 private function handleAttachmentAsset($entryId, SimpleXMLElement $attachment)
 {
     $attachmentPlugin = KalturaAttachmentClientPlugin::get($this->xmlBulkUploadEngine->getClient());
     $attachmentAsset = new KalturaAttachmentAsset();
     $attachmentAsset->tags = $this->xmlBulkUploadEngine->implodeChildElements($attachment->tags);
     $this->xmlBulkUploadEngine->impersonate();
     //needed since $this->xmlBulkUploadEngine->getAssetParamsId calles to unimpersonate
     if (isset($attachment->fileExt)) {
         $attachmentAsset->fileExt = $attachment->fileExt;
     }
     if (isset($attachment->description)) {
         $attachmentAsset->partnerDescription = $attachment->description;
     }
     if (isset($attachment->filename)) {
         $attachmentAsset->filename = $attachment->filename;
     }
     if (isset($attachment->title)) {
         $attachmentAsset->title = $attachment->title;
     }
     if (isset($attachment['format'])) {
         $attachmentAsset->format = $attachment['format'];
     }
     $attachmentAssetId = null;
     if (isset($attachment['attachmentAssetId'])) {
         $attachmentAssetId = $attachment['attachmentAssetId'];
     }
     if ($attachmentAssetId) {
         $attachmentPlugin->attachmentAsset->update($attachmentAssetId, $attachmentAsset);
     } else {
         $attachmentAsset = $attachmentPlugin->attachmentAsset->add($entryId, $attachmentAsset);
         $attachmentAssetId = $attachmentAsset->id;
     }
     $attachmentAssetResource = $this->xmlBulkUploadEngine->getResource($attachment, 0);
     if ($attachmentAssetResource) {
         $attachmentPlugin->attachmentAsset->setContent($attachmentAssetId, $attachmentAssetResource);
     }
 }