Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / xaction / PhabricatorRepositoryFilesizeLimitTransaction.php
blob6bf74cc757b5c542fa796aa94985f6dce484f464
1 <?php
3 final class PhabricatorRepositoryFilesizeLimitTransaction
4 extends PhabricatorRepositoryTransactionType {
6 const TRANSACTIONTYPE = 'limit.filesize';
8 public function generateOldValue($object) {
9 return $object->getFilesizeLimit();
12 public function generateNewValue($object, $value) {
13 if (!strlen($value)) {
14 return null;
17 $value = phutil_parse_bytes($value);
18 if (!$value) {
19 return null;
22 return $value;
25 public function applyInternalEffects($object, $value) {
26 $object->setFilesizeLimit($value);
29 public function getTitle() {
30 $old = $this->getOldValue();
31 $new = $this->getNewValue();
33 if ($old && $new) {
34 return pht(
35 '%s changed the filesize limit for this repository from %s bytes to '.
36 '%s bytes.',
37 $this->renderAuthor(),
38 $this->renderOldValue(),
39 $this->renderNewValue());
40 } else if ($new) {
41 return pht(
42 '%s set the filesize limit for this repository to %s bytes.',
43 $this->renderAuthor(),
44 $this->renderNewValue());
45 } else {
46 return pht(
47 '%s removed the filesize limit (%s bytes) for this repository.',
48 $this->renderAuthor(),
49 $this->renderOldValue());
53 public function validateTransactions($object, array $xactions) {
54 $errors = array();
56 foreach ($xactions as $xaction) {
57 $new = $xaction->getNewValue();
59 if (!strlen($new)) {
60 continue;
63 try {
64 $value = phutil_parse_bytes($new);
65 } catch (Exception $ex) {
66 $errors[] = $this->newInvalidError(
67 pht(
68 'Unable to parse filesize limit: %s',
69 $ex->getMessage()),
70 $xaction);
71 continue;
75 return $errors;