diff --git a/resources/sql/autopatches/20160927.phurl.ngrams.php b/resources/sql/autopatches/20160927.phurl.ngrams.php new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20160927.phurl.ngrams.php @@ -0,0 +1,11 @@ +getPHID(), + array( + 'force' => true, + )); +} diff --git a/resources/sql/autopatches/20160927.phurl.ngrams.sql b/resources/sql/autopatches/20160927.phurl.ngrams.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20160927.phurl.ngrams.sql @@ -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}; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3187,14 +3187,17 @@ '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 @@ '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', diff --git a/src/applications/phurl/conduit/PhabricatorPhurlURLEditConduitAPIMethod.php b/src/applications/phurl/conduit/PhabricatorPhurlURLEditConduitAPIMethod.php new file mode 100644 --- /dev/null +++ b/src/applications/phurl/conduit/PhabricatorPhurlURLEditConduitAPIMethod.php @@ -0,0 +1,18 @@ +withNgramsConstraint( + id(new PhabricatorPhurlURLNameNgrams()), + $ngrams); + } + public function withLongURLs(array $long_urls) { $this->longURLs = $long_urls; return $this; diff --git a/src/applications/phurl/query/PhabricatorPhurlURLSearchEngine.php b/src/applications/phurl/query/PhabricatorPhurlURLSearchEngine.php --- a/src/applications/phurl/query/PhabricatorPhurlURLSearchEngine.php +++ b/src/applications/phurl/query/PhabricatorPhurlURLSearchEngine.php @@ -25,6 +25,19 @@ ->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 @@ $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; } diff --git a/src/applications/phurl/storage/PhabricatorPhurlURL.php b/src/applications/phurl/storage/PhabricatorPhurlURL.php --- a/src/applications/phurl/storage/PhabricatorPhurlURL.php +++ b/src/applications/phurl/storage/PhabricatorPhurlURL.php @@ -9,7 +9,9 @@ PhabricatorDestructibleInterface, PhabricatorMentionableInterface, PhabricatorFlaggableInterface, - PhabricatorSpacesInterface { + PhabricatorSpacesInterface, + PhabricatorConduitResultInterface, + PhabricatorNgramsInterface { protected $name; protected $alias; @@ -103,12 +105,12 @@ } 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 @@ 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()), + ); + } + } diff --git a/src/applications/phurl/storage/PhabricatorPhurlURLNameNgrams.php b/src/applications/phurl/storage/PhabricatorPhurlURLNameNgrams.php new file mode 100644 --- /dev/null +++ b/src/applications/phurl/storage/PhabricatorPhurlURLNameNgrams.php @@ -0,0 +1,18 @@ +