1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-08 10:24:48 +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', 'PhabricatorPasteApplication' => 'applications/paste/application/PhabricatorPasteApplication.php',
'PhabricatorPasteArchiveController' => 'applications/paste/controller/PhabricatorPasteArchiveController.php', 'PhabricatorPasteArchiveController' => 'applications/paste/controller/PhabricatorPasteArchiveController.php',
'PhabricatorPasteConfigOptions' => 'applications/paste/config/PhabricatorPasteConfigOptions.php', 'PhabricatorPasteConfigOptions' => 'applications/paste/config/PhabricatorPasteConfigOptions.php',
'PhabricatorPasteContentSearchEngineAttachment' => 'applications/paste/engineextension/PhabricatorPasteContentSearchEngineAttachment.php',
'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php', 'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php',
'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php', 'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php',
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php', 'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
@ -6883,6 +6884,7 @@ phutil_register_library_map(array(
'PhabricatorPasteApplication' => 'PhabricatorApplication', 'PhabricatorPasteApplication' => 'PhabricatorApplication',
'PhabricatorPasteArchiveController' => 'PhabricatorPasteController', 'PhabricatorPasteArchiveController' => 'PhabricatorPasteController',
'PhabricatorPasteConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorPasteConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPasteContentSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
'PhabricatorPasteController' => 'PhabricatorController', 'PhabricatorPasteController' => 'PhabricatorController',
'PhabricatorPasteDAO' => 'PhabricatorLiskDAO', 'PhabricatorPasteDAO' => 'PhabricatorLiskDAO',
'PhabricatorPasteEditController' => 'PhabricatorPasteController', 'PhabricatorPasteEditController' => 'PhabricatorPasteController',

View file

@ -5,6 +5,7 @@ interface PhabricatorConduitResultInterface
public function getFieldSpecificationsForConduit(); public function getFieldSpecificationsForConduit();
public function getFieldValuesForConduit(); 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(); 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; return $fields;
} }
public function getSearchAttachments() { public function getSearchAttachments($object) {
return array( return array(
id(new PhabricatorProjectsSearchEngineAttachment()) id(new PhabricatorProjectsSearchEngineAttachment())
->setAttachmentKey('projects'), ->setAttachmentKey('projects'),

View file

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

View file

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

View file

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