Ejemplo n.º 1
0
 public static function getContentsByFileSync(FileSync $file_sync, $local = true, $fetch_from_remote_if_no_local = true, $strict = true)
 {
     if ($local) {
         $full_path = $file_sync->getFullPath();
         $real_path = realpath($full_path);
         if (file_exists($real_path)) {
             $startTime = microtime(true);
             $contents = file_get_contents($real_path);
             KalturaLog::info("file was found locally at [{$real_path}] fgc took [" . (microtime(true) - $startTime) . "]");
             return $contents;
         } else {
             KalturaLog::info("file was not found locally [{$full_path}]");
             throw new kFileSyncException("Cannot find file on local disk [{$full_path}] for file sync [" . $file_sync->getId() . "]", kFileSyncException::FILE_DOES_NOT_EXIST_ON_DISK);
         }
     }
     if ($fetch_from_remote_if_no_local) {
         if (!in_array($file_sync->getDc(), kDataCenterMgr::getDcIds())) {
             if ($strict) {
                 throw new Exception("File sync is remote - cannot get contents, id = [" . $file_sync->getId() . "]");
             } else {
                 return null;
             }
         }
         // if $fetch_from_remote_if_no_local is false - $file_sync shoule be null , this if is in fact redundant
         // TODO - curl to the remote
         $content = kDataCenterMgr::retrieveFileFromRemoteDataCenter($file_sync);
         return $content;
     }
 }
Ejemplo n.º 2
0
 public static function getContentsByFileSync(FileSync $file_sync, $local = true, $fetch_from_remote_if_no_local = true, $strict = true)
 {
     if ($local) {
         $real_path = realpath($file_sync->getFullPath());
         if (file_exists($real_path)) {
             KalturaLog::log(__METHOD__ . " - file was found locally at [{$real_path}]");
             return file_get_contents($real_path);
         } else {
             KalturaLog::log(__METHOD__ . " - file was not found locally [{$real_path}]");
             if ($strict) {
                 throw new Exception("Cannot find file on local disk [{$real_path}] for file sync [" . $file_sync->getId() . "]");
             } else {
                 return null;
             }
         }
     }
     if ($fetch_from_remote_if_no_local) {
         // if $fetch_from_remote_if_no_local is false - $file_sync shoule be null , this if is in fact redundant
         // TODO - curl to the remote
         $content = kDataCenterMgr::retrieveFileFromRemoteDataCenter($file_sync);
         return $content;
     }
 }
Ejemplo n.º 3
0
 /**
  * @param FileSync $fileSync
  */
 protected static function purgeFileSync(FileSync $fileSync)
 {
     KalturaLog::info("Purging file sync [" . $fileSync->getId() . "]");
     $fullPath = $fileSync->getFullPath();
     if ($fullPath && file_exists($fullPath)) {
         KalturaLog::debug("Purging file sync [" . $fileSync->getId() . "] path [{$fullPath}]");
         if (is_dir($fullPath)) {
             $command = "rm -fr {$fullPath}";
             KalturaLog::debug("Executing: {$command}");
             if (self::$dryRun) {
                 self::incrementSummary('dirs');
             } else {
                 $returnedValue = null;
                 passthru($command, $returnedValue);
                 if ($returnedValue === 0) {
                     self::incrementSummary('dirs');
                 } else {
                     KalturaLog::err("Failed purging file sync [" . $fileSync->getId() . "] directory path [{$fullPath}]");
                     return;
                 }
             }
         } else {
             $fileSize = filesize($fullPath);
             if (self::$dryRun || unlink($fullPath)) {
                 self::incrementSummary('bytes', $fileSize);
                 self::incrementSummary('files');
             } else {
                 KalturaLog::err("Failed purging file sync [" . $fileSync->getId() . "] file path [{$fullPath}]");
                 return;
             }
         }
     } else {
         KalturaLog::debug("File sync [" . $fileSync->getId() . "] path [{$fullPath}] does not exist");
     }
     $fileSync->setStatus(FileSync::FILE_SYNC_STATUS_PURGED);
     $fileSync->save();
 }
Ejemplo n.º 4
0
 /**
  * @param FileSync $fileSync
  * @param bool $local
  * @param string $fileName
  * @param bool $forceProxy
  */
 protected function serveThumbToFile(FileSync $fileSync, $local, $fileName, $forceProxy = false)
 {
     header("Content-Disposition: attachment; filename=\"{$fileName}\"");
     if ($local) {
         $filePath = $fileSync->getFullPath();
         $mimeType = kFile::mimeType($filePath);
         kFile::dumpFile($filePath, $mimeType);
     } else {
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         KalturaLog::info("Redirecting to [{$remoteUrl}]");
         if ($forceProxy) {
             kFile::dumpUrl($remoteUrl);
         } else {
             // or redirect if no proxy
             header("Location: {$remoteUrl}");
         }
     }
 }