mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +01:00
Added a token_token
table in anticipation of some data-driven tokens
Summary: Ref T11217. This just adds the table that we'll store tokens in. It doesn't make use of the table at all yet. This is mostly pulled from this diff (D16178). Specifically I mostly followed Evan's instructions related to the token table here: D16178#189120. Test Plan: I ran `./bin/storage upgrade` successfully and there were no schema errors. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley, yelirekim Maniphest Tasks: T11217 Differential Revision: https://secure.phabricator.com/D16621
This commit is contained in:
parent
bc1cb06b07
commit
32d660c08f
3 changed files with 180 additions and 0 deletions
15
resources/sql/autopatches/20160928.tokentoken.sql
Normal file
15
resources/sql/autopatches/20160928.tokentoken.sql
Normal file
|
@ -0,0 +1,15 @@
|
|||
CREATE TABLE {$NAMESPACE}_token.token_token (
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
phid VARBINARY(64) NOT NULL,
|
||||
name VARCHAR(64) NOT NULL COLLATE {$COLLATE_TEXT},
|
||||
flavor VARCHAR(128) NOT NULL COLLATE {$COLLATE_TEXT},
|
||||
status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT},
|
||||
builtinKey VARCHAR(32) COLLATE {$COLLATE_TEXT},
|
||||
dateCreated INT UNSIGNED NOT NULL,
|
||||
dateModified INT UNSIGNED NOT NULL,
|
||||
creatorPHID VARBINARY(64) NOT NULL,
|
||||
tokenImagePHID VARBINARY(64),
|
||||
UNIQUE KEY `key_phid` (phid),
|
||||
UNIQUE KEY `key_builtin` (builtinKey),
|
||||
KEY `key_creator` (creatorPHID, dateModified)
|
||||
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
|
|
@ -3780,6 +3780,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorTokensApplication' => 'applications/tokens/application/PhabricatorTokensApplication.php',
|
||||
'PhabricatorTokensCurtainExtension' => 'applications/tokens/engineextension/PhabricatorTokensCurtainExtension.php',
|
||||
'PhabricatorTokensSettingsPanel' => 'applications/settings/panel/PhabricatorTokensSettingsPanel.php',
|
||||
'PhabricatorTokensToken' => 'applications/tokens/storage/PhabricatorTokensToken.php',
|
||||
'PhabricatorTooltipUIExample' => 'applications/uiexample/examples/PhabricatorTooltipUIExample.php',
|
||||
'PhabricatorTransactionChange' => 'applications/transactions/data/PhabricatorTransactionChange.php',
|
||||
'PhabricatorTransactionRemarkupChange' => 'applications/transactions/data/PhabricatorTransactionRemarkupChange.php',
|
||||
|
@ -8824,6 +8825,13 @@ phutil_register_library_map(array(
|
|||
'PhabricatorTokensApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorTokensCurtainExtension' => 'PHUICurtainExtension',
|
||||
'PhabricatorTokensSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorTokensToken' => array(
|
||||
'PhabricatorTokenDAO',
|
||||
'PhabricatorDestructibleInterface',
|
||||
'PhabricatorSubscribableInterface',
|
||||
'PhabricatorFlaggableInterface',
|
||||
'PhabricatorConduitResultInterface',
|
||||
),
|
||||
'PhabricatorTooltipUIExample' => 'PhabricatorUIExample',
|
||||
'PhabricatorTransactionChange' => 'Phobject',
|
||||
'PhabricatorTransactionRemarkupChange' => 'PhabricatorTransactionChange',
|
||||
|
|
157
src/applications/tokens/storage/PhabricatorTokensToken.php
Normal file
157
src/applications/tokens/storage/PhabricatorTokensToken.php
Normal file
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorTokensToken extends PhabricatorTokenDAO
|
||||
implements
|
||||
PhabricatorDestructibleInterface,
|
||||
PhabricatorSubscribableInterface,
|
||||
PhabricatorFlaggableInterface,
|
||||
PhabricatorConduitResultInterface {
|
||||
|
||||
protected $name;
|
||||
protected $flavor;
|
||||
protected $status;
|
||||
protected $creatorPHID;
|
||||
protected $tokenImagePHID;
|
||||
protected $builtinKey;
|
||||
|
||||
|
||||
const STATUS_ACTIVE = 'active';
|
||||
const STATUS_ARCHIVED = 'archived';
|
||||
|
||||
protected function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_AUX_PHID => true,
|
||||
self::CONFIG_COLUMN_SCHEMA => array(
|
||||
'name' => 'text64',
|
||||
'flavor' => 'text128',
|
||||
'status' => 'text32',
|
||||
'tokenImagePHID' => 'phid?',
|
||||
'builtinKey' => 'text32?',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
'key_creator' => array(
|
||||
'columns' => array('creatorPHID', 'dateModified'),
|
||||
),
|
||||
'key_builtin' => array(
|
||||
'columns' => array('builtinKey'),
|
||||
'unique' => true,
|
||||
),
|
||||
),
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public function getTableName() {
|
||||
return 'token_token';
|
||||
}
|
||||
|
||||
public function generatePHID() {
|
||||
return PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorTokenTokenPHIDType::TYPECONST);
|
||||
}
|
||||
|
||||
public static function initializeNewToken(PhabricatorUser $actor) {
|
||||
$app = id(new PhabricatorApplicationQuery())
|
||||
->setViewer($actor)
|
||||
->withClasses(array('PhabricatorTokensApplication'))
|
||||
->executeOne();
|
||||
|
||||
$token = id(new self())
|
||||
->setCreatorPHID($actor->getPHID())
|
||||
->setStatus(self::STATUS_ACTIVE)
|
||||
->setTokenImagePHID('');
|
||||
return $token;
|
||||
}
|
||||
|
||||
public function isArchived() {
|
||||
return ($this->getStatus() == self::STATUS_ARCHIVED);
|
||||
}
|
||||
|
||||
public static function getStatusNameMap() {
|
||||
return array(
|
||||
self::STATUS_ACTIVE => pht('Active'),
|
||||
self::STATUS_ARCHIVED => pht('Archived'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getTokenImageURI() {
|
||||
return $this->getTokenImageFile()->getBestURI();
|
||||
}
|
||||
|
||||
public function attachTokenImageFile(PhabricatorFile $file) {
|
||||
$this->tokenImageFile = $file;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTokenImageFile() {
|
||||
return $this->assertAttached($this->tokenImageFile);
|
||||
}
|
||||
|
||||
public function getViewURI() {
|
||||
return '/tokens/view/'.$this->getID().'/';
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
||||
|
||||
public function destroyObjectPermanently(
|
||||
PhabricatorDestructionEngine $engine) {
|
||||
|
||||
$this->openTransaction();
|
||||
|
||||
$tokens = id(new PhabricatorTokenGiven())
|
||||
->loadAllWhere('tokenPHID = %s', $this->getPHID());
|
||||
foreach ($tokens as $token) {
|
||||
$token->delete();
|
||||
}
|
||||
if ($this->getTokenImagePHID()) {
|
||||
id(new PhabricatorFile())
|
||||
->loadOneWhere('filePHID = %s', $this->getTokenImagePHID())
|
||||
->delete();
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
|
||||
$this->saveTransaction();
|
||||
}
|
||||
|
||||
/* -( PhabricatorSubscribableInterface Implementation )-------------------- */
|
||||
|
||||
|
||||
public function isAutomaticallySubscribed($phid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorConduitResultInterface )---------------------------------- */
|
||||
|
||||
|
||||
public function getFieldSpecificationsForConduit() {
|
||||
return array(
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('name')
|
||||
->setType('string')
|
||||
->setDescription(pht('The name of the token.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('flavor')
|
||||
->setType('string')
|
||||
->setDescription(pht('Token flavor.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('status')
|
||||
->setType('string')
|
||||
->setDescription(pht('Archived or active status.')),
|
||||
);
|
||||
}
|
||||
|
||||
public function getFieldValuesForConduit() {
|
||||
return array(
|
||||
'name' => $this->getName(),
|
||||
'flavor' => $this->getFlavor(),
|
||||
'status' => $this->getStatus(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getConduitSearchAttachments() {
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue