mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-26 05:29:06 +01:00
Summary: Ref T10537. For Nuance, I want to introduce new sources (like "GitHub" or "GitHub via Nuance" or something) but this needs to modularize eventually. Split ContentSource apart so applications can add new content sources. Test Plan: This change has huge surface area, so I'll hold it until post-release. I think it's fairly safe (and if it does break anything, the breaks should be fatals, not anything subtle or difficult to fix), there's just no reason not to hold it for a few hours. - Viewed new module page. - Grepped for all removed functions/constants. - Viewed some transactions. - Hovered over timestamps to get content source details. - Added a comment via Conduit. - Added a comment via web. - Ran `bin/storage upgrade --namespace XXXXX --no-quickstart -f` to re-run all historic migrations. - Generated some objects with `bin/lipsum`. - Ran a bulk job on some tasks. - Ran unit tests. {F1190182} Reviewers: chad Reviewed By: chad Maniphest Tasks: T10537 Differential Revision: https://secure.phabricator.com/D15521
72 lines
1.9 KiB
PHP
72 lines
1.9 KiB
PHP
<?php
|
|
|
|
final class PasteCreateConduitAPIMethod extends PasteConduitAPIMethod {
|
|
|
|
public function getAPIMethodName() {
|
|
return 'paste.create';
|
|
}
|
|
|
|
public function getMethodDescription() {
|
|
return pht('Create a new paste.');
|
|
}
|
|
|
|
protected function defineParamTypes() {
|
|
return array(
|
|
'content' => 'required string',
|
|
'title' => 'optional string',
|
|
'language' => 'optional string',
|
|
);
|
|
}
|
|
|
|
protected function defineReturnType() {
|
|
return 'nonempty dict';
|
|
}
|
|
|
|
protected function defineErrorTypes() {
|
|
return array(
|
|
'ERR-NO-PASTE' => pht('Paste may not be empty.'),
|
|
);
|
|
}
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
$content = $request->getValue('content');
|
|
$title = $request->getValue('title');
|
|
$language = $request->getValue('language');
|
|
|
|
if (!strlen($content)) {
|
|
throw new ConduitException('ERR-NO-PASTE');
|
|
}
|
|
|
|
$title = nonempty($title, pht('Masterwork From Distant Lands'));
|
|
$language = nonempty($language, '');
|
|
|
|
$viewer = $request->getUser();
|
|
|
|
$paste = PhabricatorPaste::initializeNewPaste($viewer);
|
|
|
|
$xactions = array();
|
|
|
|
$xactions[] = id(new PhabricatorPasteTransaction())
|
|
->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT)
|
|
->setNewValue($content);
|
|
|
|
$xactions[] = id(new PhabricatorPasteTransaction())
|
|
->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE)
|
|
->setNewValue($title);
|
|
|
|
$xactions[] = id(new PhabricatorPasteTransaction())
|
|
->setTransactionType(PhabricatorPasteTransaction::TYPE_LANGUAGE)
|
|
->setNewValue($language);
|
|
|
|
$editor = id(new PhabricatorPasteEditor())
|
|
->setActor($viewer)
|
|
->setContinueOnNoEffect(true)
|
|
->setContentSource($request->newContentSource());
|
|
|
|
$xactions = $editor->applyTransactions($paste, $xactions);
|
|
|
|
$paste->attachRawContent($content);
|
|
return $this->buildPasteInfoDictionary($paste);
|
|
}
|
|
|
|
}
|