@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

Josh Cox 32d660c0 bc1cb06b

+180
+15
resources/sql/autopatches/20160928.tokentoken.sql
··· 1 + CREATE TABLE {$NAMESPACE}_token.token_token ( 2 + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 3 + phid VARBINARY(64) NOT NULL, 4 + name VARCHAR(64) NOT NULL COLLATE {$COLLATE_TEXT}, 5 + flavor VARCHAR(128) NOT NULL COLLATE {$COLLATE_TEXT}, 6 + status VARCHAR(32) NOT NULL COLLATE {$COLLATE_TEXT}, 7 + builtinKey VARCHAR(32) COLLATE {$COLLATE_TEXT}, 8 + dateCreated INT UNSIGNED NOT NULL, 9 + dateModified INT UNSIGNED NOT NULL, 10 + creatorPHID VARBINARY(64) NOT NULL, 11 + tokenImagePHID VARBINARY(64), 12 + UNIQUE KEY `key_phid` (phid), 13 + UNIQUE KEY `key_builtin` (builtinKey), 14 + KEY `key_creator` (creatorPHID, dateModified) 15 + ) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
+8
src/__phutil_library_map__.php
··· 3780 3780 'PhabricatorTokensApplication' => 'applications/tokens/application/PhabricatorTokensApplication.php', 3781 3781 'PhabricatorTokensCurtainExtension' => 'applications/tokens/engineextension/PhabricatorTokensCurtainExtension.php', 3782 3782 'PhabricatorTokensSettingsPanel' => 'applications/settings/panel/PhabricatorTokensSettingsPanel.php', 3783 + 'PhabricatorTokensToken' => 'applications/tokens/storage/PhabricatorTokensToken.php', 3783 3784 'PhabricatorTooltipUIExample' => 'applications/uiexample/examples/PhabricatorTooltipUIExample.php', 3784 3785 'PhabricatorTransactionChange' => 'applications/transactions/data/PhabricatorTransactionChange.php', 3785 3786 'PhabricatorTransactionRemarkupChange' => 'applications/transactions/data/PhabricatorTransactionRemarkupChange.php', ··· 8824 8825 'PhabricatorTokensApplication' => 'PhabricatorApplication', 8825 8826 'PhabricatorTokensCurtainExtension' => 'PHUICurtainExtension', 8826 8827 'PhabricatorTokensSettingsPanel' => 'PhabricatorSettingsPanel', 8828 + 'PhabricatorTokensToken' => array( 8829 + 'PhabricatorTokenDAO', 8830 + 'PhabricatorDestructibleInterface', 8831 + 'PhabricatorSubscribableInterface', 8832 + 'PhabricatorFlaggableInterface', 8833 + 'PhabricatorConduitResultInterface', 8834 + ), 8827 8835 'PhabricatorTooltipUIExample' => 'PhabricatorUIExample', 8828 8836 'PhabricatorTransactionChange' => 'Phobject', 8829 8837 'PhabricatorTransactionRemarkupChange' => 'PhabricatorTransactionChange',
+157
src/applications/tokens/storage/PhabricatorTokensToken.php
··· 1 + <?php 2 + 3 + final class PhabricatorTokensToken extends PhabricatorTokenDAO 4 + implements 5 + PhabricatorDestructibleInterface, 6 + PhabricatorSubscribableInterface, 7 + PhabricatorFlaggableInterface, 8 + PhabricatorConduitResultInterface { 9 + 10 + protected $name; 11 + protected $flavor; 12 + protected $status; 13 + protected $creatorPHID; 14 + protected $tokenImagePHID; 15 + protected $builtinKey; 16 + 17 + 18 + const STATUS_ACTIVE = 'active'; 19 + const STATUS_ARCHIVED = 'archived'; 20 + 21 + protected function getConfiguration() { 22 + return array( 23 + self::CONFIG_AUX_PHID => true, 24 + self::CONFIG_COLUMN_SCHEMA => array( 25 + 'name' => 'text64', 26 + 'flavor' => 'text128', 27 + 'status' => 'text32', 28 + 'tokenImagePHID' => 'phid?', 29 + 'builtinKey' => 'text32?', 30 + ), 31 + self::CONFIG_KEY_SCHEMA => array( 32 + 'key_creator' => array( 33 + 'columns' => array('creatorPHID', 'dateModified'), 34 + ), 35 + 'key_builtin' => array( 36 + 'columns' => array('builtinKey'), 37 + 'unique' => true, 38 + ), 39 + ), 40 + ) + parent::getConfiguration(); 41 + } 42 + 43 + public function getTableName() { 44 + return 'token_token'; 45 + } 46 + 47 + public function generatePHID() { 48 + return PhabricatorPHID::generateNewPHID( 49 + PhabricatorTokenTokenPHIDType::TYPECONST); 50 + } 51 + 52 + public static function initializeNewToken(PhabricatorUser $actor) { 53 + $app = id(new PhabricatorApplicationQuery()) 54 + ->setViewer($actor) 55 + ->withClasses(array('PhabricatorTokensApplication')) 56 + ->executeOne(); 57 + 58 + $token = id(new self()) 59 + ->setCreatorPHID($actor->getPHID()) 60 + ->setStatus(self::STATUS_ACTIVE) 61 + ->setTokenImagePHID(''); 62 + return $token; 63 + } 64 + 65 + public function isArchived() { 66 + return ($this->getStatus() == self::STATUS_ARCHIVED); 67 + } 68 + 69 + public static function getStatusNameMap() { 70 + return array( 71 + self::STATUS_ACTIVE => pht('Active'), 72 + self::STATUS_ARCHIVED => pht('Archived'), 73 + ); 74 + } 75 + 76 + public function getTokenImageURI() { 77 + return $this->getTokenImageFile()->getBestURI(); 78 + } 79 + 80 + public function attachTokenImageFile(PhabricatorFile $file) { 81 + $this->tokenImageFile = $file; 82 + return $this; 83 + } 84 + 85 + public function getTokenImageFile() { 86 + return $this->assertAttached($this->tokenImageFile); 87 + } 88 + 89 + public function getViewURI() { 90 + return '/tokens/view/'.$this->getID().'/'; 91 + } 92 + 93 + 94 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 95 + 96 + public function destroyObjectPermanently( 97 + PhabricatorDestructionEngine $engine) { 98 + 99 + $this->openTransaction(); 100 + 101 + $tokens = id(new PhabricatorTokenGiven()) 102 + ->loadAllWhere('tokenPHID = %s', $this->getPHID()); 103 + foreach ($tokens as $token) { 104 + $token->delete(); 105 + } 106 + if ($this->getTokenImagePHID()) { 107 + id(new PhabricatorFile()) 108 + ->loadOneWhere('filePHID = %s', $this->getTokenImagePHID()) 109 + ->delete(); 110 + } 111 + 112 + $this->delete(); 113 + 114 + $this->saveTransaction(); 115 + } 116 + 117 + /* -( PhabricatorSubscribableInterface Implementation )-------------------- */ 118 + 119 + 120 + public function isAutomaticallySubscribed($phid) { 121 + return false; 122 + } 123 + 124 + 125 + /* -( PhabricatorConduitResultInterface )---------------------------------- */ 126 + 127 + 128 + public function getFieldSpecificationsForConduit() { 129 + return array( 130 + id(new PhabricatorConduitSearchFieldSpecification()) 131 + ->setKey('name') 132 + ->setType('string') 133 + ->setDescription(pht('The name of the token.')), 134 + id(new PhabricatorConduitSearchFieldSpecification()) 135 + ->setKey('flavor') 136 + ->setType('string') 137 + ->setDescription(pht('Token flavor.')), 138 + id(new PhabricatorConduitSearchFieldSpecification()) 139 + ->setKey('status') 140 + ->setType('string') 141 + ->setDescription(pht('Archived or active status.')), 142 + ); 143 + } 144 + 145 + public function getFieldValuesForConduit() { 146 + return array( 147 + 'name' => $this->getName(), 148 + 'flavor' => $this->getFlavor(), 149 + 'status' => $this->getStatus(), 150 + ); 151 + } 152 + 153 + public function getConduitSearchAttachments() { 154 + return array(); 155 + } 156 + 157 + }