mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 20:10:55 +01:00
Add conduit feed.query method
Summary: This is not totally done yet, and i'm submitting for feedback. Test Plan: Played with various settings in local conduit console. Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley Maniphest Tasks: T790 Differential Revision: https://secure.phabricator.com/D1555
This commit is contained in:
parent
8df14b8505
commit
c3281c8757
4 changed files with 159 additions and 1 deletions
|
@ -124,6 +124,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_diffusion_getcommits_Method' => 'applications/conduit/method/diffusion/getcommits',
|
||||
'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'applications/conduit/method/diffusion/getrecentcommitsbypath',
|
||||
'ConduitAPI_feed_publish_Method' => 'applications/conduit/method/feed/publish',
|
||||
'ConduitAPI_feed_query_Method' => 'applications/conduit/method/feed/query',
|
||||
'ConduitAPI_file_download_Method' => 'applications/conduit/method/file/download',
|
||||
'ConduitAPI_file_info_Method' => 'applications/conduit/method/file/info',
|
||||
'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/upload',
|
||||
|
@ -929,6 +930,7 @@ phutil_register_library_map(array(
|
|||
'ConduitAPI_diffusion_getcommits_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_diffusion_getrecentcommitsbypath_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_feed_publish_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_feed_query_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_file_download_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_file_info_Method' => 'ConduitAPIMethod',
|
||||
'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod',
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group conduit
|
||||
*/
|
||||
final class ConduitAPI_feed_query_Method extends ConduitAPIMethod {
|
||||
|
||||
public function getMethodDescription() {
|
||||
return "(UNSTABLE!!) Query the feed for stories";
|
||||
}
|
||||
|
||||
private function getDefaultLimit() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
public function defineParamTypes() {
|
||||
return array(
|
||||
'filterPHIDs' => 'optional list <phid>',
|
||||
'limit' => 'optional int (default '.$this->getDefaultLimit().')',
|
||||
'after' => 'optional int',
|
||||
'view' => 'optional string (data, html, html-summary)',
|
||||
);
|
||||
}
|
||||
|
||||
private function getSupportedViewTypes() {
|
||||
return array(
|
||||
'html' => 'Full HTML presentation of story',
|
||||
'data' => 'Dictionary with various data of the story',
|
||||
'html-summary' => 'Story contains only the title of the story',
|
||||
);
|
||||
}
|
||||
|
||||
public function defineErrorTypes() {
|
||||
|
||||
$view_types = array_keys($this->getSupportedViewTypes());
|
||||
$view_types = implode(', ', $view_types);
|
||||
|
||||
return array(
|
||||
'ERR-UNKNOWN-TYPE' =>
|
||||
'Unsupported view type, possibles are: ' . $view_types
|
||||
);
|
||||
}
|
||||
|
||||
public function defineReturnType() {
|
||||
return 'nonempty dict';
|
||||
}
|
||||
|
||||
protected function execute(ConduitAPIRequest $request) {
|
||||
|
||||
$results = array();
|
||||
$user = $request->getUser();
|
||||
|
||||
$view_type = $request->getValue('view');
|
||||
if (!$view_type) {
|
||||
$view_type = 'data';
|
||||
}
|
||||
|
||||
$limit = $request->getValue('limit');
|
||||
if (!$limit) {
|
||||
$limit = $this->getDefaultLimit();
|
||||
}
|
||||
$filter_phids = $request->getValue('filter_phids');
|
||||
if (!$filter_phids) {
|
||||
$filter_phids = array();
|
||||
}
|
||||
$after = $request->getValue('after');
|
||||
|
||||
$query = id(new PhabricatorFeedQuery())
|
||||
->setLimit($limit)
|
||||
->setFilterPHIDs($filter_phids)
|
||||
->setAfter($after);
|
||||
$stories = $query->execute();
|
||||
|
||||
if ($stories) {
|
||||
$handle_phids = array_mergev(mpull($stories, 'getRequiredHandlePHIDs'));
|
||||
$object_phids = array_mergev(mpull($stories, 'getRequiredObjectPHIDs'));
|
||||
$handles = id(new PhabricatorObjectHandleData($handle_phids))
|
||||
->loadHandles();
|
||||
$objects = id(new PhabricatorObjectHandleData($object_phids))
|
||||
->loadObjects();
|
||||
|
||||
foreach ($stories as $story) {
|
||||
|
||||
$story->setHandles($handles);
|
||||
$story->setObjects($objects);
|
||||
|
||||
$story_data = $story->getStoryData();
|
||||
|
||||
$data = null;
|
||||
|
||||
$view = $story->renderView();
|
||||
$view->setEpoch($story->getEpoch());
|
||||
$view->setViewer($user);
|
||||
|
||||
switch ($view_type) {
|
||||
case 'html':
|
||||
$data = $view->render();
|
||||
break;
|
||||
case 'html-summary':
|
||||
$view->setOneLineStory(true);
|
||||
$data = $view->render();
|
||||
break;
|
||||
case 'data':
|
||||
$data = array(
|
||||
'class' => $story_data->getStoryType(),
|
||||
'epoch' => $story_data->getEpoch(),
|
||||
'authorPHID' => $story_data->getAuthorPHID(),
|
||||
'chronologicalKey' => $story_data->getChronologicalKey(),
|
||||
'data' => $story_data->getStoryData(),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new ConduitException('ERR-UNKNOWN-TYPE');
|
||||
}
|
||||
|
||||
$results[$story_data->getPHID()] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
17
src/applications/conduit/method/feed/query/__init__.php
Normal file
17
src/applications/conduit/method/feed/query/__init__.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/conduit/method/base');
|
||||
phutil_require_module('phabricator', 'applications/conduit/protocol/exception');
|
||||
phutil_require_module('phabricator', 'applications/feed/query');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('ConduitAPI_feed_query_Method.php');
|
|
@ -75,7 +75,7 @@ abstract class PhabricatorFeedStory {
|
|||
return $this->objects;
|
||||
}
|
||||
|
||||
final protected function getStoryData() {
|
||||
final public function getStoryData() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue