mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-17 20:32:41 +01:00
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
This commit is contained in:
parent
f2bb9bc061
commit
fc82118848
9 changed files with 169 additions and 5 deletions
11
resources/sql/autopatches/20160927.phurl.ngrams.php
Normal file
11
resources/sql/autopatches/20160927.phurl.ngrams.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
$table = new PhabricatorPhurlURL();
|
||||
|
||||
foreach (new LiskMigrationIterator($table) as $url) {
|
||||
PhabricatorSearchWorker::queueDocumentForIndexing(
|
||||
$url->getPHID(),
|
||||
array(
|
||||
'force' => true,
|
||||
));
|
||||
}
|
7
resources/sql/autopatches/20160927.phurl.ngrams.sql
Normal file
7
resources/sql/autopatches/20160927.phurl.ngrams.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
CREATE TABLE {$NAMESPACE}_phurl.phurl_phurlname_ngrams (
|
||||
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
objectID INT UNSIGNED NOT NULL,
|
||||
ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT},
|
||||
KEY `key_object` (objectID),
|
||||
KEY `key_ngram` (ngram, objectID)
|
||||
) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
|
|
@ -3187,14 +3187,17 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php',
|
||||
'PhabricatorPhurlURLCommentController' => 'applications/phurl/controller/PhabricatorPhurlURLCommentController.php',
|
||||
'PhabricatorPhurlURLCreateCapability' => 'applications/phurl/capability/PhabricatorPhurlURLCreateCapability.php',
|
||||
'PhabricatorPhurlURLEditConduitAPIMethod' => 'applications/phurl/conduit/PhabricatorPhurlURLEditConduitAPIMethod.php',
|
||||
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
|
||||
'PhabricatorPhurlURLEditEngine' => 'applications/phurl/editor/PhabricatorPhurlURLEditEngine.php',
|
||||
'PhabricatorPhurlURLEditor' => 'applications/phurl/editor/PhabricatorPhurlURLEditor.php',
|
||||
'PhabricatorPhurlURLListController' => 'applications/phurl/controller/PhabricatorPhurlURLListController.php',
|
||||
'PhabricatorPhurlURLMailReceiver' => 'applications/phurl/mail/PhabricatorPhurlURLMailReceiver.php',
|
||||
'PhabricatorPhurlURLNameNgrams' => 'applications/phurl/storage/PhabricatorPhurlURLNameNgrams.php',
|
||||
'PhabricatorPhurlURLPHIDType' => 'applications/phurl/phid/PhabricatorPhurlURLPHIDType.php',
|
||||
'PhabricatorPhurlURLQuery' => 'applications/phurl/query/PhabricatorPhurlURLQuery.php',
|
||||
'PhabricatorPhurlURLReplyHandler' => 'applications/phurl/mail/PhabricatorPhurlURLReplyHandler.php',
|
||||
'PhabricatorPhurlURLSearchConduitAPIMethod' => 'applications/phurl/conduit/PhabricatorPhurlURLSearchConduitAPIMethod.php',
|
||||
'PhabricatorPhurlURLSearchEngine' => 'applications/phurl/query/PhabricatorPhurlURLSearchEngine.php',
|
||||
'PhabricatorPhurlURLTransaction' => 'applications/phurl/storage/PhabricatorPhurlURLTransaction.php',
|
||||
'PhabricatorPhurlURLTransactionComment' => 'applications/phurl/storage/PhabricatorPhurlURLTransactionComment.php',
|
||||
|
@ -8104,18 +8107,23 @@ phutil_register_library_map(array(
|
|||
'PhabricatorMentionableInterface',
|
||||
'PhabricatorFlaggableInterface',
|
||||
'PhabricatorSpacesInterface',
|
||||
'PhabricatorConduitResultInterface',
|
||||
'PhabricatorNgramsInterface',
|
||||
),
|
||||
'PhabricatorPhurlURLAccessController' => 'PhabricatorPhurlController',
|
||||
'PhabricatorPhurlURLCommentController' => 'PhabricatorPhurlController',
|
||||
'PhabricatorPhurlURLCreateCapability' => 'PhabricatorPolicyCapability',
|
||||
'PhabricatorPhurlURLEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
|
||||
'PhabricatorPhurlURLEditController' => 'PhabricatorPhurlController',
|
||||
'PhabricatorPhurlURLEditEngine' => 'PhabricatorEditEngine',
|
||||
'PhabricatorPhurlURLEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'PhabricatorPhurlURLListController' => 'PhabricatorPhurlController',
|
||||
'PhabricatorPhurlURLMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
'PhabricatorPhurlURLNameNgrams' => 'PhabricatorSearchNgrams',
|
||||
'PhabricatorPhurlURLPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorPhurlURLQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorPhurlURLReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
||||
'PhabricatorPhurlURLSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||
'PhabricatorPhurlURLSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorPhurlURLTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'PhabricatorPhurlURLTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPhurlURLEditConduitAPIMethod
|
||||
extends PhabricatorEditEngineAPIMethod {
|
||||
|
||||
public function getAPIMethodName() {
|
||||
return 'phurls.edit';
|
||||
}
|
||||
|
||||
public function newEditEngine() {
|
||||
return new PhabricatorPhurlURLEditEngine();
|
||||
}
|
||||
|
||||
public function getMethodSummary() {
|
||||
return pht(
|
||||
'Apply transactions to create a new Phurl URL or edit an existing one.');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPhurlURLSearchConduitAPIMethod
|
||||
extends PhabricatorSearchEngineAPIMethod {
|
||||
|
||||
public function getAPIMethodName() {
|
||||
return 'phurls.search';
|
||||
}
|
||||
|
||||
public function newSearchEngine() {
|
||||
return new PhabricatorPhurlURLSearchEngine();
|
||||
}
|
||||
|
||||
public function getMethodSummary() {
|
||||
return pht('Read information about Phurl URLS.');
|
||||
}
|
||||
|
||||
}
|
|
@ -29,6 +29,12 @@ final class PhabricatorPhurlURLQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withNameNgrams($ngrams) {
|
||||
return $this->withNgramsConstraint(
|
||||
id(new PhabricatorPhurlURLNameNgrams()),
|
||||
$ngrams);
|
||||
}
|
||||
|
||||
public function withLongURLs(array $long_urls) {
|
||||
$this->longURLs = $long_urls;
|
||||
return $this;
|
||||
|
|
|
@ -25,6 +25,19 @@ final class PhabricatorPhurlURLSearchEngine
|
|||
->setLabel(pht('Created By'))
|
||||
->setKey('authorPHIDs')
|
||||
->setDatasource(new PhabricatorPeopleUserFunctionDatasource()),
|
||||
id(new PhabricatorSearchTextField())
|
||||
->setLabel(pht('Name Contains'))
|
||||
->setKey('name')
|
||||
->setDescription(pht('Search for Phurl URLs by name substring.')),
|
||||
id(new PhabricatorSearchStringListField())
|
||||
->setLabel(pht('Aliases'))
|
||||
->setKey('aliases')
|
||||
->setDescription(pht('Search for Phurl URLs by alias.')),
|
||||
id(new PhabricatorSearchStringListField())
|
||||
->setLabel(pht('Long URLs'))
|
||||
->setKey('longurls')
|
||||
->setDescription(
|
||||
pht('Search for Phurl URLs by the non-shortened URL.')),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -35,6 +48,18 @@ final class PhabricatorPhurlURLSearchEngine
|
|||
$query->withAuthorPHIDs($map['authorPHIDs']);
|
||||
}
|
||||
|
||||
if ($map['name'] !== null) {
|
||||
$query->withNameNgrams($map['name']);
|
||||
}
|
||||
|
||||
if ($map['aliases']) {
|
||||
$query->withAliases($map['aliases']);
|
||||
}
|
||||
|
||||
if ($map['longurls']) {
|
||||
$query->withLongURLs($map['longurls']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,9 @@ final class PhabricatorPhurlURL extends PhabricatorPhurlDAO
|
|||
PhabricatorDestructibleInterface,
|
||||
PhabricatorMentionableInterface,
|
||||
PhabricatorFlaggableInterface,
|
||||
PhabricatorSpacesInterface {
|
||||
PhabricatorSpacesInterface,
|
||||
PhabricatorConduitResultInterface,
|
||||
PhabricatorNgramsInterface {
|
||||
|
||||
protected $name;
|
||||
protected $alias;
|
||||
|
@ -103,12 +105,12 @@ final class PhabricatorPhurlURL extends PhabricatorPhurlDAO
|
|||
} else {
|
||||
$path = '/u/'.$this->getID();
|
||||
}
|
||||
$short_domain = PhabricatorEnv::getEnvConfig('phurl.short-uri');
|
||||
if (!$short_domain) {
|
||||
return $path;
|
||||
$domain = PhabricatorEnv::getEnvConfig('phurl.short-uri');
|
||||
if (!$domain) {
|
||||
$domain = PhabricatorEnv::getEnvConfig('phabricator.base-uri');
|
||||
}
|
||||
|
||||
$uri = new PhutilURI($short_domain);
|
||||
$uri = new PhutilURI($domain);
|
||||
$uri->setPath($path);
|
||||
return (string)$uri;
|
||||
}
|
||||
|
@ -202,4 +204,55 @@ final class PhabricatorPhurlURL extends PhabricatorPhurlDAO
|
|||
public function getSpacePHID() {
|
||||
return $this->spacePHID;
|
||||
}
|
||||
|
||||
/* -( PhabricatorConduitResultInterface )---------------------------------- */
|
||||
|
||||
|
||||
public function getFieldSpecificationsForConduit() {
|
||||
return array(
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('name')
|
||||
->setType('string')
|
||||
->setDescription(pht('URL name.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('alias')
|
||||
->setType('string')
|
||||
->setDescription(pht('The alias for the URL.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('longurl')
|
||||
->setType('string')
|
||||
->setDescription(pht('The pre-shortened URL.')),
|
||||
id(new PhabricatorConduitSearchFieldSpecification())
|
||||
->setKey('description')
|
||||
->setType('string')
|
||||
->setDescription(pht('A description of the URL.')),
|
||||
);
|
||||
}
|
||||
|
||||
public function getFieldValuesForConduit() {
|
||||
return array(
|
||||
'name' => $this->getName(),
|
||||
'alias' => $this->getAlias(),
|
||||
'description' => $this->getDescription(),
|
||||
'urls' => array(
|
||||
'long' => $this->getLongURL(),
|
||||
'short' => $this->getRedirectURI(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function getConduitSearchAttachments() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/* -( PhabricatorNgramInterface )------------------------------------------ */
|
||||
|
||||
|
||||
public function newNgrams() {
|
||||
return array(
|
||||
id(new PhabricatorPhurlURLNameNgrams())
|
||||
->setValue($this->getName()),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPhurlURLNameNgrams
|
||||
extends PhabricatorSearchNgrams {
|
||||
|
||||
public function getNgramKey() {
|
||||
return 'phurlname';
|
||||
}
|
||||
|
||||
public function getColumnName() {
|
||||
return 'name';
|
||||
}
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'phurl';
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue