Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96619808
PhabricatorRepositoryEncodingTransaction.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Dec 29, 01:16
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Dec 31, 01:16 (2 d)
Engine
blob
Format
Raw Data
Handle
23200988
Attached To
rPH Phabricator
PhabricatorRepositoryEncodingTransaction.php
View Options
<?php
final
class
PhabricatorRepositoryEncodingTransaction
extends
PhabricatorRepositoryTransactionType
{
const
TRANSACTIONTYPE
=
'repo:encoding'
;
public
function
generateOldValue
(
$object
)
{
return
$object
->
getDetail
(
'encoding'
);
}
public
function
applyInternalEffects
(
$object
,
$value
)
{
$object
->
setDetail
(
'encoding'
,
$value
);
}
public
function
getTitle
()
{
$old
=
$this
->
getOldValue
();
$new
=
$this
->
getNewValue
();
if
(
strlen
(
$old
)
&&
!
strlen
(
$new
))
{
return
pht
(
'%s removed the %s encoding configured for this repository.'
,
$this
->
renderAuthor
(),
$this
->
renderOldValue
());
}
else
if
(
strlen
(
$new
)
&&
!
strlen
(
$old
))
{
return
pht
(
'%s set the encoding for this repository to %s.'
,
$this
->
renderAuthor
(),
$this
->
renderNewValue
());
}
else
{
return
pht
(
'%s changed the repository encoding from %s to %s.'
,
$this
->
renderAuthor
(),
$this
->
renderOldValue
(),
$this
->
renderNewValue
());
}
}
public
function
validateTransactions
(
$object
,
array
$xactions
)
{
$errors
=
array
();
foreach
(
$xactions
as
$xaction
)
{
// Make sure the encoding is valid by converting to UTF-8. This tests
// that the user has mbstring installed, and also that they didn't
// type a garbage encoding name. Note that we're converting from
// UTF-8 to the target encoding, because mbstring is fine with
// converting from a nonsense encoding.
$encoding
=
$xaction
->
getNewValue
();
if
(!
strlen
(
$encoding
))
{
continue
;
}
try
{
phutil_utf8_convert
(
'.'
,
$encoding
,
'UTF-8'
);
}
catch
(
Exception
$ex
)
{
$errors
[]
=
$this
->
newInvalidError
(
pht
(
'Repository encoding "%s" is not valid: %s'
,
$encoding
,
$ex
->
getMessage
()),
$xaction
);
}
}
return
$errors
;
}
}
Event Timeline
Log In to Comment