2011-02-08 10:53:59 -08:00
|
|
|
<?php
|
|
|
|
|
2011-07-04 13:04:22 -07:00
|
|
|
/**
|
2012-07-11 11:40:10 -07:00
|
|
|
* @task markup Markup Interface
|
2011-07-04 13:04:22 -07:00
|
|
|
* @group maniphest
|
|
|
|
*/
|
2012-07-11 11:40:10 -07:00
|
|
|
final class ManiphestTransaction extends ManiphestDAO
|
|
|
|
implements PhabricatorMarkupInterface {
|
|
|
|
|
|
|
|
const MARKUP_FIELD_BODY = 'markup:body';
|
2011-02-08 10:53:59 -08:00
|
|
|
|
|
|
|
protected $taskID;
|
|
|
|
protected $authorPHID;
|
|
|
|
protected $transactionType;
|
|
|
|
protected $oldValue;
|
|
|
|
protected $newValue;
|
|
|
|
protected $comments;
|
2011-06-01 11:19:55 -07:00
|
|
|
protected $metadata = array();
|
Track content sources (email, web, conduit, mobile) for replies
Summary:
When an object is updated, record the content source for the update. This mostly
isn't terribly useful but one concrete thing I want to do with it is let admins
audit via-email replies more easily since there are a bunch of options which let
you do hyjinx if you intentionally configure them insecurely. I think having a
little more auditability around this feature is generally good. At some point
I'm going to turn this into a link admins can click to see details.
It also allows us to see how frequently different mechanisms are used, and lets
you see if someone is at their desk or on a mobile or whatever, at least
indirectly.
The "tablet" and "mobile" sources are currently unused but I figured I'd throw
them in anyway. SMS support should definitely happen at some point.
Not 100% sure about the design for this, I might change it to plain text at some
point.
Test Plan: Updated objects and saw update sources rendered.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, epriestley, jungejason
Differential Revision: 844
2011-08-22 10:25:45 -07:00
|
|
|
protected $contentSource;
|
2011-02-08 10:53:59 -08:00
|
|
|
|
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'oldValue' => self::SERIALIZATION_JSON,
|
|
|
|
'newValue' => self::SERIALIZATION_JSON,
|
2011-06-01 11:19:55 -07:00
|
|
|
'metadata' => self::SERIALIZATION_JSON,
|
2011-02-08 10:53:59 -08:00
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function extractPHIDs() {
|
|
|
|
$phids = array();
|
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
|
|
|
case ManiphestTransactionType::TYPE_CCS:
|
2011-02-20 20:08:16 -08:00
|
|
|
case ManiphestTransactionType::TYPE_PROJECTS:
|
2011-02-08 10:53:59 -08:00
|
|
|
foreach ($this->getOldValue() as $phid) {
|
|
|
|
$phids[] = $phid;
|
|
|
|
}
|
|
|
|
foreach ($this->getNewValue() as $phid) {
|
|
|
|
$phids[] = $phid;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ManiphestTransactionType::TYPE_OWNER:
|
|
|
|
$phids[] = $this->getOldValue();
|
|
|
|
$phids[] = $this->getNewValue();
|
|
|
|
break;
|
2012-07-02 15:42:06 -07:00
|
|
|
case ManiphestTransactionType::TYPE_EDGE:
|
2012-07-05 05:48:30 -07:00
|
|
|
$phids = array_merge(
|
|
|
|
$phids,
|
|
|
|
array_keys($this->getOldValue() + $this->getNewValue()));
|
|
|
|
break;
|
2011-02-17 14:32:01 -08:00
|
|
|
case ManiphestTransactionType::TYPE_ATTACH:
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
if (!is_array($old)) {
|
|
|
|
$old = array();
|
|
|
|
}
|
|
|
|
if (!is_array($new)) {
|
|
|
|
$new = array();
|
|
|
|
}
|
|
|
|
$val = array_merge(array_values($old), array_values($new));
|
|
|
|
foreach ($val as $stuff) {
|
|
|
|
foreach ($stuff as $phid => $ignored) {
|
|
|
|
$phids[] = $phid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-02-08 10:53:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
$phids[] = $this->getAuthorPHID();
|
|
|
|
|
|
|
|
return $phids;
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:03:28 -08:00
|
|
|
public function getMetadataValue($key, $default = null) {
|
|
|
|
if (!is_array($this->metadata)) {
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
return idx($this->metadata, $key, $default);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setMetadataValue($key, $value) {
|
|
|
|
if (!is_array($this->metadata)) {
|
|
|
|
$this->metadata = array();
|
|
|
|
}
|
|
|
|
$this->metadata[$key] = $value;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-09 12:47:24 -08:00
|
|
|
public function canGroupWith($target) {
|
|
|
|
if ($target->getAuthorPHID() != $this->getAuthorPHID()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($target->hasComments() && $this->hasComments()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$ttime = $target->getDateCreated();
|
2011-02-09 20:12:20 -08:00
|
|
|
$stime = $this->getDateCreated();
|
2011-02-09 12:47:24 -08:00
|
|
|
if (abs($stime - $ttime) > 60) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($target->getTransactionType() == $this->getTransactionType()) {
|
2011-12-23 19:03:28 -08:00
|
|
|
$aux_type = ManiphestTransactionType::TYPE_AUXILIARY;
|
|
|
|
if ($this->getTransactionType() == $aux_type) {
|
|
|
|
$that_key = $target->getMetadataValue('aux:key');
|
|
|
|
$this_key = $this->getMetadataValue('aux:key');
|
|
|
|
if ($that_key == $this_key) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-09 12:47:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasComments() {
|
|
|
|
return (bool)strlen(trim($this->getComments()));
|
|
|
|
}
|
|
|
|
|
Track content sources (email, web, conduit, mobile) for replies
Summary:
When an object is updated, record the content source for the update. This mostly
isn't terribly useful but one concrete thing I want to do with it is let admins
audit via-email replies more easily since there are a bunch of options which let
you do hyjinx if you intentionally configure them insecurely. I think having a
little more auditability around this feature is generally good. At some point
I'm going to turn this into a link admins can click to see details.
It also allows us to see how frequently different mechanisms are used, and lets
you see if someone is at their desk or on a mobile or whatever, at least
indirectly.
The "tablet" and "mobile" sources are currently unused but I figured I'd throw
them in anyway. SMS support should definitely happen at some point.
Not 100% sure about the design for this, I might change it to plain text at some
point.
Test Plan: Updated objects and saw update sources rendered.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, epriestley, jungejason
Differential Revision: 844
2011-08-22 10:25:45 -07:00
|
|
|
public function setContentSource(PhabricatorContentSource $content_source) {
|
|
|
|
$this->contentSource = $content_source->serialize();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getContentSource() {
|
|
|
|
return PhabricatorContentSource::newFromSerialized($this->contentSource);
|
|
|
|
}
|
2011-02-09 12:47:24 -08:00
|
|
|
|
2012-07-11 11:40:10 -07:00
|
|
|
|
|
|
|
/* -( Markup Interface )--------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task markup
|
|
|
|
*/
|
|
|
|
public function getMarkupFieldKey($field) {
|
|
|
|
if ($this->shouldUseMarkupCache($field)) {
|
|
|
|
$id = $this->getID();
|
|
|
|
} else {
|
|
|
|
$id = PhabricatorHash::digest($this->getMarkupText($field));
|
|
|
|
}
|
|
|
|
return "maniphest:x:{$field}:{$id}";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task markup
|
|
|
|
*/
|
|
|
|
public function getMarkupText($field) {
|
|
|
|
return $this->getComments();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task markup
|
|
|
|
*/
|
|
|
|
public function newMarkupEngine($field) {
|
|
|
|
return PhabricatorMarkupEngine::newManiphestMarkupEngine();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task markup
|
|
|
|
*/
|
|
|
|
public function didMarkupText(
|
|
|
|
$field,
|
|
|
|
$output,
|
|
|
|
PhutilMarkupEngine $engine) {
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @task markup
|
|
|
|
*/
|
|
|
|
public function shouldUseMarkupCache($field) {
|
|
|
|
return (bool)$this->getID();
|
|
|
|
}
|
|
|
|
|
2011-02-08 10:53:59 -08:00
|
|
|
}
|