2012-12-11 22:59:20 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class PhabricatorApplicationTransactionComment
|
|
|
|
extends PhabricatorLiskDAO
|
2014-05-02 03:25:30 +02:00
|
|
|
implements
|
|
|
|
PhabricatorMarkupInterface,
|
|
|
|
PhabricatorPolicyInterface,
|
2014-07-21 15:59:22 +02:00
|
|
|
PhabricatorDestructibleInterface {
|
2012-12-11 22:59:20 +01:00
|
|
|
|
Modernize Macro application
Summary: Adds feed, email, notifications, comments, partial editing, subscriptions, enable/disable, flags and crumbs to Macro.
Test Plan:
{F26839}
{F26840}
{F26841}
{F26842}
{F26843}
{F26844}
{F26845}
Reviewers: vrana, btrahan, chad
Reviewed By: vrana
CC: aran
Maniphest Tasks: T2157, T175, T2104
Differential Revision: https://secure.phabricator.com/D4141
2012-12-11 23:01:03 +01:00
|
|
|
const MARKUP_FIELD_COMMENT = 'markup:comment';
|
|
|
|
|
2012-12-11 22:59:20 +01:00
|
|
|
protected $transactionPHID;
|
|
|
|
protected $commentVersion;
|
|
|
|
protected $authorPHID;
|
|
|
|
protected $viewPolicy;
|
|
|
|
protected $editPolicy;
|
|
|
|
protected $content;
|
|
|
|
protected $contentSource;
|
|
|
|
protected $isDeleted = 0;
|
|
|
|
|
|
|
|
abstract public function getApplicationTransactionObject();
|
|
|
|
|
|
|
|
public function generatePHID() {
|
|
|
|
return PhabricatorPHID::generateNewPHID(
|
|
|
|
PhabricatorPHIDConstants::PHID_TYPE_XCMT);
|
|
|
|
}
|
|
|
|
|
2015-01-13 20:47:05 +01:00
|
|
|
protected function getConfiguration() {
|
2012-12-11 22:59:20 +01:00
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
2014-09-18 17:32:44 +02:00
|
|
|
self::CONFIG_COLUMN_SCHEMA => array(
|
|
|
|
'transactionPHID' => 'phid?',
|
|
|
|
'commentVersion' => 'uint32',
|
|
|
|
'content' => 'text',
|
|
|
|
'contentSource' => 'text',
|
|
|
|
'isDeleted' => 'bool',
|
|
|
|
),
|
|
|
|
self::CONFIG_KEY_SCHEMA => array(
|
|
|
|
'key_version' => array(
|
|
|
|
'columns' => array('transactionPHID', 'commentVersion'),
|
2014-09-19 20:46:44 +02:00
|
|
|
'unique' => true,
|
2014-09-18 17:32:44 +02:00
|
|
|
),
|
|
|
|
),
|
2012-12-11 22:59:20 +01:00
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getApplicationName() {
|
|
|
|
return $this->getApplicationTransactionObject()->getApplicationName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTableName() {
|
|
|
|
$xaction = $this->getApplicationTransactionObject();
|
|
|
|
return self::getTableNameFromTransaction($xaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getTableNameFromTransaction(
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
return $xaction->getTableName().'_comment';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setContentSource(PhabricatorContentSource $content_source) {
|
|
|
|
$this->contentSource = $content_source->serialize();
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-05-24 19:48:34 +02:00
|
|
|
public function setContentSourceFromRequest(AphrontRequest $request) {
|
|
|
|
return $this->setContentSource(
|
|
|
|
PhabricatorContentSource::newFromRequest($request));
|
|
|
|
}
|
|
|
|
|
2012-12-11 22:59:20 +01:00
|
|
|
public function getContentSource() {
|
|
|
|
return PhabricatorContentSource::newFromSerialized($this->contentSource);
|
|
|
|
}
|
|
|
|
|
2014-05-05 19:55:32 +02:00
|
|
|
public function getIsRemoved() {
|
|
|
|
return ($this->getIsDeleted() == 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setIsRemoved($removed) {
|
|
|
|
if ($removed) {
|
|
|
|
$this->setIsDeleted(2);
|
|
|
|
} else {
|
|
|
|
$this->setIsDeleted(0);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-12-11 22:59:20 +01:00
|
|
|
|
|
|
|
/* -( PhabricatorMarkupInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getMarkupFieldKey($field) {
|
|
|
|
return PhabricatorPHIDConstants::PHID_TYPE_XCMT.':'.$this->getPHID();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function newMarkupEngine($field) {
|
2013-04-01 21:06:02 +02:00
|
|
|
return PhabricatorMarkupEngine::getEngine();
|
2012-12-11 22:59:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getMarkupText($field) {
|
|
|
|
return $this->getContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function didMarkupText($field, $output, PhutilMarkupEngine $engine) {
|
2013-02-26 06:10:41 +01:00
|
|
|
require_celerity_resource('phabricator-remarkup-css');
|
|
|
|
return phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-remarkup',
|
|
|
|
),
|
|
|
|
$output);
|
2012-12-11 22:59:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function shouldUseMarkupCache($field) {
|
|
|
|
return (bool)$this->getPHID();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -( PhabricatorPolicyInterface Implementation )-------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
switch ($capability) {
|
|
|
|
case PhabricatorPolicyCapability::CAN_VIEW:
|
|
|
|
return $this->getViewPolicy();
|
|
|
|
case PhabricatorPolicyCapability::CAN_EDIT:
|
|
|
|
return $this->getEditPolicy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return ($viewer->getPHID() == $this->getAuthorPHID());
|
|
|
|
}
|
|
|
|
|
2013-09-27 17:43:41 +02:00
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
// TODO: (T603) Policies are murky.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-05-02 03:25:30 +02:00
|
|
|
|
2014-07-21 15:59:22 +02:00
|
|
|
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
2014-05-02 03:25:30 +02:00
|
|
|
|
|
|
|
public function destroyObjectPermanently(
|
|
|
|
PhabricatorDestructionEngine $engine) {
|
|
|
|
$this->openTransaction();
|
|
|
|
$this->delete();
|
|
|
|
$this->saveTransaction();
|
|
|
|
}
|
|
|
|
|
2012-12-11 22:59:20 +01:00
|
|
|
}
|