Path: blob/master/src/applications/paste/xaction/PhabricatorPasteContentTransaction.php
12242 views
<?php12final class PhabricatorPasteContentTransaction3extends PhabricatorPasteTransactionType {45const TRANSACTIONTYPE = 'paste.create';67private $filePHID;89public function generateOldValue($object) {10return $object->getFilePHID();11}1213public function applyInternalEffects($object, $value) {14$object->setFilePHID($value);15}1617public function extractFilePHIDs($object, $value) {18$file_phid = $this->getFilePHID($object, $value);19return array($file_phid);20}2122public function validateTransactions($object, array $xactions) {23if ($object->getFilePHID() || $xactions) {24return array();25}2627$error = $this->newError(28pht('Required'),29pht('You must provide content to create a paste.'));30$error->setIsMissingFieldError(true);3132return array($error);33}3435public function generateNewValue($object, $value) {36return $this->getFilePHID($object, $value);37}3839private function getFilePHID($object, $value) {40if ($this->filePHID === null) {41$this->filePHID = $this->newFilePHID($object, $value);42}4344return $this->filePHID;45}4647private function newFilePHID($object, $value) {48// If this transaction does not really change the paste content, return49// the current file PHID so this transaction no-ops.50$old_content = $object->getRawContent();51if ($value === $old_content) {52$file_phid = $object->getFilePHID();53if ($file_phid) {54return $file_phid;55}56}5758$editor = $this->getEditor();59$actor = $editor->getActor();6061$file = $this->newFileForPaste($actor, $value);6263return $file->getPHID();64}6566private function newFileForPaste(PhabricatorUser $actor, $data) {67$editor = $this->getEditor();6869$file_name = $editor->getNewPasteTitle();70if (!strlen($file_name)) {71$file_name = 'raw-paste-data.txt';72}7374return PhabricatorFile::newFromFileData(75$data,76array(77'name' => $file_name,78'mime-type' => 'text/plain; charset=utf-8',79'authorPHID' => $actor->getPHID(),80'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,81));82}8384public function getIcon() {85return 'fa-plus';86}8788public function getTitle() {89return pht(90'%s edited the content of this paste.',91$this->renderAuthor());92}9394public function getTitleForFeed() {95return pht(96'%s edited %s.',97$this->renderAuthor(),98$this->renderObject());99}100101public function hasChangeDetailView() {102return true;103}104105public function getMailDiffSectionHeader() {106return pht('CHANGES TO PASTE CONTENT');107}108109public function newChangeDetailView() {110$viewer = $this->getViewer();111112$old = $this->getOldValue();113$new = $this->getNewValue();114115$files = id(new PhabricatorFileQuery())116->setViewer($viewer)117->withPHIDs(array($old, $new))118->execute();119$files = mpull($files, null, 'getPHID');120121$old_text = '';122if (idx($files, $old)) {123$old_text = $files[$old]->loadFileData();124}125126$new_text = '';127if (idx($files, $new)) {128$new_text = $files[$new]->loadFileData();129}130131return id(new PhabricatorApplicationTransactionTextDiffDetailView())132->setViewer($viewer)133->setOldText($old_text)134->setNewText($new_text);135}136137}138139140