/** * @param EntryDistribution $entryDistribution * @param SimpleXMLElement $xmlElement * @return SimpleXMLElement */ public function contributeDistribution(EntryDistribution $entryDistribution, SimpleXMLElement $mrss) { $distributionsProvider = null; $distributionsProfile = DistributionProfilePeer::retrieveByPK($entryDistribution->getDistributionProfileId()); if ($distributionsProfile) { $distributionsProvider = $distributionsProfile->getProvider(); } $distribution = $mrss->addChild('distribution'); $distribution->addAttribute('entryDistributionId', $entryDistribution->getId()); $distribution->addAttribute('distributionProfileId', $entryDistribution->getDistributionProfileId()); $distribution->addAttribute('lastReport', $entryDistribution->getLastReport(null)); if ($distributionsProvider) { $distribution->addAttribute('provider', $distributionsProvider->getName()); if ($distributionsProvider->getType() == DistributionProviderType::GENERIC) { $distribution->addAttribute('distributionProviderId', $distributionsProvider->getId()); } elseif ($distributionsProvider->getType() == DistributionProviderType::SYNDICATION) { if ($distributionsProfile instanceof SyndicationDistributionProfile) { $distribution->addAttribute('feedId', $distributionsProfile->getFeedId()); } } else { $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaContentDistributionProvider'); foreach ($pluginInstances as $pluginInstance) { if ($pluginInstance->getProvider() === $distributionsProvider) { $pluginInstance->contributeMRSS($entryDistribution, $distribution); } } } } if ($entryDistribution->getRemoteId()) { $distribution->addChild('remoteId', $entryDistribution->getRemoteId()); } if ($entryDistribution->getSunrise(null)) { $distribution->addChild('sunrise', $entryDistribution->getSunrise(null)); } if ($entryDistribution->getSunset(null)) { $distribution->addChild('sunset', $entryDistribution->getSunset(null)); } $flavorAssetIds = explode(',', $entryDistribution->getFlavorAssetIds()); $flavorAssetIdsNode = $distribution->addChild('flavorAssetIds'); foreach ($flavorAssetIds as $flavorAssetId) { $flavorAssetIdsNode->addChild('flavorAssetId', $flavorAssetId); } $thumbAssetIds = explode(',', $entryDistribution->getThumbAssetIds()); $thumbAssetIdsNode = $distribution->addChild('thumbAssetIds'); foreach ($thumbAssetIds as $thumbAssetId) { $thumbAssetIdsNode->addChild('thumbAssetId', $thumbAssetId); } }
/** * @param EntryDistribution $entryDistribution * @param entry $entry * @param DistributionProfile $distributionProfile * @return boolean */ public static function assignAssets(EntryDistribution $entryDistribution, entry $entry, DistributionProfile $distributionProfile) { $submittingStatuses = array(EntryDistributionStatus::PENDING, EntryDistributionStatus::QUEUED, EntryDistributionStatus::SUBMITTING, EntryDistributionStatus::IMPORT_SUBMITTING, EntryDistributionStatus::ERROR_SUBMITTING); // if not in first submmiting status then it's an update and need to check if update is supported. if (!in_array($entryDistribution->getStatus(), $submittingStatuses)) { $distributionProvider = $distributionProfile->getProvider(); if (!$distributionProvider) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider not found"); return false; } if (!$distributionProvider->isUpdateEnabled() || !$distributionProvider->isMediaUpdateEnabled()) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProvider->getName() . "] does not support update"); return false; } } $requiredAssetsConditions = $distributionProfile->getRequiredAssetDistributionRules(); $optionalAssetsConditions = $distributionProfile->getOptionalAssetDistributionRules(); $assetDistributionRules = array_merge($requiredAssetsConditions, $optionalAssetsConditions); if (!is_array($assetDistributionRules)) { return false; } $assetIds = array(); $originalList = $entryDistribution->getAssetIds(); $entryAssets = assetPeer::retrieveReadyByEntryId($entryDistribution->getEntryId()); foreach ($assetDistributionRules as $assetDistributionRule) { /* @var $assetDistributionRule kAssetDistributionRule */ foreach ($entryAssets as $asset) { /* @var $asset asset */ if ($assetDistributionRule->fulfilled($asset)) { $assetIds[] = $asset->getId(); } } } $entryDistribution->setAssetIds($assetIds); return $originalList != $entryDistribution->getAssetIds(); }
public function transformXslForEntry(EntryDistribution $entryDistribution, $xsl, $xslParams = array()) { $xslParams['entryDistributionId'] = $entryDistribution->getId(); $xslParams['distributionProfileId'] = $entryDistribution->getDistributionProfileId(); $mrssDoc = $this->getEntryMrssDoc($entryDistribution); $xslDoc = new DOMDocument(); $xslDoc->loadXML($xsl); $xslt = new XSLTProcessor(); $xslt->registerPHPFunctions(); // it is safe to register all php fuctions here $xslt->setParameter('', $xslParams); $xslt->importStyleSheet($xslDoc); return $xslt->transformToXml($mrssDoc); }
/** * @param EntryDistribution $entryDistribution */ public static function onEntryDistributionUpdateRequired(EntryDistribution $entryDistribution) { $distributionProfileId = $entryDistribution->getDistributionProfileId(); $distributionProfile = DistributionProfilePeer::retrieveByPK($distributionProfileId); if (!$distributionProfile) { return true; } $distributionProvider = $distributionProfile->getProvider(); if (!$distributionProvider) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider not found"); return true; } if (!$distributionProvider->isUpdateEnabled()) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProvider->getName() . "] does not support update"); return true; } $ignoreStatuses = array(EntryDistributionStatus::PENDING, EntryDistributionStatus::DELETED, EntryDistributionStatus::DELETING, EntryDistributionStatus::QUEUED, EntryDistributionStatus::REMOVED); if (in_array($entryDistribution->getStatus(), $ignoreStatuses)) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] status [" . $entryDistribution->getStatus() . "] does not require update"); return true; } if ($entryDistribution->getDirtyStatus() == EntryDistributionDirtyStatus::UPDATE_REQUIRED) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] already requires update"); return true; } $distributionProfileId = $entryDistribution->getDistributionProfileId(); $distributionProfile = DistributionProfilePeer::retrieveByPK($distributionProfileId); if (!$distributionProfile) { KalturaLog::err("Entry distribution [" . $entryDistribution->getId() . "] profile [{$distributionProfileId}] not found"); return true; } $distributionProvider = $distributionProfile->getProvider(); if (!$distributionProvider->isUpdateEnabled()) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProvider->getName() . "] does not support update"); return true; } if ($distributionProfile->getUpdateEnabled() != DistributionProfileActionStatus::AUTOMATIC) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] should not be updated automatically"); $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::UPDATE_REQUIRED); $entryDistribution->save(); return true; } self::submitUpdateEntryDistribution($entryDistribution, $distributionProfile); return true; }
public function getAllFieldValues(EntryDistribution $entryDistribution) { if (is_null($this->fieldValuesByEntryDistributionId) || !is_array($this->fieldValuesByEntryDistributionId) || !isset($this->fieldValuesByEntryDistributionId[$entryDistribution->getId()])) { $valuesXmlObj = $this->getFieldValuesXml($entryDistribution); if (!$valuesXmlObj) { KalturaLog::err('Error transforming XML for distribution profile [' . $this->getId() . '] and entry distribution id [' . $entryDistribution->getId() . ']'); return null; } $valuesXmlStr = $valuesXmlObj->saveXML(); KalturaLog::debug('All field values result XML: ' . $valuesXmlStr); $fieldValues = array(); $fieldConfigArray = $this->getFieldConfigArray(); foreach ($fieldConfigArray as $fieldConfig) { $fieldName = $fieldConfig->getFieldName(); $fieldValues[$fieldName] = $this->getFieldValueFromXml($fieldName, $valuesXmlObj); } $this->fieldValuesByEntryDistributionId[$entryDistribution->getId()] = $fieldValues; } return $this->fieldValuesByEntryDistributionId[$entryDistribution->getId()]; }
/** * @param EntryDistribution $entryDistribution * @param int $action enum from DistributionAction * @return array<kDistributionValidationError> */ public function validateForSubmission(EntryDistribution $entryDistribution, $action) { $validationErrors = array(); $distributionProvider = $this->getProvider(); if (!$distributionProvider) { KalturaLog::err("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $this->getProviderType() . "] not found"); return $validationErrors; } if ($action == DistributionAction::UPDATE || $entryDistribution->getStatus() == EntryDistributionStatus::READY || $entryDistribution->getStatus() == EntryDistributionStatus::ERROR_UPDATING) { if (!$distributionProvider->isUpdateEnabled() || !$distributionProvider->isMediaUpdateEnabled()) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProvider->getName() . "] does not support update"); return $validationErrors; } } $requiredFlavorParamsIds = $this->getRequiredFlavorParamsIdsArray(); KalturaLog::log("Required Flavor Params Ids [" . print_r($requiredFlavorParamsIds, true) . "]"); $entryFlavorAssets = assetPeer::retrieveReadyFlavorsByEntryId($entryDistribution->getEntryId()); $requiredFlavorParamsIdsKeys = array_flip($requiredFlavorParamsIds); foreach ($entryFlavorAssets as $entryFlavorAsset) { $flavorParamsId = $entryFlavorAsset->getFlavorParamsId(); if (isset($requiredFlavorParamsIdsKeys[$flavorParamsId])) { unset($requiredFlavorParamsIds[$requiredFlavorParamsIdsKeys[$flavorParamsId]]); } } foreach ($requiredFlavorParamsIds as $requiredFlavorParamsId) { $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_FLAVOR, $requiredFlavorParamsId); } $requiredThumbDimensions = $this->getRequiredThumbDimensionsObjects(); KalturaLog::log("Required Thumb Dimensions [" . print_r($requiredThumbDimensions, true) . "]"); $entryThumbAssets = assetPeer::retrieveReadyThumbnailsByEntryId($entryDistribution->getEntryId()); $requiredThumbDimensionsWithKeys = array(); foreach ($requiredThumbDimensions as $requiredThumbDimension) { $key = $requiredThumbDimension->getKey(); $requiredThumbDimensionsWithKeys[$key] = $requiredThumbDimension; } foreach ($entryThumbAssets as $entryThumbAsset) { $key = $entryThumbAsset->getWidth() . 'x' . $entryThumbAsset->getHeight(); if (isset($requiredThumbDimensionsWithKeys[$key])) { unset($requiredThumbDimensionsWithKeys[$key]); } } foreach ($requiredThumbDimensionsWithKeys as $key => $requiredThumbDimension) { $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_THUMBNAIL, $key); } $entryAssets = assetPeer::retrieveReadyByEntryId($entryDistribution->getEntryId()); $requiredAssetDistributionRules = $this->getRequiredAssetDistributionRules(); foreach ($requiredAssetDistributionRules as $entryAssetDistributionRule) { $foundMatchingAsset = false; /* @var $entryAssetDistributionRule kAssetDistributionRule */ foreach ($entryAssets as $entryAsset) { /* @var $entryAsset asset */ if ($entryAssetDistributionRule->fulfilled($entryAsset)) { $foundMatchingAsset = true; break; } } if (!$foundMatchingAsset) { $validationErrors[] = $this->createValidationError($action, DistributionErrorType::MISSING_ASSET, $entryAssetDistributionRule->getValidationError()); } } return $validationErrors; }
/** * @param EntryDistribution $entryDistribution * @param SimpleXMLElement $mrss * @return SimpleXMLElement */ public function contributeDistribution(EntryDistribution $entryDistribution, SimpleXMLElement $mrss) { $distributionsProvider = null; $distributionsProfile = DistributionProfilePeer::retrieveByPK($entryDistribution->getDistributionProfileId()); if ($distributionsProfile) { $distributionsProvider = $distributionsProfile->getProvider(); } $distribution = $mrss->addChild('distribution'); $distribution->addAttribute('entryDistributionId', $entryDistribution->getId()); $distribution->addAttribute('distributionProfileId', $entryDistribution->getDistributionProfileId()); if ($distributionsProfile) { $distribution->addAttribute('distributionProfileName', $distributionsProfile->getName()); } if ($distributionsProvider) { $distribution->addAttribute('provider', $distributionsProvider->getName()); if ($distributionsProvider->getType() == DistributionProviderType::GENERIC) { $distribution->addAttribute('distributionProviderId', $distributionsProvider->getId()); } elseif ($distributionsProvider->getType() == DistributionProviderType::SYNDICATION) { if ($distributionsProfile instanceof SyndicationDistributionProfile) { $distribution->addAttribute('feedId', $distributionsProfile->getFeedId()); } } else { $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaContentDistributionProvider'); foreach ($pluginInstances as $pluginInstance) { if ($pluginInstance->getProvider() === $distributionsProvider) { $pluginInstance->contributeMRSS($entryDistribution, $distribution); } } } } if ($entryDistribution->getRemoteId()) { $distribution->addChild('remoteId', $entryDistribution->getRemoteId()); } if ($entryDistribution->getSunrise(null)) { $distribution->addChild('sunrise', $entryDistribution->getSunrise(null)); } if ($entryDistribution->getSunset(null)) { $distribution->addChild('sunset', $entryDistribution->getSunset(null)); } $flavorAssetIds = explode(',', $entryDistribution->getFlavorAssetIds()); $flavorAssetIdsNode = $distribution->addChild('flavorAssetIds'); foreach ($flavorAssetIds as $flavorAssetId) { $flavorAssetIdsNode->addChild('flavorAssetId', $flavorAssetId); } $thumbAssetIds = explode(',', $entryDistribution->getThumbAssetIds()); $thumbAssetIdsNode = $distribution->addChild('thumbAssetIds'); foreach ($thumbAssetIds as $thumbAssetId) { $thumbAssetIdsNode->addChild('thumbAssetId', $thumbAssetId); } $assetIds = explode(',', $entryDistribution->getAssetIds()); $assetIdsNode = $distribution->addChild('assetIds'); foreach ($assetIds as $assetId) { $assetIdsNode->addChild('assetId', $assetId); } if ($entryDistribution->getErrorDescription()) { $distribution->addChild('errorDescription', kMrssManager::stringToSafeXml($entryDistribution->getErrorDescription())); } $distribution->addChild('createdAt', $entryDistribution->getCreatedAt(kMrssManager::FORMAT_DATETIME)); $distribution->addChild('updatedAt', $entryDistribution->getUpdatedAt(kMrssManager::FORMAT_DATETIME)); if ($entryDistribution->getSubmittedAt(null)) { $distribution->addChild('submittedAt', $entryDistribution->getSubmittedAt(kMrssManager::FORMAT_DATETIME)); } if ($entryDistribution->getLastReport(null)) { $distribution->addChild('lastReport', $entryDistribution->getLastReport(kMrssManager::FORMAT_DATETIME)); } if ($entryDistribution->getDirtyStatus()) { $distribution->addChild('dirtyStatus', $entryDistribution->getDirtyStatus()); } $distribution->addChild('status', $entryDistribution->getStatus()); $distribution->addChild('sunStatus', $entryDistribution->getSunStatus()); if ($entryDistribution->getPlays()) { $distribution->addChild('plays', $entryDistribution->getPlays()); } if ($entryDistribution->getViews()) { $distribution->addChild('views', $entryDistribution->getViews()); } if ($entryDistribution->getErrorNumber()) { $distribution->addChild('errorNumber', $entryDistribution->getErrorNumber()); } if ($entryDistribution->getErrorType()) { $distribution->addChild('errorType', $entryDistribution->getErrorType()); } }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param EntryDistribution $value A EntryDistribution object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(EntryDistribution $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * @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); }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param EntryDistribution $value A EntryDistribution object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(EntryDistribution $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) { self::$instances[$key] = $obj; kMemoryManager::registerPeer('EntryDistributionPeer'); } } }
/** * @param EntryDistribution $entryDistribution * @param int $fileSubType * @param string $fileName * @param bool $forceProxy * @throws KalturaAPIException */ protected function serveFile(EntryDistribution $entryDistribution, $fileSubType, $fileName, $forceProxy = false) { $syncKey = $entryDistribution->getSyncKey($fileSubType); if (!kFileSyncUtils::fileSync_exists($syncKey)) { throw new KalturaAPIException(ContentDistributionErrors::ENTRY_DISTRIBUTION_MISSING_LOG, $entryDistribution->getId(), $fileSubType); } list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); header("Content-Disposition: attachment; filename=\"{$fileName}\""); if ($local) { $filePath = $fileSync->getFullPath(); $mimeType = kFile::mimeType($filePath); kFile::dumpFile($filePath, $mimeType); } else { $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); KalturaLog::info("Redirecting to [{$remoteUrl}]"); if ($forceProxy) { kFile::dumpUrl($remoteUrl); } else { // or redirect if no proxy header("Location: {$remoteUrl}"); } } }