@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move Files to ModularTransactions

Summary: Ref T11357. A lot of file creation doesn't go through transactions, so we only actually have one real transaction type: editing a file name.

Test Plan:
Created and edited files.

{F4559287}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11357

Differential Revision: https://secure.phabricator.com/D17610

+71 -138
+5 -1
src/__phutil_library_map__.php
··· 2765 2765 'PhabricatorFileLightboxController' => 'applications/files/controller/PhabricatorFileLightboxController.php', 2766 2766 'PhabricatorFileLinkView' => 'view/layout/PhabricatorFileLinkView.php', 2767 2767 'PhabricatorFileListController' => 'applications/files/controller/PhabricatorFileListController.php', 2768 + 'PhabricatorFileNameTransaction' => 'applications/files/xaction/PhabricatorFileNameTransaction.php', 2768 2769 'PhabricatorFileQuery' => 'applications/files/query/PhabricatorFileQuery.php', 2769 2770 'PhabricatorFileROT13StorageFormat' => 'applications/files/format/PhabricatorFileROT13StorageFormat.php', 2770 2771 'PhabricatorFileRawStorageFormat' => 'applications/files/format/PhabricatorFileRawStorageFormat.php', ··· 2783 2784 'PhabricatorFileTransaction' => 'applications/files/storage/PhabricatorFileTransaction.php', 2784 2785 'PhabricatorFileTransactionComment' => 'applications/files/storage/PhabricatorFileTransactionComment.php', 2785 2786 'PhabricatorFileTransactionQuery' => 'applications/files/query/PhabricatorFileTransactionQuery.php', 2787 + 'PhabricatorFileTransactionType' => 'applications/files/xaction/PhabricatorFileTransactionType.php', 2786 2788 'PhabricatorFileTransform' => 'applications/files/transform/PhabricatorFileTransform.php', 2787 2789 'PhabricatorFileTransformController' => 'applications/files/controller/PhabricatorFileTransformController.php', 2788 2790 'PhabricatorFileTransformListController' => 'applications/files/controller/PhabricatorFileTransformListController.php', ··· 7890 7892 'PhabricatorFileLightboxController' => 'PhabricatorFileController', 7891 7893 'PhabricatorFileLinkView' => 'AphrontTagView', 7892 7894 'PhabricatorFileListController' => 'PhabricatorFileController', 7895 + 'PhabricatorFileNameTransaction' => 'PhabricatorFileTransactionType', 7893 7896 'PhabricatorFileQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 7894 7897 'PhabricatorFileROT13StorageFormat' => 'PhabricatorFileStorageFormat', 7895 7898 'PhabricatorFileRawStorageFormat' => 'PhabricatorFileStorageFormat', ··· 7905 7908 'PhabricatorFileTestCase' => 'PhabricatorTestCase', 7906 7909 'PhabricatorFileTestDataGenerator' => 'PhabricatorTestDataGenerator', 7907 7910 'PhabricatorFileThumbnailTransform' => 'PhabricatorFileImageTransform', 7908 - 'PhabricatorFileTransaction' => 'PhabricatorApplicationTransaction', 7911 + 'PhabricatorFileTransaction' => 'PhabricatorModularTransaction', 7909 7912 'PhabricatorFileTransactionComment' => 'PhabricatorApplicationTransactionComment', 7910 7913 'PhabricatorFileTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 7914 + 'PhabricatorFileTransactionType' => 'PhabricatorModularTransactionType', 7911 7915 'PhabricatorFileTransform' => 'Phobject', 7912 7916 'PhabricatorFileTransformController' => 'PhabricatorFileController', 7913 7917 'PhabricatorFileTransformListController' => 'PhabricatorFileController',
+1 -1
src/applications/badges/xaction/PhabricatorBadgesBadgeNameTransaction.php
··· 43 43 $new_value = $xaction->getNewValue(); 44 44 $new_length = strlen($new_value); 45 45 if ($new_length > $max_length) { 46 - $errors[] = $this->newRequiredError( 46 + $errors[] = $this->newInvalidError( 47 47 pht('The name can be no longer than %s characters.', 48 48 new PhutilNumber($max_length))); 49 49 }
+2 -2
src/applications/files/controller/PhabricatorFileEditController.php
··· 31 31 $file_name = $request->getStr('name'); 32 32 $errors = array(); 33 33 34 - $type_name = PhabricatorFileTransaction::TYPE_NAME; 34 + $type_name = PhabricatorFileNameTransaction::TRANSACTIONTYPE; 35 35 36 36 $xactions = array(); 37 37 ··· 40 40 ->setNewValue($can_view); 41 41 42 42 $xactions[] = id(new PhabricatorFileTransaction()) 43 - ->setTransactionType(PhabricatorFileTransaction::TYPE_NAME) 43 + ->setTransactionType($type_name) 44 44 ->setNewValue($file_name); 45 45 46 46 $editor = id(new PhabricatorFileEditor())
-67
src/applications/files/editor/PhabricatorFileEditor.php
··· 17 17 $types[] = PhabricatorTransactions::TYPE_COMMENT; 18 18 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 19 19 20 - $types[] = PhabricatorFileTransaction::TYPE_NAME; 21 - 22 20 return $types; 23 21 } 24 22 25 - protected function getCustomTransactionOldValue( 26 - PhabricatorLiskDAO $object, 27 - PhabricatorApplicationTransaction $xaction) { 28 - 29 - switch ($xaction->getTransactionType()) { 30 - case PhabricatorFileTransaction::TYPE_NAME: 31 - return $object->getName(); 32 - } 33 - } 34 - 35 - protected function getCustomTransactionNewValue( 36 - PhabricatorLiskDAO $object, 37 - PhabricatorApplicationTransaction $xaction) { 38 - 39 - switch ($xaction->getTransactionType()) { 40 - case PhabricatorFileTransaction::TYPE_NAME: 41 - return $xaction->getNewValue(); 42 - } 43 - } 44 - 45 - protected function applyCustomInternalTransaction( 46 - PhabricatorLiskDAO $object, 47 - PhabricatorApplicationTransaction $xaction) { 48 - 49 - switch ($xaction->getTransactionType()) { 50 - case PhabricatorFileTransaction::TYPE_NAME: 51 - $object->setName($xaction->getNewValue()); 52 - break; 53 - } 54 - } 55 - 56 - protected function applyCustomExternalTransaction( 57 - PhabricatorLiskDAO $object, 58 - PhabricatorApplicationTransaction $xaction) {} 59 - 60 23 protected function shouldSendMail( 61 24 PhabricatorLiskDAO $object, 62 25 array $xactions) { ··· 110 73 protected function supportsSearch() { 111 74 return false; 112 75 } 113 - 114 - protected function validateTransaction( 115 - PhabricatorLiskDAO $object, 116 - $type, 117 - array $xactions) { 118 - 119 - $errors = parent::validateTransaction($object, $type, $xactions); 120 - 121 - switch ($type) { 122 - case PhabricatorFileTransaction::TYPE_NAME: 123 - $missing = $this->validateIsEmptyTextField( 124 - $object->getName(), 125 - $xactions); 126 - 127 - if ($missing) { 128 - $error = new PhabricatorApplicationTransactionValidationError( 129 - $type, 130 - pht('Required'), 131 - pht('File name is required.'), 132 - nonempty(last($xactions), null)); 133 - 134 - $error->setIsMissingFieldError(true); 135 - $errors[] = $error; 136 - } 137 - break; 138 - } 139 - 140 - return $errors; 141 - } 142 - 143 76 144 77 }
+3 -66
src/applications/files/storage/PhabricatorFileTransaction.php
··· 1 1 <?php 2 2 3 3 final class PhabricatorFileTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_NAME = 'file:name'; 4 + extends PhabricatorModularTransaction { 7 5 8 6 public function getApplicationName() { 9 7 return 'file'; ··· 17 15 return new PhabricatorFileTransactionComment(); 18 16 } 19 17 20 - public function getTitle() { 21 - $author_phid = $this->getAuthorPHID(); 22 - 23 - $old = $this->getOldValue(); 24 - $new = $this->getNewValue(); 25 - 26 - switch ($this->getTransactionType()) { 27 - case self::TYPE_NAME: 28 - return pht( 29 - '%s updated the name for this file from "%s" to "%s".', 30 - $this->renderHandleLink($author_phid), 31 - $old, 32 - $new); 33 - break; 34 - } 35 - 36 - return parent::getTitle(); 18 + public function getBaseTransactionClass() { 19 + return 'PhabricatorFileTransactionType'; 37 20 } 38 21 39 - public function getTitleForFeed() { 40 - $author_phid = $this->getAuthorPHID(); 41 - $object_phid = $this->getObjectPHID(); 42 - 43 - $old = $this->getOldValue(); 44 - $new = $this->getNewValue(); 45 - 46 - $type = $this->getTransactionType(); 47 - switch ($type) { 48 - case self::TYPE_NAME: 49 - return pht( 50 - '%s updated the name of %s from "%s" to "%s".', 51 - $this->renderHandleLink($author_phid), 52 - $this->renderHandleLink($object_phid), 53 - $old, 54 - $new); 55 - break; 56 - } 57 - 58 - return parent::getTitleForFeed(); 59 - } 60 - 61 - public function getIcon() { 62 - $old = $this->getOldValue(); 63 - $new = $this->getNewValue(); 64 - 65 - switch ($this->getTransactionType()) { 66 - case self::TYPE_NAME: 67 - return 'fa-pencil'; 68 - } 69 - 70 - return parent::getIcon(); 71 - } 72 - 73 - 74 - public function getColor() { 75 - $old = $this->getOldValue(); 76 - $new = $this->getNewValue(); 77 - 78 - switch ($this->getTransactionType()) { 79 - case self::TYPE_NAME: 80 - return PhabricatorTransactions::COLOR_BLUE; 81 - } 82 - 83 - return parent::getColor(); 84 - } 85 22 }
+1 -1
src/applications/files/storage/__tests__/PhabricatorFileTestCase.php
··· 32 32 // First, change the name: this should not scramble the secret. 33 33 $xactions = array(); 34 34 $xactions[] = id(new PhabricatorFileTransaction()) 35 - ->setTransactionType(PhabricatorFileTransaction::TYPE_NAME) 35 + ->setTransactionType(PhabricatorFileNameTransaction::TRANSACTIONTYPE) 36 36 ->setNewValue('test.dat2'); 37 37 38 38 $engine = id(new PhabricatorFileEditor())
+55
src/applications/files/xaction/PhabricatorFileNameTransaction.php
··· 1 + <?php 2 + 3 + final class PhabricatorFileNameTransaction 4 + extends PhabricatorFileTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'file:name'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getName(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setName($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s updated the name for this file from "%s" to "%s".', 19 + $this->renderAuthor(), 20 + $this->renderOldValue(), 21 + $this->renderNewValue()); 22 + } 23 + 24 + public function getTitleForFeed() { 25 + return pht( 26 + '%s updated the name of %s from "%s" to "%s".', 27 + $this->renderAuthor(), 28 + $this->renderObject(), 29 + $this->renderOldValue(), 30 + $this->renderNewValue()); 31 + } 32 + 33 + public function validateTransactions($object, array $xactions) { 34 + $errors = array(); 35 + 36 + if ($this->isEmptyTextTransaction($object->getName(), $xactions)) { 37 + $errors[] = $this->newRequiredError(pht('Files must have a name.')); 38 + } 39 + 40 + $max_length = $object->getColumnMaximumByteLength('name'); 41 + foreach ($xactions as $xaction) { 42 + $new_value = $xaction->getNewValue(); 43 + $new_length = strlen($new_value); 44 + if ($new_length > $max_length) { 45 + $errors[] = $this->newInvalidError( 46 + pht( 47 + 'File names must not be longer than %s character(s).', 48 + new PhutilNumber($max_length))); 49 + } 50 + } 51 + 52 + return $errors; 53 + } 54 + 55 + }
+4
src/applications/files/xaction/PhabricatorFileTransactionType.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorFileTransactionType 4 + extends PhabricatorModularTransactionType {}