From 4a2d961e7632b3df75d259769c60de269c0c11a2 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 12 May 2022 14:39:34 -0700 Subject: [PATCH] Adjust paste content transaction to support earlier file PHID extraction Summary: Ref T13603. New transactional file attachment extracts PHIDs earlier than the older mechanism did. Allow either pathway to save content and extract a PHID. Test Plan: - Created and modified a paste. - Confirmed both pathways do old and new storage writes. Maniphest Tasks: T13603 Differential Revision: https://secure.phabricator.com/D21817 --- .../PhabricatorPasteContentTransaction.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/applications/paste/xaction/PhabricatorPasteContentTransaction.php b/src/applications/paste/xaction/PhabricatorPasteContentTransaction.php index 8df9ad8057..00c01b0fcb 100644 --- a/src/applications/paste/xaction/PhabricatorPasteContentTransaction.php +++ b/src/applications/paste/xaction/PhabricatorPasteContentTransaction.php @@ -5,6 +5,8 @@ final class PhabricatorPasteContentTransaction const TRANSACTIONTYPE = 'paste.create'; + private $filePHID; + public function generateOldValue($object) { return $object->getFilePHID(); } @@ -14,7 +16,8 @@ final class PhabricatorPasteContentTransaction } public function extractFilePHIDs($object, $value) { - return array($value); + $file_phid = $this->getFilePHID($object, $value); + return array($file_phid); } public function validateTransactions($object, array $xactions) { @@ -31,6 +34,18 @@ final class PhabricatorPasteContentTransaction } public function generateNewValue($object, $value) { + return $this->getFilePHID($object, $value); + } + + private function getFilePHID($object, $value) { + if ($this->filePHID === null) { + $this->filePHID = $this->newFilePHID($object, $value); + } + + return $this->filePHID; + } + + private function newFilePHID($object, $value) { // If this transaction does not really change the paste content, return // the current file PHID so this transaction no-ops. $old_content = $object->getRawContent();