1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Add DoorkeeperExternalObject

Summary:
Ref T2852. This table holds data about external objects and allows us to write edges to them.

Objects are identified with an `<applicationType, applicationDomain, objectType, objectID>` tuple. For example, Asana tasks will be, e.g., `<asana, asana.com, asana:task, 93829279873>` or similar.

Test Plan: Ran storage upgrade.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2852

Differential Revision: https://secure.phabricator.com/D6271
This commit is contained in:
epriestley 2013-06-24 15:54:36 -07:00
parent 6020e213e9
commit f54a5d8087
6 changed files with 140 additions and 0 deletions

View file

@ -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;

View file

@ -533,6 +533,8 @@ phutil_register_library_map(array(
'DivinerRenderer' => 'applications/diviner/renderer/DivinerRenderer.php', 'DivinerRenderer' => 'applications/diviner/renderer/DivinerRenderer.php',
'DivinerStaticPublisher' => 'applications/diviner/publisher/DivinerStaticPublisher.php', 'DivinerStaticPublisher' => 'applications/diviner/publisher/DivinerStaticPublisher.php',
'DivinerWorkflow' => 'applications/diviner/workflow/DivinerWorkflow.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', 'DrydockAllocatorWorker' => 'applications/drydock/worker/DrydockAllocatorWorker.php',
'DrydockApacheWebrootInterface' => 'applications/drydock/interface/webroot/DrydockApacheWebrootInterface.php', 'DrydockApacheWebrootInterface' => 'applications/drydock/interface/webroot/DrydockApacheWebrootInterface.php',
'DrydockBlueprint' => 'applications/drydock/blueprint/DrydockBlueprint.php', 'DrydockBlueprint' => 'applications/drydock/blueprint/DrydockBlueprint.php',
@ -2404,6 +2406,12 @@ phutil_register_library_map(array(
'DivinerRemarkupRuleSymbol' => 'PhutilRemarkupRule', 'DivinerRemarkupRuleSymbol' => 'PhutilRemarkupRule',
'DivinerStaticPublisher' => 'DivinerPublisher', 'DivinerStaticPublisher' => 'DivinerPublisher',
'DivinerWorkflow' => 'PhutilArgumentWorkflow', 'DivinerWorkflow' => 'PhutilArgumentWorkflow',
'DoorkeeperDAO' => 'PhabricatorLiskDAO',
'DoorkeeperExternalObject' =>
array(
0 => 'DoorkeeperDAO',
1 => 'PhabricatorPolicyInterface',
),
'DrydockAllocatorWorker' => 'PhabricatorWorker', 'DrydockAllocatorWorker' => 'PhabricatorWorker',
'DrydockApacheWebrootInterface' => 'DrydockWebrootInterface', 'DrydockApacheWebrootInterface' => 'DrydockWebrootInterface',
'DrydockCommandInterface' => 'DrydockInterface', 'DrydockCommandInterface' => 'DrydockInterface',

View file

@ -0,0 +1,9 @@
<?php
abstract class DoorkeeperDAO extends PhabricatorLiskDAO {
public function getApplicationName() {
return 'doorkeeper';
}
}

View file

@ -0,0 +1,79 @@
<?php
final class DoorkeeperExternalObject extends DoorkeeperDAO
implements PhabricatorPolicyInterface {
protected $objectKey;
protected $applicationType;
protected $applicationDomain;
protected $objectType;
protected $objectID;
protected $objectURI;
protected $importerPHID;
protected $properties = array();
protected $viewPolicy;
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => 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;
}
}

View file

@ -48,6 +48,7 @@ final class PhabricatorPHIDConstants {
const PHID_TYPE_BOOK = 'BOOK'; const PHID_TYPE_BOOK = 'BOOK';
const PHID_TYPE_ATOM = 'ATOM'; const PHID_TYPE_ATOM = 'ATOM';
const PHID_TYPE_AUTH = 'AUTH'; const PHID_TYPE_AUTH = 'AUTH';
const PHID_TYPE_XOBJ = 'XOBJ';
const PHID_TYPE_VOID = 'VOID'; const PHID_TYPE_VOID = 'VOID';
const PHID_VOID = 'PHID-VOID-00000000000000000000'; const PHID_VOID = 'PHID-VOID-00000000000000000000';

View file

@ -195,6 +195,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'type' => 'db', 'type' => 'db',
'name' => 'auth', 'name' => 'auth',
), ),
'db.doorkeeper' => array(
'type' => 'db',
'name' => 'doorkeeper',
),
'0000.legacy.sql' => array( '0000.legacy.sql' => array(
'type' => 'sql', 'type' => 'sql',
'name' => $this->getPatchPath('0000.legacy.sql'), 'name' => $this->getPatchPath('0000.legacy.sql'),
@ -1394,6 +1398,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'type' => 'sql', 'type' => 'sql',
'name' => $this->getPatchPath('20130621.diffcommentunphid.sql'), 'name' => $this->getPatchPath('20130621.diffcommentunphid.sql'),
), ),
'20130622.doorkeeper.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('20130622.doorkeeper.sql'),
),
); );
} }
} }