@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<?php
2
3final class PhabricatorRepositoryCopyTimeLimitTransaction
4 extends PhabricatorRepositoryTransactionType {
5
6 const TRANSACTIONTYPE = 'limit.copy';
7
8 public function generateOldValue($object) {
9 return $object->getCopyTimeLimit();
10 }
11
12 public function generateNewValue($object, $value) {
13 if (!strlen($value)) {
14 return null;
15 }
16
17 $value = (int)$value;
18 if (!$value) {
19 return null;
20 }
21
22 return $value;
23 }
24
25 public function applyInternalEffects($object, $value) {
26 $object->setCopyTimeLimit($value);
27 }
28
29 public function getTitle() {
30 $old = $this->getOldValue();
31 $new = $this->getNewValue();
32
33 if ($old && $new) {
34 return pht(
35 '%s changed the copy time limit for this repository from %s seconds '.
36 'to %s seconds.',
37 $this->renderAuthor(),
38 $this->renderOldValue(),
39 $this->renderNewValue());
40 } else if ($new) {
41 return pht(
42 '%s set the copy time limit for this repository to %s seconds.',
43 $this->renderAuthor(),
44 $this->renderNewValue());
45 } else {
46 return pht(
47 '%s reset the copy time limit (%s seconds) for this repository '.
48 'to the default value.',
49 $this->renderAuthor(),
50 $this->renderOldValue());
51 }
52 }
53
54 public function validateTransactions($object, array $xactions) {
55 $errors = array();
56
57 foreach ($xactions as $xaction) {
58 $new = $xaction->getNewValue();
59
60 if (!strlen($new)) {
61 continue;
62 }
63
64 if (!preg_match('/^\d+\z/', $new)) {
65 $errors[] = $this->newInvalidError(
66 pht(
67 'Unable to parse copy time limit, specify a positive number '.
68 'of seconds.'),
69 $xaction);
70 continue;
71 }
72 }
73
74 return $errors;
75 }
76
77}