diff --git a/resources/sql/patches/20130622.doorkeeper.sql b/resources/sql/patches/20130622.doorkeeper.sql new file mode 100644 index 0000000000..80329f03d5 --- /dev/null +++ b/resources/sql/patches/20130622.doorkeeper.sql @@ -0,0 +1,35 @@ +CREATE TABLE {$NAMESPACE}_doorkeeper.doorkeeper_externalobject ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + phid VARCHAR(64) NOT NULL COLLATE utf8_bin, + objectKey CHAR(12) NOT NULL COLLATE utf8_bin, + applicationType VARCHAR(32) NOT NULL COLLATE utf8_bin, + applicationDomain VARCHAR(32) NOT NULL COLLATE utf8_bin, + objectType VARCHAR(32) NOT NULL COLLATE utf8_bin, + objectID VARCHAR(64) NOT NULL COLLATE utf8_bin, + objectURI VARCHAR(128) COLLATE utf8_bin, + importerPHID VARCHAR(64) COLLATE utf8_bin, + properties LONGTEXT NOT NULL COLLATE utf8_bin, + viewPolicy VARCHAR(64) NOT NULL COLLATE utf8_bin, + dateCreated INT UNSIGNED NOT NULL, + dateModified INT UNSIGNED NOT NULL, + UNIQUE KEY `key_phid` (phid), + UNIQUE KEY `key_object` (objectKey), + KEY `key_full` (applicationType, applicationDomain, objectType, objectID) +) ENGINE=InnoDB, COLLATE utf8_general_ci; + +CREATE TABLE {$NAMESPACE}_doorkeeper.edge ( + src VARCHAR(64) NOT NULL COLLATE utf8_bin, + type INT UNSIGNED NOT NULL COLLATE utf8_bin, + dst VARCHAR(64) NOT NULL COLLATE utf8_bin, + dateCreated INT UNSIGNED NOT NULL, + seq INT UNSIGNED NOT NULL, + dataID INT UNSIGNED, + PRIMARY KEY (src, type, dst), + KEY (src, type, dateCreated, seq) +) ENGINE=InnoDB, COLLATE utf8_general_ci; + +CREATE TABLE {$NAMESPACE}_doorkeeper.edgedata ( + id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + data LONGTEXT NOT NULL COLLATE utf8_bin +) ENGINE=InnoDB, COLLATE utf8_general_ci; + diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3924ee8e35..2514a3e624 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -533,6 +533,8 @@ phutil_register_library_map(array( 'DivinerRenderer' => 'applications/diviner/renderer/DivinerRenderer.php', 'DivinerStaticPublisher' => 'applications/diviner/publisher/DivinerStaticPublisher.php', 'DivinerWorkflow' => 'applications/diviner/workflow/DivinerWorkflow.php', + 'DoorkeeperDAO' => 'applications/doorkeeper/storage/DoorkeeperDAO.php', + 'DoorkeeperExternalObject' => 'applications/doorkeeper/storage/DoorkeeperExternalObject.php', 'DrydockAllocatorWorker' => 'applications/drydock/worker/DrydockAllocatorWorker.php', 'DrydockApacheWebrootInterface' => 'applications/drydock/interface/webroot/DrydockApacheWebrootInterface.php', 'DrydockBlueprint' => 'applications/drydock/blueprint/DrydockBlueprint.php', @@ -2404,6 +2406,12 @@ phutil_register_library_map(array( 'DivinerRemarkupRuleSymbol' => 'PhutilRemarkupRule', 'DivinerStaticPublisher' => 'DivinerPublisher', 'DivinerWorkflow' => 'PhutilArgumentWorkflow', + 'DoorkeeperDAO' => 'PhabricatorLiskDAO', + 'DoorkeeperExternalObject' => + array( + 0 => 'DoorkeeperDAO', + 1 => 'PhabricatorPolicyInterface', + ), 'DrydockAllocatorWorker' => 'PhabricatorWorker', 'DrydockApacheWebrootInterface' => 'DrydockWebrootInterface', 'DrydockCommandInterface' => 'DrydockInterface', diff --git a/src/applications/doorkeeper/storage/DoorkeeperDAO.php b/src/applications/doorkeeper/storage/DoorkeeperDAO.php new file mode 100644 index 0000000000..19ec3ea84f --- /dev/null +++ b/src/applications/doorkeeper/storage/DoorkeeperDAO.php @@ -0,0 +1,9 @@ + true, + self::CONFIG_SERIALIZATION => array( + 'properties' => self::SERIALIZATION_JSON, + ), + ) + parent::getConfiguration(); + } + + public function generatePHID() { + return PhabricatorPHID::generateNewPHID( + PhabricatorPHIDConstants::PHID_TYPE_XOBJ); + } + + public function getProperty($key, $default = null) { + return idx($this->properties, $key, $default); + } + + public function setProperty($key, $value) { + $this->properties[$key] = $value; + return $this; + } + + public function getObjectKey() { + $key = parent::getObjectKey(); + if ($key === null) { + $key = PhabricatorHash::digestForIndex( + implode( + ':', + array( + $this->getApplicationType(), + $this->getApplicationDomain(), + $this->getObjectType(), + $this->getObjectID(), + ))); + } + return $key; + } + + public function save() { + if (!$this->objectKey) { + $this->objectKey = $this->getObjectKey(); + } + return parent::save(); + } + + +/* -( PhabricatorPolicyInterface )----------------------------------------- */ + + public function getCapabilities() { + return array( + PhabricatorPolicyCapability::CAN_VIEW, + ); + } + + public function getPolicy($capability) { + return $this->viewPolicy; + } + + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { + return false; + } + +} diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index 84cffbf1bf..04e154d6d8 100644 --- a/src/applications/phid/PhabricatorPHIDConstants.php +++ b/src/applications/phid/PhabricatorPHIDConstants.php @@ -48,6 +48,7 @@ final class PhabricatorPHIDConstants { const PHID_TYPE_BOOK = 'BOOK'; const PHID_TYPE_ATOM = 'ATOM'; const PHID_TYPE_AUTH = 'AUTH'; + const PHID_TYPE_XOBJ = 'XOBJ'; const PHID_TYPE_VOID = 'VOID'; const PHID_VOID = 'PHID-VOID-00000000000000000000'; diff --git a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php index d324ca5226..5a269bc899 100644 --- a/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php +++ b/src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php @@ -195,6 +195,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'type' => 'db', 'name' => 'auth', ), + 'db.doorkeeper' => array( + 'type' => 'db', + 'name' => 'doorkeeper', + ), '0000.legacy.sql' => array( 'type' => 'sql', 'name' => $this->getPatchPath('0000.legacy.sql'), @@ -1394,6 +1398,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList { 'type' => 'sql', 'name' => $this->getPatchPath('20130621.diffcommentunphid.sql'), ), + '20130622.doorkeeper.sql' => array( + 'type' => 'sql', + 'name' => $this->getPatchPath('20130622.doorkeeper.sql'), + ), ); } }