Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1131852
PhabricatorDifferentialMigrateHunkWorkflow.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
PhabricatorDifferentialMigrateHunkWorkflow.php
View Options
<?php
final
class
PhabricatorDifferentialMigrateHunkWorkflow
extends
PhabricatorDifferentialManagementWorkflow
{
protected
function
didConstruct
()
{
$this
->
setName
(
'migrate-hunk'
)
->
setExamples
(
'**migrate-hunk** --id __hunk__ --to __storage__'
)
->
setSynopsis
(
pht
(
'Migrate storage engines for a hunk.'
))
->
setArguments
(
array
(
array
(
'name'
=>
'id'
,
'param'
=>
'id'
,
'help'
=>
pht
(
'Hunk ID to migrate.'
),
),
array
(
'name'
=>
'to'
,
'param'
=>
'storage'
,
'help'
=>
pht
(
'Storage engine to migrate to.'
),
),
));
}
public
function
execute
(
PhutilArgumentParser
$args
)
{
$id
=
$args
->
getArg
(
'id'
);
if
(!
$id
)
{
throw
new
PhutilArgumentUsageException
(
pht
(
'Specify a hunk to migrate with --id.'
));
}
$storage
=
$args
->
getArg
(
'to'
);
switch
(
$storage
)
{
case
DifferentialHunk
::
DATATYPE_TEXT
:
case
DifferentialHunk
::
DATATYPE_FILE
:
break
;
default
:
throw
new
PhutilArgumentUsageException
(
pht
(
'Specify a hunk storage engine with --to.'
));
}
$hunk
=
$this
->
loadHunk
(
$id
);
$old_data
=
$hunk
->
getChanges
();
switch
(
$storage
)
{
case
DifferentialHunk
::
DATATYPE_TEXT
:
$hunk
->
saveAsText
();
$this
->
logOkay
(
pht
(
'TEXT'
),
pht
(
'Convereted hunk to text storage.'
));
break
;
case
DifferentialHunk
::
DATATYPE_FILE
:
$hunk
->
saveAsFile
();
$this
->
logOkay
(
pht
(
'FILE'
),
pht
(
'Convereted hunk to file storage.'
));
break
;
}
$hunk
=
$this
->
loadHunk
(
$id
);
$new_data
=
$hunk
->
getChanges
();
if
(
$old_data
!==
$new_data
)
{
throw
new
Exception
(
pht
(
'Integrity check failed: new file data differs fom old data!'
));
}
return
0
;
}
private
function
loadHunk
(
$id
)
{
$hunk
=
id
(
new
DifferentialHunk
())->
load
(
$id
);
if
(!
$hunk
)
{
throw
new
PhutilArgumentUsageException
(
pht
(
'No hunk exists with ID "%s".'
,
$id
));
}
return
$hunk
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Jul 1, 5:46 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
280970
Default Alt Text
PhabricatorDifferentialMigrateHunkWorkflow.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment