Differential D21817 Diff 52025 src/applications/paste/xaction/PhabricatorPasteContentTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/paste/xaction/PhabricatorPasteContentTransaction.php
<?php | <?php | ||||
final class PhabricatorPasteContentTransaction | final class PhabricatorPasteContentTransaction | ||||
extends PhabricatorPasteTransactionType { | extends PhabricatorPasteTransactionType { | ||||
const TRANSACTIONTYPE = 'paste.create'; | const TRANSACTIONTYPE = 'paste.create'; | ||||
private $filePHID; | |||||
public function generateOldValue($object) { | public function generateOldValue($object) { | ||||
return $object->getFilePHID(); | return $object->getFilePHID(); | ||||
} | } | ||||
public function applyInternalEffects($object, $value) { | public function applyInternalEffects($object, $value) { | ||||
$object->setFilePHID($value); | $object->setFilePHID($value); | ||||
} | } | ||||
public function extractFilePHIDs($object, $value) { | public function extractFilePHIDs($object, $value) { | ||||
return array($value); | $file_phid = $this->getFilePHID($object, $value); | ||||
return array($file_phid); | |||||
} | } | ||||
public function validateTransactions($object, array $xactions) { | public function validateTransactions($object, array $xactions) { | ||||
if ($object->getFilePHID() || $xactions) { | if ($object->getFilePHID() || $xactions) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$error = $this->newError( | $error = $this->newError( | ||||
pht('Required'), | pht('Required'), | ||||
pht('You must provide content to create a paste.')); | pht('You must provide content to create a paste.')); | ||||
$error->setIsMissingFieldError(true); | $error->setIsMissingFieldError(true); | ||||
return array($error); | return array($error); | ||||
} | } | ||||
public function generateNewValue($object, $value) { | 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 | // If this transaction does not really change the paste content, return | ||||
// the current file PHID so this transaction no-ops. | // the current file PHID so this transaction no-ops. | ||||
$old_content = $object->getRawContent(); | $old_content = $object->getRawContent(); | ||||
if ($value === $old_content) { | if ($value === $old_content) { | ||||
$file_phid = $object->getFilePHID(); | $file_phid = $object->getFilePHID(); | ||||
if ($file_phid) { | if ($file_phid) { | ||||
return $file_phid; | return $file_phid; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |