public function getFullRESTValue(PFUser $user, Tracker_Artifact_Changeset $changeset) { $classname_with_namespace = 'Tuleap\\Tracker\\REST\\Artifact\\ArtifactFieldValueFullRepresentation'; $artifact_field_value_full_representation = new $classname_with_namespace(); $artifact_field_value_full_representation->build($this->getId(), Tracker_FormElementFactory::instance()->getType($this), $this->getLabel(), (int) $changeset->getArtifact()->getPerTrackerArtifactId()); return $artifact_field_value_full_representation; }
/** * Same as exportFullHistory() but only the current state of the artifact */ public function exportSnapshotWithoutComments(SimpleXMLElement $artifacts_xml, Tracker_Artifact_Changeset $changeset) { $artifact_xml = $artifacts_xml->addChild('artifact'); $artifact_xml->addAttribute('id', $changeset->getArtifact()->getId()); $artifact_xml->addAttribute('tracker_id', $changeset->getArtifact()->getTrackerId()); $this->changeset_exporter->exportWithoutComments($artifact_xml, $changeset); }
/** * @return Tracker_Artifact_Changeset */ public function build() { $changeset = new Tracker_Artifact_Changeset($this->id, $this->artifact, $this->submitted_by, $this->submitted_on, $this->email); if ($this->comment !== null) { $changeset->setLatestComment($this->comment); } return $changeset; }
private function getRawMailForChangeset(Tracker_Artifact_Changeset $changeset) { $raw_mails = $this->getCachedRawMailByChangesetsForArtifact($changeset->getArtifact()); $changeset_id = $changeset->getId(); if (isset($raw_mails[$changeset_id])) { return $raw_mails[$changeset_id]; } return null; }
private function hasChanges(Tracker_Artifact_Changeset $new_changeset, Tracker_Artifact_Changeset $previous_changeset = null) { if (!$previous_changeset) { return true; } $new_value = $new_changeset->getValue($this->field); $previous_value = $previous_changeset->getValue($this->field); $diff = $new_value->getArtifactLinkInfoDiff($previous_value); return $diff->hasChanges(); }
/** * Fetch the value in a specific changeset * @param Tracker_Artifact_Changeset $changeset * @return string */ public function fetchRawValueFromChangeset($changeset) { $value = ''; if ($v = $changeset->getValue($this)) { if ($row = $this->getValueDao()->searchById($v->getId(), $this->id)->getRow()) { $value = $row['value']; } } return $value; }
public function exportFullHistory(SimpleXMLElement $artifact_xml, Tracker_Artifact_Changeset $changeset) { $changeset_xml = $artifact_xml->addChild('changeset'); if ($changeset->getSubmittedBy()) { $this->user_xml_exporter->exportUserByUserId($changeset->getSubmittedBy(), $changeset_xml, 'submitted_by'); } elseif ($changeset->getEmail()) { $this->user_xml_exporter->exportUserByMail($changeset->getEmail(), $changeset_xml, 'submitted_by'); } $submitted_on = $changeset_xml->addChild('submitted_on', date('c', $changeset->getSubmittedOn())); $submitted_on->addAttribute('format', 'ISO8601'); $comments_node = $changeset_xml->addChild('comments'); if ($changeset->getComment()) { $changeset->getComment()->exportToXML($comments_node); } $this->values_exporter->exportChangedFields($artifact_xml, $changeset_xml, $changeset->getArtifact(), $changeset->getValues()); }
private function fetchFormattedMailUserInfo(PFUser $user) { $hp = Codendi_HTMLPurifier::instance(); if ($user && !$user->isAnonymous()) { $user_info = '<a href="mailto:' . $hp->purify($user->getEmail()) . '">' . $hp->purify($user->getRealName()) . ' (' . $hp->purify($user->getUserName()) . ') </a>'; } else { $user = UserManager::instance()->getUserAnonymous(); $user->setEmail($this->changeset->getEmail()); $user_info = $GLOBALS['Language']->getText('tracker_include_artifact', 'anon_user'); } return $user_info; }
/** * 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; }
private function getCrossReferenceListForREST(Tracker_Artifact_Changeset $changeset) { $crf = new CrossReferenceFactory($changeset->getArtifact()->getId(), Tracker_Artifact::REFERENCE_NATURE, $this->getTracker()->getGroupId()); $crf->fetchDatas(); $list = array(); $refs = $crf->getFormattedCrossReferences(); if (!empty($refs['target'])) { foreach ($refs['target'] as $refTgt) { $list[] = array(self::REST_REF_INDEX => $refTgt['ref'], self::REST_REF_URL => $refTgt['url'], self::REST_REF_DIRECTION => self::REST_REF_DIRECTION_OUT); } } if (!empty($refs['source'])) { foreach ($refs['source'] as $refSrc) { $list[] = array(self::REST_REF_INDEX => $refSrc['ref'], self::REST_REF_URL => $refSrc['url'], self::REST_REF_DIRECTION => self::REST_REF_DIRECTION_IN); } } if (!empty($refs['both'])) { foreach ($refs['both'] as $refBoth) { $list[] = array(self::REST_REF_INDEX => $refBoth['ref'], self::REST_REF_URL => $refBoth['url'], self::REST_REF_DIRECTION => self::REST_REF_DIRECTION_BOTH); } } return $list; }
public function extractArtifactDateFields(Tracker_Artifact $artifact, Tracker_Artifact_Changeset $last_changeset, array &$properties) { $tracker = $artifact->getTracker(); $custom_date_fields = $this->form_element_factory->getUsedCustomDateFields($tracker); foreach ($custom_date_fields as $date_field) { $last_changeset_value = $last_changeset->getValue($date_field); if ($last_changeset->getValue($date_field) && $last_changeset_value) { $properties[$date_field->getName()] = date('c', $last_changeset_value->getTimestamp()); } } $core_date_fields = $this->form_element_factory->getCoreDateFields($tracker); foreach ($core_date_fields as $date_field) { if ($date_field instanceof Tracker_FormElement_Field_SubmittedOn) { $properties[$date_field->getName()] = date('c', $artifact->getSubmittedOn()); } elseif ($date_field instanceof Tracker_FormElement_Field_LastUpdateDate) { $properties[$date_field->getName()] = date('c', $artifact->getLastUpdateDate()); } } $last_modified = $artifact->getLastUpdateDate(); if ($last_modified === -1) { $last_modified = $artifact->getSubmittedOn(); } $properties[self::LAST_UPDATE_PROPERTY] = date('c', $last_modified); }
public function testDisplayDiffShouldNotStripHtmlTagsInPlainTextFormat() { $diff = "@@ -1 +1 @@\n- Quelle est la couleur <b> du <i> cheval blanc d'Henri IV?\n+ Quelle est la couleur <b> du <i> <s> cheval blanc d'Henri IV?"; $format = 'text'; $field = new MockTracker_FormElement_Field_Date(); $field->setReturnValue('getLabel', 'Summary'); $changeset = new Tracker_Artifact_Changeset(null, null, null, null, null); $result = $changeset->displayDiff($diff, $format, $field); $this->assertPattern('%Quelle est la couleur <b> du <i> <s> cheval blanc%', $result); $this->assertPattern('%Summary%', $result); }
/** * Fetch the value in a specific changeset * @param Tracker_Artifact_Changeset $changeset * @return string */ public function fetchRawValueFromChangeset($changeset) { $value = ''; if ($v = $changeset->getValue($this)) { if (isset($v['value_id'])) { $v = array($v); } foreach ($v as $val) { if ($val['value_id'] != 100) { if ($row = $this->getValueDao()->searchById($val['value_id'], $this->id)->getRow()) { if ($value) { $value .= ', '; } $value .= $row['filename']; } } } } return $value; }
/** * Retrieve sliced linked artifacts according to user's permissions * * This is nearly the same as a paginated list however, for performance * reasons, the total size may be different than the sum of total paginated * artifacts. * * Example to illustrate the difference between paginated and sliced: * * Given that artifact links are [12, 13, 24, 39, 65, 69] * And that the user cannot see artifact #39 * When I request linked artifacts by bunchs of 2 * Then I get [[12, 13], [24], [65, 69]] # instead of [[12, 13], [24, 65], [69]] * And total size will be 6 # instead of 5 * * @param Tracker_Artifact_Changeset $changeset The changeset you want to retrieve artifact from * @param PFUser $user The user who will see the artifacts * @param int $limit The number of artifact to fetch * @param int $offset The offset * * @return Tracker_Artifact_PaginatedArtifacts */ public function getSlicedLinkedArtifacts(Tracker_Artifact_Changeset $changeset, PFUser $user, $limit, $offset) { $changeset_value = $changeset->getValue($this); if (!$changeset_value) { return new Tracker_Artifact_PaginatedArtifacts(array(), 0); } $artifact_ids = $changeset_value->getArtifactIds(); $size = count($artifact_ids); $artifacts = array(); foreach (array_slice($artifact_ids, $offset, $limit) as $id) { $this->addArtifactUserCanViewFromId($artifacts, $id, $user); } return new Tracker_Artifact_PaginatedArtifacts($artifacts, $size); }
private function getEmail(PFUser $user, Tracker_Artifact $artifact, Tracker_Artifact_Changeset $changeset) { return "<" . $artifact->getId() . "-" . $this->getHash($user, $artifact) . "-" . $user->getId() . "-" . $changeset->getId() . "@" . $this->host . ">"; }
/** * Return REST value of a field for a given changeset * * @param PFUser $user * @param Tracker_Artifact_Changeset $changeset * * @return mixed | null if no values */ public function getRESTValue(PFUser $user, Tracker_Artifact_Changeset $changeset) { $value = $changeset->getValue($this); if ($value) { return $value->getRESTValue($user); } }
/** * Fetch the value in a specific changeset * @param Tracker_Artifact_Changeset $changeset * @return string */ public function fetchRawValueFromChangeset($changeset) { $value = ''; $values_array = array(); if ($v = $changeset->getValue($this->field)) { $values = $v->getListValues(); foreach ($values as $val) { $values_array[] = $val->getLabel(); } } return implode(",", $values_array); }
private function linkRawMailToChangeset($raw_mail, Tracker_Artifact_Changeset $changeset) { $this->logger->debug('Linking created changeset (' . $changeset->getId() . ') to the raw mail.'); $this->incoming_mail_dao->save($changeset->getId(), $raw_mail); }
public function addChangeset(Tracker_Artifact_Changeset $changeset) { $this->changesets[$changeset->getId()] = $changeset; }
public function getFullRESTValueForAnonymous(Tracker_Artifact_Changeset $changeset) { $user = new PFUser(); $user->setEmail($changeset->getEmail()); $user->setRealName($changeset->getEmail()); $class_user_representation = '\\Tuleap\\User\\REST\\UserRepresentation'; $user_representation = new $class_user_representation(); $user_representation->build($user); return $user_representation; }
/** * * @param Tracker_Artifact_Changeset $changeset * @return string */ public function getFirstValueFor(Tracker_Artifact_Changeset $changeset) { if ($this->userCanRead()) { $value = $changeset->getValue($this); if ($value && ($last_values = $value->getListValues())) { // let's assume there is no more that one status if ($label = array_shift($last_values)->getLabel()) { return $label; } } } }
/** * Get the value of this field * * @param Tracker_Artifact_Changeset $changeset The changeset (needed in only few cases like 'lud' field) * @param int $value_id The id of the value * @param boolean $has_changed If the changeset value has changed from the rpevious one * * @return Tracker_Artifact_ChangesetValue or null if not found */ public function getChangesetValue($changeset, $value_id, $has_changed) { $changeset_value = new Tracker_Artifact_ChangesetValue_Date($value_id, $this, $has_changed, $changeset->getSubmittedOn()); return $changeset_value; }
/** * Get the value of this field * * @param Tracker_Artifact_Changeset $changeset The changeset (needed in only few cases like 'lud' field) * @param int $value_id The id of the value * @param boolean $has_changed If the changeset value has changed from the previous one * * @return Tracker_Artifact_ChangesetValue or null if not found */ public function getChangesetValue($changeset, $value_id, $has_changed) { $changeset_value = null; $value_ids = $this->getValueDao()->searchById($value_id, $this->id); $ugroups = array(); foreach ($value_ids as $v) { $ugroups[] = $v['ugroup_id']; } $changeset_value = new Tracker_Artifact_ChangesetValue_PermissionsOnArtifact($value_id, $this, $has_changed, $changeset->getArtifact()->useArtifactPermissions(), $ugroups); return $changeset_value; }
/** * say if the changeset is the first one for this artifact * * @return bool */ public function isFirstChangeset(Tracker_Artifact_Changeset $changeset) { $c = $this->getFirstChangeset(); return $c->getId() == $changeset->getId(); }
/** * Retrieve linked artifacts according to user's permissions * * @param Tracker_Artifact_Changeset $changeset The changeset you want to retrieve artifact from * @param User $user The user who will see the artifacts * * @return array of Tracker_Artifact */ public function getLinkedArtifacts(Tracker_Artifact_Changeset $changeset, User $user) { $artifacts = array(); $changeset_value = $changeset->getValue($this); if ($changeset_value) { foreach ($changeset_value->getArtifactIds() as $id) { $artifact = $this->getArtifactFactory()->getArtifactById($id); if ($artifact && $artifact->userCanView($user)) { $artifacts[] = $artifact; } } } return $artifacts; }
public function getFullRESTValue(PFUser $user, Tracker_Artifact_Changeset $changeset) { $value = new Tracker_FormElement_Field_List_Bind_UsersValue($changeset->getArtifact()->getSubmittedBy()); $submitted_by_value = $value->getFullRESTValue($this); $classname_with_namespace = 'Tuleap\\Tracker\\REST\\Artifact\\ArtifactFieldValueFullRepresentation'; $artifact_field_value_full_representation = new $classname_with_namespace(); $artifact_field_value_full_representation->build($this->getId(), Tracker_FormElementFactory::instance()->getType($this), $this->getLabel(), $submitted_by_value); return $artifact_field_value_full_representation; }
private function linkRawMailToChangeset($raw_mail, Tracker_Artifact_Changeset $changeset) { $this->incoming_mail_dao->save($changeset->getId(), $raw_mail); }
public function getJsonValue(PFUser $user, Tracker_Artifact_Changeset $changeset) { if ($this->userCanRead($user)) { $value = $changeset->getValue($this); return $value ? $value->getJsonValue() : ''; } return null; }
public function format(Tracker_Artifact_Changeset $changeset) { return array('id' => $changeset->getId(), 'submitted_by' => $changeset->getSubmittedBy(), 'submitted_on' => date('c', $changeset->getSubmittedOn()), 'email' => $changeset->getEmail(), 'html' => $this->getChangeContentForJson($changeset)); }
/** * @see Transition_PostAction::after() * @param Tracker_Artifact_Changeset $changeset */ public function after(Tracker_Artifact_Changeset $changeset) { if (!$this->isDefined()) { return; } $build_parameters = array(self::BUILD_PARAMETER_USER => $changeset->getSubmittedBy(), self::BUILD_PARAMETER_PROJECT_ID => $changeset->getArtifact()->getTracker()->getProject()->getID(), self::BUILD_PARAMETER_ARTIFACT_ID => $changeset->getArtifact()->getId(), self::BUILD_PARAMETER_TRACKER_ID => $changeset->getArtifact()->getTracker()->getId(), self::BUILD_PARAMETER_TRIGGER_FIELD_VALUE => $this->getTransition()->getFieldValueTo()->getLabel()); try { $this->ci_client->launchJobBuild($this->job_url, $build_parameters); $feedback = $GLOBALS['Language']->getText('workflow_postaction', 'ci_build_succeeded', array($this->job_url)); $GLOBALS['Response']->addFeedback('info', $feedback); } catch (Jenkins_ClientUnableToLaunchBuildException $exception) { $GLOBALS['Response']->addFeedback('error', $exception->getMessage()); } }