1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 02:32:42 +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:
epriestley 2013-02-17 06:37:09 -08:00
parent 2231e5200a
commit 0ca7c77c10
6 changed files with 90 additions and 13 deletions

View file

@ -680,6 +680,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationTransactionController' => 'applications/transactions/controller/PhabricatorApplicationTransactionController.php', 'PhabricatorApplicationTransactionController' => 'applications/transactions/controller/PhabricatorApplicationTransactionController.php',
'PhabricatorApplicationTransactionEditor' => 'applications/transactions/editor/PhabricatorApplicationTransactionEditor.php', 'PhabricatorApplicationTransactionEditor' => 'applications/transactions/editor/PhabricatorApplicationTransactionEditor.php',
'PhabricatorApplicationTransactionFeedStory' => 'applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php', 'PhabricatorApplicationTransactionFeedStory' => 'applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php',
'PhabricatorApplicationTransactionInterface' => 'applications/transactions/interface/PhabricatorApplicationTransactionInterface.php',
'PhabricatorApplicationTransactionNoEffectException' => 'applications/transactions/exception/PhabricatorApplicationTransactionNoEffectException.php', 'PhabricatorApplicationTransactionNoEffectException' => 'applications/transactions/exception/PhabricatorApplicationTransactionNoEffectException.php',
'PhabricatorApplicationTransactionNoEffectResponse' => 'applications/transactions/response/PhabricatorApplicationTransactionNoEffectResponse.php', 'PhabricatorApplicationTransactionNoEffectResponse' => 'applications/transactions/response/PhabricatorApplicationTransactionNoEffectResponse.php',
'PhabricatorApplicationTransactionQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionQuery.php', 'PhabricatorApplicationTransactionQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionQuery.php',
@ -2390,6 +2391,7 @@ phutil_register_library_map(array(
array( array(
0 => 'PhabricatorFileDAO', 0 => 'PhabricatorFileDAO',
1 => 'PhabricatorSubscribableInterface', 1 => 'PhabricatorSubscribableInterface',
2 => 'PhabricatorApplicationTransactionInterface',
), ),
'PhabricatorFileInfoController' => 'PhabricatorFileController', 'PhabricatorFileInfoController' => 'PhabricatorFileController',
'PhabricatorFileLinkListView' => 'AphrontView', 'PhabricatorFileLinkListView' => 'AphrontView',

View file

@ -1,7 +1,9 @@
<?php <?php
final class PhabricatorFileImageMacro extends PhabricatorFileDAO final class PhabricatorFileImageMacro extends PhabricatorFileDAO
implements PhabricatorSubscribableInterface { implements
PhabricatorSubscribableInterface,
PhabricatorApplicationTransactionInterface {
protected $filePHID; protected $filePHID;
protected $phid; protected $phid;
@ -23,5 +25,13 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO
return false; return false;
} }
public function getApplicationTransactionEditor() {
return new PhabricatorMacroEditor();
}
public function getApplicationTransactionObject() {
return new PhabricatorMacroTransaction();
}
} }

View file

@ -8,7 +8,8 @@ final class PholioMock extends PholioDAO
PhabricatorMarkupInterface, PhabricatorMarkupInterface,
PhabricatorPolicyInterface, PhabricatorPolicyInterface,
PhabricatorSubscribableInterface, PhabricatorSubscribableInterface,
PhabricatorTokenReceiverInterface { PhabricatorTokenReceiverInterface,
PhabricatorApplicationTransactionInterface {
const MARKUP_FIELD_DESCRIPTION = 'markup:description'; const MARKUP_FIELD_DESCRIPTION = 'markup:description';
@ -123,4 +124,17 @@ final class PholioMock extends PholioDAO
return (bool)$this->getID(); return (bool)$this->getID();
} }
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new PholioMockEditor();
}
public function getApplicationTransactionObject() {
return new PholioTransaction();
}
} }

View file

@ -58,17 +58,49 @@ final class PhabricatorSubscriptionsEditController
$handle->getURI()); $handle->getURI());
} }
$editor = id(new PhabricatorSubscriptionsEditor()) if ($object instanceof PhabricatorApplicationTransactionInterface) {
->setActor($user) if ($is_add) {
->setObject($object); $xaction_value = array(
'+' => array($user->getPHID()),
);
} else {
$xaction_value = array(
'-' => array($user->getPHID()),
);
}
if ($is_add) { $xaction = id($object->getApplicationTransactionObject())
$editor->subscribeExplicit(array($user->getPHID()), $explicit = true); ->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 { } 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 // TODO: We should just render the "Unsubscribe" action and swap it out
// in the document for Ajax requests. // in the document for Ajax requests.

View file

@ -170,9 +170,20 @@ abstract class PhabricatorApplicationTransactionEditor
case PhabricatorTransactions::TYPE_SUBSCRIBERS: case PhabricatorTransactions::TYPE_SUBSCRIBERS:
$subeditor = id(new PhabricatorSubscriptionsEditor()) $subeditor = id(new PhabricatorSubscriptionsEditor())
->setObject($object) ->setObject($object)
->setActor($this->requireActor()) ->setActor($this->requireActor());
->subscribeExplicit($xaction->getNewValue())
->save(); $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; break;
} }
return $this->applyCustomExternalTransaction($object, $xaction); return $this->applyCustomExternalTransaction($object, $xaction);

View file

@ -0,0 +1,8 @@
<?php
interface PhabricatorApplicationTransactionInterface {
public function getApplicationTransactionEditor();
public function getApplicationTransactionObject();
}