diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 86725c3..9f313ec 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1,149 +1,153 @@ 2, 'class' => array( 'SemiStructuredBaseController' => 'controller/SemiStructuredBaseController.php', 'SemiStructuredDAO' => 'storage/SemiStructuredDAO.php', 'SemiStructuredDataApplication' => 'application/SemiStructuredDataApplication.php', 'SemiStructuredInstanceConfiguredCustomField' => 'customfield/SemiStructuredInstanceConfiguredCustomField.php', 'SemiStructuredInstanceConfiguredCustomFieldStorage' => 'storage/SemiStructuredInstanceConfiguredCustomFieldStorage.php', 'SemiStructuredInstanceCustomField' => 'customfield/SemiStructuredInstanceCustomField.php', 'SemiStructuredInstanceCustomFieldNumericIndex' => 'storage/SemiStructuredInstanceCustomFieldNumericIndex.php', 'SemiStructuredInstanceCustomFieldStringIndex' => 'storage/SemiStructuredInstanceCustomFieldStringIndex.php', + 'SemiStructuredInstanceEditConduitAPIMethod' => 'conduit/SemiStructuredInstanceEditConduitAPIMethod.php', + 'SemiStructuredInstanceSearchConduitAPIMethod' => 'conduit/SemiStructuredInstanceSearchConduitAPIMethod.php', 'SemiStructuredObjectInstance' => 'storage/SemiStructuredObjectInstance.php', 'SemiStructuredObjectInstanceClassTransaction' => 'xaction/instance/SemiStructuredObjectInstanceClassTransaction.php', 'SemiStructuredObjectInstanceController' => 'controller/instance/SemiStructuredObjectInstanceController.php', 'SemiStructuredObjectInstanceDescriptionTransaction' => 'xaction/instance/SemiStructuredObjectInstanceDescriptionTransaction.php', 'SemiStructuredObjectInstanceEditController' => 'controller/instance/SemiStructuredObjectInstanceEditController.php', 'SemiStructuredObjectInstanceEditEngine' => 'editor/SemiStructuredObjectInstanceEditEngine.php', 'SemiStructuredObjectInstanceListController' => 'controller/instance/SemiStructuredObjectInstanceListController.php', 'SemiStructuredObjectInstanceMailReceiver' => 'mail/SemiStructuredObjectInstanceMailReceiver.php', 'SemiStructuredObjectInstanceNameTransaction' => 'xaction/instance/SemiStructuredObjectInstanceNameTransaction.php', 'SemiStructuredObjectInstancePHIDType' => 'phid/SemiStructuredObjectInstancePHIDType.php', 'SemiStructuredObjectInstanceQuery' => 'query/SemiStructuredObjectInstanceQuery.php', 'SemiStructuredObjectInstanceRawDataTransaction' => 'xaction/instance/SemiStructuredObjectInstanceRawDataTransaction.php', 'SemiStructuredObjectInstanceReplyHandler' => 'mail/SemiStructuredObjectInstanceReplyHandler.php', 'SemiStructuredObjectInstanceSearchEngine' => 'query/SemiStructuredObjectInstanceSearchEngine.php', 'SemiStructuredObjectInstanceTransaction' => 'storage/SemiStructuredObjectInstanceTransaction.php', 'SemiStructuredObjectInstanceTransactionComment' => 'storage/SemiStructuredObjectInstanceTransactionComment.php', 'SemiStructuredObjectInstanceTransactionEditor' => 'editor/SemiStructuredObjectInstanceTransactionEditor.php', 'SemiStructuredObjectInstanceTransactionQuery' => 'query/SemiStructuredObjectInstanceTransactionQuery.php', 'SemiStructuredObjectInstanceTransactionType' => 'xaction/instance/SemiStructuredObjectInstanceTransactionType.php', 'SemiStructuredObjectInstanceViewController' => 'controller/instance/SemiStructuredObjectInstanceViewController.php', 'SemiStructuredObjectNewInstanceController' => 'controller/class/SemiStructuredObjectNewInstanceController.php', 'SemiStructuredObjectType' => 'storage/SemiStructuredObjectType.php', 'SemiStructuredObjectTypeArchiveController' => 'controller/class/SemiStructuredObjectTypeArchiveController.php', 'SemiStructuredObjectTypeController' => 'controller/class/SemiStructuredObjectTypeController.php', 'SemiStructuredObjectTypeCustomFieldsTransaction' => 'xaction/class/SemiStructuredObjectTypeCustomFieldsTransaction.php', 'SemiStructuredObjectTypeDescriptionTransaction' => 'xaction/class/SemiStructuredObjectTypeDescriptionTransaction.php', 'SemiStructuredObjectTypeEditController' => 'controller/class/SemiStructuredObjectTypeEditController.php', 'SemiStructuredObjectTypeEditEngine' => 'editor/SemiStructuredObjectTypeEditEngine.php', 'SemiStructuredObjectTypeFerretEngine' => 'engine/SemiStructuredObjectTypeFerretEngine.php', 'SemiStructuredObjectTypeListController' => 'controller/class/SemiStructuredObjectTypeListController.php', 'SemiStructuredObjectTypeMailReceiver' => 'mail/SemiStructuredObjectTypeMailReceiver.php', 'SemiStructuredObjectTypeNameTransaction' => 'xaction/class/SemiStructuredObjectTypeNameTransaction.php', 'SemiStructuredObjectTypePHIDType' => 'phid/SemiStructuredObjectTypePHIDType.php', 'SemiStructuredObjectTypeQuery' => 'query/SemiStructuredObjectTypeQuery.php', 'SemiStructuredObjectTypeRemarkupRule' => 'remarkup/SemiStructuredObjectTypeRemarkupRule.php', 'SemiStructuredObjectTypeReplyHandler' => 'mail/SemiStructuredObjectTypeReplyHandler.php', 'SemiStructuredObjectTypeSearchEngine' => 'query/SemiStructuredObjectTypeSearchEngine.php', 'SemiStructuredObjectTypeStatusTransaction' => 'xaction/class/SemiStructuredObjectTypeStatusTransaction.php', 'SemiStructuredObjectTypeTransaction' => 'storage/SemiStructuredObjectTypeTransaction.php', 'SemiStructuredObjectTypeTransactionComment' => 'storage/SemiStructuredObjectTypeTransactionComment.php', 'SemiStructuredObjectTypeTransactionEditor' => 'editor/SemiStructuredObjectTypeTransactionEditor.php', 'SemiStructuredObjectTypeTransactionQuery' => 'query/SemiStructuredObjectTypeTransactionQuery.php', 'SemiStructuredObjectTypeTransactionType' => 'xaction/class/SemiStructuredObjectTypeTransactionType.php', 'SemiStructuredObjectTypeViewController' => 'controller/class/SemiStructuredObjectTypeViewController.php', 'SemiStructuredPatchList' => 'storage/SemiStructuredPatchList.php', 'SemiStructuredSchemaSpec' => 'storage/SemiStructuredSchemaSpec.php', 'SemiStructuredStaticSearchField' => '_to_upstream/SemiStructuredStaticSearchField.php', ), 'function' => array(), 'xmap' => array( 'SemiStructuredBaseController' => 'PhabricatorController', 'SemiStructuredDAO' => 'PhabricatorLiskDAO', 'SemiStructuredDataApplication' => 'PhabricatorApplication', 'SemiStructuredInstanceConfiguredCustomField' => array( 'SemiStructuredInstanceCustomField', 'PhabricatorStandardCustomFieldInterface', ), 'SemiStructuredInstanceConfiguredCustomFieldStorage' => 'PhabricatorCustomFieldStorage', 'SemiStructuredInstanceCustomField' => 'PhabricatorCustomField', 'SemiStructuredInstanceCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage', 'SemiStructuredInstanceCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage', + 'SemiStructuredInstanceEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', + 'SemiStructuredInstanceSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'SemiStructuredObjectInstance' => array( 'SemiStructuredDAO', 'PhabricatorPolicyInterface', 'PhabricatorApplicationTransactionInterface', 'PhabricatorSubscribableInterface', 'PhabricatorFlaggableInterface', 'PhabricatorProjectInterface', 'PhabricatorMentionableInterface', 'PhabricatorCustomFieldInterface', 'PhabricatorDestructibleInterface', ), 'SemiStructuredObjectInstanceClassTransaction' => 'SemiStructuredObjectInstanceTransactionType', 'SemiStructuredObjectInstanceController' => 'SemiStructuredBaseController', 'SemiStructuredObjectInstanceDescriptionTransaction' => 'SemiStructuredObjectInstanceTransactionType', 'SemiStructuredObjectInstanceEditController' => 'SemiStructuredBaseController', 'SemiStructuredObjectInstanceEditEngine' => 'PhabricatorEditEngine', 'SemiStructuredObjectInstanceListController' => 'SemiStructuredObjectTypeController', 'SemiStructuredObjectInstanceMailReceiver' => 'PhabricatorObjectMailReceiver', 'SemiStructuredObjectInstanceNameTransaction' => 'SemiStructuredObjectInstanceTransactionType', 'SemiStructuredObjectInstancePHIDType' => 'PhabricatorPHIDType', 'SemiStructuredObjectInstanceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'SemiStructuredObjectInstanceRawDataTransaction' => 'SemiStructuredObjectInstanceTransactionType', 'SemiStructuredObjectInstanceReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'SemiStructuredObjectInstanceSearchEngine' => 'PhabricatorApplicationSearchEngine', 'SemiStructuredObjectInstanceTransaction' => 'PhabricatorModularTransaction', 'SemiStructuredObjectInstanceTransactionComment' => 'PhabricatorApplicationTransactionComment', 'SemiStructuredObjectInstanceTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 'SemiStructuredObjectInstanceTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'SemiStructuredObjectInstanceTransactionType' => 'PhabricatorModularTransactionType', 'SemiStructuredObjectInstanceViewController' => 'SemiStructuredObjectInstanceController', 'SemiStructuredObjectNewInstanceController' => 'SemiStructuredObjectTypeController', 'SemiStructuredObjectType' => array( 'SemiStructuredDAO', 'PhabricatorPolicyInterface', 'PhabricatorApplicationTransactionInterface', 'PhabricatorMentionableInterface', 'PhabricatorSubscribableInterface', 'PhabricatorProjectInterface', 'PhabricatorFlaggableInterface', 'PhabricatorDestructibleInterface', 'PhabricatorFerretInterface', ), 'SemiStructuredObjectTypeArchiveController' => 'SemiStructuredBaseController', 'SemiStructuredObjectTypeController' => 'SemiStructuredBaseController', 'SemiStructuredObjectTypeCustomFieldsTransaction' => 'SemiStructuredObjectTypeTransactionType', 'SemiStructuredObjectTypeDescriptionTransaction' => 'SemiStructuredObjectTypeTransactionType', 'SemiStructuredObjectTypeEditController' => 'SemiStructuredBaseController', 'SemiStructuredObjectTypeEditEngine' => 'PhabricatorEditEngine', 'SemiStructuredObjectTypeFerretEngine' => 'PhabricatorFerretEngine', 'SemiStructuredObjectTypeListController' => 'SemiStructuredBaseController', 'SemiStructuredObjectTypeMailReceiver' => 'PhabricatorObjectMailReceiver', 'SemiStructuredObjectTypeNameTransaction' => 'SemiStructuredObjectTypeTransactionType', 'SemiStructuredObjectTypePHIDType' => 'PhabricatorPHIDType', 'SemiStructuredObjectTypeQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'SemiStructuredObjectTypeRemarkupRule' => 'PhabricatorObjectRemarkupRule', 'SemiStructuredObjectTypeReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'SemiStructuredObjectTypeSearchEngine' => 'PhabricatorApplicationSearchEngine', 'SemiStructuredObjectTypeStatusTransaction' => 'SemiStructuredObjectTypeTransactionType', 'SemiStructuredObjectTypeTransaction' => 'PhabricatorModularTransaction', 'SemiStructuredObjectTypeTransactionComment' => 'PhabricatorApplicationTransactionComment', 'SemiStructuredObjectTypeTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 'SemiStructuredObjectTypeTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'SemiStructuredObjectTypeTransactionType' => 'PhabricatorModularTransactionType', 'SemiStructuredObjectTypeViewController' => 'SemiStructuredObjectTypeController', 'SemiStructuredPatchList' => 'PhabricatorSQLPatchList', 'SemiStructuredSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'SemiStructuredStaticSearchField' => 'PhabricatorSearchField', ), )); diff --git a/src/conduit/SemiStructuredInstanceEditConduitAPIMethod.php b/src/conduit/SemiStructuredInstanceEditConduitAPIMethod.php new file mode 100644 index 0000000..61d65a5 --- /dev/null +++ b/src/conduit/SemiStructuredInstanceEditConduitAPIMethod.php @@ -0,0 +1,19 @@ +setViewer(PhabricatorUser::getOmnipotentUser()) + ->withIDs(array(2)) + ->executeOne(); +$e->setObjectType($cls); + return $e; + } + + public function getMethodSummary() { + return pht('Read information about Object Instances.'); + } + +} + +// search fields to allow +// - custom fields -> may be hard - fields not available early enough. maybe just load all possible fields from all types? +// - class ID (vs phid) ? +// default output to include +// - class phid +// - raw data +// - custom fields +// - description, title diff --git a/src/editor/SemiStructuredObjectInstanceEditEngine.php b/src/editor/SemiStructuredObjectInstanceEditEngine.php index a0b1103..ca27d47 100644 --- a/src/editor/SemiStructuredObjectInstanceEditEngine.php +++ b/src/editor/SemiStructuredObjectInstanceEditEngine.php @@ -1,143 +1,148 @@ objectType = $object_type; return $this; } protected function newEditableObject() { $viewer = $this->getViewer(); return SemiStructuredObjectInstance::initializeNewObjectInstance( $viewer, $this->objectType); } protected function newObjectQuery() { return new SemiStructuredObjectInstanceQuery(); } protected function getObjectCreateTitleText($object) { return pht('Create Object Instance'); } protected function getObjectCreateButtonText($object) { return pht('Create Object Instance'); } protected function getObjectCreateCancelURI($object) { // TODO if objjec has link to class - go to that class return '/semistructured/'; } protected function getEditorURI() { return $this->getApplication()->getApplicationURI('editinstance/'); } public function getCreateURI($form_key) { if ($this->objectType) { return $this->getApplication()->getApplicationURI( "type/{$this->objectType->getID()}/new/"); } return null; } protected function getObjectEditTitleText($object) { return pht('Edit Object: %d', $object->getID()); } protected function getObjectEditShortText($object) { return pht('Edit Object'); } protected function getObjectCreateShortText() { return pht('Create Object Instance'); } protected function getObjectName() { return pht('Object Instance'); } protected function getObjectViewURI($object) { return $object->getURI(); } protected function buildCustomEditFields($object) { $fields = array( - id(id(new PhabricatorStaticEditField()) - ->setKey('objecttype') - ->setLabel(pht('Object Type')) - ->setValue($object->getClass()->getName())), - id(new PhabricatorIntEditField()) + id(new PhabricatorTextEditField()) ->setKey('classPHID') ->setLabel(pht('Object Type')) ->setDescription(pht('Type of the object.')) ->setConduitDescription(pht('Set type of object.')) ->setIsHidden(true) ->setTransactionType( SemiStructuredObjectInstanceClassTransaction::TRANSACTIONTYPE) ->setIsRequired(true) ->setValue($object->getClassPHID()), id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setDescription(pht('Name of the object.')) ->setConduitDescription(pht('Rename the object.')) ->setConduitTypeDescription(pht('New object name.')) ->setTransactionType( SemiStructuredObjectInstanceNameTransaction::TRANSACTIONTYPE) ->setValue($object->getName()), - id(new PhabricatorRemarkupEditField()) + id(new PhabricatorRemarkupEditField()) ->setKey('description') ->setLabel(pht('Free text')) ->setDescription(pht('Object instance free text (Remarkup).')) ->setConduitTypeDescription(pht('New object free type.')) ->setTransactionType( SemiStructuredObjectInstanceDescriptionTransaction::TRANSACTIONTYPE) ->setValue($object->getDescription()), id(new PhabricatorTextAreaEditField()) ->setKey('rawdata') ->setLabel(pht('Structured content')) ->setDescription(pht('Object structured data (JSON).')) - ->setConduitTypeDescription(pht('Object body (JSON).')) + ->setConduitTypeDescription(pht('Object body (JSON, but as a String!).')) ->setMonospaced(true) ->setIsRequired(true) ->setTransactionType( SemiStructuredObjectInstanceRawDataTransaction::TRANSACTIONTYPE) ->setValue($object->getRawData()), ); + if ($this->objectType) { + array_unshift( + $fields, + (new PhabricatorStaticEditField()) + ->setKey('objecttype') + ->setLabel(pht('Object Type')) + ->setValue($this->objectType->getName())); + } + return $fields; } } diff --git a/src/query/SemiStructuredObjectInstanceSearchEngine.php b/src/query/SemiStructuredObjectInstanceSearchEngine.php index 1d9dec0..0b5013c 100644 --- a/src/query/SemiStructuredObjectInstanceSearchEngine.php +++ b/src/query/SemiStructuredObjectInstanceSearchEngine.php @@ -1,166 +1,167 @@ objectType = $object_type; return $this; } public function getObjectType() { return $this->objectType; } public function getResultTypeDescription() { return pht('Object Instances'); } public function getApplicationClassName() { return 'SemiStructuredDataApplication'; } public function newQuery() { $query = id(new SemiStructuredObjectInstanceQuery()); if ($this->getObjectType()) { $query->withObjectType($this->getObjectType()); } return $query; } protected function buildCustomSearchFields() { - return array( -// TODO object class + $fields = array( + ); - id(new SemiStructuredStaticSearchField()) + if ($this->getObjectType()) { + $fields[] = id(new SemiStructuredStaticSearchField()) ->setKey('objecttype') ->setLabel(pht('Object Type')) - ->setValue($this->getObjectType()->getName()), - + ->setValue($this->getObjectType()->getName()); + } - ); + return $fields; } protected function getURI($path) { return "/semistruct/type/{$this->getObjectType()->getID()}/{$path}"; } protected function getBuiltinQueryNames() { $names = array(); $names['all'] = pht('All Instances'); return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); $viewer = $this->requireViewer(); switch ($query_key) { case 'all': return $query; case 'open': return $query->setParameter( 'statuses', array( SemiStructuredObjectType::STATUS_ACTIVE, )); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); // TODO type id/phid // if ($map['statuses']) { // $query->withStatuses($map['statuses']); // } // if ($map['editable'] !== null) { // $query->withCanEdit($map['editable']); // } return $query; } protected function getRequiredHandlePHIDsForResultList( array $objects, PhabricatorSavedQuery $query) { return array(); } public function renderResultsDirectly(array $items) { return $this->renderResultList( $items, new PhabricatorSavedQuery(), array()); } protected function renderResultList( array $items, PhabricatorSavedQuery $query , array $handles) { $viewer = $this->requireViewer(); if ($items) { $edge_query = id(new PhabricatorEdgeQuery()) ->withSourcePHIDs(mpull($items, 'getPHID')) ->withEdgeTypes( array( PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, )); $edge_query->execute(); } $list = id(new PHUIObjectItemListView()) ->setViewer($viewer); foreach ($items as $instance) { $item = id(new PHUIObjectItemView()) ->setViewer($viewer) ->setObjectName($instance->getName()) ->setHeader($instance->getName()) ->setHref($instance->getURI()) ->setObject($instance); $icon = id(new PHUIIconView()) ->setIcon($instance->getIcon()); $item->setImageIcon($icon); $item->setEpoch($instance->getDateModified()); $phid = $instance->getPHID(); $project_phids = $edge_query->getDestinationPHIDs(array($phid)); $project_handles = $viewer->loadHandles($project_phids); $item->addAttribute( id(new PHUIHandleTagListView()) ->setLimit(4) ->setNoDataString(pht('No Tags')) ->setSlim(true) ->setHandles($project_handles)); $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No objects found.')); return $result; } } diff --git a/src/storage/SemiStructuredObjectInstance.php b/src/storage/SemiStructuredObjectInstance.php index 9fdb9f7..64048b1 100644 --- a/src/storage/SemiStructuredObjectInstance.php +++ b/src/storage/SemiStructuredObjectInstance.php @@ -1,180 +1,223 @@ setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) // TODO take policies from class? // ->setEditPolicy($actor->getPHID()) ->setStatus(self::STATUS_ACTIVE); if ($object_class !== null) { $object ->setClassPHID($object_class->getPHID()) ->attachClass($object_class); } return $object; } public function attachClass( SemiStructuredObjectType $object_class = null) { $this->class = $object_class; return $this; } public function getClass() { return $this->assertAttached($this->class); } public function hasAttachedClass() { return $this->class !== self::ATTACHABLE; } public function getURI() { return urisprintf('/semistruct/instance/%d/', $this->getID()); } public function getIcon() { // TODO customize in Type return SemiStructuredDataApplication::ICON_OBJECT_INSTANCE; } public static function getStatusNameMap() { return array( // TODO remove this self::STATUS_ACTIVE => pht('Active'), self::STATUS_ARCHIVED => pht('Archived'), ); } protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_SERIALIZATION => array( 'rawData' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( 'name' => 'sort255', 'description' => 'text', 'status' => 'text32', ), self::CONFIG_KEY_SCHEMA => array( 'classPHID' => array( 'columns' => array('classPHID'), ), ), ) + parent::getConfiguration(); } public function getPHIDType() { return SemiStructuredObjectInstancePHIDType::TYPECONST; } /* -( PhabricatorApplicationTransactionInterface )------------------------- */ public function getApplicationTransactionEditor() { return new SemiStructuredObjectInstanceTransactionEditor(); } public function getApplicationTransactionTemplate() { return new SemiStructuredObjectInstanceTransaction(); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, ); } public function getPolicy($capability) { return ''; // TODO switch ($capability) { // TODO case PhabricatorPolicyCapability::CAN_VIEW: return $this->getViewPolicy(); case PhabricatorPolicyCapability::CAN_EDIT: return $this->getEditPolicy(); } } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return true; } - /* -( PhabricatorCustomFieldInterface )------------------------------------ */ +/* -( PhabricatorCustomFieldInterface )------------------------------------ */ public function getCustomFieldSpecificationForRole($role) { - return PhabricatorEnv::getEnvConfig('user.fields'); + return array(); } public function getCustomFieldBaseClass() { return 'SemiStructuredInstanceCustomField'; } public function getCustomFields() { return $this->assertAttached($this->customFields); } public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) { $this->customFields = $fields; return $this; } +/* -( PhabricatorConduitResultInterface )---------------------------------- */ + + + public function getFieldSpecificationsForConduit() { + return array( + (new PhabricatorConduitSearchFieldSpecification()) + ->setKey('name') + ->setType('string') + ->setDescription(pht('The name of the instance.')), + (new PhabricatorConduitSearchFieldSpecification()) + ->setKey('description') + ->setType('remarkup') + ->setDescription(pht('The description.')), + (new PhabricatorConduitSearchFieldSpecification()) + ->setKey('classPHID') + ->setType('phid') + ->setDescription(pht('The Type of this Instance.')), + (new PhabricatorConduitSearchFieldSpecification()) + ->setKey('rawData') + ->setType('map') + ->setDescription(pht('The raw structured data')), + +// TODO custom fields + + ); + } + + public function getFieldValuesForConduit() { + return array( + 'name' => $this->getName(), + 'description' => array( + 'raw' => $this->getDescription(), + ), + 'classPHID' => $this->getClassPHID(), + 'rawData' => json_decode($this->getRawData()), + ); + } + + public function getConduitSearchAttachments() { + return array(); + } + + /* -( PhabricatorDestructibleInterface )----------------------------------- */ public function destroyObjectPermanently( PhabricatorDestructionEngine $engine) { $this->openTransaction(); $this->delete(); $this->saveTransaction(); } /* -( PhabricatorSubscribableInterface )----------------------------------- */ public function isAutomaticallySubscribed($phid) { return false; } } diff --git a/src/xaction/instance/SemiStructuredObjectInstanceClassTransaction.php b/src/xaction/instance/SemiStructuredObjectInstanceClassTransaction.php index 5f09bf4..e04ea54 100644 --- a/src/xaction/instance/SemiStructuredObjectInstanceClassTransaction.php +++ b/src/xaction/instance/SemiStructuredObjectInstanceClassTransaction.php @@ -1,38 +1,41 @@ getClassPHID(); } public function applyInternalEffects($object, $value) { $object->setClassPHID($value); } public function validateTransactions($object, array $xactions) { $errors = array(); if (!$xactions) { if (!$object->getClassPHID()) { $errors[] = $this->newInvalidError(pht('ClassPHID is required!')); } } + foreach ($xactions as $xaction) { $new_value = $xaction->getNewValue(); + // TODO figure out why getOldValue is null $old_value = $xaction->getOldValue(); + $old_value = $object->getClassPHID(); if ($old_value !== null && $new_value != $old_value) { $errors[] = $this->newInvalidError( pht('ClassPHID cannot be changed.')); } } return $errors; } }