Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistUploadWorkflow.php
| Show All 26 Lines | EOTEXT | ||||
| ); | ); | ||||
| } | } | ||||
| public function getArguments() { | public function getArguments() { | ||||
| return array( | return array( | ||||
| 'json' => array( | 'json' => array( | ||||
| 'help' => pht('Output upload information in JSON format.'), | 'help' => pht('Output upload information in JSON format.'), | ||||
| ), | ), | ||||
| 'temporary' => array( | |||||
| 'help' => pht( | |||||
| 'Mark the file as temporary. Temporary files will be deleted '. | |||||
| 'automatically after 24 hours.'), | |||||
| ), | |||||
| '*' => 'paths', | '*' => 'paths', | ||||
| ); | ); | ||||
| } | } | ||||
| protected function didParseArguments() { | protected function didParseArguments() { | ||||
| if (!$this->getArgument('paths')) { | if (!$this->getArgument('paths')) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| pht('Specify one or more files to upload.')); | pht('Specify one or more files to upload.')); | ||||
| } | } | ||||
| $this->paths = $this->getArgument('paths'); | $this->paths = $this->getArgument('paths'); | ||||
| $this->json = $this->getArgument('json'); | $this->json = $this->getArgument('json'); | ||||
| } | } | ||||
| public function requiresAuthentication() { | public function requiresAuthentication() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function run() { | public function run() { | ||||
| $is_temporary = $this->getArgument('temporary'); | |||||
| $conduit = $this->getConduit(); | $conduit = $this->getConduit(); | ||||
| $results = array(); | $results = array(); | ||||
| $uploader = id(new ArcanistFileUploader()) | $uploader = id(new ArcanistFileUploader()) | ||||
| ->setConduitClient($conduit); | ->setConduitClient($conduit); | ||||
| foreach ($this->paths as $path) { | foreach ($this->paths as $key => $path) { | ||||
| $file = id(new ArcanistFileDataRef()) | $file = id(new ArcanistFileDataRef()) | ||||
| ->setName(basename($path)) | ->setName(basename($path)) | ||||
| ->setPath($path); | ->setPath($path); | ||||
| $uploader->addFile($file); | $uploader->addFile($file, $key); | ||||
| if ($is_temporary) { | |||||
| $uploader->setDeleteFileAfterEpoch( | |||||
| $key, | |||||
| time() + phutil_units('24 hours in seconds')); | |||||
| } | |||||
| } | } | ||||
| $files = $uploader->uploadFiles(); | $files = $uploader->uploadFiles(); | ||||
| $results = array(); | $results = array(); | ||||
| foreach ($files as $file) { | foreach ($files as $file) { | ||||
| // TODO: This could be handled more gracefully; just preserving behavior | // TODO: This could be handled more gracefully; just preserving behavior | ||||
| // until we introduce `file.query` and modernize this. | // until we introduce `file.query` and modernize this. | ||||
| ▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines | |||||