Changeset View
Changeset View
Standalone View
Standalone View
src/applications/paste/editor/PhabricatorPasteEditor.php
| <?php | <?php | ||||
| final class PhabricatorPasteEditor | final class PhabricatorPasteEditor | ||||
| extends PhabricatorApplicationTransactionEditor { | extends PhabricatorApplicationTransactionEditor { | ||||
| private $fileName; | |||||
| public function getEditorApplicationClass() { | public function getEditorApplicationClass() { | ||||
| return 'PhabricatorPasteApplication'; | return 'PhabricatorPasteApplication'; | ||||
| } | } | ||||
| public function getEditorObjectsDescription() { | public function getEditorObjectsDescription() { | ||||
| return pht('Pastes'); | return pht('Pastes'); | ||||
| } | } | ||||
| Show All 22 Lines | public function getTransactionTypes() { | ||||
| $types[] = PhabricatorPasteTransaction::TYPE_STATUS; | $types[] = PhabricatorPasteTransaction::TYPE_STATUS; | ||||
| $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; | $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; | ||||
| $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; | $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; | ||||
| $types[] = PhabricatorTransactions::TYPE_COMMENT; | $types[] = PhabricatorTransactions::TYPE_COMMENT; | ||||
| return $types; | return $types; | ||||
| } | } | ||||
| protected function shouldApplyInitialEffects( | |||||
| PhabricatorLiskDAO $object, | |||||
| array $xactions) { | |||||
| return true; | |||||
| } | |||||
| protected function applyInitialEffects( | |||||
| PhabricatorLiskDAO $object, | |||||
| array $xactions) { | |||||
| // Find the most user-friendly filename we can by examining the title of | |||||
| // the paste and the pending transactions. We'll use this if we create a | |||||
| // new file to store raw content later. | |||||
| $name = $object->getTitle(); | |||||
| if (!strlen($name)) { | |||||
| $name = 'paste.raw'; | |||||
| } | |||||
| $type_title = PhabricatorPasteTransaction::TYPE_TITLE; | |||||
| foreach ($xactions as $xaction) { | |||||
| if ($xaction->getTransactionType() == $type_title) { | |||||
| $name = $xaction->getNewValue(); | |||||
| } | |||||
| } | |||||
| $this->fileName = $name; | |||||
| } | |||||
| protected function getCustomTransactionOldValue( | protected function getCustomTransactionOldValue( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
| switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
| case PhabricatorPasteTransaction::TYPE_CONTENT: | case PhabricatorPasteTransaction::TYPE_CONTENT: | ||||
| return $object->getFilePHID(); | return $object->getFilePHID(); | ||||
| case PhabricatorPasteTransaction::TYPE_TITLE: | case PhabricatorPasteTransaction::TYPE_TITLE: | ||||
| return $object->getTitle(); | return $object->getTitle(); | ||||
| case PhabricatorPasteTransaction::TYPE_LANGUAGE: | case PhabricatorPasteTransaction::TYPE_LANGUAGE: | ||||
| return $object->getLanguage(); | return $object->getLanguage(); | ||||
| case PhabricatorPasteTransaction::TYPE_STATUS: | case PhabricatorPasteTransaction::TYPE_STATUS: | ||||
| return $object->getStatus(); | return $object->getStatus(); | ||||
| } | } | ||||
| } | } | ||||
| protected function getCustomTransactionNewValue( | protected function getCustomTransactionNewValue( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
| switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
| case PhabricatorPasteTransaction::TYPE_CONTENT: | |||||
| case PhabricatorPasteTransaction::TYPE_TITLE: | case PhabricatorPasteTransaction::TYPE_TITLE: | ||||
| case PhabricatorPasteTransaction::TYPE_LANGUAGE: | case PhabricatorPasteTransaction::TYPE_LANGUAGE: | ||||
| case PhabricatorPasteTransaction::TYPE_STATUS: | case PhabricatorPasteTransaction::TYPE_STATUS: | ||||
| return $xaction->getNewValue(); | return $xaction->getNewValue(); | ||||
| case PhabricatorPasteTransaction::TYPE_CONTENT: | |||||
| // If this transaction does not really change the paste content, return | |||||
| // the current file PHID so this transaction no-ops. | |||||
| $new_content = $xaction->getNewValue(); | |||||
| $old_content = $object->getRawContent(); | |||||
| $file_phid = $object->getFilePHID(); | |||||
| if (($new_content === $old_content) && $file_phid) { | |||||
| return $file_phid; | |||||
| } | |||||
| $file = self::initializeFileForPaste( | |||||
| $this->getActor(), | |||||
| $this->fileName, | |||||
| $xaction->getNewValue()); | |||||
| return $file->getPHID(); | |||||
| } | } | ||||
| } | } | ||||
| protected function applyCustomInternalTransaction( | protected function applyCustomInternalTransaction( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
| switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
| ▲ Show 20 Lines • Show All 118 Lines • Show Last 20 Lines | |||||