Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F12661726
ArcanistUploadWorkflow.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
ArcanistUploadWorkflow.php
View Options
<?php
/**
* Upload a file to Phabricator.
*/
final
class
ArcanistUploadWorkflow
extends
ArcanistWorkflow
{
private
$paths
;
private
$json
;
public
function
getWorkflowName
()
{
return
'upload'
;
}
public
function
getCommandSynopses
()
{
return
phutil_console_format
(
<<<EOTEXT
**upload** __file__ [__file__ ...] [--json]
EOTEXT
);
}
public
function
getCommandHelp
()
{
return
phutil_console_format
(
<<<EOTEXT
Supports: filesystems
Upload a file from local disk.
EOTEXT
);
}
public
function
getArguments
()
{
return
array
(
'json'
=>
array
(
'help'
=>
'Output upload information in JSON format.'
,
),
'*'
=>
'paths'
,
);
}
protected
function
didParseArguments
()
{
if
(!
$this
->
getArgument
(
'paths'
))
{
throw
new
ArcanistUsageException
(
'Specify one or more files to upload.'
);
}
$this
->
paths
=
$this
->
getArgument
(
'paths'
);
$this
->
json
=
$this
->
getArgument
(
'json'
);
}
public
function
requiresAuthentication
()
{
return
true
;
}
private
function
getPaths
()
{
return
$this
->
paths
;
}
private
function
getJSON
()
{
return
$this
->
json
;
}
public
function
run
()
{
$conduit
=
$this
->
getConduit
();
$results
=
array
();
foreach
(
$this
->
paths
as
$path
)
{
$name
=
basename
(
$path
);
$this
->
writeStatusMessage
(
"Uploading '{$name}'...
\n
"
);
try
{
$data
=
Filesystem
::
readFile
(
$path
);
}
catch
(
FilesystemException
$ex
)
{
$this
->
writeStatusMessage
(
"Unable to upload file: "
.
$ex
->
getMessage
().
"
\n
"
);
$results
[
$path
]
=
null
;
continue
;
}
$phid
=
$conduit
->
callMethodSynchronous
(
'file.upload'
,
array
(
'data_base64'
=>
base64_encode
(
$data
),
'name'
=>
$name
,
));
$info
=
$conduit
->
callMethodSynchronous
(
'file.info'
,
array
(
'phid'
=>
$phid
,
));
$results
[
$path
]
=
$info
;
if
(!
$this
->
getJSON
())
{
$id
=
$info
[
'id'
];
echo
" F{$id} {$name}: "
.
$info
[
'uri'
].
"
\n\n
"
;
}
}
if
(
$this
->
getJSON
())
{
echo
json_encode
(
$results
).
"
\n
"
;
}
else
{
$this
->
writeStatusMessage
(
"Done.
\n
"
);
}
return
0
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 28, 15:48 (13 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1046944
Default Alt Text
ArcanistUploadWorkflow.php (2 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment