Page MenuHomePhabricator

D12561.id30152.diff
No OneTemporary

D12561.id30152.diff

diff --git a/src/applications/files/controller/PhabricatorFileEditController.php b/src/applications/files/controller/PhabricatorFileEditController.php
--- a/src/applications/files/controller/PhabricatorFileEditController.php
+++ b/src/applications/files/controller/PhabricatorFileEditController.php
@@ -26,11 +26,13 @@
}
$title = pht('Edit %s', $file->getName());
+ $file_name = $file->getName();
$view_uri = '/'.$file->getMonogram();
$validation_exception = null;
if ($request->isFormPost()) {
$can_view = $request->getStr('canView');
+ $file_name = $request->getStr('name');
$xactions = array();
@@ -38,6 +40,10 @@
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
->setNewValue($can_view);
+ $xactions[] = id(new PhabricatorFileTransaction())
+ ->setTransactionType(PhabricatorFileTransaction::TYPE_NAME)
+ ->setNewValue($file_name);
+
$editor = id(new PhabricatorFileEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
@@ -61,6 +67,12 @@
$form = id(new AphrontFormView())
->setUser($viewer)
+ ->appendChild(
+ id(new AphrontFormTextControl())
+ ->setName('name')
+ ->setValue($file_name)
+ ->setLabel(pht('Name'))
+ ->setError(true))
->appendChild(
id(new AphrontFormPolicyControl())
->setUser($viewer)
diff --git a/src/applications/files/editor/PhabricatorFileEditor.php b/src/applications/files/editor/PhabricatorFileEditor.php
--- a/src/applications/files/editor/PhabricatorFileEditor.php
+++ b/src/applications/files/editor/PhabricatorFileEditor.php
@@ -17,16 +17,30 @@
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
+ $types[] = PhabricatorFileTransaction::TYPE_NAME;
+
return $types;
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {}
+ PhabricatorApplicationTransaction $xaction) {
+
+ switch ($xaction->getTransactionType()) {
+ case PhabricatorFileTransaction::TYPE_NAME:
+ return $object->getName();
+ }
+ }
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {}
+ PhabricatorApplicationTransaction $xaction) {
+
+ switch ($xaction->getTransactionType()) {
+ case PhabricatorFileTransaction::TYPE_NAME:
+ return $xaction->getNewValue();
+ }
+ }
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
@@ -36,6 +50,9 @@
case PhabricatorTransactions::TYPE_VIEW_POLICY:
$object->setViewPolicy($xaction->getNewValue());
break;
+ case PhabricatorFileTransaction::TYPE_NAME:
+ $object->setName($xaction->getNewValue());
+ break;
}
}
diff --git a/src/applications/files/storage/PhabricatorFileTransaction.php b/src/applications/files/storage/PhabricatorFileTransaction.php
--- a/src/applications/files/storage/PhabricatorFileTransaction.php
+++ b/src/applications/files/storage/PhabricatorFileTransaction.php
@@ -3,6 +3,8 @@
final class PhabricatorFileTransaction
extends PhabricatorApplicationTransaction {
+ const TYPE_NAME = 'file:name';
+
public function getApplicationName() {
return 'file';
}
@@ -15,4 +17,81 @@
return new PhabricatorFileTransactionComment();
}
+ public function getTitle() {
+ $author_phid = $this->getAuthorPHID();
+
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
+ switch ($this->getTransactionType()) {
+ case self::TYPE_NAME:
+ return pht(
+ '%s updated the name for this file.',
+ $this->renderHandleLink($author_phid));
+ break;
+ }
+
+ return parent::getTitle();
+ }
+
+ public function getTitleForFeed() {
+ $author_phid = $this->getAuthorPHID();
+ $object_phid = $this->getObjectPHID();
+
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
+ $type = $this->getTransactionType();
+ switch ($type) {
+ case self::TYPE_NAME:
+ return pht(
+ '%s updated the name of %s.',
+ $this->renderHandleLink($author_phid),
+ $this->renderHandleLink($object_phid));
+ break;
+ }
+
+ return parent::getTitleForFeed();
+ }
+
+ public function getIcon() {
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
+ switch ($this->getTransactionType()) {
+ case self::TYPE_NAME:
+ return 'fa-pencil';
+ }
+
+ return parent::getIcon();
+ }
+
+
+ public function getColor() {
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
+ switch ($this->getTransactionType()) {
+ case self::TYPE_NAME:
+ return PhabricatorTransactions::COLOR_BLUE;
+ }
+
+ return parent::getColor();
+ }
+
+ public function hasChangeDetails() {
+ switch ($this->getTransactionType()) {
+ case self::TYPE_NAME:
+ return true;
+ }
+ return parent::hasChangeDetails();
+ }
+
+ public function renderChangeDetails(PhabricatorUser $viewer) {
+ return $this->renderTextCorpusChangeDetails(
+ $viewer,
+ $this->getOldValue(),
+ $this->getNewValue());
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Mar 5 2025, 10:02 PM (7 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7227564
Default Alt Text
D12561.id30152.diff (5 KB)

Event Timeline