Exemple #1
0
 function testGetfilePath()
 {
     $file = new FRSFile();
     $filepath = 'path';
     $file->setFilePath($filepath);
     $filename = 'name';
     $file->setFileName($filename);
     $this->assertequal($filepath, $file->getFilePath());
     $file->setFilePath(null);
     $this->assertequal($filename, $file->getFilePath());
 }
Exemple #2
0
 /**
  * addUploadedFile - add a file in the file release manager, in the release $release_id, in package $package_id of the project $group_id with given values
  *
  * @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 string $filename the name of the file we want to add (only file name, not directory)
  * @param int $type_id the ID of the type of the file
  * @param int $processor_id the ID of the processor of the file
  * @param string $reference_md5 the md5sum of the file calculated in client side
  * @param string $comment A comment/description of the uploaded file
  * @return int the ID of the new created file, 
  *              or a soap fault if :
  *              - group_id does not match with a valid project, 
  *              - package_id does not match with a valid package,
  *              - package_id does not belong to the project group_id,
  *              - release_id does not match with a valid release,
  *              - release_id does not belong to the project group_id,
  *              - the user does not have the permissions to create a file
  *              - the md5 comparison failed
  *              - the file creation failed.
  */
 function addUploadedFile($sessionKey, $group_id, $package_id, $release_id, $filename, $type_id, $processor_id, $reference_md5, $comment)
 {
     if (session_continue($sessionKey)) {
         try {
             $pm = ProjectManager::instance();
             $pm->getGroupByIdForSoap($group_id, 'addUploadedFile');
         } 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', 'addUploadedFile');
         }
         // 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', 'addUploadedFile');
         }
         $file_fact = new FRSFileFactory();
         if ($file_fact->userCanAdd($group_id)) {
             $user = UserManager::instance()->getCurrentUser();
             $file = new FRSFile();
             $file->setRelease($release);
             $file->setFileName(basename($filename));
             $file->setTypeID($type_id);
             $file->setProcessorID($processor_id);
             $file->setReferenceMd5($reference_md5);
             $file->setUserID($user->getId());
             $file->setComment($comment);
             try {
                 $file_fact->createFile($file);
                 $release_fact->emailNotification($release);
                 return $file->getFileID();
             } catch (Exception $e) {
                 return new SoapFault(invalid_file_fault, $e->getMessage(), 'addUploadedFile');
             }
         } else {
             return new SoapFault(invalid_file_fault, 'User is not allowed to add a file', 'addUploadedFile');
         }
     } else {
         return new SoapFault(invalid_session_fault, 'Invalid Session', 'addUploadedFile');
     }
 }
Exemple #3
0
function frs_process_release_form($is_update, $request, $group_id, $title, $url)
{
    global $frspf, $frsrf, $frsff;
    $pm = ProjectManager::instance();
    //get and filter all inputs from $request
    $release = array();
    $res = $request->get('release');
    $vName = new Valid_String();
    $vPackage_id = new Valid_UInt();
    $vStatus_id = new Valid_UInt();
    if ($vName->validate($res['name']) && $vPackage_id->validate($res['package_id']) && $vStatus_id->validate($res['status_id'])) {
        $release['status_id'] = $res['status_id'];
        $release['name'] = $res['name'];
        $release['package_id'] = $res['package_id'];
    } else {
        $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('file_admin_editreleases', 'rel_update_failed'));
        $GLOBALS['Response']->redirect('/file/showfiles.php?group_id=' . $group_id);
    }
    $um = UserManager::instance();
    $user = $um->getCurrentUser();
    $vDate = new Valid_String();
    if ($vDate->validate($res['date'])) {
        $release['date'] = $res['date'];
    } else {
        $release['date'] = "";
    }
    $vRelease_notes = new Valid_Text();
    if ($vRelease_notes->validate($res['release_notes'])) {
        $release['release_notes'] = $res['release_notes'];
    } else {
        $release['release_notes'] = "";
    }
    $vChange_log = new Valid_Text();
    if ($vChange_log->validate($res['change_log'])) {
        $release['change_log'] = $res['change_log'];
    } else {
        $release['change_log'] = "";
    }
    if ($request->valid(new Valid_String('js'))) {
        $js = $request->get('js');
    } else {
        $js = "";
    }
    if ($request->validArray(new Valid_String('ftp_file'))) {
        $ftp_file = $request->get('ftp_file');
    } else {
        $ftp_file = array();
    }
    if ($request->validArray(new Valid_UInt('file_processor'))) {
        $file_processor = $request->get('file_processor');
    } else {
        $file_processor = array();
    }
    if ($request->validArray(new Valid_UInt('file_type'))) {
        $file_type = $request->get('file_type');
    } else {
        $file_type = array();
    }
    if ($request->validArray(new Valid_String('reference_md5'))) {
        $reference_md5 = $request->get('reference_md5');
    } else {
        $reference_md5 = array();
    }
    if ($request->validArray(new Valid_String('comment'))) {
        $comment = $request->get('comment');
    } else {
        $comment = array();
    }
    if ($request->validArray(new Valid_UInt('ftp_file_processor'))) {
        $ftp_file_processor = $request->get('ftp_file_processor');
    } else {
        $ftp_file_processor = array();
    }
    if ($request->validArray(new Valid_UInt('ftp_file_type'))) {
        $ftp_file_type = $request->get('ftp_file_type');
    } else {
        $ftp_file_type = array();
    }
    if ($request->validArray(new Valid_String('ftp_reference_md5'))) {
        $ftp_reference_md5 = $request->get('ftp_reference_md5');
    } else {
        $ftp_reference_md5 = array();
    }
    if ($request->valid(new Valid_String('release_news_subject'))) {
        $release_news_subject = $request->get('release_news_subject');
    } else {
        $release_news_subject = "";
    }
    if ($request->valid(new Valid_Text('release_news_details'))) {
        $release_news_details = $request->get('release_news_details');
    } else {
        $release_news_details = "";
    }
    if ($request->valid(new Valid_WhiteList('private_news', array(0, 1)))) {
        $private_news = $request->get('private_news');
    } else {
        $private_news = 0;
    }
    if ($request->validArray(new Valid_UInt('ugroups'))) {
        $ugroups = $request->get('ugroups');
    } else {
        $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('file_admin_editreleases', 'rel_update_failed'));
        $GLOBALS['Response']->redirect('/file/showfiles.php?group_id=' . $group_id);
    }
    if ($request->valid(new Valid_WhiteList('release_submit_news', array(0, 1)))) {
        $release_submit_news = (int) $request->get('release_submit_news');
    } else {
        $release_submit_news = 0;
    }
    if ($request->valid(new Valid_WhiteList('notification', array(0, 1)))) {
        $notification = $request->get('notification');
    } else {
        $notification = 0;
    }
    if ($is_update) {
        if ($request->validArray(new Valid_UInt('release_files_to_delete'))) {
            $release_files_to_delete = $request->get('release_files_to_delete');
        } else {
            $release_files_to_delete = array();
        }
        if ($request->validArray(new Valid_UInt('release_files'))) {
            $release_files = $request->get('release_files');
        } else {
            $release_files = array();
        }
        if ($request->validArray(new Valid_UInt('release_file_processor'))) {
            $release_file_processor = $request->get('release_file_processor');
        } else {
            $release_file_processor = array();
        }
        if ($request->validArray(new Valid_UInt('release_file_type'))) {
            $release_file_type = $request->get('release_file_type');
        } else {
            $release_file_type = array();
        }
        if ($request->validArray(new Valid_String('release_reference_md5'))) {
            $release_reference_md5 = $request->get('release_reference_md5');
        } else {
            $release_reference_md5 = array();
        }
        if ($request->validArray(new Valid_UInt('new_release_id'))) {
            $new_release_id = $request->get('new_release_id');
        } else {
            $new_release_id = array();
        }
        if ($request->validArray(new Valid_String('release_time'))) {
            $release_time = $request->get('release_time');
        } else {
            $release_time = array();
        }
        if ($request->validArray(new Valid_String('reference_md5'))) {
            $reference_md5 = $request->get('reference_md5');
        } else {
            $reference_md5 = array();
        }
        if ($request->validArray(new Valid_Text('release_comment'))) {
            $release_comment = $request->get('release_comment');
        } else {
            $release_comment = array();
        }
        if ($request->valid(new Valid_UInt('id'))) {
            $release['release_id'] = $request->get('id');
        } else {
            exit;
        }
    }
    $validator = new frsValidator();
    if ($is_update) {
        $valid = $validator->isValidForUpdate($release, $group_id);
    } else {
        $valid = $validator->isValidForCreation($release, $group_id);
    }
    if ($valid) {
        //uplaod release_notes and change_log if needed
        $data_uploaded = false;
        if (isset($_FILES['uploaded_change_log']) && !$_FILES['uploaded_change_log']['error']) {
            $code = addslashes(fread(fopen($_FILES['uploaded_change_log']['tmp_name'], 'r'), file_utils_get_size($_FILES['uploaded_change_log']['tmp_name'])));
            if (strlen($code) > 0 && strlen($code) < $GLOBALS['sys_max_size_upload']) {
                //size is fine
                $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('file_admin_editreleases', 'data_uploaded'));
                $data_uploaded = true;
                $release['change_log'] = $code;
            } else {
                //too big or small
                $GLOBALS['Response']->addFeedback('warning', $GLOBALS['Language']->getText('file_admin_editreleases', 'length_err', $GLOBALS['sys_max_size_upload']));
            }
        }
        if (isset($_FILES['uploaded_release_notes']) && !$_FILES['uploaded_release_notes']['error']) {
            $code = addslashes(fread(fopen($_FILES['uploaded_release_notes']['tmp_name'], 'r'), file_utils_get_size($_FILES['uploaded_release_notes']['tmp_name'])));
            if (strlen($code) > 0 && strlen($code) < $GLOBALS['sys_max_size_upload']) {
                //size is fine
                if (!$data_uploaded) {
                    $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('file_admin_editreleases', 'data_uploaded'));
                }
                $release['release_notes'] = $code;
            } else {
                //too big or small
                $GLOBALS['Response']->addFeedback('warning', $GLOBALS['Language']->getText('file_admin_editreleases', 'length_err', $GLOBALS['sys_max_size_upload']));
            }
        }
        if ($is_update) {
            // make sure that we don't change the date by error because of timezone reasons.
            // eg: release created in India (GMT +5:30) at 2004-06-03.
            // MLS in Los Angeles (GMT -8) changes the release notes
            // the release_date that we showed MLS is 2004-06-02.
            // with mktime(0,0,0,2,6,2004); we will change the unix time in the database
            // and the people in India will discover that their release has been created on 2004-06-02
            $rel =& $frsrf->getFRSReleaseFromDb($release['release_id']);
            if (format_date('Y-m-d', $rel->getReleaseDate()) == $release['date']) {
                // the date didn't change => don't update it
                $unix_release_time = $rel->getReleaseDate();
            } else {
                $date_list = split("-", $release['date'], 3);
                $unix_release_time = mktime(0, 0, 0, $date_list[1], $date_list[2], $date_list[0]);
            }
        } else {
            //parse the date
            $date_list = split("-", $release['date'], 3);
            $unix_release_time = mktime(0, 0, 0, $date_list[1], $date_list[2], $date_list[0]);
        }
        //now we create or update the release
        $array = array('release_date' => $unix_release_time, 'name' => $release['name'], 'status_id' => $release['status_id'], 'package_id' => $release['package_id'], 'notes' => $release['release_notes'], 'changes' => $release['change_log']);
        if ($is_update) {
            $array['release_id'] = $release['release_id'];
        }
        if ($is_update) {
            $res = $frsrf->update($array);
            if (!$res) {
                $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('file_admin_editreleases', 'rel_update_failed'));
                //insert failed - go back to definition screen
            } else {
                //release added - now show the detail page for this new release
                $release_id = $array['release_id'];
                $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('file_admin_editreleases', 'rel_updated', $release['name']));
            }
        } else {
            $res = $frsrf->create($array);
            if (!$res) {
                $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language'] > getText('file_admin_editreleases', 'add_rel_fail'));
                //insert failed - go back to definition screen
            } else {
                //release added - now show the detail page for this new release
                $release_id = $res;
                $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('file_admin_editreleases', 'rel_added'));
            }
        }
        if ($res) {
            // extract cross references
            $reference_manager =& ReferenceManager::instance();
            $reference_manager->extractCrossRef($release['release_notes'], $release_id, ReferenceManager::REFERENCE_NATURE_RELEASE, $group_id);
            $reference_manager->extractCrossRef($release['change_log'], $release_id, ReferenceManager::REFERENCE_NATURE_RELEASE, $group_id);
            //set the release permissions
            list($return_code, $feedbacks) = permission_process_selection_form($group_id, 'RELEASE_READ', $release_id, $ugroups);
            if (!$return_code) {
                $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('file_admin_editpackages', 'perm_update_err'));
                $GLOBALS['Response']->addFeedback('error', $feedbacks);
            }
            //submit news if requested
            if ($release_id && user_ismember($group_id, 'A') && $release_submit_news) {
                news_submit($group_id, $release_news_subject, $release_news_details, $private_news, 3);
            }
            // Send notification
            if ($notification) {
                $rel = $frsrf->getFRSReleaseFromDb($release_id);
                $count = $frsrf->emailNotification($rel);
                if ($count === false) {
                    $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('global', 'mail_failed', array($GLOBALS['sys_email_admin'])));
                } else {
                    if ($count > 0) {
                        $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('file_admin_editreleases', 'email_sent', $count));
                    }
                }
            }
            $group = $pm->getProject($group_id);
            $group_unix_name = $group->getUnixName(false);
            $project_files_dir = $GLOBALS['ftp_frs_dir_prefix'] . '/' . $group_unix_name;
            if ($is_update) {
                $files =& $rel->getFiles();
                //remove files
                foreach ($release_files_to_delete as $rel_file) {
                    $res =& $frsff->getFRSFileFromDb($rel_file);
                    $fname = $res->getFileName();
                    $res = $frsff->delete_file($group_id, $rel_file);
                    if ($res == 0) {
                        $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('file_admin_editreleases', 'f_not_yours', basename($fname)));
                    } else {
                        $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('file_admin_editreleases', 'file_deleted', basename($fname)));
                    }
                }
                //update files
                $index = 0;
                foreach ($release_files as $rel_file) {
                    if (!$release_files_to_delete || !in_array($rel_file, $release_files_to_delete)) {
                        $package_id = $release['package_id'];
                        $fname = $files[$index]->getFileName();
                        $list = split('/', $fname);
                        $fname = $list[sizeof($list) - 1];
                        if ($new_release_id[$index] != $release_id) {
                            //changing to a different release for this file
                            //see if the new release is valid for this project
                            $res2 = $frsrf->getFRSReleaseFromDb($new_release_id[$index], $group_id);
                            if (!$res2 || count($res2) < 1) {
                                //release not found for this project
                                $GLOBALS['Response']->addFeedback('warning', $GLOBALS['Language']->getText('file_admin_editreleases', 'rel_not_yours', $fname));
                            } else {
                                $package_id = $res2->getPackageID();
                            }
                        }
                        if ($new_release_id[$index] == $release_id || $res2) {
                            if (!ereg("[0-9]{4}-[0-9]{2}-[0-9]{2}", $release_time[$index])) {
                                $GLOBALS['Response']->addFeedback('warning', $GLOBALS['Language']->getText('file_admin_editreleases', 'data_not_parsed_file', $fname));
                            } else {
                                $res2 =& $frsff->getFRSFileFromDb($rel_file);
                                if (format_date('Y-m-d', $res2->getReleaseTime()) == $release_time[$index]) {
                                    $unix_release_time = $res2->getReleaseTime();
                                } else {
                                    $date_list = split("-", $release_time[$index], 3);
                                    $unix_release_time = mktime(0, 0, 0, $date_list[1], $date_list[2], $date_list[0]);
                                }
                                $array = array('release_id' => $new_release_id[$index], 'release_time' => $unix_release_time, 'type_id' => $release_file_type[$index], 'processor_id' => $release_file_processor[$index], 'file_id' => $rel_file, 'comment' => $release_comment[$index], 'filename' => 'p' . $package_id . '_r' . $new_release_id[$index] . '/' . $fname, 'filepath' => 'p' . $package_id . '_r' . $new_release_id[$index] . '/' . $fname . '_' . $unix_release_time);
                                if ($release_reference_md5[$index] && $release_reference_md5[$index] != '') {
                                    $array['reference_md5'] = $release_reference_md5[$index];
                                }
                                $res = $frsff->update($array);
                                if ($res) {
                                    $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('file_admin_editreleases', 'file_updated', $fname));
                                }
                            }
                        }
                    }
                    $index++;
                }
            }
            //add new files
            //files processing
            $http_files_list = array();
            $processor_type_list = array();
            $file_type_list = array();
            $http_files_processor_type_list = array();
            $ftp_files_processor_type_list = array();
            if (isset($js) && $js == 'no_js') {
                //if javascript is not allowed, there is maximum one file to upload
                // TODO : fix warnings due to array instead of string for "file_processor", "file_type" & "reference_md5"
                if ($ftp_file[0] != -1) {
                    $ftp_files_processor_type_list[] = array('name' => $ftp_file[0], 'processor' => $file_processor, 'type' => $file_type, 'reference_md5' => $reference_md5, 'comment' => $comment);
                } else {
                    if (trim($_FILES['file']['name'][0]) != '') {
                        $http_files_processor_type_list[] = array('error' => $_FILES['file']['error'][0], 'name' => stripslashes($_FILES['file']['name'][0]), 'tmp_name' => $_FILES['file']['tmp_name'][0], 'processor' => $file_processor, 'type' => $file_type, 'reference_md5' => $reference_md5, 'comment' => $comment);
                    }
                }
            } else {
                //get http files with the associated processor type and file type in allowed javascript case
                $nb_files = isset($_FILES['file']) ? count($_FILES['file']['name']) : 0;
                for ($i = 0; $i < $nb_files; $i++) {
                    if (trim($_FILES['file']['name'][$i]) != '') {
                        $http_files_processor_type_list[] = array('error' => $_FILES['file']['error'][$i], 'name' => stripslashes($_FILES['file']['name'][$i]), 'tmp_name' => $_FILES['file']['tmp_name'][$i], 'processor' => $file_processor[$i], 'type' => $file_type[$i], 'reference_md5' => $reference_md5[$i], 'comment' => $comment[$i]);
                    }
                }
                //remove hidden ftp_file input (if the user let the select boxe on --choose file)
                $tmp_file_list = array();
                $index = 0;
                foreach ($ftp_file as $file) {
                    if (trim($file) != '') {
                        $ftp_files_processor_type_list[] = array('name' => $file, 'processor' => $ftp_file_processor[$index], 'type' => $ftp_file_type[$index], 'reference_md5' => $ftp_reference_md5[$index]);
                        $index++;
                    }
                }
            }
            if (count($http_files_processor_type_list) > 0 || count($ftp_files_processor_type_list) > 0) {
                //see if this release belongs to this project
                $res1 =& $frsrf->getFRSReleaseFromDb($release_id, $group_id);
                if (!$res1 || count($res1) < 1) {
                    //release not found for this project
                    $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('file_admin_editreleases', 'rel_not_yours'));
                } else {
                    $now = time();
                    $addingFiles = false;
                    //iterate and add the http files to the frs_file table
                    foreach ($http_files_processor_type_list as $file) {
                        $filename = $file['name'];
                        if (isset($file['error'])) {
                            switch ($file['error']) {
                                case UPLOAD_ERR_OK:
                                    // all is OK
                                    break;
                                case UPLOAD_ERR_INI_SIZE:
                                case UPLOAD_ERR_FORM_SIZE:
                                    $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('global', 'error_upload_size', $file['error']));
                                    break;
                                case UPLOAD_ERR_PARTIAL:
                                    $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('global', 'error_upload_partial', $file['error']));
                                    break;
                                case UPLOAD_ERR_NO_FILE:
                                    $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('global', 'error_upload_nofile', $file['error']));
                                    break;
                                default:
                                    $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('global', 'error_upload_unknown', $file['error']));
                            }
                        }
                        if (is_uploaded_file($file['tmp_name'])) {
                            $uploaddir = $frsff->getSrcDir($request->getProject());
                            $uploadfile = $uploaddir . "/" . basename($filename);
                            if (!file_exists($uploaddir) || !is_writable($uploaddir) || !move_uploaded_file($file['tmp_name'], $uploadfile)) {
                                $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('file_admin_editreleases', 'not_add_file') . ": " . basename($filename));
                            } else {
                                $newFile = new FRSFile();
                                $newFile->setRelease($res1);
                                $newFile->setFileName($filename);
                                $newFile->setProcessorID($file['processor']);
                                $newFile->setTypeID($file['type']);
                                $newFile->setReferenceMd5($file['reference_md5']);
                                $newFile->setUserId($user->getId());
                                $newFile->setComment($file['comment']);
                                try {
                                    $frsff->createFile($newFile);
                                    $addingFiles = true;
                                } catch (Exception $e) {
                                    $GLOBALS['Response']->addFeedback('error', $e->getMessage());
                                }
                            }
                        } else {
                            $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('file_admin_editreleases', 'not_add_file') . ": " . basename($filename));
                        }
                    }
                    //iterate and add the ftp files to the frs_file table
                    foreach ($ftp_files_processor_type_list as $file) {
                        $filename = $file['name'];
                        $newFile = new FRSFile();
                        $newFile->setRelease($res1);
                        $newFile->setFileName($filename);
                        $newFile->setProcessorID($file['processor']);
                        $newFile->setTypeID($file['type']);
                        $newFile->setReferenceMd5($file['reference_md5']);
                        $newFile->setUserId($user->getId());
                        try {
                            $frsff->createFile($newFile, ~FRSFileFactory::COMPUTE_MD5);
                            $addingFiles = true;
                            $em = EventManager::instance();
                            $em->processEvent(Event::COMPUTE_MD5SUM, array('fileId' => $newFile->getFileID()));
                            $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('file_admin_editreleases', 'offline_md5', $filename));
                        } catch (Exception $e) {
                            $GLOBALS['Response']->addFeedback('error', $e->getMessage());
                        }
                    }
                }
                if ($addingFiles) {
                    $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('file_admin_editreleases', 'add_files'));
                }
            }
            //redirect to files
            $GLOBALS['Response']->redirect('/file/?group_id=' . $group_id);
        }
    } else {
        $GLOBALS['Response']->addFeedback('error', $validator->getErrors());
    }
    frs_display_release_form($is_update, $release, $group_id, $title, $url);
}
 /**
  * Force the upload directory creation, and move the file $file_name in the good directory
  *
  * @global $GLOBALS['codendi_bin_prefix']
  *
  * @param int    $group_id       the ID of the project we want to upload the file
  * @param string $file_name      the name of the file we want to upload
  * @param string $upload_sub_dir the name of the sub-directory the file will be moved in
  *
  * @return Boolean True if file is moved to it's final location (false otherwise)
  */
 public function moveFileForge(FRSFile $file)
 {
     $release = $file->getRelease();
     $project = $release->getProject();
     $unixName = $project->getUnixName(false);
     $upload_sub_dir = $this->getUploadSubDirectory($release);
     $fileName = $file->getFileName();
     $filePath = $this->getResolvedFileName($file->getFileName());
     if (!file_exists($GLOBALS['ftp_frs_dir_prefix'] . '/' . $unixName . '/' . $upload_sub_dir . '/' . escapeshellarg($filePath))) {
         $fileName = escapeshellarg($fileName);
         $cmdFilePath = escapeshellarg($filePath);
         $ret_val = null;
         $exec_res = null;
         $src_dir = $this->getSrcDir($project);
         $cmd = $this->fileforge . " {$fileName} " . $unixName . "/" . $upload_sub_dir . '/' . $cmdFilePath . " {$src_dir} 2>&1";
         exec($cmd, $exec_res, $ret_val);
         // Warning. Posix common value for success is 0 (zero), but in php 0 == false.
         // So "convert" the unix "success" value to the php one (basically 0 => true).
         if ($ret_val == 0) {
             $file->setFileName($upload_sub_dir . '/' . $file->getFileName());
             $file->setFilePath($upload_sub_dir . '/' . $filePath);
             return true;
         }
     }
     return false;
 }
 function testCreateFileDbEntryMovedFile()
 {
     // Create toto.txt in the release directory
     mkdir($GLOBALS['ftp_frs_dir_prefix'] . '/prj/p123_r456');
     touch($GLOBALS['ftp_frs_dir_prefix'] . '/prj/p123_r456/toto.txt');
     touch($GLOBALS['ftp_incoming_dir'] . '/toto.txt');
     $p = new MockProject();
     $p->setReturnValue('getUnixName', 'prj');
     $r = new FRSRelease();
     $r->setReleaseID(456);
     $r->setPackageID(123);
     $r->setProject($p);
     $f = new FRSFile();
     $f->setFileName('toto.txt');
     $f->setRelease($r);
     $f->setFileLocation($GLOBALS['ftp_frs_dir_prefix'] . '/prj/p123_r456');
     $ff = new FRSFileFactoryTestCreateFiles();
     $ff->setReturnValue('moveFileForge', True);
     $ff->setReturnValue('create', False);
     try {
         $ff->createFile($f, ~FRSFileFactory::COMPUTE_MD5);
     } catch (Exception $e) {
         $this->assertIsA($e, 'FRSFileDbException');
     }
     //Cleanup
     unlink($GLOBALS['ftp_frs_dir_prefix'] . '/prj/p123_r456/toto.txt');
     unlink($GLOBALS['ftp_incoming_dir'] . '/toto.txt');
     rmdir($GLOBALS['ftp_frs_dir_prefix'] . '/prj/p123_r456');
 }
 /**
  * Creates a new file under the release
  *
  * @param String $name
  * @param Binary $data
  *
  * @return void
  *
  * @see plugins/webdav/include/lib/Sabre/DAV/Sabre_DAV_Directory#createFile($name, $data)
  */
 function createFile($name, $data = null)
 {
     if ($this->userCanWrite()) {
         $utils = $this->getUtils();
         // Create file in the staging area
         $this->createFileIntoIncoming($name, $data);
         $fileSize = $utils->getIncomingFileSize($name);
         if ($fileSize > $this->getMaxFileSize()) {
             throw new Sabre_DAV_Exception_RequestedRangeNotSatisfiable($GLOBALS['Language']->getText('plugin_webdav_download', 'error_file_size'));
         }
         $release = $this->getRelease();
         $newFile = new FRSFile();
         $newFile->setRelease($release);
         $newFile->setFileName($name);
         $newFile->setProcessorID(100);
         $newFile->setTypeID(100);
         $newFile->setUserId($this->getUser()->getId());
         try {
             $frsff = $utils->getFileFactory();
             $frsff->createFile($newFile);
             $utils->getReleaseFactory()->emailNotification($release);
         } catch (Exception $e) {
             throw new Sabre_DAV_Exception_BadRequest($e->getMessage());
         }
     } else {
         throw new Sabre_DAV_Exception_Forbidden($GLOBALS['Language']->getText('plugin_webdav_common', 'file_denied_create'));
     }
 }
 private function importFile(Project $project, FRSRelease $release, PFUser $user, SimpleXMLElement $xml_file, $extraction_path)
 {
     $user = empty($xml_file->user) ? $user : $this->user_finder->getUser($xml_file->user);
     $attrs = $xml_file->attributes();
     $src = $extraction_path . '/' . $attrs['src'];
     $name = isset($attrs['name']) ? (string) $attrs['name'] : basename($src);
     $md5 = strtolower(md5_file($src));
     $time = strtotime($attrs['release-time']);
     $date = strtotime($attrs['post-date']);
     $desc = "";
     $type_id = $this->getFileTypeDao()->searchTypeId($attrs['filetype']);
     if (is_null($type_id)) {
         throw new Exception("Invalid filetype '{$attrs['filetype']}'");
     }
     $proc_id = $this->getProcessorDao()->searchProcessorId($project->getID(), $attrs['arch']);
     if (is_null($proc_id)) {
         throw new Exception("Invalid architecture '{$attrs['arch']}'");
     }
     foreach ($xml_file->children() as $elem) {
         if ($elem->getName() != "description") {
             continue;
         }
         $desc .= (string) $elem;
     }
     if (isset($attrs['md5sum'])) {
         $expected_md5 = strtolower($attrs['md5sum']);
         if ($expected_md5 != $md5) {
             throw new Exception("Import of file {$src} failed because the file is corrupted " . "(expected MD5 {$expected_md5}, got {$md5})");
         }
     }
     $dirPath = $this->file_factory->getSrcDir($project);
     $dest = "{$dirPath}/{$name}";
     if (!copy($src, $dest)) {
         throw new Exception("Could not copy {$src} to {$dest}");
     }
     $newFile = new FRSFile();
     $newFile->setGroup($project);
     $newFile->setRelease($release);
     $newFile->setFileName($name);
     $newFile->setProcessorID($proc_id);
     $newFile->setTypeID($type_id);
     $newFile->setReferenceMd5($md5);
     $newFile->setComputedMd5($md5);
     $newFile->setUserId($user->getId());
     $newFile->setComment($desc);
     $newFile->setReleaseTime($time);
     $newFile->setPostDate($date);
     $this->file_factory->createFile($newFile);
 }