@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 PholioImageNameTransaction
4 extends PholioImageTransactionType {
5
6 const TRANSACTIONTYPE = 'image-name';
7
8 public function generateOldValue($object) {
9 $name = null;
10 $phid = null;
11 $image = $this->getImageForXaction($object);
12 if ($image) {
13 $name = $image->getName();
14 $phid = $image->getPHID();
15 }
16 return array($phid => $name);
17 }
18
19 public function applyInternalEffects($object, $value) {
20 $image = $this->getImageForXaction($object);
21 $value = (string)head($this->getNewValue());
22 $image->setName($value);
23 $image->save();
24 }
25
26 public function getTitle() {
27 $old = $this->getOldValue();
28 $new = $this->getNewValue();
29
30 return pht(
31 '%s renamed an image (%s) from %s to %s.',
32 $this->renderAuthor(),
33 $this->renderHandle(key($new)),
34 $this->renderValue((string)head($old)),
35 $this->renderValue((string)head($new)));
36 }
37
38 public function getTitleForFeed() {
39 return pht(
40 '%s updated the image names of %s.',
41 $this->renderAuthor(),
42 $this->renderObject());
43 }
44
45 public function mergeTransactions(
46 $object,
47 PhabricatorApplicationTransaction $u,
48 PhabricatorApplicationTransaction $v) {
49
50 $raw_new_value_u = $u->getNewValue();
51 $raw_new_value_v = $v->getNewValue();
52 $phid_u = head_key($raw_new_value_u);
53 $phid_v = head_key($raw_new_value_v);
54 if ($phid_u == $phid_v) {
55 return $v;
56 }
57
58 return null;
59 }
60
61 public function validateTransactions($object, array $xactions) {
62 $errors = array();
63
64 $max_length = $object->getColumnMaximumByteLength('name');
65 foreach ($xactions as $xaction) {
66 $new_value = head(array_values($xaction->getNewValue()));
67 $new_length = strlen($new_value);
68 if ($new_length > $max_length) {
69 $errors[] = $this->newInvalidError(
70 pht(
71 'Mock image titles must not be longer than %s character(s).',
72 new PhutilNumber($max_length)));
73 } else if ($new_length === 0) {
74 $errors[] = $this->newInvalidError(
75 pht(
76 'Mock images must have a title.'));
77 }
78 }
79
80 return $errors;
81 }
82
83
84}