2011-07-29 19:05:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload a file to Phabricator.
|
|
|
|
*
|
|
|
|
* @group workflow
|
|
|
|
*/
|
|
|
|
final class ArcanistUploadWorkflow extends ArcanistBaseWorkflow {
|
|
|
|
|
|
|
|
private $paths;
|
2011-07-30 05:17:49 +02:00
|
|
|
private $json;
|
2011-07-29 19:05:07 +02:00
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 17:35:03 +02:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'upload';
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:02:37 +01:00
|
|
|
public function getCommandSynopses() {
|
2011-07-29 19:05:07 +02:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
2011-07-30 05:17:49 +02:00
|
|
|
**upload** __file__ [__file__ ...] [--json]
|
2012-03-05 19:02:37 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2011-07-29 19:05:07 +02:00
|
|
|
Supports: filesystems
|
|
|
|
Upload a file from local disk.
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
2011-07-30 05:17:49 +02:00
|
|
|
'json' => array(
|
|
|
|
'help' => 'Output upload information in JSON format.',
|
|
|
|
),
|
2011-07-29 19:05:07 +02:00
|
|
|
'*' => 'paths',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function didParseArguments() {
|
|
|
|
if (!$this->getArgument('paths')) {
|
|
|
|
throw new ArcanistUsageException("Specify one or more files to upload.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->paths = $this->getArgument('paths');
|
2011-07-30 05:17:49 +02:00
|
|
|
$this->json = $this->getArgument('json');
|
2011-07-29 19:05:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPaths() {
|
|
|
|
return $this->paths;
|
|
|
|
}
|
|
|
|
|
2011-07-30 05:17:49 +02:00
|
|
|
private function getJSON() {
|
|
|
|
return $this->json;
|
|
|
|
}
|
|
|
|
|
2011-07-29 19:05:07 +02:00
|
|
|
public function run() {
|
|
|
|
|
|
|
|
$conduit = $this->getConduit();
|
|
|
|
|
2011-07-30 05:17:49 +02:00
|
|
|
$results = array();
|
|
|
|
|
2011-07-29 19:05:07 +02:00
|
|
|
foreach ($this->paths as $path) {
|
|
|
|
$name = basename($path);
|
2011-07-30 05:17:49 +02:00
|
|
|
$this->writeStatusMessage("Uploading '{$name}'...\n");
|
2011-07-29 19:05:07 +02:00
|
|
|
try {
|
|
|
|
$data = Filesystem::readFile($path);
|
|
|
|
} catch (FilesystemException $ex) {
|
2011-07-30 05:17:49 +02:00
|
|
|
$this->writeStatusMessage(
|
|
|
|
"Unable to upload file: ".$ex->getMessage()."\n");
|
|
|
|
$results[$path] = null;
|
2011-07-29 19:05:07 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$phid = $conduit->callMethodSynchronous(
|
|
|
|
'file.upload',
|
|
|
|
array(
|
|
|
|
'data_base64' => base64_encode($data),
|
|
|
|
'name' => $name,
|
|
|
|
));
|
|
|
|
$info = $conduit->callMethodSynchronous(
|
|
|
|
'file.info',
|
|
|
|
array(
|
|
|
|
'phid' => $phid,
|
|
|
|
));
|
|
|
|
|
2011-07-30 05:17:49 +02:00
|
|
|
$results[$path] = $info;
|
|
|
|
|
|
|
|
if (!$this->getJSON()) {
|
2012-07-21 15:44:21 +02:00
|
|
|
$id = $info['id'];
|
|
|
|
echo " F{$id} {$name}: ".$info['uri']."\n\n";
|
2011-07-30 05:17:49 +02:00
|
|
|
}
|
2011-07-29 19:05:07 +02:00
|
|
|
}
|
|
|
|
|
2011-07-30 05:17:49 +02:00
|
|
|
if ($this->getJSON()) {
|
|
|
|
echo json_encode($results)."\n";
|
|
|
|
} else {
|
|
|
|
$this->writeStatusMessage("Done.\n");
|
|
|
|
}
|
2011-07-29 19:05:07 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|