function addFile($session_ser, $group_id, $package_id, $release_id, $name, $base64_contents, $type_id, $processor_id, $release_time) { continue_session($session_ser); $grp =& group_get_object($group_id); if (!$grp || !is_object($grp)) { return new soap_fault('', 'addFile', 'Could Not Get Group', 'Could Not Get Group'); } elseif ($grp->isError()) { return new soap_fault('', 'addFile', $grp->getErrorMessage(), $grp->getErrorMessage()); } $frsp =& frspackage_get_object($package_id); if (!$frsp || !is_object($frsp)) { return new soap_fault('', 'addFile', 'Could Not Get Package', 'Could Not Get Package'); } else { if ($frsp->isError()) { return new soap_fault('', 'addFile', $frsp->getErrorMessage(), $frsp->getErrorMessage()); } } $frsr =& frsrelease_get_object($release_id); if (!$frsr || !is_object($frsr)) { return new soap_fault('', 'addFile', 'Could Not Get Release', 'Could Not Get Release'); } else { if ($frsr->isError()) { return new soap_fault('', 'addFile', $frsr->getErrorMessage(), $frsr->getErrorMessage()); } } $frsf = new FRSFile($frsr); if (!$frsf || !is_object($frsf)) { return new soap_fault('', 'addFile', 'Could Not Get File', 'Could Not Get File'); } $tmpname = tempnam("/tmp", "gforge_cli_frs"); $fh = fopen($tmpname, "wb"); if (!$fh) { return new soap_fault('', 'addFile', 'Could not create temporary file in directory /tmp'); } fwrite($fh, base64_decode($base64_contents)); fclose($fh); if (!$frsf->create($name, $tmpname, $type_id, $processor_id, $release_time)) { @unlink($tmpname); return new soap_fault('', 'addFile', $frsf->getErrorMessage(), $frsf->getErrorMessage()); } else { @unlink($tmpname); return $frsf->getID(); } }
/** * update - update an existing file in this FRSFileRelease/FRSPackage. * * @param int The type_id of this file from the frs-file-types table. * @param int The processor_id of this file from the frs-processor-types table. * @param int The release_date of this file in unix time (seconds). * @param int The release_id of the release this file belongs to (if not set, defaults to the release id of this file). * @return boolean success. */ function update($type_id, $processor_id, $release_time, $release_id = false) { $perm =& $this->FRSRelease->FRSPackage->Group->getPermission(session_get_user()); if (!$perm || !is_object($perm) || !$perm->isReleaseTechnician()) { $this->setPermissionDeniedError(); return false; } // Sanity checks if ($release_id) { // Check that the new FRSRelease id exists if ($FRSRelease = frsrelease_get_object($release_id)) { // Check that the new FRSRelease id belongs to the group of this FRSFile if ($FRSRelease->FRSPackage->Group->getID() != $this->FRSRelease->FRSPackage->Group->getID()) { $this->setError('FRSFile:: No Valid Group Object'); return false; } } else { $this->setError('FRSFile:: No Valid FRSRelease Object'); return false; } } else { // If release_id is not set, defaults to the release id of this file $release_id = $this->FRSRelease->getID(); } // Update database db_begin(); $res = db_query("UPDATE frs_file SET\n\t\t\ttype_id='{$type_id}',\n\t\t\tprocessor_id='{$processor_id}',\n\t\t\trelease_time='{$release_time}',\n\t\t\trelease_id='{$release_id}'\n\t\t\tWHERE file_id='" . $this->getID() . "'"); if (!$res || db_affected_rows($res) < 1) { $this->setError('FRSFile::update() Error On Update: ' . db_error()); return false; } // Move physically file if needed if ($release_id != $this->FRSRelease->getID()) { $old_file_location = $GLOBALS['sys_upload_dir'] . '/' . $this->FRSRelease->FRSPackage->Group->getUnixName() . '/' . $this->FRSRelease->FRSPackage->getFileName() . '/' . $this->FRSRelease->getFileName() . '/' . $this->data_array['filename']; $new_file_location = $GLOBALS['sys_upload_dir'] . '/' . $FRSRelease->FRSPackage->Group->getUnixName() . '/' . $FRSRelease->FRSPackage->getFileName() . '/' . $FRSRelease->getFileName() . '/' . $this->data_array['filename']; if (file_exists($new_file_location)) { db_rollback(); $this->setError(_('That filename already exists in this project space')); return false; } $cmd = "/bin/mv {$old_file_location} {$new_file_location}"; exec($cmd, $out); if (!file_exists($new_file_location)) { db_rollback(); $this->setError(_('File cannot be moved to the permanent location') . ': ' . $new_file_location); return false; } } db_commit(); return true; }