diff --git a/resources/sql/20230427.semistructured.1.objectinstance.sql b/resources/sql/20230427.semistructured.1.objectinstance.sql new file mode 100644 index 0000000..c3ada15 --- /dev/null +++ b/resources/sql/20230427.semistructured.1.objectinstance.sql @@ -0,0 +1,16 @@ +CREATE TABLE {$NAMESPACE}_semistructured.semistructured_objectinstance ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + phid VARBINARY(64) NOT NULL, + dateCreated INT UNSIGNED NOT NULL, + dateModified INT UNSIGNED NOT NULL, + + classPHID VARBINARY(64) NOT NULL, + status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT}, + rawData LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT}, + + UNIQUE KEY `key_phid` (phid), + KEY `classPHID` (classPHID) +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; + +CREATE TABLE {$NAMESPACE}_semistructured.semistructured_objectinstancetransaction + LIKE {$NAMESPACE}_file.file_transaction; diff --git a/resources/sql/20230427.semistructured.2.objecttype.sql b/resources/sql/20230427.semistructured.2.objecttype.sql new file mode 100644 index 0000000..232ec94 --- /dev/null +++ b/resources/sql/20230427.semistructured.2.objecttype.sql @@ -0,0 +1,15 @@ +CREATE TABLE {$NAMESPACE}_semistructured.semistructured_objecttype ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + phid VARBINARY(64) NOT NULL, + dateCreated INT UNSIGNED NOT NULL, + dateModified INT UNSIGNED NOT NULL, + + name VARCHAR(255) NOT NULL COLLATE {$COLLATE_SORT}, + description LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT}, + status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT}, + + UNIQUE KEY `key_phid` (phid) +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; + +CREATE TABLE {$NAMESPACE}_semistructured.semistructured_objecttypetransaction + LIKE {$NAMESPACE}_file.file_transaction; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index cb669a2..0baa48d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1,18 +1,44 @@ 2, 'class' => array( + 'SemiStructuredBaseController' => 'applications/semistruct/controller/SemiStructuredBaseController.php', + 'SemiStructuredDAO' => 'applications/semistruct/storage/SemiStructuredDAO.php', 'SemiStructuredDataApplication' => 'applications/semistruct/application/SemiStructuredDataApplication.php', + 'SemiStructuredObjectInstance' => 'applications/semistruct/storage/SemiStructuredObjectInstance.php', + 'SemiStructuredObjectInstancePHIDType' => 'applications/semistruct/phid/SemiStructuredObjectInstancePHIDType.php', + 'SemiStructuredObjectType' => 'applications/semistruct/storage/SemiStructuredObjectType.php', + 'SemiStructuredObjectTypePHIDType' => 'applications/semistruct/phid/SemiStructuredObjectTypePHIDType.php', + 'SemiStructuredPatchList' => 'applications/semistruct/storage/SemiStructuredPatchList.php', ), 'function' => array(), 'xmap' => array( + 'SemiStructuredBaseController' => 'PhabricatorController', + 'SemiStructuredDAO' => 'PhabricatorLiskDAO', 'SemiStructuredDataApplication' => 'PhabricatorApplication', + 'SemiStructuredObjectInstance' => array( + 'SemiStructuredDAO', + 'PhabricatorPolicyInterface', + 'PhabricatorApplicationTransactionInterface', + 'PhabricatorFlaggableInterface', + 'PhabricatorDestructibleInterface', + ), + 'SemiStructuredObjectInstancePHIDType' => 'PhabricatorPHIDType', + 'SemiStructuredObjectType' => array( + 'SemiStructuredDAO', + 'PhabricatorPolicyInterface', + 'PhabricatorApplicationTransactionInterface', + 'PhabricatorFlaggableInterface', + 'PhabricatorDestructibleInterface', + ), + 'SemiStructuredObjectTypePHIDType' => 'PhabricatorPHIDType', + 'SemiStructuredPatchList' => 'PhabricatorSQLPatchList', ), )); diff --git a/src/application/SemiStructuredDataApplication.php b/src/application/SemiStructuredDataApplication.php index 8e14cbf..873b6b1 100644 --- a/src/application/SemiStructuredDataApplication.php +++ b/src/application/SemiStructuredDataApplication.php @@ -1,23 +1,23 @@ array( ), ); } } diff --git a/src/controller/SemiStructuredBaseController.php b/src/controller/SemiStructuredBaseController.php new file mode 100644 index 0000000..4ad8018 --- /dev/null +++ b/src/controller/SemiStructuredBaseController.php @@ -0,0 +1,11 @@ +newApplicationMenu() + // ->setSearchEngine(new PhabricatorBadgesSearchEngine()); + ; + } + +} diff --git a/src/phid/SemiStructuredObjectInstancePHIDType.php b/src/phid/SemiStructuredObjectInstancePHIDType.php new file mode 100644 index 0000000..2ed055c --- /dev/null +++ b/src/phid/SemiStructuredObjectInstancePHIDType.php @@ -0,0 +1,42 @@ +withPHIDs($phids); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $item = $objects[$phid]; + + $id = $item->getID(); + + $handle->setName($item->getName()); + // TODO $handle->setURI("/semistruct/object/view/{$id}/"); + } + } + +} diff --git a/src/phid/SemiStructuredObjectTypePHIDType.php b/src/phid/SemiStructuredObjectTypePHIDType.php new file mode 100644 index 0000000..2de90bf --- /dev/null +++ b/src/phid/SemiStructuredObjectTypePHIDType.php @@ -0,0 +1,42 @@ +withPHIDs($phids); + } + + public function loadHandles( + PhabricatorHandleQuery $query, + array $handles, + array $objects) { + + foreach ($handles as $phid => $handle) { + $item = $objects[$phid]; + + $id = $item->getID(); + + $handle->setName($item->getName()); + $handle->setURI("/semistruct/types/view/{$id}/"); + } + } + +} diff --git a/src/storage/SemiStructuredDAO.php b/src/storage/SemiStructuredDAO.php new file mode 100644 index 0000000..38c4bd2 --- /dev/null +++ b/src/storage/SemiStructuredDAO.php @@ -0,0 +1,9 @@ +setClassPHID($object_class->getPHID()) + ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) // TODO take policies from class? + ->setEditPolicy($actor->getPHID()) + ->setStatus(self::STATUS_ACTIVE); + } + + public static function getStatusNameMap() { + return array( + self::STATUS_ACTIVE => pht('Active'), + self::STATUS_ARCHIVED => pht('Archived'), + ); + } + + protected function getConfiguration() { + return array( + self::CONFIG_AUX_PHID => true, + self::CONFIG_COLUMN_SCHEMA => array( + 'name' => 'sort255', + 'status' => 'text32', + 'classPHID' => 'phid', + 'rawData' => 'text', + ), + self::CONFIG_KEY_SCHEMA => array( + 'classPHID' => array( + 'columns' => array('classPHID'), + ), + ), + ) + parent::getConfiguration(); + } + + +/* -( PhabricatorApplicationTransactionInterface )------------------------- */ + + + public function getApplicationTransactionEditor() { + return new PhabricatorDashboardPanelTransactionEditor(); + } + + public function getApplicationTransactionTemplate() { + return new PhabricatorDashboardPanelTransaction(); + } + + +/* -( PhabricatorPolicyInterface )----------------------------------------- */ + + + public function getCapabilities() { + return array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + ); + } + + public function getPolicy($capability) { + switch ($capability) { + case PhabricatorPolicyCapability::CAN_VIEW: + return $this->getViewPolicy(); + case PhabricatorPolicyCapability::CAN_EDIT: + return $this->getEditPolicy(); + } + } + + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { + return false; + } + + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + $this->openTransaction(); + $this->delete(); + $this->saveTransaction(); + } + +} diff --git a/src/storage/SemiStructuredObjectType.php b/src/storage/SemiStructuredObjectType.php new file mode 100644 index 0000000..356e0ba --- /dev/null +++ b/src/storage/SemiStructuredObjectType.php @@ -0,0 +1,99 @@ +setName('') + ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) + ->setEditPolicy($actor->getPHID()) // TODO config for deflt + ->setStatus(self::STATUS_ACTIVE); + } + + public static function getStatusNameMap() { + return array( + self::STATUS_ACTIVE => pht('Active'), + self::STATUS_ARCHIVED => pht('Archived'), + ); + } + + protected function getConfiguration() { + return array( + self::CONFIG_AUX_PHID => true, + self::CONFIG_COLUMN_SCHEMA => array( + 'name' => 'sort255', + 'status' => 'text32', + 'description' => 'text', + ), + ) + parent::getConfiguration(); + } + + + +/* -( PhabricatorApplicationTransactionInterface )------------------------- */ + + + public function getApplicationTransactionEditor() { + return new PhabricatorDashboardPanelTransactionEditor(); + } + + public function getApplicationTransactionTemplate() { + return new PhabricatorDashboardPanelTransaction(); + } + + +/* -( PhabricatorPolicyInterface )----------------------------------------- */ + + + public function getCapabilities() { + return array( + PhabricatorPolicyCapability::CAN_VIEW, + PhabricatorPolicyCapability::CAN_EDIT, + ); + } + + public function getPolicy($capability) { + switch ($capability) { + case PhabricatorPolicyCapability::CAN_VIEW: + return $this->getViewPolicy(); + case PhabricatorPolicyCapability::CAN_EDIT: + return $this->getEditPolicy(); + } + } + + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { + return false; + } + + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + $this->openTransaction(); + $this->delete(); + $this->saveTransaction(); + } + +} diff --git a/src/storage/SemiStructuredPatchList.php b/src/storage/SemiStructuredPatchList.php new file mode 100644 index 0000000..a993662 --- /dev/null +++ b/src/storage/SemiStructuredPatchList.php @@ -0,0 +1,27 @@ + array( + 'name' => 'semistructured', + 'type' => 'db', + 'after' => array(), + ), + ); + + + $auto = $this->buildPatchesFromDirectory($root.'/resources/sql/'); + + return $db_patches + $auto; + } + +}