2013-12-08 23:34:09 +01:00
|
|
|
<?php
|
|
|
|
|
2014-03-26 00:09:51 +01:00
|
|
|
final class HarbormasterPublishFragmentBuildStepImplementation
|
2014-03-26 00:09:21 +01:00
|
|
|
extends HarbormasterBuildStepImplementation {
|
2013-12-08 23:34:09 +01:00
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return pht('Publish Fragment');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getGenericDescription() {
|
|
|
|
return pht('Publish a fragment based on a file artifact.');
|
|
|
|
}
|
|
|
|
|
2015-08-06 13:19:42 +02:00
|
|
|
|
|
|
|
public function getBuildStepGroupKey() {
|
|
|
|
return HarbormasterPrototypeBuildStepGroup::GROUPKEY;
|
|
|
|
}
|
|
|
|
|
2013-12-08 23:34:09 +01:00
|
|
|
public function getDescription() {
|
|
|
|
return pht(
|
2014-03-26 00:10:50 +01:00
|
|
|
'Publish file artifact %s as fragment %s.',
|
|
|
|
$this->formatSettingForDescription('artifact'),
|
|
|
|
$this->formatSettingForDescription('path'));
|
2013-12-08 23:34:09 +01: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['artifact']);
|
|
|
|
|
|
|
|
$file = $artifact->loadPhabricatorFile();
|
|
|
|
|
|
|
|
$fragment = id(new PhragmentFragmentQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withPaths(array($path))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if ($fragment === null) {
|
|
|
|
PhragmentFragment::createFromFile(
|
|
|
|
PhabricatorUser::getOmnipotentUser(),
|
|
|
|
$file,
|
|
|
|
$path,
|
|
|
|
PhabricatorPolicies::getMostOpenPolicy(),
|
|
|
|
PhabricatorPolicies::POLICY_USER);
|
|
|
|
} else {
|
2014-06-09 20:36:49 +02:00
|
|
|
if ($file->getMimeType() === 'application/zip') {
|
2013-12-08 23:34:09 +01:00
|
|
|
$fragment->updateFromZIP(PhabricatorUser::getOmnipotentUser(), $file);
|
|
|
|
} else {
|
|
|
|
$fragment->updateFromFile(PhabricatorUser::getOmnipotentUser(), $file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-26 00:02:34 +01:00
|
|
|
public function getArtifactInputs() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'name' => pht('Publishes File'),
|
|
|
|
'key' => $this->getSetting('artifact'),
|
|
|
|
'type' => HarbormasterBuildArtifact::TYPE_FILE,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-03-26 00:08:40 +01:00
|
|
|
public function getFieldSpecifications() {
|
2013-12-08 23:34:09 +01:00
|
|
|
return array(
|
|
|
|
'path' => array(
|
2014-03-26 00:08:40 +01:00
|
|
|
'name' => pht('Path'),
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
),
|
2013-12-08 23:34:09 +01:00
|
|
|
'artifact' => array(
|
2014-03-26 00:08:40 +01:00
|
|
|
'name' => pht('File Artifact'),
|
|
|
|
'type' => 'text',
|
|
|
|
'required' => true,
|
|
|
|
),
|
|
|
|
);
|
2013-12-08 23:34:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|