2012-01-24 16:11:37 +01:00
|
|
|
<?php
|
|
|
|
|
2013-10-22 22:49:28 +02:00
|
|
|
final class PhabricatorProjectTransaction
|
2017-05-16 23:40:15 +02:00
|
|
|
extends PhabricatorModularTransaction {
|
2012-01-24 16:11:37 +01:00
|
|
|
|
2014-09-18 20:00:50 +02:00
|
|
|
const TYPE_LOCKED = 'project:locked';
|
2015-12-23 12:42:51 +01:00
|
|
|
const TYPE_PARENT = 'project:parent';
|
2015-12-23 12:12:20 +01:00
|
|
|
const TYPE_MILESTONE = 'project:milestone';
|
2016-02-08 20:24:32 +01:00
|
|
|
const TYPE_HASWORKBOARD = 'project:hasworkboard';
|
2016-02-12 15:19:26 +01:00
|
|
|
const TYPE_DEFAULT_SORT = 'project:sort';
|
|
|
|
const TYPE_DEFAULT_FILTER = 'project:filter';
|
2016-02-16 15:52:32 +01:00
|
|
|
const TYPE_BACKGROUND = 'project:background';
|
2014-02-10 23:32:30 +01:00
|
|
|
|
|
|
|
// NOTE: This is deprecated, members are just a normal edge now.
|
|
|
|
const TYPE_MEMBERS = 'project:members';
|
2012-01-24 16:11:37 +01:00
|
|
|
|
2015-06-16 23:25:13 +02:00
|
|
|
const MAILTAG_METADATA = 'project-metadata';
|
|
|
|
const MAILTAG_MEMBERS = 'project-members';
|
|
|
|
const MAILTAG_WATCHERS = 'project-watchers';
|
|
|
|
const MAILTAG_OTHER = 'project-other';
|
2015-05-16 01:33:31 +02:00
|
|
|
|
2013-10-22 22:49:28 +02:00
|
|
|
public function getApplicationName() {
|
|
|
|
return 'project';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationTransactionType() {
|
2014-07-24 00:05:46 +02:00
|
|
|
return PhabricatorProjectProjectPHIDType::TYPECONST;
|
2012-01-24 16:11:37 +01:00
|
|
|
}
|
|
|
|
|
2017-05-16 23:40:15 +02:00
|
|
|
public function getBaseTransactionClass() {
|
|
|
|
return 'PhabricatorProjectTransactionType';
|
|
|
|
}
|
|
|
|
|
2013-10-22 22:49:37 +02:00
|
|
|
public function getRequiredHandlePHIDs() {
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
$req_phids = array();
|
|
|
|
switch ($this->getTransactionType()) {
|
2015-05-13 22:50:28 +02:00
|
|
|
case self::TYPE_MEMBERS:
|
2013-10-22 22:49:37 +02:00
|
|
|
$add = array_diff($new, $old);
|
|
|
|
$rem = array_diff($old, $new);
|
|
|
|
$req_phids = array_merge($add, $rem);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_merge($req_phids, parent::getRequiredHandlePHIDs());
|
|
|
|
}
|
|
|
|
|
2016-02-29 01:28:43 +01:00
|
|
|
public function shouldHide() {
|
|
|
|
switch ($this->getTransactionType()) {
|
|
|
|
case PhabricatorTransactions::TYPE_EDGE:
|
|
|
|
$edge_type = $this->getMetadataValue('edge:type');
|
|
|
|
switch ($edge_type) {
|
|
|
|
case PhabricatorProjectSilencedEdgeType::EDGECONST:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::shouldHide();
|
|
|
|
}
|
|
|
|
|
2016-02-12 15:19:26 +01:00
|
|
|
public function shouldHideForFeed() {
|
|
|
|
switch ($this->getTransactionType()) {
|
|
|
|
case self::TYPE_HASWORKBOARD:
|
|
|
|
case self::TYPE_DEFAULT_SORT:
|
|
|
|
case self::TYPE_DEFAULT_FILTER:
|
2016-02-16 15:52:32 +01:00
|
|
|
case self::TYPE_BACKGROUND:
|
2016-02-12 15:19:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::shouldHideForFeed();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldHideForMail(array $xactions) {
|
|
|
|
switch ($this->getTransactionType()) {
|
|
|
|
case self::TYPE_HASWORKBOARD:
|
|
|
|
case self::TYPE_DEFAULT_SORT:
|
|
|
|
case self::TYPE_DEFAULT_FILTER:
|
2016-02-16 15:52:32 +01:00
|
|
|
case self::TYPE_BACKGROUND:
|
2016-02-12 15:19:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-01-19 19:14:27 +01:00
|
|
|
|
2016-02-12 15:19:26 +01:00
|
|
|
return parent::shouldHideForMail($xactions);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIcon() {
|
2015-01-19 19:14:27 +01:00
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
2015-05-13 22:50:28 +02:00
|
|
|
case self::TYPE_LOCKED:
|
2015-01-19 19:14:27 +01:00
|
|
|
if ($new) {
|
|
|
|
return 'fa-lock';
|
|
|
|
} else {
|
|
|
|
return 'fa-unlock';
|
|
|
|
}
|
2015-05-13 22:50:28 +02:00
|
|
|
case self::TYPE_MEMBERS:
|
2015-01-19 19:14:27 +01:00
|
|
|
return 'fa-user';
|
|
|
|
}
|
|
|
|
return parent::getIcon();
|
|
|
|
}
|
|
|
|
|
2013-10-22 22:49:37 +02:00
|
|
|
public function getTitle() {
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
2015-12-27 15:45:53 +01:00
|
|
|
$author_phid = $this->getAuthorPHID();
|
|
|
|
$author_handle = $this->renderHandleLink($author_phid);
|
2013-10-22 22:49:37 +02:00
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
2015-12-27 15:45:53 +01:00
|
|
|
case PhabricatorTransactions::TYPE_CREATE:
|
|
|
|
return pht(
|
|
|
|
'%s created this project.',
|
|
|
|
$this->renderHandleLink($author_phid));
|
|
|
|
|
2015-05-13 22:50:28 +02:00
|
|
|
case self::TYPE_LOCKED:
|
2014-09-18 20:00:50 +02:00
|
|
|
if ($new) {
|
|
|
|
return pht(
|
2015-05-22 09:27:56 +02:00
|
|
|
"%s locked this project's membership.",
|
2014-09-18 20:00:50 +02:00
|
|
|
$author_handle);
|
|
|
|
} else {
|
|
|
|
return pht(
|
2015-05-22 09:27:56 +02:00
|
|
|
"%s unlocked this project's membership.",
|
2014-09-18 20:00:50 +02:00
|
|
|
$author_handle);
|
|
|
|
}
|
2015-05-16 01:33:31 +02:00
|
|
|
break;
|
2014-09-18 20:00:50 +02:00
|
|
|
|
2015-05-13 22:50:28 +02:00
|
|
|
case self::TYPE_MEMBERS:
|
2013-10-22 22:49:37 +02:00
|
|
|
$add = array_diff($new, $old);
|
|
|
|
$rem = array_diff($old, $new);
|
|
|
|
|
|
|
|
if ($add && $rem) {
|
|
|
|
return pht(
|
2015-01-01 05:40:04 +01:00
|
|
|
'%s changed project member(s), added %d: %s; removed %d: %s.',
|
2013-10-22 22:49:37 +02:00
|
|
|
$author_handle,
|
|
|
|
count($add),
|
|
|
|
$this->renderHandleList($add),
|
|
|
|
count($rem),
|
|
|
|
$this->renderHandleList($rem));
|
|
|
|
} else if ($add) {
|
|
|
|
if (count($add) == 1 && (head($add) == $this->getAuthorPHID())) {
|
|
|
|
return pht(
|
|
|
|
'%s joined this project.',
|
|
|
|
$author_handle);
|
|
|
|
} else {
|
|
|
|
return pht(
|
2015-01-01 05:40:04 +01:00
|
|
|
'%s added %d project member(s): %s.',
|
2013-10-22 22:49:37 +02:00
|
|
|
$author_handle,
|
|
|
|
count($add),
|
|
|
|
$this->renderHandleList($add));
|
|
|
|
}
|
|
|
|
} else if ($rem) {
|
|
|
|
if (count($rem) == 1 && (head($rem) == $this->getAuthorPHID())) {
|
|
|
|
return pht(
|
|
|
|
'%s left this project.',
|
|
|
|
$author_handle);
|
|
|
|
} else {
|
|
|
|
return pht(
|
2015-01-01 05:40:04 +01:00
|
|
|
'%s removed %d project member(s): %s.',
|
2013-10-22 22:49:37 +02:00
|
|
|
$author_handle,
|
|
|
|
count($rem),
|
|
|
|
$this->renderHandleList($rem));
|
|
|
|
}
|
|
|
|
}
|
2015-05-16 01:33:31 +02:00
|
|
|
break;
|
2016-02-08 20:24:32 +01:00
|
|
|
|
|
|
|
case self::TYPE_HASWORKBOARD:
|
|
|
|
if ($new) {
|
|
|
|
return pht(
|
|
|
|
'%s enabled the workboard for this project.',
|
|
|
|
$author_handle);
|
|
|
|
} else {
|
|
|
|
return pht(
|
|
|
|
'%s disabled the workboard for this project.',
|
|
|
|
$author_handle);
|
|
|
|
}
|
2016-02-12 15:19:26 +01:00
|
|
|
|
|
|
|
case self::TYPE_DEFAULT_SORT:
|
|
|
|
return pht(
|
|
|
|
'%s changed the default sort order for the project workboard.',
|
|
|
|
$author_handle);
|
|
|
|
|
|
|
|
case self::TYPE_DEFAULT_FILTER:
|
|
|
|
return pht(
|
|
|
|
'%s changed the default filter for the project workboard.',
|
|
|
|
$author_handle);
|
2016-02-16 15:52:32 +01:00
|
|
|
|
|
|
|
case self::TYPE_BACKGROUND:
|
|
|
|
return pht(
|
|
|
|
'%s changed the background color of the project workboard.',
|
|
|
|
$author_handle);
|
2013-10-22 22:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getTitle();
|
|
|
|
}
|
|
|
|
|
2015-05-02 02:34:43 +02:00
|
|
|
public function getTitleForFeed() {
|
|
|
|
$author_phid = $this->getAuthorPHID();
|
|
|
|
$object_phid = $this->getObjectPHID();
|
|
|
|
$author_handle = $this->renderHandleLink($author_phid);
|
|
|
|
$object_handle = $this->renderHandleLink($object_phid);
|
|
|
|
|
|
|
|
$old = $this->getOldValue();
|
|
|
|
$new = $this->getNewValue();
|
|
|
|
|
|
|
|
switch ($this->getTransactionType()) {
|
|
|
|
case self::TYPE_LOCKED:
|
|
|
|
if ($new) {
|
|
|
|
return pht(
|
2017-05-19 23:08:55 +02:00
|
|
|
'%s locked membership for %s.',
|
2015-05-02 02:34:43 +02:00
|
|
|
$author_handle,
|
|
|
|
$object_handle);
|
|
|
|
} else {
|
|
|
|
return pht(
|
2017-05-19 23:08:55 +02:00
|
|
|
'%s unlocked membership for %s.',
|
2015-05-02 02:34:43 +02:00
|
|
|
$author_handle,
|
|
|
|
$object_handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getTitleForFeed();
|
|
|
|
}
|
|
|
|
|
2015-05-16 01:33:31 +02:00
|
|
|
public function getMailTags() {
|
|
|
|
$tags = array();
|
|
|
|
switch ($this->getTransactionType()) {
|
2017-05-18 20:03:31 +02:00
|
|
|
case PhabricatorProjectNameTransaction::TRANSACTIONTYPE:
|
|
|
|
case PhabricatorProjectSlugsTransaction::TRANSACTIONTYPE:
|
2017-05-19 00:14:02 +02:00
|
|
|
case PhabricatorProjectImageTransaction::TRANSACTIONTYPE:
|
2017-05-19 01:15:24 +02:00
|
|
|
case PhabricatorProjectIconTransaction::TRANSACTIONTYPE:
|
2017-05-19 01:32:04 +02:00
|
|
|
case PhabricatorProjectColorTransaction::TRANSACTIONTYPE:
|
2015-05-16 01:33:31 +02:00
|
|
|
$tags[] = self::MAILTAG_METADATA;
|
|
|
|
break;
|
|
|
|
case PhabricatorTransactions::TYPE_EDGE:
|
|
|
|
$type = $this->getMetadata('edge:type');
|
|
|
|
$type = head($type);
|
|
|
|
$type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
|
|
|
|
$type_watcher = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
|
|
|
|
if ($type == $type_member) {
|
|
|
|
$tags[] = self::MAILTAG_MEMBERS;
|
|
|
|
} else if ($type == $type_watcher) {
|
|
|
|
$tags[] = self::MAILTAG_WATCHERS;
|
|
|
|
} else {
|
|
|
|
$tags[] = self::MAILTAG_OTHER;
|
|
|
|
}
|
|
|
|
break;
|
2017-05-18 20:24:59 +02:00
|
|
|
case PhabricatorProjectStatusTransaction::TRANSACTIONTYPE:
|
2015-05-16 01:33:31 +02:00
|
|
|
case self::TYPE_LOCKED:
|
|
|
|
default:
|
|
|
|
$tags[] = self::MAILTAG_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
|
2012-01-24 16:11:37 +01:00
|
|
|
}
|