/** * Add an artefact in the tracker * * @return Tracker_Artifact or false if an error occured */ public function create(Tracker $tracker, array $fields_data, PFUser $user, $submitted_on, $send_notification) { $artifact = $this->getBareArtifact($tracker, $user, $submitted_on); if (!$this->fields_validator->validate($artifact, $fields_data)) { return; } $use_artifact_permissions = 0; $id = $this->artifact_dao->create($tracker->id, $user->getId(), $submitted_on, $use_artifact_permissions); if (!$id) { return; } $artifact->setId($id); $changeset_id = $this->changeset_creator->create($artifact, $fields_data, $user, $submitted_on); if (!$changeset_id) { return; } $changeset = new Tracker_Artifact_Changeset($changeset_id, $artifact, $artifact->getSubmittedBy(), $artifact->getSubmittedOn(), $user->getEmail()); if ($send_notification) { $changeset->notify(); } return $artifact; }
/** * Add an artefact in the tracker * * @param Tracker $tracker The tracker this artifact belongs to * @param array $fields_data The data of the artifact to create * @param User $user The user that want to create the artifact * @param string $email The email if the user is anonymous (null if anonymous) * @param boolean $send_notification true if a notification must be sent, false otherwise * * @return Tracker_Artifact or false if an error occured */ public function createArtifact(Tracker $tracker, $fields_data, User $user, $email, $send_notification = true) { $artifact = $this->getInstanceFromRow(array('id' => 0, 'tracker_id' => $tracker->id, 'submitted_by' => $user->getId(), 'submitted_on' => $_SERVER['REQUEST_TIME'], 'use_artifact_permissions' => 0)); //validate the request if ($ok = $artifact->validateFields($fields_data, true)) { //If all is ok, save the artifact $use_artifact_permissions = 0; if ($id = $this->getDao()->create($tracker->id, $user->getId(), $use_artifact_permissions)) { $artifact->setId($id); //create the first changeset if ($changeset_id = $artifact->createInitialChangeset($fields_data, $user, $email)) { $submitted_by = $artifact->getSubmittedBy(); $submitted_on = $artifact->getSubmittedOn(); $changeset = new Tracker_Artifact_Changeset($changeset_id, $artifact, $submitted_by, $submitted_on, $email); if ($send_notification) { $changeset->notify(); } return $artifact; } } } return false; }