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;
     }
 }