/**
  * Process stored event
  *
  * @return Boolean
  */
 public function process()
 {
     list($project_path, $file_id, $old_path) = $this->getParametersAsArray();
     $file_factory = new FRSFileFactory();
     $file = $file_factory->getFRSFileFromDb($file_id);
     if (!$file) {
         $this->error('File does not exist with ID ' . $file_id);
         return false;
     }
     $file_path = $file->getFilePath();
     $this->createNecessaryFolders($project_path, $file_path);
     if (!file_exists($project_path . $old_path)) {
         $this->error('Cannot find file to move: ' . $file_id . ' from: ' . $project_path . $old_path);
         return false;
     }
     if (file_exists($project_path . $file_path)) {
         $this->error('File already exists at location: ' . $file_id . ' location: ' . $project_path . $file_path);
         return false;
     }
     if (rename($project_path . $old_path, $project_path . $file_path)) {
         $this->done();
         return true;
     }
     $this->error('Unable to move file: ' . $file_id . ' from: ' . $project_path . $old_path . ' to ' . $project_path . $file_path);
     return false;
 }
示例#2
0
 /**
  * updateFileComment - Update the comment of a File in a release with the values given by
  *  group_id, package_id, release_id, file_id and comment.
  *
  * @param string    $sessionKey the session hash associated with the session opened by the person who calls the service
  * @param int       $group_id the ID of the group we want to add the file
  * @param int       $package_id the ID of the package we want to add the file
  * @param int       $release_id the ID of the release we want to add the file
  * @param int       $file_id the ID of the file we want to retrieve the content
  * @param string    $comment A comment/description of the uploaded file
  * @return boolean true if the file was updated, or a soap fault if:
  *      - group_id does not match with a valid project,
  *      - the package_id, release_id, file_id does not match
  *      - the user does not have permissions to delete this file
  *      - the system was not able to update the file.
  */
 function updateFileComment($sessionKey, $group_id, $package_id, $release_id, $file_id, $comment)
 {
     if (session_continue($sessionKey)) {
         try {
             $project_manager = ProjectManager::instance();
             $project_manager->getGroupByIdForSoap($group_id, 'updateFileComment');
         } catch (SoapFault $e) {
             return $e;
         }
         // retieve the package
         $pkg_fact = new FRSPackageFactory();
         $package =& $pkg_fact->getFRSPackageFromDb($package_id);
         if (!$package || $package->getGroupID() != $group_id) {
             return new SoapFault(invalid_package_fault, 'Invalid Package', 'updateFileComment');
         }
         // retrieve the release
         $release_fact = new FRSReleaseFactory();
         $release =& $release_fact->getFRSReleaseFromDb($release_id);
         if (!$release || $release->getPackageID() != $package_id) {
             return new SoapFault(invalid_release_fault, 'Invalid Release', 'updateFileComment');
         }
         // retrieve the file
         $file_factory = new FRSFileFactory();
         if (!$file_factory->userCanAdd($group_id)) {
             return new SoapFault(invalid_file_fault, 'User is not allowed to update file', 'updateFileComment');
         }
         $file = $file_factory->getFRSFileFromDb($file_id);
         if (!$file) {
             return new SoapFault(invalid_file_fault, 'Invalid File', 'updateFileComment');
         }
         $data_array = array('comment' => $comment, 'file_id' => $file_id);
         try {
             $file_factory->update($data_array);
         } catch (Exception $e) {
             return new SoapFault(invalid_file_fault, 'Unable to update: ' . $e->getMessage(), 'updateFileComment');
         }
     } else {
         return new SoapFault(invalid_session_fault, 'Invalid Session', 'updateFileComment');
     }
     return true;
 }
示例#3
0
文件: frs.php 项目: nterray/tuleap
 /**
  * getFileChunk - returns the content (encoded in base64) of FRSFiles that belongs to the release identified by file_id, part of release_id, package_id, in project group_id. 
  *
  * @param string $sessionKey the session hash associated with the session opened by the person who calls the service
  * @param int $group_id the ID of the group we want to retrieve the content of file
  * @param int $package_id the ID of the package we want to retrieve the content of file
  * @param int $release_id the ID of the release we want to retrieve the content of file
  * @param int $file_id the ID of the file we want to retrieve the content
  * @return the content of the file (encoded in base64) $file_id that belongs to the project identified by $group_id, in the package $package_id, in the release $release_id 
  *         or a soap fault if 
  *              - group_id does not match with a valid project or 
  *              - package_id does not match with group_id, or 
  *              - release_id does not match with package_id, or 
  *              - file_id does not match with release_id, or
  *              - the file is not present on the server
  */
 function getFileChunk($sessionKey, $group_id, $package_id, $release_id, $file_id, $offset, $size)
 {
     if (session_continue($sessionKey)) {
         try {
             $pm = ProjectManager::instance();
             $pm->getGroupByIdForSoap($group_id, 'getFileChunk');
         } catch (SoapFault $e) {
             return $e;
         }
         // retieve the package
         $pkg_fact = new FRSPackageFactory();
         $package =& $pkg_fact->getFRSPackageFromDb($package_id);
         if (!$package || $package->isDeleted() || $package->getGroupID() != $group_id) {
             return new SoapFault(invalid_package_fault, 'Invalid Package', 'getFileChunk');
         }
         // check access rights to this package
         if (!$package->userCanRead() || !$package->isActive()) {
             return new SoapFault(invalid_package_fault, 'Permission to this Package denied', 'getFileChunk');
         }
         // retrieve the release
         $release_fact = new FRSReleaseFactory();
         $release =& $release_fact->getFRSReleaseFromDb($release_id);
         if (!$release || $release->isDeleted() || $release->getPackageID() != $package_id) {
             return new SoapFault(invalid_release_fault, 'Invalid Release', 'getFileChunk');
         }
         // check access rights to this release
         if (!$release->userCanRead() || !$release->isActive()) {
             return new SoapFault(invalid_release_fault, 'Permission to this Release denied', 'getFileChunk');
         }
         $file_fact = new FRSFileFactory();
         $file =& $file_fact->getFRSFileFromDb($file_id);
         if (!$file || !$file->isActive() || $file->getReleaseID() != $release_id) {
             return new SoapFault(invalid_file_fault, 'Invalid File', 'getFileChunk');
         }
         if (!$file->fileExists()) {
             return new SoapFault(invalid_file_fault, 'File doesn\'t exist on the server', 'getFileChunk');
         }
         // Log the download action
         $file->logDownload();
         $contents = $file->getContent($offset, $size);
         return base64_encode($contents);
     } else {
         return new SoapFault(invalid_session_fault, 'getFile', 'Invalid Session', 'getFileChunk');
     }
 }
示例#4
0
require_once 'common/frs/FRSFileFactory.class.php';
require_once 'www/file/file_utils.php';
list(, $group_id, $file_id) = explode('/', $_SERVER['PATH_INFO']);
// Must have a group_id and file_id otherwise
// we cannot do much
$vGroupId = new Valid_groupId();
$vGroupId->required();
$vFileId = new Valid_UInt();
$vFileId->required();
if (!$vFileId->validate($file_id) || !$vGroupId->validate($group_id)) {
    exit_missing_param();
}
// Now make an innerjoin on the 4 tables to be sure
// that the file_id we have belongs to the given group_id
$frsff = new FRSFileFactory();
$file =& $frsff->getFRSFileFromDb($file_id, $group_id);
if (!$file || $file->isError()) {
    exit_error($Language->getText('file_download', 'incorrect_release_id'), $Language->getText('file_download', 'report_error', $GLOBALS['sys_name']));
}
// Check permissions for downloading the file, and check that the file has the active status
if (!$file->userCanDownload() || !$file->isActive()) {
    exit_error($Language->getText('file_download', 'access_denied'), $Language->getText('file_download', 'access_not_authorized', session_make_url("/project/memberlist.php?group_id={$group_id}")));
}
if (!$file->fileExists()) {
    exit_error($Language->getText('global', 'error'), $Language->getText('file_download', 'file_not_available'));
}
// Log the download in the Log system
$file->logDownload(user_getid());
// Start download
if (!$file->download()) {
    exit_error($Language->getText('global', 'error'), $Language->getText('file_download', 'file_not_available'));
示例#5
0
 private function getProjectIdForSystemReference($keyword, $value)
 {
     $ref_gid = null;
     $nature = $this->getSystemReferenceNatureByKeyword($keyword);
     switch ($nature) {
         case self::REFERENCE_NATURE_RELEASE:
             $release_factory = new FRSReleaseFactory();
             $release = $release_factory->getFRSReleaseFromDb($value);
             if ($release) {
                 $ref_gid = $release->getProject()->getID();
             }
             break;
         case self::REFERENCE_NATURE_FILE:
             $file_factory = new FRSFileFactory();
             $file = $file_factory->getFRSFileFromDb($value);
             if ($file) {
                 $ref_gid = $file->getGroup()->getID();
             }
             break;
         case self::REFERENCE_NATURE_FORUM:
             $forum_dao = new ForumDao();
             $forum_group_id_row = $forum_dao->searchByGroupForumId($value)->getRow();
             if ($forum_group_id_row) {
                 $ref_gid = $forum_group_id_row['group_id'];
             }
             break;
         case self::REFERENCE_NATURE_FORUMMESSAGE:
             $forum_dao = new ForumDao();
             $message_group_id_row = $forum_dao->getMessageProjectId($value);
             if ($message_group_id_row) {
                 $ref_gid = $message_group_id_row['group_id'];
             }
             break;
         case self::REFERENCE_NATURE_NEWS:
             $news_dao = new NewsBytesDao();
             $news_group_id_row = $news_dao->searchByForumId($value)->getRow();
             if ($news_group_id_row) {
                 $ref_gid = $news_group_id_row['group_id'];
             }
             break;
     }
     return $ref_gid;
 }
function frs_file_restore_process($request, $group_id)
{
    $fileId = $request->getValidated('id', 'uint', 0);
    if ($fileId > 0) {
        $fileFactory = new FRSFileFactory();
        $file = $fileFactory->getFRSFileFromDb($fileId);
        $file_name = $file->getFileName();
        $basename = basename($file_name);
        $release_id = $file->getReleaseID();
        if (!$fileFactory->isSameFileMarkedToBeRestored($basename, $release_id, $group_id)) {
            if (!$fileFactory->isFileNameExist($file_name, $group_id)) {
                if ($fileFactory->markFileToBeRestored($file)) {
                    $GLOBALS['Response']->addFeedback('info', 'File marked to be restored');
                } else {
                    $GLOBALS['Response']->addFeedback('error', 'File not restored');
                }
            } else {
                $GLOBALS['Response']->addFeedback('error', 'There is already a file with this filename having an active status');
            }
        } else {
            $GLOBALS['Response']->addFeedback('error', 'A file with a same name is marked to be restored');
        }
    } else {
        $GLOBALS['Response']->addFeedback('error', 'Bad file id');
    }
    $GLOBALS['Response']->redirect('?group_id=' . $group_id);
}
示例#7
0
        $font_size_normal = 'medium';
    } else {
        if (browser_is_mac()) {
            //mac users need bigger fonts
            $font_size = 'medium';
            $font_size_normal = 'medium';
        } else {
            //linux and other users
            $font_size = 'small';
            $font_size_normal = 'medium';
        }
    }
}
if (!$request->existAndNonEmpty('filename')) {
    # Get it from DB
    $res =& $frsff->getFRSFileFromDb($file_id);
    if (count($res) > 0) {
        $filename = $res->getFileName();
    }
} else {
    $vFileName = new Valid_String('filename');
    if ($request->valid($vFileName)) {
        $filename = $request->get('filename');
    } else {
        exit_missing_param();
    }
}
if (!$GLOBALS['sys_frs_license_mandatory']) {
    // Display license popup?
    // This is useful when using a 'file #123' reference, that points to this script
    $res =& $frspf->getFRSPackageByFileIdFromDb($file_id);
 /**
  * Returns new FRSFile from its Id
  *
  * @param Integer $fileId
  *
  * @return FRSFile
  */
 function getFRSFileFromId($fileId)
 {
     $frsff = new FRSFileFactory();
     return $frsff->getFRSFileFromDb($fileId, $this->getProject()->getGroupId());
 }