/**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @return BatchJob
  */
 protected static function addSubmitDeleteJob(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile)
 {
     $entryDistribution->setStatus(EntryDistributionStatus::DELETING);
     $entryDistribution->setDirtyStatus(null);
     if (!$entryDistribution->save()) {
         KalturaLog::err("Unable to save entry distribution [" . $entryDistribution->getId() . "] status");
         return null;
     }
     $jobData = new kDistributionDeleteJobData();
     $jobData->setDistributionProfileId($entryDistribution->getDistributionProfileId());
     $jobData->setEntryDistributionId($entryDistribution->getId());
     $jobData->setProviderType($distributionProfile->getProviderType());
     $jobData->setRemoteId($entryDistribution->getRemoteId());
     $jobData->setMediaFiles($entryDistribution->getMediaFiles());
     $batchJob = new BatchJob();
     $batchJob->setEntryId($entryDistribution->getEntryId());
     $batchJob->setPartnerId($entryDistribution->getPartnerId());
     $jobType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_DELETE);
     $jobSubType = $distributionProfile->getProviderType();
     return kJobsManager::addJob($batchJob, $jobData, $jobType, $jobSubType);
 }
 /**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @return BatchJob
  */
 protected static function addSubmitDeleteJob(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile)
 {
     $entryDistribution->setStatus(EntryDistributionStatus::DELETING);
     if (!$entryDistribution->save()) {
         KalturaLog::err("Unable to save entry distribution [" . $entryDistribution->getId() . "] status");
         $entryDistribution->reload();
         return null;
     }
     $entryDistribution->setDirtyStatus(null);
     //Moved down to ensure previous save is done Atomically
     $entryDistribution->save();
     $jobData = new kDistributionDeleteJobData();
     $jobData->setDistributionProfileId($entryDistribution->getDistributionProfileId());
     $jobData->setEntryDistributionId($entryDistribution->getId());
     $jobData->setProviderType($distributionProfile->getProviderType());
     $jobData->setRemoteId($entryDistribution->getRemoteId());
     $jobData->setMediaFiles($entryDistribution->getMediaFiles());
     $batchJob = new BatchJob();
     $batchJob->setEntryId($entryDistribution->getEntryId());
     $batchJob->setPartnerId($entryDistribution->getPartnerId());
     $batchJob->setObjectId($entryDistribution->getId());
     $batchJob->setObjectType(kPluginableEnumsManager::apiToCore('BatchJobObjectType', ContentDistributionBatchJobObjectType::ENTRY_DISTRIBUTION));
     $jobType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_DELETE);
     $jobSubType = $distributionProfile->getProviderType();
     return kJobsManager::addJob($batchJob, $jobData, $jobType, $jobSubType);
 }
 protected function getFieldValuesXml(EntryDistribution $entryDistribution, $fieldName = null)
 {
     $entry = entryPeer::retrieveByPKNoFilter($entryDistribution->getEntryId());
     if (!$entry) {
         KalturaLog::err('Entry not found with ID [' . $entryDistribution->getEntryId() . ']');
         return null;
     }
     // set the default criteria to use the current entry distribution partner id (it is restored later)
     // this is needed for related entries under kMetadataMrssManager which is using retrieveByPK without the correct partner id filter
     $oldEntryCriteria = entryPeer::getCriteriaFilter()->getFilter();
     myPartnerUtils::resetPartnerFilter('entry');
     myPartnerUtils::addPartnerToCriteria('entry', $entryDistribution->getPartnerId(), true);
     try {
         $mrss = null;
         $mrssParams = new kMrssParameters();
         if ($this->getItemXpathsToExtend()) {
             $mrssParams->setItemXpathsToExtend($this->getItemXpathsToExtend());
         }
         $mrss = kMrssManager::getEntryMrssXml($entry, $mrss, $mrssParams);
         $mrssStr = $mrss->asXML();
     } catch (Exception $e) {
         // restore the original criteria so it will not get stuck due to the exception
         entryPeer::getCriteriaFilter()->setFilter($oldEntryCriteria);
         throw $e;
     }
     // restore the original criteria
     entryPeer::getCriteriaFilter()->setFilter($oldEntryCriteria);
     if (!$mrssStr) {
         KalturaLog::err('No MRSS returned for entry [' . $entry->getId() . ']');
         return null;
     }
     $mrssObj = new DOMDocument();
     if (!$mrssObj->loadXML($mrssStr)) {
         KalturaLog::err('Error loading MRSS XML object for entry [' . $entry->getId() . ']');
         return null;
     }
     $xslObj = new DOMDocument();
     $xslStr = $this->getFieldValuesXslt($entryDistribution, $fieldName);
     $xslStr = trim($xslStr);
     if (!$xslObj->loadXML($xslStr)) {
         KalturaLog::err('Error loading distribution profile XSLT for profile ID [' . $this->getId() . ']');
         return null;
     }
     $proc = new XSLTProcessor();
     $proc->registerPHPFunctions(kXml::getXslEnabledPhpFunctions());
     $proc->importStyleSheet($xslObj);
     $resultXml = $proc->transformToXml($mrssObj);
     //in order to keep the UTF-8 encoding we transformToXml http://www.php.net/manual/en/xsltprocessor.transformtodoc.php#69305
     $resultXmlObj = new DOMDocument();
     $resultXmlObj->loadXML($resultXml);
     if (!$resultXmlObj) {
         KalturaLog::err('Error transforming XML for distribution profile [' . $this->getId() . '] and entry id [' . $entry->getId() . ']');
         return null;
     }
     /* DEBUG logs
     		KalturaLog::log('entry mrss = '.$mrssStr);
     		KalturaLog::log('profile xslt = '.$xslStr);
     		*/
     KalturaLog::debug('Result XML: ' . $resultXmlObj->saveXML());
     return $resultXmlObj;
 }
 /**
  * @param EntryDistribution $entryDistribution
  * @param DistributionProfile $distributionProfile
  * @return BatchJob
  */
 protected static function addSubmitDeleteJob(EntryDistribution $entryDistribution, DistributionProfile $distributionProfile)
 {
     $jobData = new kDistributionDeleteJobData();
     $jobData->setDistributionProfileId($entryDistribution->getDistributionProfileId());
     $jobData->setEntryDistributionId($entryDistribution->getId());
     $jobData->setProviderType($distributionProfile->getProviderType());
     $jobData->setRemoteId($entryDistribution->getRemoteId());
     $batchJob = new BatchJob();
     $batchJob->setEntryId($entryDistribution->getEntryId());
     $batchJob->setPartnerId($entryDistribution->getPartnerId());
     $jobType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_DELETE);
     $jobSubType = $distributionProfile->getProviderType();
     return kJobsManager::addJob($batchJob, $jobData, $jobType, $jobSubType);
 }