1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Add a "content" attachment for Pastes for Conduit API

Summary: Ref T9964. Builds on D14772. Allows callers to get the raw content of pastes as an attachment.

Test Plan:
  - Read docs.
  - Executed attachment query.
  - Saw raw paste content.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9964

Differential Revision: https://secure.phabricator.com/D14774
This commit is contained in:
epriestley 2015-12-14 06:01:04 -08:00
parent c0e20a11c1
commit 3db175f79d
11 changed files with 55 additions and 4 deletions

View file

@ -2643,6 +2643,7 @@ phutil_register_library_map(array(
'PhabricatorPasteApplication' => 'applications/paste/application/PhabricatorPasteApplication.php',
'PhabricatorPasteArchiveController' => 'applications/paste/controller/PhabricatorPasteArchiveController.php',
'PhabricatorPasteConfigOptions' => 'applications/paste/config/PhabricatorPasteConfigOptions.php',
'PhabricatorPasteContentSearchEngineAttachment' => 'applications/paste/engineextension/PhabricatorPasteContentSearchEngineAttachment.php',
'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php',
'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php',
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
@ -6883,6 +6884,7 @@ phutil_register_library_map(array(
'PhabricatorPasteApplication' => 'PhabricatorApplication',
'PhabricatorPasteArchiveController' => 'PhabricatorPasteController',
'PhabricatorPasteConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPasteContentSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
'PhabricatorPasteController' => 'PhabricatorController',
'PhabricatorPasteDAO' => 'PhabricatorLiskDAO',
'PhabricatorPasteEditController' => 'PhabricatorPasteController',

View file

@ -5,6 +5,7 @@ interface PhabricatorConduitResultInterface
public function getFieldSpecificationsForConduit();
public function getFieldValuesForConduit();
public function getConduitSearchAttachments();
}
@ -28,4 +29,8 @@ interface PhabricatorConduitResultInterface
);
}
public function getConduitSearchAttachments() {
return array();
}
*/

View file

@ -29,4 +29,8 @@ final class ConduitResultSearchEngineExtension
return $object->getFieldValuesForConduit();
}
public function getSearchAttachments($object) {
return $object->getConduitSearchAttachments();
}
}

View file

@ -437,4 +437,8 @@ final class ManiphestTask extends ManiphestDAO
);
}
public function getConduitSearchAttachments() {
return array();
}
}

View file

@ -395,4 +395,8 @@ final class PhabricatorOwnersPackage
);
}
public function getConduitSearchAttachments() {
return array();
}
}

View file

@ -0,0 +1,24 @@
<?php
final class PhabricatorPasteContentSearchEngineAttachment
extends PhabricatorSearchEngineAttachment {
public function getAttachmentName() {
return pht('Paste Content');
}
public function getAttachmentDescription() {
return pht('Get the full content for each paste.');
}
public function willLoadAttachmentData($query, $spec) {
$query->needRawContent(true);
}
public function getAttachmentForObject($object, $data, $spec) {
return array(
'data' => $object->getRawContent(),
);
}
}

View file

@ -285,4 +285,11 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
);
}
public function getConduitSearchAttachments() {
return array(
id(new PhabricatorPasteContentSearchEngineAttachment())
->setAttachmentKey('content'),
);
}
}

View file

@ -49,7 +49,7 @@ final class PhabricatorProjectsSearchEngineExtension
return $fields;
}
public function getSearchAttachments() {
public function getSearchAttachments($object) {
return array(
id(new PhabricatorProjectsSearchEngineAttachment())
->setAttachmentKey('projects'),

View file

@ -1319,10 +1319,11 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
public function getConduitSearchAttachments() {
$extensions = $this->getEngineExtensions();
$object = $this->newResultObject();
$attachments = array();
foreach ($extensions as $extension) {
$extension_attachments = $extension->getSearchAttachments();
$extension_attachments = $extension->getSearchAttachments($object);
foreach ($extension_attachments as $attachment) {
$attachment_key = $attachment->getAttachmentKey();
if (isset($attachments[$attachment_key])) {

View file

@ -40,7 +40,7 @@ abstract class PhabricatorSearchEngineExtension extends Phobject {
return array();
}
public function getSearchAttachments() {
public function getSearchAttachments($object) {
return array();
}

View file

@ -50,7 +50,7 @@ final class PhabricatorSubscriptionsSearchEngineExtension
return $fields;
}
public function getSearchAttachments() {
public function getSearchAttachments($object) {
return array(
id(new PhabricatorSubscriptionsSearchEngineAttachment())
->setAttachmentKey('subscribers'),