/** * updateArtifact - update the artifact $artifact_id in tracker $tracker_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 update the artifact * @param int $tracker_id the ID of the tracker we want to update the artifact * @param int $artifact_id the ID of the artifact to update * @param array{SOAPArtifactFieldValue} $value the fields value to update * @param string $comment the comment associated with the modification, or null if no follow-up comment. * * @return int The artifact id if update was fine, * or a soap fault if : * - group_id does not match with a valid project, * - tracker_id does not match with a valid tracker, * - artifact_id does not match with a valid artifact, * - the given values are breaking a field dependency rule * - the artifact modification failed. */ function updateArtifact($sessionKey, $group_id, $tracker_id, $artifact_id, $value, $comment) { if (session_continue($sessionKey)) { $user = UserManager::instance()->getCurrentUser(); $pm = ProjectManager::instance(); try { $project = $pm->getGroupByIdForSoap($group_id, 'updateArtifact'); } catch (SoapFault $e) { return $e; } $tf = TrackerFactory::instance(); $tracker = $tf->getTrackerById($tracker_id); if ($tracker == null) { return new SoapFault(get_tracker_fault, 'Could not get Tracker.', 'updateArtifact'); } elseif ($tracker->getGroupId() != $group_id) { return new SoapFault(get_tracker_fault, 'Could not get Tracker.', 'updateArtifact'); } $af = Tracker_ArtifactFactory::instance(); if ($artifact = $af->getArtifactById($artifact_id)) { if ($artifact->getTrackerId() != $tracker_id) { return new SoapFault(get_tracker_fault, 'Could not get Artifact.', 'updateArtifact'); } //Check Field Dependencies // TODO : implement it /*require_once('common/tracker/ArtifactRulesManager.class.php'); $arm =& new ArtifactRulesManager(); if (!$arm->validate($ath->getID(), $data, $art_field_fact)) { return new SoapFault(invalid_field_dependency_fault, 'Invalid Field Dependency', 'updateArtifact'); }*/ $fef = Tracker_FormElementFactory::instance(); $fields_data = array(); foreach ($value as $field_value) { // field are identified by name, we need to retrieve the field id if ($field_value->field_name) { $field = $fef->getUsedFieldByName($tracker_id, $field_value->field_name); if ($field) { $field_data = $field->getFieldData($field_value->field_value); if ($field_data != null) { // $field_value is an object: SOAP must cast it in ArtifactFieldValue if (isset($fields_data[$field->getId()])) { if (!is_array($fields_data[$field->getId()])) { $fields_data[$field->getId()] = array($fields_data[$field->getId()]); } $fields_data[$field->getId()][] = $field_data; } else { $fields_data[$field->getId()] = $field_data; } } else { return new SoapFault(update_artifact_fault, 'Unknown value ' . $field_value->field_value . ' for field: ' . $field_value->field_name, 'addArtifact'); } } else { return new SoapFault(update_artifact_fault, 'Unknown field: ' . $field_value->field_name, 'addArtifact'); } } } if ($artifact->createNewChangeset($fields_data, $comment, $user, null)) { return $artifact_id; } else { $response = new Response(); if ($response->feedbackHasErrors()) { return new SoapFault(update_artifact_fault, $response->getRawFeedback(), 'updateArtifact'); } else { return new SoapFault(update_artifact_fault, 'Unknown error', 'updateArtifact'); } } } else { return new SoapFault(get_tracker_fault, 'Could not get Artifact.', 'updateArtifact'); } } else { return new SoapFault(invalid_session_fault, 'Invalid Session ', 'updateArtifact'); } }