* TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
* ALONE BASIS."
*/
-
require_once $gfcommon.'include/Error.class.php';
require_once $gfcommon.'tracker/ArtifactMessage.class.php';
require_once $gfcommon.'tracker/ArtifactExtraField.class.php';
}
}
}
-
-
+
/**
* create - construct a new Artifact in the database.
*
* @param int The ID of the user to which this artifact is to be assigned.
* @param int The artifacts priority.
* @param array Array of extra fields like: array(15=>'foobar',22=>'1');
+ * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
* @return id on success / false on failure.
*/
- function create( $summary, $details, $assigned_to=100, $priority=3, $extra_fields=array()) {
+ function create( $summary, $details, $assigned_to=100, $priority=3, $extra_fields=array(), $importData = array()) {
//
// make sure this person has permission to add artifacts
//
+
if (!$this->ArtifactType->isPublic()) {
//
// Only admins can post/modify private artifacts
//
// get the user_id
//
- if (session_loggedin()) {
- $user=user_getid();
+
+ if(array_key_exists('user', $importData)){
+ $user = $importData['user'];
} else {
- if ($this->ArtifactType->allowsAnon()) {
- $user=100;
+ if (session_loggedin()) {
+ $user=user_getid();
} else {
- $this->setError(_('Artifact: This ArtifactType Does Not Allow Anonymous Submissions. Please Login.'));
- return false;
+ if ($this->ArtifactType->allowsAnon()) {
+ $user=100;
+ } else {
+ $this->setError(_('Artifact: This ArtifactType Does Not Allow Anonymous Submissions. Please Login.'));
+ return false;
+ }
}
- }
+ }
+
//
// data validation
}
db_begin();
-
+ if (array_key_exists('time',$importData)){
+ $time = $importData['time'];
+ } else {
+ $time = time();
+ }
$res = db_query_params ('INSERT INTO artifact
(group_artifact_id,status_id,priority,
submitted_by,assigned_to,open_date,summary,details)
$priority,
$user,
$assigned_to,
- time(),
+ $time,
htmlspecialchars($summary),
htmlspecialchars($details))) ;
if (!$res) {
*
* @param string The name of the field in the database being modified.
* @param string The former value of this field.
+ * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
* @access private
* @return boolean success.
*/
- function addHistory($field_name,$old_value) {
- if (!session_loggedin()) {
- $user=100;
+ function addHistory($field_name,$old_value, $importData = array()) {
+ if (array_key_exists('user', $importData)){
+ $user = $importData['user'];
+ } else {
+ if (!session_loggedin()) {
+ $user=100;
+ } else {
+ $user=user_getid();
+ }
+ }
+ if (array_key_exists('time',$importData)){
+ $time = $importData['time'];
} else {
- $user=user_getid();
+ $time = time();
}
return db_query_params ('INSERT INTO artifact_history(artifact_id,field_name,old_value,mod_by,entrydate) VALUES ($1,$2,$3,$4,$5)',
array ($this->getID(),
$field_name,
addslashes($old_value),
$user,
- time())) ;
+ $time)) ;
+ }
+
+ /**
+ * setStatus - set the status of this artifact.
+ *
+ * @param int The artifact status ID.
+ * @param int Closing date if status = 1
+ *
+ * @return boolean success.
+ */
+ function setStatus($status_id, $closingTime=False) {
+ db_begin();
+ $qpa = db_construct_qpa (false, 'UPDATE artifact SET status_id=$1', array ($status_id)) ;
+ if ($closingTime && $status_id != 1) {
+ $time=$closingTime;
+ $qpa = db_construct_qpa ($qpa, ', close_date=$1 ', array ($time)) ;
+ }
+ $qpa = db_construct_qpa ($qpa,
+ 'WHERE artifact_id=$1 AND group_artifact_id=$2',
+ array ($this->getID(), $artifact_type_id)) ;
+ $result=db_query_qpa($qpa);
+
+ if (!$result || db_affected_rows($result) < 1) {
+ $this->setError('Error - update failed!'.db_error());
+ db_rollback();
+ return false;
+ } else {
+ if (!$this->fetchData($this->getID())) {
+ db_rollback();
+ return false;
+ }
+ }
+
+
+ //commiting changes
+ db_commit();
+ return true;
}
/**
* @param string Item filesize.
* @param binary Binary item data.
* @param string Item description.
- * @return id on success / false on failure.
+ * @param array Array of data to change submitter and time of submit like: array('user' => 127, 'time' => 1234556789)
+ * @return id on success / false on failure.
*/
- function create($filename, $filetype, $filesize, $bin_data, $description='None') {
+ function create($filename, $filetype, $filesize, $bin_data, $description='None', $importData = array()) {
// Some browsers don't supply mime type if they don't know it
if (!$filetype) {
// Let's be on safe side?
return false;
}
- if (session_loggedin()) {
- $userid=user_getid();
+ if (array_key_exists('user', $importData)){
+ $userid = $importData['user'];
} else {
- $userid=100;
+ if (session_loggedin()) {
+ $userid=user_getid();
+ } else {
+ $userid=100;
+ }
+ }
+
+ if (array_key_exists('time',$importData)){
+ $time = $importData['time'];
+ } else {
+ $time = time();
}
+
// If $filetype is "text/plain", $bin_data convert UTF-8 encoding.
if (strcasecmp($filetype,"text/plain") === 0 &&
$filename,
$filesize,
$filetype,
- time(),
+ $time,
$userid)) ;
$id=db_insertid($res,'artifact_file','id');
$this->setError('ArtifactFile: '.db_error());
return false;
} else {
-/*
-//
-// skip this unless we need it later - save a db query
-//
- //
- // Now set up our internal data structures
- //
- if (!$this->fetchData($id)) {
- db_rollback();
- return false;
- }
-*/
db_commit();
- $this->Artifact->addHistory('File Added',$id.': '.$filename);
+ // If time is set, no need to add to history, will be done in batch
+ if (!array_key_exists('time', $importData)){
+ $this->Artifact->addHistory('File Added',$id.': '.$filename);
+ }
$this->Artifact->UpdateLastModifiedDate();
$this->clearError();
return $id;