Skip to content

Commit 524c2ac

Browse files
author
epriestley
committedJun 6, 2013
Flesh out ApplicationTransactions/CustomField integration
Summary: None of this code is reachable yet. See discussion in D6147. Ref T1703. Provide tighter integration between ApplicationTransactions and CustomField. Basically, I'm just trying to get all the shared stuff into the base implementation. Test Plan: Code not reachable. Reviewers: chad, seporaitis Reviewed By: chad CC: aran Maniphest Tasks: T1703 Differential Revision: https://secure.phabricator.com/D6149
1 parent b7c5841 commit 524c2ac

8 files changed

+462
-14
lines changed
 

‎src/__phutil_library_map__.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@
921921
'PhabricatorCustomFieldDataNotAvailableException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldDataNotAvailableException.php',
922922
'PhabricatorCustomFieldImplementationIncompleteException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldImplementationIncompleteException.php',
923923
'PhabricatorCustomFieldIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldIndexStorage.php',
924+
'PhabricatorCustomFieldInterface' => 'infrastructure/customfield/interface/PhabricatorCustomFieldInterface.php',
925+
'PhabricatorCustomFieldNotAttachedException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldNotAttachedException.php',
924926
'PhabricatorCustomFieldNumericIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldNumericIndexStorage.php',
925927
'PhabricatorCustomFieldStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStorage.php',
926928
'PhabricatorCustomFieldStringIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStringIndexStorage.php',
@@ -1541,7 +1543,7 @@
15411543
'PhabricatorUnitsTestCase' => 'view/__tests__/PhabricatorUnitsTestCase.php',
15421544
'PhabricatorUser' => 'applications/people/storage/PhabricatorUser.php',
15431545
'PhabricatorUserDAO' => 'applications/people/storage/PhabricatorUserDAO.php',
1544-
'PhabricatorUserEditor' => 'applications/people/PhabricatorUserEditor.php',
1546+
'PhabricatorUserEditor' => 'applications/people/editor/PhabricatorUserEditor.php',
15451547
'PhabricatorUserEmail' => 'applications/people/storage/PhabricatorUserEmail.php',
15461548
'PhabricatorUserLDAPInfo' => 'applications/people/storage/PhabricatorUserLDAPInfo.php',
15471549
'PhabricatorUserLog' => 'applications/people/storage/PhabricatorUserLog.php',
@@ -1554,6 +1556,7 @@
15541556
'PhabricatorUserStatusInvalidEpochException' => 'applications/people/exception/PhabricatorUserStatusInvalidEpochException.php',
15551557
'PhabricatorUserStatusOverlapException' => 'applications/people/exception/PhabricatorUserStatusOverlapException.php',
15561558
'PhabricatorUserTestCase' => 'applications/people/storage/__tests__/PhabricatorUserTestCase.php',
1559+
'PhabricatorUserTransaction' => 'applications/people/storage/PhabricatorUserTransaction.php',
15571560
'PhabricatorWorkboardExample' => 'applications/uiexample/examples/PhabricatorWorkboardExample.php',
15581561
'PhabricatorWorkboardView' => 'view/layout/PhabricatorWorkboardView.php',
15591562
'PhabricatorWorker' => 'infrastructure/daemon/workers/PhabricatorWorker.php',
@@ -2764,6 +2767,7 @@
27642767
'PhabricatorCustomFieldDataNotAvailableException' => 'Exception',
27652768
'PhabricatorCustomFieldImplementationIncompleteException' => 'Exception',
27662769
'PhabricatorCustomFieldIndexStorage' => 'PhabricatorLiskDAO',
2770+
'PhabricatorCustomFieldNotAttachedException' => 'Exception',
27672771
'PhabricatorCustomFieldNumericIndexStorage' => 'PhabricatorCustomFieldIndexStorage',
27682772
'PhabricatorCustomFieldStorage' => 'PhabricatorLiskDAO',
27692773
'PhabricatorCustomFieldStringIndexStorage' => 'PhabricatorCustomFieldIndexStorage',
@@ -3385,6 +3389,7 @@
33853389
'PhabricatorUserStatusInvalidEpochException' => 'Exception',
33863390
'PhabricatorUserStatusOverlapException' => 'Exception',
33873391
'PhabricatorUserTestCase' => 'PhabricatorTestCase',
3392+
'PhabricatorUserTransaction' => 'PhabricatorApplicationTransaction',
33883393
'PhabricatorWorkboardExample' => 'PhabricatorUIExample',
33893394
'PhabricatorWorkboardView' => 'AphrontView',
33903395
'PhabricatorWorkerActiveTask' => 'PhabricatorWorkerTask',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
final class PhabricatorUserTransaction
4+
extends PhabricatorApplicationTransaction {
5+
6+
public function getApplicationName() {
7+
return 'user';
8+
}
9+
10+
public function getApplicationTransactionType() {
11+
return PhabricatorPHIDConstants::PHID_TYPE_USER;
12+
}
13+
14+
public function getApplicationTransactionCommentObject() {
15+
return null;
16+
}
17+
18+
public function getApplicationObjectTypeName() {
19+
return pht('user');
20+
}
21+
22+
}
23+

‎src/applications/transactions/constants/PhabricatorTransactions.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ final class PhabricatorTransactions {
77
const TYPE_VIEW_POLICY = 'core:view-policy';
88
const TYPE_EDIT_POLICY = 'core:edit-policy';
99
const TYPE_EDGE = 'core:edge';
10+
const TYPE_CUSTOMFIELD = 'core:customfield';
1011

1112
const COLOR_RED = 'red';
1213
const COLOR_ORANGE = 'orange';

‎src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php

+56
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public function getTransactionTypes() {
7878
$types[] = PhabricatorTransactions::TYPE_SUBSCRIBERS;
7979
}
8080

81+
if ($this->object instanceof PhabricatorCustomFieldInterface) {
82+
$types[] = PhabricatorTransactions::TYPE_CUSTOMFIELD;
83+
}
84+
8185
return $types;
8286
}
8387

@@ -121,6 +125,9 @@ private function getTransactionOldValue(
121125
$old_edges = $old_edges[$edge_src][$edge_type];
122126
}
123127
return $old_edges;
128+
case PhabricatorTransactions::TYPE_CUSTOMFIELD:
129+
$field = $this->getCustomFieldForTransaction($object, $xaction);
130+
return $field->getOldValueForApplicationTransactions();
124131
default:
125132
return $this->getCustomTransactionOldValue($object, $xaction);
126133
}
@@ -137,6 +144,9 @@ private function getTransactionNewValue(
137144
return $xaction->getNewValue();
138145
case PhabricatorTransactions::TYPE_EDGE:
139146
return $this->getEdgeTransactionNewValue($xaction);
147+
case PhabricatorTransactions::TYPE_CUSTOMFIELD:
148+
$field = $this->getCustomFieldForTransaction($object, $xaction);
149+
return $field->getNewValueForApplicationTransactions();
140150
default:
141151
return $this->getCustomTransactionNewValue($object, $xaction);
142152
}
@@ -161,6 +171,9 @@ protected function transactionHasEffect(
161171
switch ($xaction->getTransactionType()) {
162172
case PhabricatorTransactions::TYPE_COMMENT:
163173
return $xaction->hasComment();
174+
case PhabricatorTransactions::TYPE_CUSTOMFIELD:
175+
$field = $this->getCustomFieldForTransaction($object, $xaction);
176+
return $field->getApplicationTransactionHasEffect($xaction);
164177
}
165178

166179
return ($xaction->getOldValue() !== $xaction->getNewValue());
@@ -176,6 +189,9 @@ private function applyInternalEffects(
176189
case PhabricatorTransactions::TYPE_EDIT_POLICY:
177190
$object->setEditPolicy($xaction->getNewValue());
178191
break;
192+
case PhabricatorTransactions::TYPE_CUSTOMFIELD:
193+
$field = $this->getCustomFieldForTransaction($object, $xaction);
194+
return $field->applyApplicationTransactionInternalEffects($xaction);
179195
}
180196
return $this->applyCustomInternalTransaction($object, $xaction);
181197
}
@@ -240,6 +256,9 @@ private function applyExternalEffects(
240256

241257
$editor->save();
242258
break;
259+
case PhabricatorTransactions::TYPE_CUSTOMFIELD:
260+
$field = $this->getCustomFieldForTransaction($object, $xaction);
261+
return $field->applyApplicationTransactionExternalEffects($xaction);
243262
}
244263

245264
return $this->applyCustomExternalTransaction($object, $xaction);
@@ -1244,4 +1263,41 @@ protected function supportsSearch() {
12441263
return false;
12451264
}
12461265

1266+
1267+
/* -( Custom Fields )------------------------------------------------------- */
1268+
1269+
1270+
/**
1271+
* @task customfield
1272+
*/
1273+
private function getCustomFieldForTransaction(
1274+
PhabricatorLiskDAO $object,
1275+
PhabricatorApplicationTransaction $xaction) {
1276+
1277+
$field_key = $xaction->getMetadataValue('customfield:key');
1278+
if (!$field_key) {
1279+
throw new Exception(
1280+
"Custom field transaction has no 'customfield:key'!");
1281+
}
1282+
1283+
$field = PhabricatorCustomField::getObjectField(
1284+
$object,
1285+
PhabricatorCustomField::ROLE_APPLICATIONTRANSACTIONS,
1286+
$field_key);
1287+
1288+
if (!$field) {
1289+
throw new Exception(
1290+
"Custom field transaction has invalid 'customfield:key'; field ".
1291+
"'{$field_key}' is disabled or does not exist.");
1292+
}
1293+
1294+
if (!$field->shouldAppearInApplicationTransactions()) {
1295+
throw new Exception(
1296+
"Custom field transaction '{$field_key}' does not implement ".
1297+
"integration for ApplicationTransactions.");
1298+
}
1299+
1300+
return $field;
1301+
}
1302+
12471303
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
final class PhabricatorCustomFieldNotAttachedException
4+
extends Exception {
5+
6+
}

0 commit comments

Comments
 (0)
Failed to load comments.