/** * @param EntryDistribution $entryDistribution * @param entry $entry * @param DistributionProfile $distributionProfile * @return boolean true if the list of thumbnails modified */ public static function assignThumbAssets(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; } } $thumbAssetsIds = array(); $thumbDimensions = $distributionProfile->getThumbDimensionsObjects(); $thumbDimensionsWithKeys = array(); foreach ($thumbDimensions as $thumbDimension) { $thumbDimensionsWithKeys[$thumbDimension->getKey()] = $thumbDimension; } $originalList = $entryDistribution->getThumbAssetIds(); // remove deleted thumb assets $assignedThumbAssetIds = $originalList; if ($assignedThumbAssetIds) { $assignedThumbAssets = assetPeer::retrieveByIds(explode(',', $assignedThumbAssetIds)); foreach ($assignedThumbAssets as $assignedThumbAsset) { $key = $assignedThumbAsset->getWidth() . 'x' . $assignedThumbAsset->getHeight(); if (isset($thumbDimensionsWithKeys[$key])) { unset($thumbDimensionsWithKeys[$key]); $thumbAssetsIds[] = $assignedThumbAsset->getId(); } } } // add new thumb assets $requiredThumbParamsIds = $distributionProfile->getAutoCreateThumbArray(); $thumbAssets = assetPeer::retrieveReadyThumbnailsByEntryId($entry->getId()); foreach ($thumbAssets as $thumbAsset) { if (in_array($thumbAsset->getFlavorParamsId(), $requiredThumbParamsIds)) { $thumbAssetsIds[] = $thumbAsset->getId(); KalturaLog::log("Assign thumb asset [" . $thumbAsset->getId() . "] from required thumbnail params ids"); continue; } $key = $thumbAsset->getWidth() . 'x' . $thumbAsset->getHeight(); if (isset($thumbDimensionsWithKeys[$key])) { unset($thumbDimensionsWithKeys[$key]); KalturaLog::log("Assign thumb asset [" . $thumbAsset->getId() . "] from dimension [{$key}]"); $thumbAssetsIds[] = $thumbAsset->getId(); } } $entryDistribution->setThumbAssetIds($thumbAssetsIds); return $originalList != $entryDistribution->getThumbAssetIds(); }
/** * @param EntryDistribution $entryDistribution * @param entry $entry * @param DistributionProfile $distributionProfile * @return boolean true if the list of thumbnails modified */ public static function assignThumbAssets(EntryDistribution $entryDistribution, entry $entry, DistributionProfile $distributionProfile) { $thumbAssetsIds = array(); $thumbDimensions = $distributionProfile->getThumbDimensionsObjects(); $thumbDimensionsWithKeys = array(); foreach ($thumbDimensions as $thumbDimension) { $thumbDimensionsWithKeys[$thumbDimension->getKey()] = $thumbDimension; } $originalList = $entryDistribution->getThumbAssetIds(); // remove deleted thumb assets $assignedThumbAssetIds = $originalList; if ($assignedThumbAssetIds) { $thumbAssetsIds = explode(',', $assignedThumbAssetIds); $assignedThumbAssets = thumbAssetPeer::retrieveByIds($thumbAssetsIds); foreach ($assignedThumbAssets as $assignedThumbAsset) { $key = $assignedThumbAsset->getWidth() . 'x' . $assignedThumbAsset->getHeight(); if (isset($thumbDimensionsWithKeys[$key])) { unset($thumbDimensionsWithKeys[$key]); } } } // add new thumb assets $requiredThumbParamsIds = $distributionProfile->getAutoCreateThumbArray(); $thumbAssets = thumbAssetPeer::retreiveReadyByEntryId($entry->getId()); foreach ($thumbAssets as $thumbAsset) { if (in_array($thumbAsset->getFlavorParamsId(), $requiredThumbParamsIds)) { $thumbAssetsIds[] = $thumbAsset->getId(); KalturaLog::log("Assign thumb asset [" . $thumbAsset->getId() . "] from required thumbnail params ids"); continue; } $key = $thumbAsset->getWidth() . 'x' . $thumbAsset->getHeight(); if (isset($thumbDimensionsWithKeys[$key])) { unset($thumbDimensionsWithKeys[$key]); KalturaLog::log("Assign thumb asset [" . $thumbAsset->getId() . "] from dimension [{$key}]"); $thumbAssetsIds[] = $thumbAsset->getId(); } } $entryDistribution->setThumbAssetIds($thumbAssetsIds); return $originalList != $entryDistribution->getThumbAssetIds(); }