Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98048691
PhragmentRevertController.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
Thu, Jan 9, 01:51
Size
2 KB
Mime Type
text/x-php
Expires
Sat, Jan 11, 01:51 (1 d, 10 h)
Engine
blob
Format
Raw Data
Handle
23502506
Attached To
rPH Phabricator
PhragmentRevertController.php
View Options
<?php
final
class
PhragmentRevertController
extends
PhragmentController
{
private
$dblob
;
private
$id
;
public
function
willProcessRequest
(
array
$data
)
{
$this
->
dblob
=
$data
[
'dblob'
];
$this
->
id
=
$data
[
'id'
];
}
public
function
processRequest
()
{
$request
=
$this
->
getRequest
();
$viewer
=
$request
->
getUser
();
$fragment
=
id
(
new
PhragmentFragmentQuery
())
->
setViewer
(
$viewer
)
->
withPaths
(
array
(
$this
->
dblob
))
->
requireCapabilities
(
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
,
PhabricatorPolicyCapability
::
CAN_EDIT
,
))
->
executeOne
();
if
(
$fragment
===
null
)
{
return
new
Aphront404Response
();
}
$version
=
id
(
new
PhragmentFragmentVersionQuery
())
->
setViewer
(
$viewer
)
->
withFragmentPHIDs
(
array
(
$fragment
->
getPHID
()))
->
withIDs
(
array
(
$this
->
id
))
->
executeOne
();
if
(
$version
===
null
)
{
return
new
Aphront404Response
();
}
if
(
$request
->
isDialogFormPost
())
{
$file_phid
=
$version
->
getFilePHID
();
$file
=
null
;
if
(
$file_phid
!==
null
)
{
$file
=
id
(
new
PhabricatorFileQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$file_phid
))
->
executeOne
();
if
(
$file
===
null
)
{
throw
new
Exception
(
'The file associated with this version was not found.'
);
}
}
if
(
$file
===
null
)
{
$fragment
->
deleteFile
(
$viewer
);
}
else
{
$fragment
->
updateFromFile
(
$viewer
,
$file
);
}
return
id
(
new
AphrontRedirectResponse
())
->
setURI
(
$this
->
getApplicationURI
(
'/history/'
.
$this
->
dblob
));
}
return
$this
->
createDialog
(
$fragment
,
$version
);
}
function
createDialog
(
PhragmentFragment
$fragment
,
PhragmentFragmentVersion
$version
)
{
$request
=
$this
->
getRequest
();
$viewer
=
$request
->
getUser
();
$dialog
=
id
(
new
AphrontDialogView
())
->
setTitle
(
pht
(
'Really revert this fragment?'
))
->
setUser
(
$request
->
getUser
())
->
addSubmitButton
(
pht
(
'Revert'
))
->
addCancelButton
(
pht
(
'Cancel'
))
->
appendParagraph
(
pht
(
'Reverting this fragment to version %d will create a new version of '
.
'the fragment. It will not delete any version history.'
,
$version
->
getSequence
(),
$version
->
getSequence
()));
return
id
(
new
AphrontDialogResponse
())->
setDialog
(
$dialog
);
}
}
Event Timeline
Log In to Comment