protected function getTempFilePath($remotePath)
 {
     // create a temp file path
     $origRemotePath = $remotePath;
     $rootPath = $this->taskConfig->params->localTempPath;
     $res = self::createDir($rootPath);
     if (!$res) {
         KalturaLog::err("Cannot continue import without temp directory");
         die;
     }
     $uniqid = uniqid('import_');
     $destFile = realpath($rootPath) . "/{$uniqid}";
     // in case the url has added arguments, remove them (and reveal the real URL path)
     // in order to find the file extension
     $urlPathEndIndex = strpos($remotePath, "?");
     if ($urlPathEndIndex !== false) {
         $remotePath = substr($remotePath, 0, $urlPathEndIndex);
     }
     $ext = pathinfo($remotePath, PATHINFO_EXTENSION);
     $ext = strtolower($ext);
     if (!in_array($ext, kWAMS::getSupportedFormats())) {
         $remoteExt = kWAMS::getFileExtFromURL($origRemotePath);
         if (!empty($remoteExt)) {
             $ext = $remoteExt;
         }
     }
     if (strlen($ext)) {
         $destFile .= ".{$ext}";
     }
     return $destFile;
 }
 public static function moveFromFile($temp_file_path, FileSyncKey $target_key, $strict = true, $copyOnly = false, $cacheOnly = false)
 {
     KalturaLog::log(__METHOD__ . " - 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) {
         KalturaLog::log(__METHOD__ . " - file already exists");
         if ($strict) {
             throw new Exception("key [" . $target_key . "] already exists");
         }
     }
     $targetFullPath = self::getLocalFilePathForKey($target_key);
     if (!$targetFullPath) {
         $targetFullPath = kPathManager::getFilePath($target_key);
         KalturaLog::log(__METHOD__ . " - Generated new path [{$targetFullPath}]");
     }
     if (!file_exists(dirname($targetFullPath))) {
         KalturaLog::log(__METHOD__ . " - creating directory for file");
         kFile::fullMkdir($targetFullPath);
     }
     if (file_exists($temp_file_path)) {
         KalturaLog::log(__METHOD__ . " - {$temp_file_path} file exists");
     } else {
         KalturaLog::log(__METHOD__ . " - {$temp_file_path} file doesnt exist");
     }
     $wamsSupportedFormats = kWAMS::getSupportedFormats();
     $fileExtension = pathinfo($temp_file_path, PATHINFO_EXTENSION);
     if (in_array($fileExtension, $wamsSupportedFormats)) {
         $assetName = self::getWamsAssetNameForKey($target_key);
         if (empty($assetName)) {
             $assetName = pathinfo($temp_file_path, PATHINFO_BASENAME);
         }
         $wamsAssetId = kWAMS::getInstance($target_key->getPartnerId())->publishFileToWAMS($assetName, $temp_file_path);
         if (!empty($wamsAssetId)) {
             if (self::checkDeletedEntry($target_key, $wamsAssetId, $temp_file_path)) {
                 return;
             }
             self::addFromWAMS($wamsAssetId, $target_key, $strict, $cacheOnly);
             if (!self::isAttachment($target_key)) {
                 $wamsTempFilePath = kWAMS::getTempFilePathForAssetId($wamsAssetId, pathinfo($targetFullPath, PATHINFO_EXTENSION));
                 rename($temp_file_path, $wamsTempFilePath);
             } else {
                 unlink($temp_file_path);
             }
             return;
         } else {
             KalturaLog::err("File [{$temp_file_path}] not published to WAMS");
         }
     }
     if ($copyOnly) {
         $success = copy($temp_file_path, $targetFullPath);
     } else {
         $success = kFile::moveFile($temp_file_path, $targetFullPath);
     }
     if ($success) {
         if (!$existsFileSync) {
             self::createSyncFileForKey($target_key, $strict, false, $cacheOnly);
         }
     } else {
         KalturaLog::log(__METHOD__ . " - could not move file from [{$temp_file_path}] to [{$targetFullPath}]");
         throw new Exception("Could not move file from [{$temp_file_path}] to [{$targetFullPath}]");
     }
 }