3 final class PhabricatorRepositoryEncodingTransaction
4 extends PhabricatorRepositoryTransactionType
{
6 const TRANSACTIONTYPE
= 'repo:encoding';
8 public function generateOldValue($object) {
9 return $object->getDetail('encoding');
12 public function applyInternalEffects($object, $value) {
13 $object->setDetail('encoding', $value);
16 public function getTitle() {
17 $old = $this->getOldValue();
18 $new = $this->getNewValue();
20 if (strlen($old) && !strlen($new)) {
22 '%s removed the %s encoding configured for this repository.',
23 $this->renderAuthor(),
24 $this->renderOldValue());
25 } else if (strlen($new) && !strlen($old)) {
27 '%s set the encoding for this repository to %s.',
28 $this->renderAuthor(),
29 $this->renderNewValue());
32 '%s changed the repository encoding from %s to %s.',
33 $this->renderAuthor(),
34 $this->renderOldValue(),
35 $this->renderNewValue());
39 public function validateTransactions($object, array $xactions) {
42 foreach ($xactions as $xaction) {
43 // Make sure the encoding is valid by converting to UTF-8. This tests
44 // that the user has mbstring installed, and also that they didn't
45 // type a garbage encoding name. Note that we're converting from
46 // UTF-8 to the target encoding, because mbstring is fine with
47 // converting from a nonsense encoding.
48 $encoding = $xaction->getNewValue();
49 if (!strlen($encoding)) {
54 phutil_utf8_convert('.', $encoding, 'UTF-8');
55 } catch (Exception
$ex) {
56 $errors[] = $this->newInvalidError(
58 'Repository encoding "%s" is not valid: %s',