/** * @param KalturaDistributionJobData $data * @param KalturaExampleDistributionProfile $distributionProfile * @param KalturaExampleDistributionJobProviderData $providerData */ protected function handleUpdate(KalturaDistributionJobData $data, KalturaExampleDistributionProfile $distributionProfile, KalturaExampleDistributionJobProviderData $providerData) { $entryId = $data->entryDistribution->entryId; $partnerId = $distributionProfile->partnerId; $entry = $this->getEntry($partnerId, $entryId); $feed = new KDOMDocument(); $feed->load($this->updateXmlTemplate); $feed->documentElement->setAttribute('mediaId', $data->remoteId); $nodes = array('title' => 'name', 'description' => 'description', 'width' => 'width', 'height' => 'height'); foreach ($nodes as $nodeName => $entryAttribute) { $nodeElements = $feed->getElementsByTagName($nodeName); foreach ($nodeElements as $nodeElement) { $nodeElement->textContent = $entry->{$entryAttribute}; } } // get the first asset id $thumbAssetIds = explode(',', $data->entryDistribution->thumbAssetIds); $thumbAssetId = reset($thumbAssetIds); $thumbElements = $feed->getElementsByTagName('thumb'); $thumbElement = reset($thumbElements); $thumbElement->textContent = $this->getThumbAssetUrl($thumbAssetId); $videosElements = $feed->getElementsByTagName('videos'); $videosElement = reset($videosElements); $flavorAssets = $this->getFlavorAssets($partnerId, $data->entryDistribution->flavorAssetIds); KBatchBase::impersonate($partnerId); foreach ($flavorAssets as $flavorAsset) { $url = $this->getFlavorAssetUrl($flavorAsset->id); $videoElement = $feed->createElement('video'); $videoElement->textContent = $url; $videosElement->appendChild($videoElement); } KBatchBase::unimpersonate(); $localFile = tempnam(sys_get_temp_dir(), 'example-update-'); $feed->save($localFile); // loads ftp manager $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $ftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP, $engineOptions); $ftpManager->login(self::FTP_SERVER_URL, $distributionProfile->username, $distributionProfile->password); // put the XML file on the FTP $remoteFile = $entryId . '.xml'; $ftpManager->putFile($remoteFile, $localFile); return true; }