phorge/src/applications/phriction/conduit/PhrictionHistoryConduitAPIMethod.php
Christopher Speck dd94e2efcf Addressing PHP8 incompatibilities - Conduit
Summary:
Navigate through all the conduit pages and address PHP8 incompatibilities. Additionally test out empty form submissions on many of the "create" or "update" APIs and return more contextual errors rather than PHP8 errors.

Refs T13588

Test Plan:
- Clicked through all the conduit APIs.
- Clicked submit on empty forms, or minimally filled-in forms.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley, PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13588

Differential Revision: https://secure.phabricator.com/D21872
2023-05-30 11:58:43 -04:00

68 lines
1.6 KiB
PHP

<?php
final class PhrictionHistoryConduitAPIMethod extends PhrictionConduitAPIMethod {
public function getAPIMethodName() {
return 'phriction.history';
}
public function getMethodDescription() {
return pht('Retrieve history about a Phriction document.');
}
public function getMethodStatus() {
return self::METHOD_STATUS_FROZEN;
}
public function getMethodStatusDescription() {
return pht(
'This method is frozen and will eventually be deprecated. New code '.
'should use "phriction.content.search" instead.');
}
protected function defineParamTypes() {
return array(
'slug' => 'required string',
);
}
protected function defineReturnType() {
return 'nonempty list';
}
protected function defineErrorTypes() {
return array(
'ERR-BAD-DOCUMENT' => pht('No such document exists.'),
);
}
protected function execute(ConduitAPIRequest $request) {
$slug = $request->getValue('slug');
if ($slug === null || !strlen($slug)) {
throw new Exception(pht('Field "slug" must be non-empty.'));
}
$doc = id(new PhrictionDocumentQuery())
->setViewer($request->getUser())
->withSlugs(array(PhabricatorSlug::normalize($slug)))
->executeOne();
if (!$doc) {
throw new ConduitException('ERR-BAD-DOCUMENT');
}
$content = id(new PhrictionContent())->loadAllWhere(
'documentID = %d ORDER BY version DESC',
$doc->getID());
$results = array();
foreach ($content as $version) {
$results[] = $this->buildDocumentContentDictionary(
$doc,
$version);
}
return $results;
}
}