2011-02-08 19:53:59 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-03-14 00:21:04 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-02-08 19:53:59 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-07-04 22:04:22 +02:00
|
|
|
/**
|
|
|
|
* @group maniphest
|
|
|
|
*/
|
2012-03-14 00:21:04 +01:00
|
|
|
final class ManiphestTransaction extends ManiphestDAO {
|
2011-02-08 19:53:59 +01:00
|
|
|
|
|
|
|
protected $taskID;
|
|
|
|
protected $authorPHID;
|
|
|
|
protected $transactionType;
|
|
|
|
protected $oldValue;
|
|
|
|
protected $newValue;
|
|
|
|
protected $comments;
|
|
|
|
protected $cache;
|
2011-06-01 20:19:55 +02: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 19:25:45 +02:00
|
|
|
protected $contentSource;
|
2011-02-08 19:53:59 +01:00
|
|
|
|
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_SERIALIZATION => array(
|
|
|
|
'oldValue' => self::SERIALIZATION_JSON,
|
|
|
|
'newValue' => self::SERIALIZATION_JSON,
|
2011-06-01 20:19:55 +02:00
|
|
|
'metadata' => self::SERIALIZATION_JSON,
|
2011-02-08 19:53:59 +01:00
|
|
|
),
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function extractPHIDs() {
|
|
|
|
$phids = array();
|
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
|
|
|
case ManiphestTransactionType::TYPE_CCS:
|
2011-02-21 05:08:16 +01:00
|
|
|
case ManiphestTransactionType::TYPE_PROJECTS:
|
2011-02-08 19:53:59 +01: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-03 00:42:06 +02:00
|
|
|
case ManiphestTransactionType::TYPE_EDGE:
|
2012-07-05 14:48:30 +02:00
|
|
|
$phids = array_merge(
|
|
|
|
$phids,
|
|
|
|
array_keys($this->getOldValue() + $this->getNewValue()));
|
|
|
|
break;
|
2011-02-17 23:32:01 +01: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 19:53:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$phids[] = $this->getAuthorPHID();
|
|
|
|
|
|
|
|
return $phids;
|
|
|
|
}
|
|
|
|
|
2011-12-24 04:03:28 +01: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 21:47:24 +01:00
|
|
|
public function canGroupWith($target) {
|
|
|
|
if ($target->getAuthorPHID() != $this->getAuthorPHID()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($target->hasComments() && $this->hasComments()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$ttime = $target->getDateCreated();
|
2011-02-10 05:12:20 +01:00
|
|
|
$stime = $this->getDateCreated();
|
2011-02-09 21:47:24 +01:00
|
|
|
if (abs($stime - $ttime) > 60) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($target->getTransactionType() == $this->getTransactionType()) {
|
2011-12-24 04:03:28 +01: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 21:47:24 +01: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 19:25:45 +02: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 21:47:24 +01:00
|
|
|
|
2011-02-08 19:53:59 +01:00
|
|
|
}
|