public static function moveFromFile($temp_file_path, FileSyncKey $target_key, $strict = true, $copyOnly = false, $cacheOnly = false) { KalturaLog::debug("move file: [{$temp_file_path}] to key [{$target_key}], "); $c = FileSyncPeer::getCriteriaForFileSyncKey($target_key); if ($cacheOnly) { $c->add(FileSyncPeer::FILE_TYPE, FileSync::FILE_SYNC_FILE_TYPE_CACHE); } else { $c->add(FileSyncPeer::FILE_TYPE, array(FileSync::FILE_SYNC_FILE_TYPE_FILE, FileSync::FILE_SYNC_FILE_TYPE_LINK), Criteria::IN); } $existsFileSync = FileSyncPeer::doSelectOne($c); if ($existsFileSync) { if ($strict) { throw new Exception("key [" . $target_key . "] already exists"); } else { KalturaLog::err("file already exists"); } } list($rootPath, $filePath) = self::getLocalFilePathArrForKey($target_key); $targetFullPath = $rootPath . $filePath; if (!$targetFullPath) { $targetFullPath = kPathManager::getFilePath($target_key); KalturaLog::info("Generated new path [{$targetFullPath}]"); } $targetFullPath = str_replace(array('/', '\\'), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $targetFullPath); if (!file_exists(dirname($targetFullPath))) { self::fullMkdir($targetFullPath); } if (file_exists($temp_file_path)) { KalturaLog::info("{$temp_file_path} file exists"); } else { KalturaLog::info("{$temp_file_path} file doesnt exist"); } if (file_exists($targetFullPath)) { $time = time(); $targetFullPath .= $time; $filePath .= $time; } if ($copyOnly) { $success = copy($temp_file_path, $targetFullPath); } else { $success = kFile::moveFile($temp_file_path, $targetFullPath); } if ($success) { self::setPermissions($targetFullPath); if (!$existsFileSync) { self::createSyncFileForKey($rootPath, $filePath, $target_key, $strict, false, $cacheOnly); } } else { KalturaLog::err("could not move file from [{$temp_file_path}] to [{$targetFullPath}]"); throw new Exception("Could not move file from [{$temp_file_path}] to [{$targetFullPath}]"); } }
/** * * @param FileSyncKey $key * @return string */ public static function getLocalFilePathForKey(FileSyncKey $key, $strict = false) { KalturaLog::log(__METHOD__ . " - key [{$key}], strict [{$strict}]"); $file_sync = self::getLocalFileSyncForKey($key, $strict); if ($file_sync) { $parent_file_sync = self::resolve($file_sync); $path = $parent_file_sync->getFileRoot() . $parent_file_sync->getFilePath(); KalturaLog::log(__METHOD__ . " - path [{$path}]"); return $path; } // TODO - should return null if doesn't exists return kPathManager::getFilePath($key); }