Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F12662028
ArcanistDownloadWorkflow.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
ArcanistDownloadWorkflow.php
View Options
<?php
/**
* Download a file from Phabricator.
*/
final
class
ArcanistDownloadWorkflow
extends
ArcanistWorkflow
{
private
$id
;
private
$saveAs
;
private
$show
;
public
function
getWorkflowName
()
{
return
'download'
;
}
public
function
getCommandSynopses
()
{
return
phutil_console_format
(
<<<EOTEXT
**download** __file__ [--as __name__] [--show]
EOTEXT
);
}
public
function
getCommandHelp
()
{
return
phutil_console_format
(
<<<EOTEXT
Supports: filesystems
Download a file to local disk, e.g.:
$ arc download F33 # Download file 'F33'
EOTEXT
);
}
public
function
getArguments
()
{
return
array
(
'show'
=>
array
(
'conflicts'
=>
array
(
'as'
=>
pht
(
'Use %s to direct the file to stdout, or %s to direct '
.
'it to a named location.'
,
'--show'
,
'--as'
),
),
'help'
=>
pht
(
'Write file to stdout instead of to disk.'
),
),
'as'
=>
array
(
'param'
=>
'name'
,
'help'
=>
pht
(
'Save the file with a specific name rather than the default.'
),
),
'*'
=>
'argv'
,
);
}
protected
function
didParseArguments
()
{
$argv
=
$this
->
getArgument
(
'argv'
);
if
(!
$argv
)
{
throw
new
ArcanistUsageException
(
pht
(
'Specify a file to download.'
));
}
if
(
count
(
$argv
)
>
1
)
{
throw
new
ArcanistUsageException
(
pht
(
'Specify exactly one file to download.'
));
}
$file
=
reset
(
$argv
);
if
(!
preg_match
(
'/^F?
\d
+$/'
,
$file
))
{
throw
new
ArcanistUsageException
(
pht
(
'Specify file by ID, e.g. %s.'
,
'F123'
));
}
$this
->
id
=
(
int
)
ltrim
(
$file
,
'F'
);
$this
->
saveAs
=
$this
->
getArgument
(
'as'
);
$this
->
show
=
$this
->
getArgument
(
'show'
);
}
public
function
requiresAuthentication
()
{
return
true
;
}
public
function
run
()
{
$conduit
=
$this
->
getConduit
();
$this
->
writeStatusMessage
(
pht
(
'Getting file information...'
).
"
\n
"
);
$info
=
$conduit
->
callMethodSynchronous
(
'file.info'
,
array
(
'id'
=>
$this
->
id
,
));
$bytes
=
number_format
(
$info
[
'byteSize'
]);
$desc
=
'('
.
$bytes
.
' bytes)'
;
if
(
$info
[
'name'
])
{
$desc
=
"'"
.
$info
[
'name'
].
"' "
.
$desc
;
}
$this
->
writeStatusMessage
(
pht
(
'Downloading file %s...'
,
$desc
).
"
\n
"
);
$data
=
$conduit
->
callMethodSynchronous
(
'file.download'
,
array
(
'phid'
=>
$info
[
'phid'
],
));
$data
=
base64_decode
(
$data
);
if
(
$this
->
show
)
{
echo
$data
;
}
else
{
$path
=
Filesystem
::
writeUniqueFile
(
nonempty
(
$this
->
saveAs
,
$info
[
'name'
],
'file'
),
$data
);
$this
->
writeStatusMessage
(
pht
(
"Saved file as '%s'."
,
$path
).
"
\n
"
);
}
return
0
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 28, 15:49 (2 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1052295
Default Alt Text
ArcanistDownloadWorkflow.php (2 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment