diff --git a/resources/sql/autopatches/20141104.almanac.3.edge.sql b/resources/sql/autopatches/20141104.almanac.3.edge.sql new file mode 100644 index 0000000000..31de2a5e12 --- /dev/null +++ b/resources/sql/autopatches/20141104.almanac.3.edge.sql @@ -0,0 +1,16 @@ +CREATE TABLE {$NAMESPACE}_almanac.edge ( + src VARBINARY(64) NOT NULL, + type INT UNSIGNED NOT NULL, + dst VARBINARY(64) NOT NULL, + dateCreated INT UNSIGNED NOT NULL, + seq INT UNSIGNED NOT NULL, + dataID INT UNSIGNED, + PRIMARY KEY (src, type, dst), + KEY `src` (src, type, dateCreated, seq), + UNIQUE KEY `key_dst` (dst, type, src) +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; + +CREATE TABLE {$NAMESPACE}_almanac.edgedata ( + id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + data LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT} +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9d1fb6fd7b..aa77f1121a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -66,6 +66,7 @@ phutil_register_library_map(array( 'AlmanacPropertyInterface' => 'applications/almanac/property/AlmanacPropertyInterface.php', 'AlmanacPropertyQuery' => 'applications/almanac/query/AlmanacPropertyQuery.php', 'AlmanacQuery' => 'applications/almanac/query/AlmanacQuery.php', + 'AlmanacSchemaSpec' => 'applications/almanac/storage/AlmanacSchemaSpec.php', 'AlmanacService' => 'applications/almanac/storage/AlmanacService.php', 'AlmanacServiceController' => 'applications/almanac/controller/AlmanacServiceController.php', 'AlmanacServiceEditController' => 'applications/almanac/controller/AlmanacServiceEditController.php', @@ -3002,6 +3003,7 @@ phutil_register_library_map(array( 'PhabricatorPolicyInterface', 'PhabricatorCustomFieldInterface', 'PhabricatorApplicationTransactionInterface', + 'PhabricatorProjectInterface', 'AlmanacPropertyInterface', ), 'AlmanacDeviceController' => 'AlmanacController', @@ -3049,11 +3051,13 @@ phutil_register_library_map(array( 'AlmanacPropertyEditController' => 'AlmanacDeviceController', 'AlmanacPropertyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'AlmanacQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'AlmanacSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'AlmanacService' => array( 'AlmanacDAO', 'PhabricatorPolicyInterface', 'PhabricatorCustomFieldInterface', 'PhabricatorApplicationTransactionInterface', + 'PhabricatorProjectInterface', 'AlmanacPropertyInterface', ), 'AlmanacServiceController' => 'AlmanacController', diff --git a/src/applications/almanac/controller/AlmanacDeviceEditController.php b/src/applications/almanac/controller/AlmanacDeviceEditController.php index b8bd075d23..149d9cab37 100644 --- a/src/applications/almanac/controller/AlmanacDeviceEditController.php +++ b/src/applications/almanac/controller/AlmanacDeviceEditController.php @@ -44,10 +44,20 @@ final class AlmanacDeviceEditController $e_name = true; $validation_exception = null; + if ($is_new) { + $v_projects = array(); + } else { + $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( + $device->getPHID(), + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); + $v_projects = array_reverse($v_projects); + } + if ($request->isFormPost()) { $v_name = $request->getStr('name'); $v_view = $request->getStr('viewPolicy'); $v_edit = $request->getStr('editPolicy'); + $v_projects = $request->getArr('projects'); $type_name = AlmanacDeviceTransaction::TYPE_NAME; $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; @@ -67,6 +77,12 @@ final class AlmanacDeviceEditController ->setTransactionType($type_edit) ->setNewValue($v_edit); + $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; + $xactions[] = id(new AlmanacDeviceTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) + ->setMetadataValue('edge:type', $proj_edge_type) + ->setNewValue(array('=' => array_fuse($v_projects))); + $editor = id(new AlmanacDeviceEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) @@ -91,6 +107,12 @@ final class AlmanacDeviceEditController ->setObject($device) ->execute(); + if ($v_projects) { + $project_handles = $this->loadViewerHandles($v_projects); + } else { + $project_handles = array(); + } + $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( @@ -111,6 +133,12 @@ final class AlmanacDeviceEditController ->setPolicyObject($device) ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) ->setPolicies($policies)) + ->appendChild( + id(new AphrontFormTokenizerControl()) + ->setLabel(pht('Projects')) + ->setName('projects') + ->setValue($project_handles) + ->setDatasource(new PhabricatorProjectDatasource())) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton($cancel_uri) diff --git a/src/applications/almanac/controller/AlmanacDeviceViewController.php b/src/applications/almanac/controller/AlmanacDeviceViewController.php index 60edf5d24a..799494963a 100644 --- a/src/applications/almanac/controller/AlmanacDeviceViewController.php +++ b/src/applications/almanac/controller/AlmanacDeviceViewController.php @@ -68,7 +68,8 @@ final class AlmanacDeviceViewController $viewer = $this->getViewer(); $properties = id(new PHUIPropertyListView()) - ->setUser($viewer); + ->setUser($viewer) + ->setObject($device); return $properties; } diff --git a/src/applications/almanac/controller/AlmanacServiceEditController.php b/src/applications/almanac/controller/AlmanacServiceEditController.php index e8a642656c..6c7d69d3fe 100644 --- a/src/applications/almanac/controller/AlmanacServiceEditController.php +++ b/src/applications/almanac/controller/AlmanacServiceEditController.php @@ -44,10 +44,20 @@ final class AlmanacServiceEditController $e_name = true; $validation_exception = null; + if ($is_new) { + $v_projects = array(); + } else { + $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( + $service->getPHID(), + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); + $v_projects = array_reverse($v_projects); + } + if ($request->isFormPost()) { $v_name = $request->getStr('name'); $v_view = $request->getStr('viewPolicy'); $v_edit = $request->getStr('editPolicy'); + $v_projects = $request->getArr('projects'); $type_name = AlmanacServiceTransaction::TYPE_NAME; $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; @@ -67,6 +77,12 @@ final class AlmanacServiceEditController ->setTransactionType($type_edit) ->setNewValue($v_edit); + $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; + $xactions[] = id(new AlmanacServiceTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) + ->setMetadataValue('edge:type', $proj_edge_type) + ->setNewValue(array('=' => array_fuse($v_projects))); + $editor = id(new AlmanacServiceEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) @@ -91,6 +107,12 @@ final class AlmanacServiceEditController ->setObject($service) ->execute(); + if ($v_projects) { + $project_handles = $this->loadViewerHandles($v_projects); + } else { + $project_handles = array(); + } + $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( @@ -111,6 +133,12 @@ final class AlmanacServiceEditController ->setPolicyObject($service) ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) ->setPolicies($policies)) + ->appendChild( + id(new AphrontFormTokenizerControl()) + ->setLabel(pht('Projects')) + ->setName('projects') + ->setValue($project_handles) + ->setDatasource(new PhabricatorProjectDatasource())) ->appendChild( id(new AphrontFormSubmitControl()) ->addCancelButton($cancel_uri) diff --git a/src/applications/almanac/controller/AlmanacServiceViewController.php b/src/applications/almanac/controller/AlmanacServiceViewController.php index 6e07daf0bb..17a4b49f96 100644 --- a/src/applications/almanac/controller/AlmanacServiceViewController.php +++ b/src/applications/almanac/controller/AlmanacServiceViewController.php @@ -68,7 +68,8 @@ final class AlmanacServiceViewController $viewer = $this->getViewer(); $properties = id(new PHUIPropertyListView()) - ->setUser($viewer); + ->setUser($viewer) + ->setObject($service); return $properties; } diff --git a/src/applications/almanac/editor/AlmanacDeviceEditor.php b/src/applications/almanac/editor/AlmanacDeviceEditor.php index fbf8c29bbb..faddb7da9d 100644 --- a/src/applications/almanac/editor/AlmanacDeviceEditor.php +++ b/src/applications/almanac/editor/AlmanacDeviceEditor.php @@ -57,6 +57,7 @@ final class AlmanacDeviceEditor case AlmanacDeviceTransaction::TYPE_INTERFACE: case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: + case PhabricatorTransactions::TYPE_EDGE: return; } @@ -71,6 +72,7 @@ final class AlmanacDeviceEditor case AlmanacDeviceTransaction::TYPE_NAME: case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: + case PhabricatorTransactions::TYPE_EDGE: return; case AlmanacDeviceTransaction::TYPE_INTERFACE: $old = $xaction->getOldValue(); diff --git a/src/applications/almanac/editor/AlmanacServiceEditor.php b/src/applications/almanac/editor/AlmanacServiceEditor.php index 1a3b273751..0061f47dfd 100644 --- a/src/applications/almanac/editor/AlmanacServiceEditor.php +++ b/src/applications/almanac/editor/AlmanacServiceEditor.php @@ -54,6 +54,7 @@ final class AlmanacServiceEditor return; case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: + case PhabricatorTransactions::TYPE_EDGE: return; } @@ -68,6 +69,7 @@ final class AlmanacServiceEditor case AlmanacServiceTransaction::TYPE_NAME: case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: + case PhabricatorTransactions::TYPE_EDGE: return; } diff --git a/src/applications/almanac/storage/AlmanacDevice.php b/src/applications/almanac/storage/AlmanacDevice.php index 34ec9ff608..b7163389ba 100644 --- a/src/applications/almanac/storage/AlmanacDevice.php +++ b/src/applications/almanac/storage/AlmanacDevice.php @@ -6,6 +6,7 @@ final class AlmanacDevice PhabricatorPolicyInterface, PhabricatorCustomFieldInterface, PhabricatorApplicationTransactionInterface, + PhabricatorProjectInterface, AlmanacPropertyInterface { protected $name; diff --git a/src/applications/almanac/storage/AlmanacSchemaSpec.php b/src/applications/almanac/storage/AlmanacSchemaSpec.php new file mode 100644 index 0000000000..0f13a91d65 --- /dev/null +++ b/src/applications/almanac/storage/AlmanacSchemaSpec.php @@ -0,0 +1,10 @@ +buildEdgeSchemata(new AlmanacService()); + } + +} diff --git a/src/applications/almanac/storage/AlmanacService.php b/src/applications/almanac/storage/AlmanacService.php index cdc1a75fa6..ecb062809f 100644 --- a/src/applications/almanac/storage/AlmanacService.php +++ b/src/applications/almanac/storage/AlmanacService.php @@ -6,6 +6,7 @@ final class AlmanacService PhabricatorPolicyInterface, PhabricatorCustomFieldInterface, PhabricatorApplicationTransactionInterface, + PhabricatorProjectInterface, AlmanacPropertyInterface { protected $name;