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);
 }
 protected static function getAssetUrl(asset $asset)
 {
     $urlManager = DeliveryProfilePeer::getDeliveryProfile($asset->getEntryId());
     if ($asset instanceof flavorAsset) {
         $urlManager->initDeliveryDynamicAttributes(null, $asset);
     }
     $url = $urlManager->getFullAssetUrl($asset);
     $url = preg_replace('/^https?:\\/\\//', '', $url);
     $url = 'http://' . $url . '/ext/' . $asset->getId() . '.' . $asset->getFileExt();
     return $url;
 }
 protected static function getAssetUrl(asset $asset)
 {
     $cdnHost = myPartnerUtils::getCdnHost($asset->getPartnerId());
     $urlManager = kUrlManager::getUrlManagerByCdn($cdnHost, $asset->getEntryId());
     $urlManager->setDomain($cdnHost);
     $url = $urlManager->getAssetUrl($asset);
     $url = $cdnHost . $url;
     $url = preg_replace('/^https?:\\/\\//', '', $url);
     $url = 'http://' . $url . '/ext/' . $asset->getId() . '.' . $asset->getFileExt();
     return $url;
 }
 protected static function addImportJob($dc, $entryUrl, asset $asset)
 {
     KalturaLog::debug("Importing asset [" . $asset->getId() . "] from dc [{$dc}] with URL [{$entryUrl}]");
     $entryUrl = str_replace('//', '/', $entryUrl);
     $entryUrl = preg_replace('/^((https?)|(ftp)|(scp)|(sftp)):\\//', '$1://', $entryUrl);
     $jobData = new kImportJobData();
     $jobData->setCacheOnly(true);
     $jobData->setSrcFileUrl($entryUrl);
     $jobData->setFlavorAssetId($asset->getId());
     $batchJob = new BatchJob();
     $batchJob->setDc($dc);
     $batchJob->setEntryId($asset->getEntryId());
     $batchJob->setPartnerId($asset->getPartnerId());
     return kJobsManager::addJob($batchJob, $jobData, BatchJobType::IMPORT);
 }
 protected static function addImportJob($dc, $entryUrl, asset $asset)
 {
     $entryUrl = str_replace('//', '/', $entryUrl);
     $entryUrl = preg_replace('/^((https?)|(ftp)|(scp)|(sftp)):\\//', '$1://', $entryUrl);
     $jobData = new kImportJobData();
     $jobData->setCacheOnly(true);
     $jobData->setSrcFileUrl($entryUrl);
     $jobData->setFlavorAssetId($asset->getId());
     $batchJob = new BatchJob();
     $batchJob->setDc($dc);
     $batchJob->setEntryId($asset->getEntryId());
     $batchJob->setPartnerId($asset->getPartnerId());
     $batchJob->setObjectId($asset->getId());
     $batchJob->setObjectType(BatchJobObjectType::ASSET);
     return kJobsManager::addJob($batchJob, $jobData, BatchJobType::IMPORT);
 }
 /**
  * @param asset $asset
  * @param string $fileName
  * @param bool $forceProxy
  * @param int $version
  * @throws KalturaErrors::FILE_DOESNT_EXIST
  */
 protected function serveAsset(asset $asset, $fileName, $forceProxy = false, $version = null)
 {
     $syncKey = $asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $version);
     $fileSync = null;
     $serveRemote = false;
     $partner = PartnerPeer::retrieveByPK($asset->getPartnerId());
     switch ($partner->getStorageServePriority()) {
         case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_ONLY:
             $serveRemote = true;
             $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
             if (!$fileSync || $fileSync->getStatus() != FileSync::FILE_SYNC_STATUS_READY) {
                 throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
             }
             break;
         case StorageProfile::STORAGE_SERVE_PRIORITY_EXTERNAL_FIRST:
             $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
             if ($fileSync && $fileSync->getStatus() == FileSync::FILE_SYNC_STATUS_READY) {
                 $serveRemote = true;
             }
             break;
         case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST:
             $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
             if ($fileSync) {
                 break;
             }
             $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($syncKey);
             if (!$fileSync || $fileSync->getStatus() != FileSync::FILE_SYNC_STATUS_READY) {
                 throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
             }
             $serveRemote = true;
             break;
         case StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY:
             $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($syncKey);
             if (!$fileSync) {
                 throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
             }
             break;
     }
     if ($serveRemote && $fileSync) {
         header("Location: " . $fileSync->getExternalUrl($asset->getEntryId()));
         die;
     }
     return $this->serveFile($asset, asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET, $fileName, $asset->getEntryId(), $forceProxy);
 }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
 private function getObject($objectId, $isAsset)
 {
     if ($isAsset) {
         $this->flavorAsset = assetPeer::retrieveById($objectId);
         if (is_null($this->flavorAsset)) {
             KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
         }
         $this->entry = entryPeer::retrieveByPK($this->flavorAsset->getEntryId());
         if (is_null($this->entry)) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
         return $this->flavorAsset;
     } else {
         $this->entry = entryPeer::retrieveByPK($objectId);
         if (is_null($this->entry)) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
         return $this->entry;
     }
 }
 /**
  * @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;
 }
Ejemplo n.º 10
0
 private static function getExternalStorageUrl(Partner $partner, asset $asset, FileSyncKey $key, $servePlayManifest = false, $playManifestClientTag = null, $storageId = null)
 {
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         return null;
     }
     if (is_null($storageId) && $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
         if (kFileSyncUtils::getReadyInternalFileSyncForKey($key)) {
             // check if having file sync on kaltura dcs
             return null;
         }
     }
     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageId);
     if (!$fileSync) {
         return null;
     }
     $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc());
     if (!$storage) {
         return null;
     }
     if ($servePlayManifest) {
         // in case of an https request, if a delivery profile which supports https doesn't exist use an http cdn api host
         if (infraRequestUtils::getProtocol() == infraRequestUtils::PROTOCOL_HTTPS && DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId(), PlaybackProtocol::HTTP, "https"))) {
             $url = requestUtils::getApiCdnHost();
         } else {
             $url = infraRequestUtils::PROTOCOL_HTTP . "://" . kConf::get("cdn_api_host");
         }
         $url .= $asset->getPlayManifestUrl($playManifestClientTag, $storageId);
     } else {
         $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $asset->getEntryId()));
         if ($urlManager) {
             $dynamicAttrs = new DeliveryProfileDynamicAttributes();
             $dynamicAttrs->setFileExtension($asset->getFileExt());
             $dynamicAttrs->setStorageId($fileSync->getDc());
             $urlManager->setDynamicAttributes($dynamicAttrs);
             $url = ltrim($urlManager->getFileSyncUrl($fileSync), '/');
             if (strpos($url, "://") === false) {
                 $url = rtrim($urlManager->getUrl(), "/") . "/" . $url;
             }
         } else {
             KalturaLog::debug("Couldn't determine delivery profile for storage id");
             $url = null;
         }
     }
     return $url;
 }
Ejemplo n.º 11
0
 private static function getFileSyncForKey(FileSyncKey $srcSyncKey, flavorParamsOutput $flavor, asset $flavorAsset, Partner $partner, &$addImportJob)
 {
     $addImportJob = false;
     $isLocal = $flavor->getSourceRemoteStorageProfileId() == StorageProfile::STORAGE_KALTURA_DC;
     if ($isLocal) {
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($srcSyncKey, true, false);
     } else {
         $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($srcSyncKey, $flavor->getSourceRemoteStorageProfileId());
     }
     if (!$fileSync) {
         kBatchManager::updateEntry($flavorAsset->getEntryId(), entryStatus::ERROR_CONVERTING);
         if ($isLocal) {
             $description = "Source file sync not found: {$srcSyncKey}";
         } else {
             $description = "Remote source file sync not found {$srcSyncKey}, storage profile id [" . $flavor->getSourceRemoteStorageProfileId() . "]";
         }
         $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
         $flavorAsset->setDescription($description);
         $flavorAsset->save();
         KalturaLog::err($description);
         return null;
     }
     if ($isLocal && !$local) {
         if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL && $partner && $partner->getImportRemoteSourceForConvert()) {
             $addImportJob = true;
         } else {
             throw new kCoreException("Source file not found for flavor conversion [{$flavorAsset->getId}()]", kCoreException::SOURCE_FILE_NOT_FOUND);
         }
     }
     return $fileSync;
 }
 public function getAssetUrl(asset $asset)
 {
     $cdnHost = myPartnerUtils::getCdnHost($asset->getPartnerId());
     $urlManager = kUrlManager::getUrlManagerByCdn($cdnHost, $asset->getEntryId());
     $urlManager->setDomain($cdnHost);
     $url = $urlManager->getAssetUrl($asset);
     $url = $cdnHost . $url;
     $url = preg_replace('/^https?:\\/\\//', '', $url);
     return 'http://' . $url;
 }
Ejemplo n.º 13
0
 private static function conditionalAssetLocalFileSyncsDelete(FileSync $fileSync, asset $asset)
 {
     $unClosedStatuses = array(asset::ASSET_STATUS_QUEUED, asset::ASSET_STATUS_CONVERTING, asset::ASSET_STATUS_WAIT_FOR_CONVERT, asset::ASSET_STATUS_EXPORTING);
     $unClosedAssets = assetPeer::retrieveReadyByEntryId($asset->getEntryId(), null, $unClosedStatuses);
     if (count($unClosedAssets)) {
         $asset->setFileSyncVersionsToDelete(array($fileSync->getVersion()));
         $asset->save();
         return;
     }
     $assetsToDelete = assetPeer::retrieveReadyByEntryId($asset->getEntryId());
     self::deleteAssetLocalFileSyncsByAssetArray($assetsToDelete);
     self::deleteAssetLocalFileSyncs($fileSync->getVersion(), $asset);
 }
 private static function getExternalStorageUrl(Partner $partner, asset $asset, FileSyncKey $key, $storageId = null)
 {
     if (!$partner->getStorageServePriority() || $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
         return null;
     }
     if (is_null($storageId) && $partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
         if (kFileSyncUtils::getReadyInternalFileSyncForKey($key)) {
             // check if having file sync on kaltura dcs
             return null;
         }
     }
     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storageId);
     if (!$fileSync) {
         return null;
     }
     $storage = StorageProfilePeer::retrieveByPK($fileSync->getDc());
     if (!$storage) {
         return null;
     }
     $urlManager = kUrlManager::getUrlManagerByStorageProfile($fileSync->getDc(), $asset->getEntryId());
     $urlManager->setFileExtension($asset->getFileExt());
     $url = $storage->getDeliveryHttpBaseUrl() . '/' . $urlManager->getFileSyncUrl($fileSync);
     return $url;
 }
Ejemplo n.º 15
0
 /**
  * @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;
 }