Changeset View
Standalone View
src/applications/tokens/storage/PhabricatorTokensToken.php
- This file was added.
<?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', | |||||
epriestley: (Column doesn't exist?) | |||||
'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(); | |||||
Done Inline ActionsLet's just omit this for now -- we don't have a mailKey, and I think interacting with tokens via email seems a little silly / not worth building, at least for now. I could be wrong and maybe emailing datboi@whatever.phabricator.com will be all the rage in a few months, but doesn't feel like the highest-value interaction here. epriestley: Let's just omit this for now -- we don't have a `mailKey`, and I think interacting with tokens… | |||||
$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 )-------------------- */ | |||||
Done Inline ActionsI think this isn't right -- it's loading copies of itself by a nonexistent column. Probably intended to delete PhabricatorTokenGiven instead (replace new self() with new PhabricatorTokenGiven())? I think we could reasonably delete the File by filePHID, if filePHID is set too. epriestley: I think this isn't right -- it's loading copies of itself by a nonexistent column. Probably… | |||||
public function isAutomaticallySubscribed($phid) { | |||||
return false; | |||||
} | |||||
/* -( PhabricatorConduitResultInterface )---------------------------------- */ | |||||
Not Done Inline ActionsThis is ultimately a product question but maybe creating a token shouldn't permanently auto-subscribe you to it. We don't really have a hard-and-fast rule for this but I think the soft rule is "if you own the object", and a creator's ownership claim on a token feels a little tenuous (e.g., compared to a Differential Revision, which is clearly strongly-owned). We recently backed off on auto-subscribe on Phame blogs, and this ownership feels similarly soft to me. We can easily tweak this later, though. epriestley: This is ultimately a product question but maybe creating a token shouldn't permanently auto… | |||||
Not Done Inline ActionsWhat does it even mean to be subscribed to a token? I can't think of a scenario where I would want that. jcox: What does it even mean to be subscribed to a token? I can't think of a scenario where I would… | |||||
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(); | |||||
} | |||||
} |
(Column doesn't exist?)