private static function purgeAssetFromEdgeCast(asset $asset) { // get partner $partnerId = $asset->getPartnerId(); $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner) { KalturaLog::err('Cannot find partner with id [' . $partnerId . ']'); return false; } $mediaType = $asset instanceof thumbAsset ? self::EDGE_SERVICE_HTTP_SMALL_OBJECT_MEDIA_TYPE : self::EDGE_SERVICE_HTTP_LARGE_OBJECT_MEDIA_TYPE; $mediaTypePathList = array(); try { $mediaTypePathList[] = array('MediaType' => $mediaType, 'MediaPath' => $asset->getDownloadUrl()); // asset download url } catch (Exception $e) { KalturaLog::err('Cannot get asset URL for asset id [' . $asset->getId() . '] - ' . $e->getMessage()); } if ($asset instanceof flavorAsset) { // get a list of all URLs leading to the asset for purging $subPartnerId = $asset->getentry()->getSubpId(); $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subPartnerId); $assetId = $asset->getId(); $serveFlavorUrl = "{$partnerPath}/serveFlavor/entryId/" . $asset->getEntryId() . "/flavorId/{$assetId}" . '*'; // * wildcard should delete all serveFlavor urls $hosts = array($partner->getCdnHost(), $partner->getRtmpUrl(), $partner->getIisHost()); foreach ($hosts as $host) { if (!empty($host)) { $mediaTypePathList[] = array('MediaType' => $mediaType, 'MediaPath' => $host . $serveFlavorUrl); } } } return self::purgeFromEdgeCast($mediaTypePathList, $partner); }
private static function purgeAssetFromEdgeCast(asset $asset) { // get partner $partnerId = $asset->getPartnerId(); $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner) { KalturaLog::err('Cannot find partner with id [' . $partnerId . ']'); return false; } $mediaType = $asset instanceof thumbAsset ? self::EDGE_SERVICE_HTTP_SMALL_OBJECT_MEDIA_TYPE : self::EDGE_SERVICE_HTTP_LARGE_OBJECT_MEDIA_TYPE; $mediaTypePathList = array(); try { $mediaTypePathList[] = array('MediaType' => $mediaType, 'MediaPath' => $asset->getDownloadUrl()); // asset download url } catch (Exception $e) { KalturaLog::err('Cannot get asset URL for asset id [' . $asset->getId() . '] - ' . $e->getMessage()); } if ($asset instanceof flavorAsset) { // get a list of all URLs leading to the asset for purging $subPartnerId = $asset->getentry()->getSubpId(); $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subPartnerId); $assetId = $asset->getId(); $serveFlavorUrl = "{$partnerPath}/serveFlavor/entryId/" . $asset->getEntryId() . "/flavorId/{$assetId}" . '*'; // * wildcard should delete all serveFlavor urls $types = array(kPluginableEnumsManager::apiToCore(EdgeCastDeliveryProfileType::EDGE_CAST_HTTP), kPluginableEnumsManager::apiToCore(EdgeCastDeliveryProfileType::EDGE_CAST_RTMP)); $deliveryProfile = $partner->getDeliveryProfileIds(); $deliveryProfileIds = array(); foreach ($deliveryProfile as $key => $value) { $deliveryProfileIds = array_merge($deliveryProfileIds, $value); } $c = new Criteria(); $c->add(DeliveryProfilePeer::PARTNER_ID, $partnerId); $c->add(DeliveryProfilePeer::ID, $deliveryProfileIds, Criteria::IN); $c->addSelectColumn(DeliveryProfilePeer::HOST_NAME); $stmt = PermissionPeer::doSelectStmt($c); $hosts = $stmt->fetchAll(PDO::FETCH_COLUMN); foreach ($hosts as $host) { if (!empty($host)) { $mediaTypePathList[] = array('MediaType' => $mediaType, 'MediaPath' => $host . $serveFlavorUrl); } } } return self::purgeFromEdgeCast($mediaTypePathList, $partner); }
/** * @param asset $asset */ public static function onAssetReadyOrDeleted(asset $asset) { if (!ContentDistributionPlugin::isAllowedPartner($asset->getPartnerId())) { KalturaLog::log("Partner [" . $asset->getPartnerId() . "] is not allowed"); return true; } $entry = $asset->getentry(); if (!$entry) { KalturaLog::log("Entry [" . $asset->getEntryId() . "] not found"); return true; } $entryDistributions = EntryDistributionPeer::retrieveByEntryId($asset->getEntryId()); foreach ($entryDistributions as $entryDistribution) { $distributionProfileId = $entryDistribution->getDistributionProfileId(); $distributionProfile = DistributionProfilePeer::retrieveByPK($distributionProfileId); if (!$distributionProfile) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] profile [{$distributionProfileId}] not found"); continue; } if ($entryDistribution->getStatus() == EntryDistributionStatus::QUEUED || $entryDistribution->getStatus() == EntryDistributionStatus::PENDING) { $listChanged = kContentDistributionManager::assignFlavorAssets($entryDistribution, $entry, $distributionProfile); $listChanged = $listChanged | kContentDistributionManager::assignThumbAssets($entryDistribution, $entry, $distributionProfile); $listChanged = $listChanged | kContentDistributionManager::assignAssets($entryDistribution, $entry, $distributionProfile); if (!$listChanged) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] asset lists didn't change"); continue; } $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::SUBMIT); $entryDistribution->setValidationErrorsArray($validationErrors); $entryDistribution->save(); if ($entryDistribution->getStatus() == EntryDistributionStatus::QUEUED) { if ($entryDistribution->getDirtyStatus() != EntryDistributionDirtyStatus::SUBMIT_REQUIRED) { self::submitAddEntryDistribution($entryDistribution, $distributionProfile); } } } // submit if ($entryDistribution->getStatus() == EntryDistributionStatus::READY || $entryDistribution->getStatus() == EntryDistributionStatus::ERROR_UPDATING) { $distributionProvider = $distributionProfile->getProvider(); if (!$distributionProvider) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider not found"); continue; } if (!$distributionProvider->isUpdateEnabled() || !$distributionProvider->isMediaUpdateEnabled()) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] provider [" . $distributionProvider->getName() . "] does not support update"); continue; } $listChanged = kContentDistributionManager::assignFlavorAssets($entryDistribution, $entry, $distributionProfile); $listChanged = $listChanged | kContentDistributionManager::assignThumbAssets($entryDistribution, $entry, $distributionProfile); $listChanged = $listChanged | kContentDistributionManager::assignAssets($entryDistribution, $entry, $distributionProfile); if (!$listChanged) { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] asset lists didn't change"); continue; } $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::UPDATE); $entryDistribution->setValidationErrorsArray($validationErrors); $entryDistribution->save(); if (!count($validationErrors) && $distributionProfile->getUpdateEnabled() == DistributionProfileActionStatus::AUTOMATIC) { self::submitUpdateEntryDistribution($entryDistribution, $distributionProfile); } else { KalturaLog::log("Entry distribution [" . $entryDistribution->getId() . "] should not be updated automatically"); $entryDistribution->setDirtyStatus(EntryDistributionDirtyStatus::UPDATE_REQUIRED); $entryDistribution->save(); continue; } } // update } return true; }
/** * @param asset $asset */ public static function onAssetReadyOrDeleted(asset $asset) { if (!ContentDistributionPlugin::isAllowedPartner($asset->getPartnerId())) { return true; } $entry = $asset->getentry(); if (!$entry) { return true; } $entryDistributions = EntryDistributionPeer::retrieveByEntryId($asset->getEntryId()); foreach ($entryDistributions as $entryDistribution) { $distributionProfileId = $entryDistribution->getDistributionProfileId(); $distributionProfile = DistributionProfilePeer::retrieveByPK($distributionProfileId); if (!$distributionProfile) { continue; } $validateStatuses = array(EntryDistributionStatus::QUEUED, EntryDistributionStatus::PENDING, EntryDistributionStatus::READY); if (!in_array($entryDistribution->getStatus(), $validateStatuses)) { continue; } /* * we have special thumbnail definition for 'main menu' & 'thank you' entries * so we need to revalidate avn distribution profile because those thumbnails are not * defined in the distribution porofile so automatic revalidation doesn't work */ if ($distributionProfile instanceof AvnDistributionProfile) { $validationErrors = $distributionProfile->validateForSubmission($entryDistribution, DistributionAction::SUBMIT); $entryDistribution->setValidationErrorsArray($validationErrors); $entryDistribution->save(); } } return true; }