Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120002108
PhabricatorApplicationTransactionCommentEditor.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jul 1, 05:56
Size
3 KB
Mime Type
text/x-php
Expires
Thu, Jul 3, 05:56 (2 d)
Engine
blob
Format
Raw Data
Handle
27079472
Attached To
rPH Phabricator
PhabricatorApplicationTransactionCommentEditor.php
View Options
<?php
final
class
PhabricatorApplicationTransactionCommentEditor
extends
PhabricatorEditor
{
private
$contentSource
;
private
$actingAsPHID
;
public
function
setActingAsPHID
(
$acting_as_phid
)
{
$this
->
actingAsPHID
=
$acting_as_phid
;
return
$this
;
}
public
function
getActingAsPHID
()
{
if
(
$this
->
actingAsPHID
)
{
return
$this
->
actingAsPHID
;
}
return
$this
->
getActor
()->
getPHID
();
}
public
function
setContentSource
(
PhabricatorContentSource
$content_source
)
{
$this
->
contentSource
=
$content_source
;
return
$this
;
}
public
function
getContentSource
()
{
return
$this
->
contentSource
;
}
/**
* Edit a transaction's comment. This method effects the required create,
* update or delete to set the transaction's comment to the provided comment.
*/
public
function
applyEdit
(
PhabricatorApplicationTransaction
$xaction
,
PhabricatorApplicationTransactionComment
$comment
)
{
$this
->
validateEdit
(
$xaction
,
$comment
);
$actor
=
$this
->
requireActor
();
$comment
->
setContentSource
(
$this
->
getContentSource
());
$comment
->
setAuthorPHID
(
$this
->
getActingAsPHID
());
// TODO: This needs to be more sophisticated once we have meta-policies.
$comment
->
setViewPolicy
(
PhabricatorPolicies
::
POLICY_PUBLIC
);
$comment
->
setEditPolicy
(
$this
->
getActingAsPHID
());
$xaction
->
openTransaction
();
$xaction
->
beginReadLocking
();
if
(
$xaction
->
getID
())
{
$xaction
->
reload
();
}
$new_version
=
$xaction
->
getCommentVersion
()
+
1
;
$comment
->
setCommentVersion
(
$new_version
);
$comment
->
setTransactionPHID
(
$xaction
->
getPHID
());
$comment
->
save
();
$xaction
->
setCommentVersion
(
$new_version
);
$xaction
->
setCommentPHID
(
$comment
->
getPHID
());
$xaction
->
setViewPolicy
(
$comment
->
getViewPolicy
());
$xaction
->
setEditPolicy
(
$comment
->
getEditPolicy
());
$xaction
->
save
();
$xaction
->
endReadLocking
();
$xaction
->
saveTransaction
();
$xaction
->
attachComment
(
$comment
);
// TODO: Emit an event for notifications/feed? Can we handle them
// generically?
return
$this
;
}
/**
* Validate that the edit is permissible, and the actor has permission to
* perform it.
*/
private
function
validateEdit
(
PhabricatorApplicationTransaction
$xaction
,
PhabricatorApplicationTransactionComment
$comment
)
{
if
(!
$xaction
->
getPHID
())
{
throw
new
Exception
(
'Transaction must have a PHID before calling applyEdit()!'
);
}
$type_comment
=
PhabricatorTransactions
::
TYPE_COMMENT
;
if
(
$xaction
->
getTransactionType
()
==
$type_comment
)
{
if
(
$comment
->
getPHID
())
{
throw
new
Exception
(
'Transaction comment must not yet have a PHID!'
);
}
}
if
(!
$this
->
getContentSource
())
{
throw
new
Exception
(
'Call setContentSource() before applyEdit()!'
);
}
$actor
=
$this
->
requireActor
();
PhabricatorPolicyFilter
::
requireCapability
(
$actor
,
$xaction
,
PhabricatorPolicyCapability
::
CAN_VIEW
);
if
(
$comment
->
getIsRemoved
()
&&
$actor
->
getIsAdmin
())
{
// NOTE: Administrators can remove comments by any user, and don't need
// to pass the edit check.
}
else
{
PhabricatorPolicyFilter
::
requireCapability
(
$actor
,
$xaction
,
PhabricatorPolicyCapability
::
CAN_EDIT
);
}
}
}
Event Timeline
Log In to Comment