diff --git a/resources/sql/autopatches/20141104.almanac.3.edge.sql b/resources/sql/autopatches/20141104.almanac.3.edge.sql new file mode 100644 --- /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 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -66,6 +66,7 @@ '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 @@ 'PhabricatorPolicyInterface', 'PhabricatorCustomFieldInterface', 'PhabricatorApplicationTransactionInterface', + 'PhabricatorProjectInterface', 'AlmanacPropertyInterface', ), 'AlmanacDeviceController' => 'AlmanacController', @@ -3049,11 +3051,13 @@ '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 --- a/src/applications/almanac/controller/AlmanacDeviceEditController.php +++ b/src/applications/almanac/controller/AlmanacDeviceEditController.php @@ -44,10 +44,20 @@ $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 @@ ->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 @@ ->setObject($device) ->execute(); + if ($v_projects) { + $project_handles = $this->loadViewerHandles($v_projects); + } else { + $project_handles = array(); + } + $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( @@ -112,6 +134,12 @@ ->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) ->setValue($save_button)); diff --git a/src/applications/almanac/controller/AlmanacDeviceViewController.php b/src/applications/almanac/controller/AlmanacDeviceViewController.php --- a/src/applications/almanac/controller/AlmanacDeviceViewController.php +++ b/src/applications/almanac/controller/AlmanacDeviceViewController.php @@ -68,7 +68,8 @@ $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 --- a/src/applications/almanac/controller/AlmanacServiceEditController.php +++ b/src/applications/almanac/controller/AlmanacServiceEditController.php @@ -44,10 +44,20 @@ $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 @@ ->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 @@ ->setObject($service) ->execute(); + if ($v_projects) { + $project_handles = $this->loadViewerHandles($v_projects); + } else { + $project_handles = array(); + } + $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( @@ -112,6 +134,12 @@ ->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) ->setValue($save_button)); diff --git a/src/applications/almanac/controller/AlmanacServiceViewController.php b/src/applications/almanac/controller/AlmanacServiceViewController.php --- a/src/applications/almanac/controller/AlmanacServiceViewController.php +++ b/src/applications/almanac/controller/AlmanacServiceViewController.php @@ -68,7 +68,8 @@ $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 --- a/src/applications/almanac/editor/AlmanacDeviceEditor.php +++ b/src/applications/almanac/editor/AlmanacDeviceEditor.php @@ -57,6 +57,7 @@ case AlmanacDeviceTransaction::TYPE_INTERFACE: case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: + case PhabricatorTransactions::TYPE_EDGE: return; } @@ -71,6 +72,7 @@ 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 --- a/src/applications/almanac/editor/AlmanacServiceEditor.php +++ b/src/applications/almanac/editor/AlmanacServiceEditor.php @@ -54,6 +54,7 @@ return; case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: + case PhabricatorTransactions::TYPE_EDGE: return; } @@ -68,6 +69,7 @@ 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 --- a/src/applications/almanac/storage/AlmanacDevice.php +++ b/src/applications/almanac/storage/AlmanacDevice.php @@ -6,6 +6,7 @@ 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 --- /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 --- a/src/applications/almanac/storage/AlmanacService.php +++ b/src/applications/almanac/storage/AlmanacService.php @@ -6,6 +6,7 @@ PhabricatorPolicyInterface, PhabricatorCustomFieldInterface, PhabricatorApplicationTransactionInterface, + PhabricatorProjectInterface, AlmanacPropertyInterface { protected $name;