mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-27 07:50:57 +01:00
Integrate subscriptions with ApplicationTransactions
Summary: Fixes T2214. For objects which support ApplicationTransaction, use ApplicationTransactions to apply subscription action changes. Principally, this makes clicking "Subscribe" / "Unsubscribe" appear correctly in the transaction log. Test Plan: Clicked "Subscribe" and "Unsubscribe" a on Macros and Mocks. Reviewers: chad Reviewed By: chad CC: aran Maniphest Tasks: T2214 Differential Revision: https://secure.phabricator.com/D4986
This commit is contained in:
parent
2231e5200a
commit
0ca7c77c10
6 changed files with 90 additions and 13 deletions
|
@ -680,6 +680,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationTransactionController' => 'applications/transactions/controller/PhabricatorApplicationTransactionController.php',
|
||||
'PhabricatorApplicationTransactionEditor' => 'applications/transactions/editor/PhabricatorApplicationTransactionEditor.php',
|
||||
'PhabricatorApplicationTransactionFeedStory' => 'applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php',
|
||||
'PhabricatorApplicationTransactionInterface' => 'applications/transactions/interface/PhabricatorApplicationTransactionInterface.php',
|
||||
'PhabricatorApplicationTransactionNoEffectException' => 'applications/transactions/exception/PhabricatorApplicationTransactionNoEffectException.php',
|
||||
'PhabricatorApplicationTransactionNoEffectResponse' => 'applications/transactions/response/PhabricatorApplicationTransactionNoEffectResponse.php',
|
||||
'PhabricatorApplicationTransactionQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionQuery.php',
|
||||
|
@ -2390,6 +2391,7 @@ phutil_register_library_map(array(
|
|||
array(
|
||||
0 => 'PhabricatorFileDAO',
|
||||
1 => 'PhabricatorSubscribableInterface',
|
||||
2 => 'PhabricatorApplicationTransactionInterface',
|
||||
),
|
||||
'PhabricatorFileInfoController' => 'PhabricatorFileController',
|
||||
'PhabricatorFileLinkListView' => 'AphrontView',
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFileImageMacro extends PhabricatorFileDAO
|
||||
implements PhabricatorSubscribableInterface {
|
||||
implements
|
||||
PhabricatorSubscribableInterface,
|
||||
PhabricatorApplicationTransactionInterface {
|
||||
|
||||
protected $filePHID;
|
||||
protected $phid;
|
||||
|
@ -23,5 +25,13 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
|
|||
return false;
|
||||
}
|
||||
|
||||
public function getApplicationTransactionEditor() {
|
||||
return new PhabricatorMacroEditor();
|
||||
}
|
||||
|
||||
public function getApplicationTransactionObject() {
|
||||
return new PhabricatorMacroTransaction();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ final class PholioMock extends PholioDAO
|
|||
PhabricatorMarkupInterface,
|
||||
PhabricatorPolicyInterface,
|
||||
PhabricatorSubscribableInterface,
|
||||
PhabricatorTokenReceiverInterface {
|
||||
PhabricatorTokenReceiverInterface,
|
||||
PhabricatorApplicationTransactionInterface {
|
||||
|
||||
const MARKUP_FIELD_DESCRIPTION = 'markup:description';
|
||||
|
||||
|
@ -123,4 +124,17 @@ final class PholioMock extends PholioDAO
|
|||
return (bool)$this->getID();
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
|
||||
|
||||
|
||||
public function getApplicationTransactionEditor() {
|
||||
return new PholioMockEditor();
|
||||
}
|
||||
|
||||
public function getApplicationTransactionObject() {
|
||||
return new PholioTransaction();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -58,17 +58,49 @@ final class PhabricatorSubscriptionsEditController
|
|||
$handle->getURI());
|
||||
}
|
||||
|
||||
$editor = id(new PhabricatorSubscriptionsEditor())
|
||||
->setActor($user)
|
||||
->setObject($object);
|
||||
if ($object instanceof PhabricatorApplicationTransactionInterface) {
|
||||
if ($is_add) {
|
||||
$xaction_value = array(
|
||||
'+' => array($user->getPHID()),
|
||||
);
|
||||
} else {
|
||||
$xaction_value = array(
|
||||
'-' => array($user->getPHID()),
|
||||
);
|
||||
}
|
||||
|
||||
if ($is_add) {
|
||||
$editor->subscribeExplicit(array($user->getPHID()), $explicit = true);
|
||||
$xaction = id($object->getApplicationTransactionObject())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
|
||||
->setNewValue($xaction_value);
|
||||
|
||||
$editor = id($object->getApplicationTransactionEditor())
|
||||
->setActor($user)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContentSource(
|
||||
PhabricatorContentSource::newForSource(
|
||||
PhabricatorContentSource::SOURCE_WEB,
|
||||
array(
|
||||
'ip' => $request->getRemoteAddr(),
|
||||
)));
|
||||
|
||||
$editor->applyTransactions($object, array($xaction));
|
||||
} else {
|
||||
$editor->unsubscribe(array($user->getPHID()));
|
||||
}
|
||||
|
||||
$editor->save();
|
||||
// TODO: Eventually, get rid of this once everything implements
|
||||
// PhabriatorApplicationTransactionInterface.
|
||||
|
||||
$editor = id(new PhabricatorSubscriptionsEditor())
|
||||
->setActor($user)
|
||||
->setObject($object);
|
||||
|
||||
if ($is_add) {
|
||||
$editor->subscribeExplicit(array($user->getPHID()), $explicit = true);
|
||||
} else {
|
||||
$editor->unsubscribe(array($user->getPHID()));
|
||||
}
|
||||
|
||||
$editor->save();
|
||||
}
|
||||
|
||||
// TODO: We should just render the "Unsubscribe" action and swap it out
|
||||
// in the document for Ajax requests.
|
||||
|
|
|
@ -170,9 +170,20 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
|
||||
$subeditor = id(new PhabricatorSubscriptionsEditor())
|
||||
->setObject($object)
|
||||
->setActor($this->requireActor())
|
||||
->subscribeExplicit($xaction->getNewValue())
|
||||
->save();
|
||||
->setActor($this->requireActor());
|
||||
|
||||
$old_map = array_fuse($xaction->getOldValue());
|
||||
$new_map = array_fuse($xaction->getNewValue());
|
||||
|
||||
$subeditor->unsubscribe(
|
||||
array_keys(
|
||||
array_diff_key($old_map, $new_map)));
|
||||
|
||||
$subeditor->subscribeExplicit(
|
||||
array_keys(
|
||||
array_diff_key($new_map, $old_map)));
|
||||
|
||||
$subeditor->save();
|
||||
break;
|
||||
}
|
||||
return $this->applyCustomExternalTransaction($object, $xaction);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
interface PhabricatorApplicationTransactionInterface {
|
||||
|
||||
public function getApplicationTransactionEditor();
|
||||
public function getApplicationTransactionObject();
|
||||
|
||||
}
|
Loading…
Reference in a new issue