1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Migrate Project edges to subclass PhabricatorEdgeType

Summary: Modernize Project edges to subclass `PhabricatorEdgeType`. Largely based on D11045.

Test Plan: Add a member to a project, saw new rows in the `phabricator_project.edge` and `phabricator_user.edge` tables.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D11111
This commit is contained in:
Joshua Spence 2015-01-02 10:10:58 +11:00
parent 422b2f2b89
commit f0db6e4818
17 changed files with 238 additions and 57 deletions

View file

@ -1,6 +1,6 @@
/* These are here so `grep` will find them if we ever change things: */
/* PhabricatorEdgeConfig::TYPE_PROJ_MEMBER = 13 */
/* PhabricatorProjectProjectHasMemberEdgeType::EDGECONST = 13 */
/* PhabricatorEdgeConfig::TYPE_OBJECT_HAS_SUBSCRIBER = 21 */
INSERT IGNORE INTO {$NAMESPACE}_project.edge (src, type, dst, dateCreated)

View file

@ -9,7 +9,7 @@ foreach (new LiskMigrationIterator($table) as $project) {
$members = PhabricatorEdgeQuery::loadDestinationPHIDs(
$project->getPHID(),
PhabricatorEdgeConfig::TYPE_PROJ_MEMBER);
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST);
if (count($members)) {
echo sprintf(

View file

@ -25,7 +25,7 @@ foreach (new LiskMigrationIterator($table) as $proj) {
foreach ($members as $user_phid) {
$editor->addEdge(
$proj->getPHID(),
PhabricatorEdgeConfig::TYPE_PROJ_MEMBER,
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST,
$user_phid);
}
$editor->save();

View file

@ -2155,6 +2155,7 @@ phutil_register_library_map(array(
'PhabricatorProjectIcon' => 'applications/project/icon/PhabricatorProjectIcon.php',
'PhabricatorProjectInterface' => 'applications/project/interface/PhabricatorProjectInterface.php',
'PhabricatorProjectListController' => 'applications/project/controller/PhabricatorProjectListController.php',
'PhabricatorProjectMemberOfProjectEdgeType' => 'applications/project/edge/PhabricatorProjectMemberOfProjectEdgeType.php',
'PhabricatorProjectMembersEditController' => 'applications/project/controller/PhabricatorProjectMembersEditController.php',
'PhabricatorProjectMembersRemoveController' => 'applications/project/controller/PhabricatorProjectMembersRemoveController.php',
'PhabricatorProjectMoveController' => 'applications/project/controller/PhabricatorProjectMoveController.php',
@ -2162,6 +2163,7 @@ phutil_register_library_map(array(
'PhabricatorProjectObjectHasProjectEdgeType' => 'applications/project/edge/PhabricatorProjectObjectHasProjectEdgeType.php',
'PhabricatorProjectOrUserDatasource' => 'applications/project/typeahead/PhabricatorProjectOrUserDatasource.php',
'PhabricatorProjectProfileController' => 'applications/project/controller/PhabricatorProjectProfileController.php',
'PhabricatorProjectProjectHasMemberEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasMemberEdgeType.php',
'PhabricatorProjectProjectHasObjectEdgeType' => 'applications/project/edge/PhabricatorProjectProjectHasObjectEdgeType.php',
'PhabricatorProjectProjectPHIDType' => 'applications/project/phid/PhabricatorProjectProjectPHIDType.php',
'PhabricatorProjectQuery' => 'applications/project/query/PhabricatorProjectQuery.php',
@ -5350,6 +5352,7 @@ phutil_register_library_map(array(
'PhabricatorProjectEditorTestCase' => 'PhabricatorTestCase',
'PhabricatorProjectIcon' => 'Phobject',
'PhabricatorProjectListController' => 'PhabricatorProjectController',
'PhabricatorProjectMemberOfProjectEdgeType' => 'PhabricatorEdgeType',
'PhabricatorProjectMembersEditController' => 'PhabricatorProjectController',
'PhabricatorProjectMembersRemoveController' => 'PhabricatorProjectController',
'PhabricatorProjectMoveController' => 'PhabricatorProjectController',
@ -5357,6 +5360,7 @@ phutil_register_library_map(array(
'PhabricatorProjectObjectHasProjectEdgeType' => 'PhabricatorEdgeType',
'PhabricatorProjectOrUserDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorProjectProfileController' => 'PhabricatorProjectController',
'PhabricatorProjectProjectHasMemberEdgeType' => 'PhabricatorEdgeType',
'PhabricatorProjectProjectHasObjectEdgeType' => 'PhabricatorEdgeType',
'PhabricatorProjectProjectPHIDType' => 'PhabricatorPHIDType',
'PhabricatorProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',

View file

@ -57,7 +57,9 @@ final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO {
if ($project_phids) {
$query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($project_phids)
->withEdgeTypes(array(PhabricatorEdgeConfig::TYPE_PROJ_MEMBER));
->withEdgeTypes(array(
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST,
));
$query->execute();
$users_in_project_phids = $query->getDestinationPHIDs();
}

View file

@ -43,7 +43,9 @@ final class ProjectCreateConduitAPIMethod extends ProjectConduitAPIMethod {
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)
->setMetadataValue(
'edge:type',
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)
->setNewValue(
array(
'+' => array_fuse($members),

View file

@ -128,7 +128,7 @@ final class PhabricatorProjectEditDetailsController
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue(
'edge:type',
PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)
->setNewValue(
array(
'+' => array($viewer->getPHID() => $viewer->getPHID()),

View file

@ -42,7 +42,7 @@ final class PhabricatorProjectMembersEditController
$member_spec['+'] = array_fuse($add_members);
}
$type_member = PhabricatorEdgeConfig::TYPE_PROJ_MEMBER;
$type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
$xactions = array();

View file

@ -40,7 +40,7 @@ final class PhabricatorProjectMembersRemoveController
$member_spec = array();
$member_spec['-'] = array($remove_phid => $remove_phid);
$type_member = PhabricatorEdgeConfig::TYPE_PROJ_MEMBER;
$type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
$xactions = array();

View file

@ -56,7 +56,7 @@ final class PhabricatorProjectUpdateController
break;
}
$type_member = PhabricatorEdgeConfig::TYPE_PROJ_MEMBER;
$type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
$member_spec = array(
$edge_action => array($user->getPHID() => $user->getPHID()),
);

View file

@ -0,0 +1,103 @@
<?php
final class PhabricatorProjectMemberOfProjectEdgeType
extends PhabricatorEdgeType {
const EDGECONST = 14;
public function getInverseEdgeConstant() {
return PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
}
public function shouldWriteInverseTransactions() {
return true;
}
public function getTransactionAddString(
$actor,
$add_count,
$add_edges) {
return pht(
'%s added %s project(s): %s.',
$actor,
$add_count,
$add_edges);
}
public function getTransactionRemoveString(
$actor,
$rem_count,
$rem_edges) {
return pht(
'%s removed %s project(s): %s.',
$actor,
$rem_count,
$rem_edges);
}
public function getTransactionEditString(
$actor,
$total_count,
$add_count,
$add_edges,
$rem_count,
$rem_edges) {
return pht(
'%s edited project(s), added %s: %s; removed %s: %s.',
$actor,
$add_count,
$add_edges,
$rem_count,
$rem_edges);
}
public function getFeedAddString(
$actor,
$object,
$add_count,
$add_edges) {
return pht(
'%s added %s project(s) for %s: %s.',
$actor,
$add_count,
$object,
$add_edges);
}
public function getFeedRemoveString(
$actor,
$object,
$rem_count,
$rem_edges) {
return pht(
'%s removed %s project(s) for %s: %s.',
$actor,
$rem_count,
$object,
$rem_edges);
}
public function getFeedEditString(
$actor,
$object,
$total_count,
$add_count,
$add_edges,
$rem_count,
$rem_edges) {
return pht(
'%s edited project(s) for %s, added %s: %s; removed %s: %s.',
$actor,
$object,
$add_count,
$add_edges,
$rem_count,
$rem_edges);
}
}

View file

@ -0,0 +1,103 @@
<?php
final class PhabricatorProjectProjectHasMemberEdgeType
extends PhabricatorEdgeType {
const EDGECONST = 13;
public function getInverseEdgeConstant() {
return PhabricatorProjectMemberOfProjectEdgeType::EDGECONST;
}
public function shouldWriteInverseTransactions() {
return true;
}
public function getTransactionAddString(
$actor,
$add_count,
$add_edges) {
return pht(
'%s added %s member(s): %s.',
$actor,
$add_count,
$add_edges);
}
public function getTransactionRemoveString(
$actor,
$rem_count,
$rem_edges) {
return pht(
'%s removed %s member(s): %s.',
$actor,
$rem_count,
$rem_edges);
}
public function getTransactionEditString(
$actor,
$total_count,
$add_count,
$add_edges,
$rem_count,
$rem_edges) {
return pht(
'%s edited member(s), added %s: %s; removed %s: %s.',
$actor,
$add_count,
$add_edges,
$rem_count,
$rem_edges);
}
public function getFeedAddString(
$actor,
$object,
$add_count,
$add_edges) {
return pht(
'%s added %s member(s) for %s: %s.',
$actor,
$add_count,
$object,
$add_edges);
}
public function getFeedRemoveString(
$actor,
$object,
$rem_count,
$rem_edges) {
return pht(
'%s removed %s member(s) for %s: %s.',
$actor,
$rem_count,
$object,
$rem_edges);
}
public function getFeedEditString(
$actor,
$object,
$total_count,
$add_count,
$add_edges,
$rem_count,
$rem_edges) {
return pht(
'%s edited member(s) for %s, added %s: %s; removed %s: %s.',
$actor,
$object,
$add_count,
$add_edges,
$rem_count,
$rem_edges);
}
}

View file

@ -179,7 +179,7 @@ final class PhabricatorProjectTransactionEditor
case PhabricatorTransactions::TYPE_EDGE:
$edge_type = $xaction->getMetadataValue('edge:type');
switch ($edge_type) {
case PhabricatorEdgeConfig::TYPE_PROJ_MEMBER:
case PhabricatorProjectProjectHasMemberEdgeType::EDGECONST:
case PhabricatorEdgeConfig::TYPE_OBJECT_HAS_WATCHER:
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
@ -190,7 +190,8 @@ final class PhabricatorProjectTransactionEditor
// When removing members, we remove their subscription too.
// When unwatching, we leave subscriptions, since it's fine to be
// subscribed to a project but not be a member of it.
if ($edge_type == PhabricatorEdgeConfig::TYPE_PROJ_MEMBER) {
$edge_const = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
if ($edge_type == $edge_const) {
$rem = array_keys(array_diff_key($old, $new));
} else {
$rem = array();
@ -366,7 +367,7 @@ final class PhabricatorProjectTransactionEditor
return;
case PhabricatorTransactions::TYPE_EDGE:
switch ($xaction->getMetadataValue('edge:type')) {
case PhabricatorEdgeConfig::TYPE_PROJ_MEMBER:
case PhabricatorProjectProjectHasMemberEdgeType::EDGECONST:
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();

View file

@ -274,7 +274,9 @@ final class PhabricatorProjectEditorTestCase extends PhabricatorTestCase {
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)
->setMetadataValue(
'edge:type',
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST)
->setNewValue($spec);
$editor = id(new PhabricatorProjectTransactionEditor())

View file

@ -138,7 +138,7 @@ final class PhabricatorProjectQuery
$viewer_phid = $this->getViewer()->getPHID();
$project_phids = mpull($projects, 'getPHID');
$member_type = PhabricatorEdgeConfig::TYPE_PROJ_MEMBER;
$member_type = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
$watcher_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_WATCHER;
$need_edge_types = array();
@ -338,7 +338,7 @@ final class PhabricatorProjectQuery
$conn_r,
'LEFT JOIN %T vm ON vm.src = p.phid AND vm.type = %d AND vm.dst = %s',
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
PhabricatorEdgeConfig::TYPE_PROJ_MEMBER,
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST,
$this->getViewer()->getPHID());
}
@ -347,7 +347,7 @@ final class PhabricatorProjectQuery
$conn_r,
'JOIN %T e ON e.src = p.phid AND e.type = %d',
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
PhabricatorEdgeConfig::TYPE_PROJ_MEMBER);
PhabricatorProjectProjectHasMemberEdgeType::EDGECONST);
}
if ($this->slugs !== null) {

View file

@ -5,9 +5,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
const TABLE_NAME_EDGE = 'edge';
const TABLE_NAME_EDGEDATA = 'edgedata';
const TYPE_PROJ_MEMBER = 13;
const TYPE_MEMBER_OF_PROJ = 14;
const TYPE_OBJECT_HAS_SUBSCRIBER = 21;
const TYPE_SUBSCRIBED_TO_OBJECT = 22;
@ -103,9 +100,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
private static function getInverse($edge_type) {
static $map = array(
self::TYPE_PROJ_MEMBER => self::TYPE_MEMBER_OF_PROJ,
self::TYPE_MEMBER_OF_PROJ => self::TYPE_PROJ_MEMBER,
self::TYPE_OBJECT_HAS_SUBSCRIBER => self::TYPE_SUBSCRIBED_TO_OBJECT,
self::TYPE_SUBSCRIBED_TO_OBJECT => self::TYPE_OBJECT_HAS_SUBSCRIBER,
@ -179,10 +173,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
switch ($type) {
case self::TYPE_MOCK_HAS_TASK:
return '%s edited task(s), added %d: %s; removed %d: %s.';
case self::TYPE_PROJ_MEMBER:
return '%s edited member(s), added %d: %s; removed %d: %s.';
case self::TYPE_MEMBER_OF_PROJ:
return '%s edited project(s), added %d: %s; removed %d: %s.';
case self::TYPE_OBJECT_HAS_SUBSCRIBER:
return '%s edited subscriber(s), added %d: %s; removed %d: %s.';
case self::TYPE_SUBSCRIBED_TO_OBJECT:
@ -216,10 +206,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
switch ($type) {
case self::TYPE_MOCK_HAS_TASK:
return '%s added %d task(s): %s.';
case self::TYPE_PROJ_MEMBER:
return '%s added %d member(s): %s.';
case self::TYPE_MEMBER_OF_PROJ:
return '%s added %d project(s): %s.';
case self::TYPE_OBJECT_HAS_SUBSCRIBER:
return '%s added %d subscriber(s): %s.';
case self::TYPE_OBJECT_HAS_UNSUBSCRIBER:
@ -250,10 +236,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
switch ($type) {
case self::TYPE_MOCK_HAS_TASK:
return '%s removed %d task(s): %s.';
case self::TYPE_PROJ_MEMBER:
return '%s removed %d member(s): %s.';
case self::TYPE_MEMBER_OF_PROJ:
return '%s removed %d project(s): %s.';
case self::TYPE_OBJECT_HAS_SUBSCRIBER:
return '%s removed %d subscriber(s): %s.';
case self::TYPE_OBJECT_HAS_UNSUBSCRIBER:
@ -284,10 +266,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
switch ($type) {
case self::TYPE_MOCK_HAS_TASK:
return '%s updated tasks of %s.';
case self::TYPE_PROJ_MEMBER:
return '%s updated members of %s.';
case self::TYPE_MEMBER_OF_PROJ:
return '%s updated projects of %s.';
case self::TYPE_OBJECT_HAS_SUBSCRIBER:
return '%s updated subscribers of %s.';
case self::TYPE_OBJECT_HAS_UNSUBSCRIBER:

View file

@ -133,31 +133,31 @@ abstract class PhabricatorBaseEnglishTranslation
'%s edited member(s), added %d: %s; removed %d: %s.' =>
'%s edited members, added: %3$s; removed: %5$s.',
'%s added %d member(s): %s.' => array(
'%s added %s member(s): %s.' => array(
array(
'%s added a member: %3$s.',
'%s added members: %3$s.',
),
),
'%s removed %d member(s): %s.' => array(
'%s removed %s member(s): %s.' => array(
array(
'%s removed a member: %3$s.',
'%s removed members: %3$s.',
),
),
'%s edited project(s), added %d: %s; removed %d: %s.' =>
'%s edited project(s), added %s: %s; removed %s: %s.' =>
'%s edited projects, added: %3$s; removed: %5$s.',
'%s added %d project(s): %s.' => array(
'%s added %s project(s): %s.' => array(
array(
'%s added a project: %3$s.',
'%s added projects: %3$s.',
),
),
'%s removed %d project(s): %s.' => array(
'%s removed %s project(s): %s.' => array(
array(
'%s removed a project: %3$s.',
'%s removed projects: %3$s.',
@ -792,20 +792,6 @@ abstract class PhabricatorBaseEnglishTranslation
'%s edited %s revision(s) for %s, added %s: %s; removed %s: %s.' =>
'%s edited revisions for %3$s, added: %5$s; removed %7$s.',
'%s added %s project(s): %s.' => array(
array(
'%s added a project: %3$s.',
'%s added projects: %3$s.',
),
),
'%s removed %s project(s): %s.' => array(
array(
'%s removed a project: %3$s.',
'%s removed projects: %3$s.',
),
),
'%s edited %s project(s), added %s: %s; removed %s: %s.' =>
'%s edited projects, added %4$s; removed %6$s.',