Пример #1
0
 /**
  * will return a pair of file_root and file_path
  * This is the only function that should be extended for building a different path
  *
  * @param ISyncableFile $object
  * @param int $subType
  * @param $version
  */
 public function generateFilePathArr(ISyncableFile $object, $subType, $version = null)
 {
     //		$traces = debug_backtrace(false);
     //		foreach($traces as $i => $trace)
     //		{
     //			$file = $trace['file'];
     //			$line = $trace['line'];
     //			$class = $trace['class'];
     //			$function = $trace['function'];
     //			KalturaLog::debug("#$i Called from function [$class::$function] file[$file] line[$line]");
     //		}
     list($root, $path) = $object->generateFilePathArr($subType, $version);
     $root = str_replace('//', '/', $root);
     $path = str_replace('//', '/', $path);
     if (!kConf::hasParam('volumes')) {
         KalturaLog::debug("Path [{$root}{$path}]");
         return array($root, $path);
     }
     if (isset(self::$sessionCache[$path])) {
         return array($root, self::$sessionCache[$path]);
     }
     $volumes = kConf::get('volumes');
     $volume = $volumes[rand(0, count($volumes) - 1)];
     $newPath = str_replace('/content/', "/content/{$volume}/", $path);
     self::$sessionCache[$path] = $newPath;
     $path = $newPath;
     KalturaLog::debug("Path [{$root}{$path}]");
     return array($root, $path);
 }
Пример #2
0
 /**
  * will return a pair of file_root and file_path
  * This is the only function that should be extended for building a different path
  *
  * @param ISyncableFile $object
  * @param int $subType
  * @param $version
  */
 public function generateFilePathArr(ISyncableFile $object, $subType, $version = null)
 {
     $dateDir = date('Ymd');
     $partnerDir = floor($object->getPartnerId() / 1000);
     $path = "{$dateDir}/{$partnerDir}/" . $object->generateFileName($subType, $version);
     $root = '/';
     return array($root, $path);
 }
Пример #3
0
 /**
  * will return a pair of file_root and file_path
  * This is the only function that should be extended for building a different path
  *
  * @param ISyncableFile $object
  * @param int $subType
  * @param $version
  */
 public function generateFilePathArr(ISyncableFile $object, $subType, $version = null, $storageProfileId = null)
 {
     $storageProfile = kPathManager::getStorageProfile($storageProfileId);
     $path_format = $storageProfile->getPathFormat();
     if (is_null($path_format)) {
         $path_format = '{year}{month}{day}/{partnerDir}/{fileName}';
     }
     $fileName = $object->generateFileName($subType, $version);
     $partnerDir = floor($object->getPartnerId() / 1000);
     $path = str_replace('{fileName}', $fileName, $path_format);
     $path = str_replace('{partnerDir}', $partnerDir, $path);
     $path = str_replace('{year}', date("Y"), $path);
     $path = str_replace('{month}', date("m"), $path);
     $path = str_replace('{day}', date("d"), $path);
     $root = '/';
     return array($root, $path);
 }
 /**
  * @param ISyncableFile $syncable
  * @param int $fileSubType
  * @param string $fileName
  * @param bool $forceProxy
  * @throws KalturaErrors::FILE_DOESNT_EXIST
  */
 protected function serveFile(ISyncableFile $syncable, $fileSubType, $fileName, $entryId = null, $forceProxy = false)
 {
     /* @var $fileSync FileSync */
     $syncKey = $syncable->getSyncKey($fileSubType);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     }
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     header("Content-Disposition: attachment; filename=\"{$fileName}\"");
     if ($local) {
         $filePath = $fileSync->getFullPath();
         $wamsAssetId = $fileSync->getWamsAssetId();
         if (empty($wamsAssetId)) {
             $mimeType = kFile::mimeType($filePath);
             kFile::dumpFile($filePath, $mimeType);
         } else {
             kWAMS::getInstance($fileSync->getPartnerId())->dumpFile($wamsAssetId, pathinfo($filePath, PATHINFO_EXTENSION));
         }
     } else {
         if (in_array($fileSync->getDc(), kDataCenterMgr::getDcIds())) {
             $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
             KalturaLog::info("Redirecting to [{$remoteUrl}]");
             if ($forceProxy) {
                 kFile::dumpApiRequest($remoteUrl);
             } else {
                 //TODO find or build function which redurects the API request with all its parameters without using curl.
                 // or redirect if no proxy
                 header("Location: {$remoteUrl}");
                 die;
             }
         } else {
             $remoteUrl = $fileSync->getExternalUrl($entryId);
             header("Location: {$remoteUrl}");
             die;
         }
     }
 }
Пример #5
0
 /**
  * @param ISyncableFile $syncable
  * @param int $fileSubType
  * @param string $fileName
  * @param bool $forceProxy
  * @throws KalturaErrors::FILE_DOESNT_EXIST
  */
 protected function serveFile(ISyncableFile $syncable, $fileSubType, $fileName, $entryId = null, $forceProxy = false)
 {
     /* @var $fileSync FileSync */
     $syncKey = $syncable->getSyncKey($fileSubType);
     if (!kFileSyncUtils::fileSync_exists($syncKey)) {
         throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST);
     }
     list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
     if ($local) {
         $filePath = $fileSync->getFullPath();
         $mimeType = kFile::mimeType($filePath);
         return $this->dumpFile($filePath, $mimeType);
     } else {
         if (in_array($fileSync->getDc(), kDataCenterMgr::getDcIds())) {
             $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
             KalturaLog::info("Redirecting to [{$remoteUrl}]");
             if ($forceProxy) {
                 kFileUtils::dumpApiRequest($remoteUrl);
             } else {
                 //TODO find or build function which redurects the API request with all its parameters without using curl.
                 // or redirect if no proxy
                 header("Location: {$remoteUrl}");
                 die;
             }
         } else {
             $remoteUrl = $fileSync->getExternalUrl($entryId);
             header("Location: {$remoteUrl}");
             die;
         }
     }
 }