Пример #1
0
 protected static function createLiveReportExportDownloadUrl($partner_id, $file_name, $expiry, $applicationUrlTemplate)
 {
     // Extract simple download name
     $regex = "/^{$partner_id}_Export_[a-zA-Z0-9]+_(?<fileName>[\\w\\-]+.csv)\$/";
     if (!preg_match($regex, $file_name, $matches)) {
         KalturaLog::err("File name doesn't match expected format");
         return null;
     }
     $downloadName = $matches['fileName'];
     // Add dc to enable redirection
     $dc = kDataCenterMgr::getCurrentDc();
     $file_name = $dc['id'] . "_" . $file_name;
     $ksStr = "";
     $partner = PartnerPeer::retrieveByPK($partner_id);
     $secret = $partner->getSecret();
     $privilege = ks::PRIVILEGE_DOWNLOAD . ":" . $file_name;
     $ksStr = kSessionBase::generateSession($partner->getKSVersion(), $partner->getAdminSecret(), null, ks::TYPE_KS, $partner_id, $expiry, $privilege);
     if ($applicationUrlTemplate) {
         $url = str_replace("[ks]", $ksStr, $applicationUrlTemplate);
         $url = str_replace("[id]", $file_name, $url);
     } else {
         //url is built with DC url in order to be directed to the same DC of the saved file
         $url = kDataCenterMgr::getCurrentDcUrl() . "/api_v3/index.php/service/liveReports/action/serveReport/ks/{$ksStr}/id/{$file_name}/{$downloadName}";
     }
     return $url;
 }
Пример #2
0
 private static function createUrl($partner_id, $file_name)
 {
     $ksStr = "";
     $partner = PartnerPeer::retrieveByPK($partner_id);
     $secret = $partner->getSecret();
     $privilege = ks::PRIVILEGE_DOWNLOAD . ":" . $file_name;
     $maxExpiry = 86400;
     $expiry = $partner->getKsMaxExpiryInSeconds();
     if (!$expiry || $expiry > $maxExpiry) {
         $expiry = $maxExpiry;
     }
     $result = kSessionUtils::startKSession($partner_id, $secret, null, $ksStr, $expiry, false, "", $privilege);
     if ($result < 0) {
         throw new Exception("Failed to generate session for asset [" . $this->getId() . "] of type " . $this->getType());
     }
     //url is built with DC url in order to be directed to the same DC of the saved file
     $url = kDataCenterMgr::getCurrentDcUrl() . "/api_v3/index.php/service/report/action/serve/ks/{$ksStr}/id/{$file_name}/report.csv";
     return $url;
 }
 private static function createFileName($partner_id)
 {
     $args = func_get_args();
     $file_name = uniqid();
     $time_suffix = date("Y-m-D-H", (int) (time() / 43200) * 43200);
     // calculate for intervlas of half days (86400/2)
     $folderPath = "/content/reports/{$partner_id}";
     $fullPath = myContentStorage::getFSContentRootPath() . $folderPath;
     if (!file_exists($fullPath)) {
         kFile::fullMkfileDir($fullPath, 0777, true);
     }
     $fileName = "{$file_name}_{$time_suffix}";
     //url is built with DC url in order to be directed to the same DC of the saved file
     $url = kDataCenterMgr::getCurrentDcUrl() . "{$folderPath}/{$fileName}";
     $file_path = "{$fullPath}/{$fileName}";
     //		$path = "/content/reports/$partner_id/{$file_name}_{$time_suffix}";
     //		$file_path = myContentStorage::getFSContentRootPath() .  $path;
     //		$url = requestUtils::getHost() . $path;
     return array($file_path, $url);
 }