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

Expose conduit API methods for Phurl URLs

Summary: Fixes T10681. Adds a search API endpoint and an edit API endpoint for Phurl URLs. I still need to add the ability to search by name, alias, URL, and maybe description.

Test Plan: Test the methods through `/conduit/method/phurls.search/` and `/conduit/method/phurls.edit/`

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley, yelirekim

Maniphest Tasks: T10681

Differential Revision: https://secure.phabricator.com/D16600

Josh Cox fc821188 f2bb9bc0

+169 -5
+11
resources/sql/autopatches/20160927.phurl.ngrams.php
··· 1 + <?php 2 + 3 + $table = new PhabricatorPhurlURL(); 4 + 5 + foreach (new LiskMigrationIterator($table) as $url) { 6 + PhabricatorSearchWorker::queueDocumentForIndexing( 7 + $url->getPHID(), 8 + array( 9 + 'force' => true, 10 + )); 11 + }
+7
resources/sql/autopatches/20160927.phurl.ngrams.sql
··· 1 + CREATE TABLE {$NAMESPACE}_phurl.phurl_phurlname_ngrams ( 2 + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 3 + objectID INT UNSIGNED NOT NULL, 4 + ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT}, 5 + KEY `key_object` (objectID), 6 + KEY `key_ngram` (ngram, objectID) 7 + ) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
+8
src/__phutil_library_map__.php
··· 3187 3187 'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php', 3188 3188 'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php', 3189 3189 'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php', 3190 + 'PhabricatorPhurlURLEditConduitAPIMethod' => 'applications/phurl/conduit/PhabricatorPhurlURLEditConduitAPIMethod.php', 3190 3191 'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php', 3191 3192 'PhabricatorPhurlURLEditEngine' => 'applications/phurl/editor/PhabricatorPhurlURLEditEngine.php', 3192 3193 'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php', 3193 3194 'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php', 3194 3195 'PhabricatorPhurlURLMailReceiver' => 'applications/phurl/mail/PhabricatorPhurlURLMailReceiver.php', 3196 + 'PhabricatorPhurlURLNameNgrams' => 'applications/phurl/storage/PhabricatorPhurlURLNameNgrams.php', 3195 3197 'PhabricatorPhurlURLPHIDType' => 'applications/phurl/phid/PhabricatorPhurlURLPHIDType.php', 3196 3198 'PhabricatorPhurlURLQuery' => 'applications/phurl/query/PhabricatorPhurlURLQuery.php', 3197 3199 'PhabricatorPhurlURLReplyHandler' => 'applications/phurl/mail/PhabricatorPhurlURLReplyHandler.php', 3200 + 'PhabricatorPhurlURLSearchConduitAPIMethod' => 'applications/phurl/conduit/PhabricatorPhurlURLSearchConduitAPIMethod.php', 3198 3201 'PhabricatorPhurlURLSearchEngine' => 'applications/phurl/query/PhabricatorPhurlURLSearchEngine.php', 3199 3202 'PhabricatorPhurlURLTransaction' => 'applications/phurl/storage/PhabricatorPhurlURLTransaction.php', 3200 3203 'PhabricatorPhurlURLTransactionComment' => 'applications/phurl/storage/PhabricatorPhurlURLTransactionComment.php', ··· 8104 8107 'PhabricatorMentionableInterface', 8105 8108 'PhabricatorFlaggableInterface', 8106 8109 'PhabricatorSpacesInterface', 8110 + 'PhabricatorConduitResultInterface', 8111 + 'PhabricatorNgramsInterface', 8107 8112 ), 8108 8113 'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController', 8109 8114 'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController', 8110 8115 'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability', 8116 + 'PhabricatorPhurlURLEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 8111 8117 'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController', 8112 8118 'PhabricatorPhurlURLEditEngine' => 'PhabricatorEditEngine', 8113 8119 'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor', 8114 8120 'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController', 8115 8121 'PhabricatorPhurlURLMailReceiver' => 'PhabricatorObjectMailReceiver', 8122 + 'PhabricatorPhurlURLNameNgrams' => 'PhabricatorSearchNgrams', 8116 8123 'PhabricatorPhurlURLPHIDType' => 'PhabricatorPHIDType', 8117 8124 'PhabricatorPhurlURLQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 8118 8125 'PhabricatorPhurlURLReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 8126 + 'PhabricatorPhurlURLSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 8119 8127 'PhabricatorPhurlURLSearchEngine' => 'PhabricatorApplicationSearchEngine', 8120 8128 'PhabricatorPhurlURLTransaction' => 'PhabricatorApplicationTransaction', 8121 8129 'PhabricatorPhurlURLTransactionComment' => 'PhabricatorApplicationTransactionComment',
+18
src/applications/phurl/conduit/PhabricatorPhurlURLEditConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLEditConduitAPIMethod 4 + extends PhabricatorEditEngineAPIMethod { 5 + 6 + public function getAPIMethodName() { 7 + return 'phurls.edit'; 8 + } 9 + 10 + public function newEditEngine() { 11 + return new PhabricatorPhurlURLEditEngine(); 12 + } 13 + 14 + public function getMethodSummary() { 15 + return pht( 16 + 'Apply transactions to create a new Phurl URL or edit an existing one.'); 17 + } 18 + }
+18
src/applications/phurl/conduit/PhabricatorPhurlURLSearchConduitAPIMethod.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLSearchConduitAPIMethod 4 + extends PhabricatorSearchEngineAPIMethod { 5 + 6 + public function getAPIMethodName() { 7 + return 'phurls.search'; 8 + } 9 + 10 + public function newSearchEngine() { 11 + return new PhabricatorPhurlURLSearchEngine(); 12 + } 13 + 14 + public function getMethodSummary() { 15 + return pht('Read information about Phurl URLS.'); 16 + } 17 + 18 + }
+6
src/applications/phurl/query/PhabricatorPhurlURLQuery.php
··· 29 29 return $this; 30 30 } 31 31 32 + public function withNameNgrams($ngrams) { 33 + return $this->withNgramsConstraint( 34 + id(new PhabricatorPhurlURLNameNgrams()), 35 + $ngrams); 36 + } 37 + 32 38 public function withLongURLs(array $long_urls) { 33 39 $this->longURLs = $long_urls; 34 40 return $this;
+25
src/applications/phurl/query/PhabricatorPhurlURLSearchEngine.php
··· 25 25 ->setLabel(pht('Created By')) 26 26 ->setKey('authorPHIDs') 27 27 ->setDatasource(new PhabricatorPeopleUserFunctionDatasource()), 28 + id(new PhabricatorSearchTextField()) 29 + ->setLabel(pht('Name Contains')) 30 + ->setKey('name') 31 + ->setDescription(pht('Search for Phurl URLs by name substring.')), 32 + id(new PhabricatorSearchStringListField()) 33 + ->setLabel(pht('Aliases')) 34 + ->setKey('aliases') 35 + ->setDescription(pht('Search for Phurl URLs by alias.')), 36 + id(new PhabricatorSearchStringListField()) 37 + ->setLabel(pht('Long URLs')) 38 + ->setKey('longurls') 39 + ->setDescription( 40 + pht('Search for Phurl URLs by the non-shortened URL.')), 28 41 ); 29 42 } 30 43 ··· 33 46 34 47 if ($map['authorPHIDs']) { 35 48 $query->withAuthorPHIDs($map['authorPHIDs']); 49 + } 50 + 51 + if ($map['name'] !== null) { 52 + $query->withNameNgrams($map['name']); 53 + } 54 + 55 + if ($map['aliases']) { 56 + $query->withAliases($map['aliases']); 57 + } 58 + 59 + if ($map['longurls']) { 60 + $query->withLongURLs($map['longurls']); 36 61 } 37 62 38 63 return $query;
+58 -5
src/applications/phurl/storage/PhabricatorPhurlURL.php
··· 9 9 PhabricatorDestructibleInterface, 10 10 PhabricatorMentionableInterface, 11 11 PhabricatorFlaggableInterface, 12 - PhabricatorSpacesInterface { 12 + PhabricatorSpacesInterface, 13 + PhabricatorConduitResultInterface, 14 + PhabricatorNgramsInterface { 13 15 14 16 protected $name; 15 17 protected $alias; ··· 103 105 } else { 104 106 $path = '/u/'.$this->getID(); 105 107 } 106 - $short_domain = PhabricatorEnv::getEnvConfig('phurl.short-uri'); 107 - if (!$short_domain) { 108 - return $path; 108 + $domain = PhabricatorEnv::getEnvConfig('phurl.short-uri'); 109 + if (!$domain) { 110 + $domain = PhabricatorEnv::getEnvConfig('phabricator.base-uri'); 109 111 } 110 112 111 - $uri = new PhutilURI($short_domain); 113 + $uri = new PhutilURI($domain); 112 114 $uri->setPath($path); 113 115 return (string)$uri; 114 116 } ··· 202 204 public function getSpacePHID() { 203 205 return $this->spacePHID; 204 206 } 207 + 208 + /* -( PhabricatorConduitResultInterface )---------------------------------- */ 209 + 210 + 211 + public function getFieldSpecificationsForConduit() { 212 + return array( 213 + id(new PhabricatorConduitSearchFieldSpecification()) 214 + ->setKey('name') 215 + ->setType('string') 216 + ->setDescription(pht('URL name.')), 217 + id(new PhabricatorConduitSearchFieldSpecification()) 218 + ->setKey('alias') 219 + ->setType('string') 220 + ->setDescription(pht('The alias for the URL.')), 221 + id(new PhabricatorConduitSearchFieldSpecification()) 222 + ->setKey('longurl') 223 + ->setType('string') 224 + ->setDescription(pht('The pre-shortened URL.')), 225 + id(new PhabricatorConduitSearchFieldSpecification()) 226 + ->setKey('description') 227 + ->setType('string') 228 + ->setDescription(pht('A description of the URL.')), 229 + ); 230 + } 231 + 232 + public function getFieldValuesForConduit() { 233 + return array( 234 + 'name' => $this->getName(), 235 + 'alias' => $this->getAlias(), 236 + 'description' => $this->getDescription(), 237 + 'urls' => array( 238 + 'long' => $this->getLongURL(), 239 + 'short' => $this->getRedirectURI(), 240 + ), 241 + ); 242 + } 243 + 244 + public function getConduitSearchAttachments() { 245 + return array(); 246 + } 247 + 248 + /* -( PhabricatorNgramInterface )------------------------------------------ */ 249 + 250 + 251 + public function newNgrams() { 252 + return array( 253 + id(new PhabricatorPhurlURLNameNgrams()) 254 + ->setValue($this->getName()), 255 + ); 256 + } 257 + 205 258 }
+18
src/applications/phurl/storage/PhabricatorPhurlURLNameNgrams.php
··· 1 + <?php 2 + 3 + final class PhabricatorPhurlURLNameNgrams 4 + extends PhabricatorSearchNgrams { 5 + 6 + public function getNgramKey() { 7 + return 'phurlname'; 8 + } 9 + 10 + public function getColumnName() { 11 + return 'name'; 12 + } 13 + 14 + public function getApplicationName() { 15 + return 'phurl'; 16 + } 17 + 18 + }