Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15419843
D8969.id21274.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D8969.id21274.diff
View Options
diff --git a/src/applications/paste/conduit/ConduitAPI_paste_create_Method.php b/src/applications/paste/conduit/ConduitAPI_paste_create_Method.php
--- a/src/applications/paste/conduit/ConduitAPI_paste_create_Method.php
+++ b/src/applications/paste/conduit/ConduitAPI_paste_create_Method.php
@@ -39,28 +39,36 @@
$title = nonempty($title, 'Masterwork From Distant Lands');
$language = nonempty($language, '');
- $user = $request->getUser();
+ $viewer = $request->getUser();
- $paste_file = PhabricatorFile::newFromFileData(
- $content,
- array(
- 'name' => $title,
- 'mime-type' => 'text/plain; charset=utf-8',
- 'authorPHID' => $user->getPHID(),
- ));
+ $paste = PhabricatorPaste::initializeNewPaste($viewer);
- // TODO: This should use PhabricatorPasteEditor.
+ $file = PhabricatorPasteEditor::initializeFileForPaste(
+ $viewer,
+ $title,
+ $content);
- $paste = PhabricatorPaste::initializeNewPaste($user);
- $paste->setTitle($title);
- $paste->setLanguage($language);
- $paste->setFilePHID($paste_file->getPHID());
- $paste->save();
+ $xactions = array();
- $paste_file->attachToObject($user, $paste->getPHID());
+ $xactions[] = id(new PhabricatorPasteTransaction())
+ ->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE)
+ ->setNewValue($file->getPHID());
- $paste->attachRawContent($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)
+ ->setContentSourceFromConduitRequest($request);
+ $xactions = $editor->applyTransactions($paste, $xactions);
+
+ $paste->attachRawContent($content);
return $this->buildPasteInfoDictionary($paste);
}
diff --git a/src/applications/paste/controller/PhabricatorPasteEditController.php b/src/applications/paste/controller/PhabricatorPasteEditController.php
--- a/src/applications/paste/controller/PhabricatorPasteEditController.php
+++ b/src/applications/paste/controller/PhabricatorPasteEditController.php
@@ -95,12 +95,16 @@
if (!$errors) {
if ($is_create) {
+ $file = PhabricatorPasteEditor::initializeFileForPaste(
+ $user,
+ $v_title,
+ $v_text);
+
$xactions[] = id(new PhabricatorPasteTransaction())
->setTransactionType(PhabricatorPasteTransaction::TYPE_CREATE)
- ->setNewValue(array(
- 'title' => $v_title,
- 'text' => $v_text));
+ ->setNewValue($file->getPHID());
}
+
$xactions[] = id(new PhabricatorPasteTransaction())
->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE)
->setNewValue($v_title);
diff --git a/src/applications/paste/controller/PhabricatorPasteViewController.php b/src/applications/paste/controller/PhabricatorPasteViewController.php
--- a/src/applications/paste/controller/PhabricatorPasteViewController.php
+++ b/src/applications/paste/controller/PhabricatorPasteViewController.php
@@ -173,6 +173,13 @@
->setObjectURI($this->getRequest()->getRequestURI())
->addAction(
id(new PhabricatorActionView())
+ ->setName(pht('Edit Paste'))
+ ->setIcon('edit')
+ ->setDisabled(!$can_edit)
+ ->setWorkflow(!$can_edit)
+ ->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/')))
+ ->addAction(
+ id(new PhabricatorActionView())
->setName(pht('Fork This Paste'))
->setIcon('fork')
->setDisabled(!$can_fork)
@@ -182,14 +189,7 @@
id(new PhabricatorActionView())
->setName(pht('View Raw File'))
->setIcon('file')
- ->setHref($file->getBestURI()))
- ->addAction(
- id(new PhabricatorActionView())
- ->setName(pht('Edit Paste'))
- ->setIcon('edit')
- ->setDisabled(!$can_edit)
- ->setWorkflow(!$can_edit)
- ->setHref($this->getApplicationURI('/edit/'.$paste->getID().'/')));
+ ->setHref($file->getBestURI()));
}
private function buildPropertyView(
diff --git a/src/applications/paste/editor/PhabricatorPasteEditor.php b/src/applications/paste/editor/PhabricatorPasteEditor.php
--- a/src/applications/paste/editor/PhabricatorPasteEditor.php
+++ b/src/applications/paste/editor/PhabricatorPasteEditor.php
@@ -5,6 +5,21 @@
private $pasteFile;
+ public static function initializeFileForPaste(
+ PhabricatorUser $actor,
+ $name,
+ $data) {
+
+ return PhabricatorFile::newFromFileData(
+ $data,
+ array(
+ 'name' => $name,
+ 'mime-type' => 'text/plain; charset=utf-8',
+ 'authorPHID' => $actor->getPHID(),
+ 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
+ ));
+ }
+
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
@@ -37,8 +52,6 @@
switch ($xaction->getTransactionType()) {
case PhabricatorPasteTransaction::TYPE_CREATE:
- // this was set via applyInitialEffects
- return $object->getFilePHID();
case PhabricatorPasteTransaction::TYPE_TITLE:
case PhabricatorPasteTransaction::TYPE_LANGUAGE:
return $xaction->getNewValue();
@@ -50,74 +63,46 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
+ case PhabricatorPasteTransaction::TYPE_CREATE:
+ $object->setFilePHID($xaction->getNewValue());
+ return;
case PhabricatorPasteTransaction::TYPE_TITLE:
$object->setTitle($xaction->getNewValue());
- break;
+ return;
case PhabricatorPasteTransaction::TYPE_LANGUAGE:
$object->setLanguage($xaction->getNewValue());
- break;
+ return;
}
+
+ return parent::applyCustomInternalTransaction($object, $xaction);
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
- }
-
- protected function shouldApplyInitialEffects(
- PhabricatorLiskDAO $object,
- array $xactions) {
-
- foreach ($xactions as $xaction) {
- if ($xaction->getTransactionType() ==
- PhabricatorPasteTransaction::TYPE_CREATE) {
- return true;
- }
+ switch ($xaction->getTransactionType()) {
+ case PhabricatorPasteTransaction::TYPE_CREATE:
+ case PhabricatorPasteTransaction::TYPE_TITLE:
+ case PhabricatorPasteTransaction::TYPE_LANGUAGE:
+ return;
}
- return false;
- }
-
- protected function applyInitialEffects(
- PhabricatorLiskDAO $object,
- array $xactions) {
- foreach ($xactions as $xaction) {
- switch ($xaction->getTransactionType()) {
- case PhabricatorPasteTransaction::TYPE_CREATE:
- $data = $xaction->getNewValue();
- $paste_file = PhabricatorFile::newFromFileData(
- $data['text'],
- array(
- 'name' => $data['title'],
- 'mime-type' => 'text/plain; charset=utf-8',
- 'authorPHID' => $this->getActor()->getPHID(),
- ));
- $object->setFilePHID($paste_file->getPHID());
-
- $this->pasteFile = $paste_file;
- break;
- }
- }
+ return parent::applyCustomExternalTransaction($object, $xaction);
}
- protected function applyFinalEffects(
+ protected function extractFilePHIDsFromCustomTransaction(
PhabricatorLiskDAO $object,
- array $xactions) {
-
- // TODO: This should use extractFilePHIDs() instead, but the way
- // the transactions work right now makes pretty messy.
+ PhabricatorApplicationTransaction $xaction) {
- if ($this->pasteFile) {
- $this->pasteFile->attachToObject(
- $this->getActor(),
- $object->getPHID());
+ switch ($xaction->getTransactionType()) {
+ case PhabricatorPasteTransaction::TYPE_CREATE:
+ return array($xaction->getNewValue());
}
- return $xactions;
+ return parent::extractFilePHIDsFromCustomTransaction($object, $xaction);
}
-
protected function shouldSendMail(
PhabricatorLiskDAO $object,
array $xactions) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mar 22 2025, 9:21 AM (4 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7716820
Default Alt Text
D8969.id21274.diff (8 KB)
Attached To
Mode
D8969: Make the paste "Create" transaction take a file PHID instead of content
Attached
Detach File
Event Timeline
Log In to Comment