2013-12-06 14:11:05 +11:00
|
|
|
<?php
|
|
|
|
|
2014-03-25 16:09:51 -07:00
|
|
|
final class HarbormasterUploadArtifactBuildStepImplementation
|
2014-03-25 16:09:21 -07:00
|
|
|
extends HarbormasterBuildStepImplementation {
|
2013-12-06 14:11:05 +11:00
|
|
|
|
|
|
|
public function getName() {
|
2014-03-25 16:10:50 -07:00
|
|
|
return pht('Upload File');
|
2013-12-06 14:11:05 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getGenericDescription() {
|
2014-03-25 16:10:50 -07:00
|
|
|
return pht('Upload a file from a host to Phabricator.');
|
2013-12-06 14:11:05 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription() {
|
|
|
|
return pht(
|
2014-03-25 16:10:50 -07:00
|
|
|
'Upload %s from %s.',
|
|
|
|
$this->formatSettingForDescription('path'),
|
|
|
|
$this->formatSettingForDescription('hostartifact'));
|
2013-12-06 14:11:05 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute(
|
|
|
|
HarbormasterBuild $build,
|
|
|
|
HarbormasterBuildTarget $build_target) {
|
|
|
|
|
|
|
|
$settings = $this->getSettings();
|
|
|
|
$variables = $build_target->getVariables();
|
|
|
|
|
|
|
|
$path = $this->mergeVariables(
|
|
|
|
'vsprintf',
|
|
|
|
$settings['path'],
|
|
|
|
$variables);
|
|
|
|
|
|
|
|
$artifact = $build->loadArtifact($settings['hostartifact']);
|
|
|
|
|
|
|
|
$lease = $artifact->loadDrydockLease();
|
|
|
|
|
|
|
|
$interface = $lease->getInterface('filesystem');
|
|
|
|
|
|
|
|
// TODO: Handle exceptions.
|
|
|
|
$file = $interface->saveFile($path, $settings['name']);
|
|
|
|
|
|
|
|
// Insert the artifact record.
|
|
|
|
$artifact = $build->createArtifact(
|
|
|
|
$build_target,
|
|
|
|
$settings['name'],
|
|
|
|
HarbormasterBuildArtifact::TYPE_FILE);
|
|
|
|
$artifact->setArtifactData(array(
|
|
|
|
'filePHID' => $file->getPHID()));
|
|
|
|
$artifact->save();
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:02:34 -07:00
|
|
|
public function getArtifactInputs() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'name' => pht('Upload From Host'),
|
|
|
|
'key' => $this->getSetting('hostartifact'),
|
|
|
|
'type' => HarbormasterBuildArtifact::TYPE_HOST,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArtifactOutputs() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'name' => pht('Uploaded File'),
|
|
|
|
'key' => $this->getSetting('name'),
|
|
|
|
'type' => HarbormasterBuildArtifact::TYPE_FILE,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:08:40 -07:00
|
|
|
public function getFieldSpecifications() {
|
2013-12-06 14:11:05 +11:00
|
|
|
return array(
|
|
|
|
'path' => array(
|
2014-03-25 16:08:40 -07:00
|
|
|
'name' => pht('Path'),
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
),
|
2013-12-06 14:11:05 +11:00
|
|
|
'name' => array(
|
2014-03-25 16:08:40 -07:00
|
|
|
'name' => pht('Local Name'),
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
),
|
2013-12-06 14:11:05 +11:00
|
|
|
'hostartifact' => array(
|
2014-03-25 16:08:40 -07:00
|
|
|
'name' => pht('Host Artifact'),
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
),
|
|
|
|
);
|
2013-12-06 14:11:05 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|