Skip to content

Commit

Permalink
feature: artifact support, overwrite existing artifact if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarlovi committed Oct 29, 2018
1 parent 9b76e49 commit 6dc325e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/ProcessManagerBundle/EventListener/ArtifactListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ public function onProcessLogEvent(ProcessLogEvent $event)
$artifactPath = $record['context']['artifact'];
$fileHandle = fopen($artifactPath, 'rb', false, FileHelper::getContext());

$artifact = new Asset();
$artifact->setParent(Asset\Service::createFolderByPath($artifactAssetPath));
$artifact->setStream($fileHandle);
// TODO: name the file something like "<executable name> artifact <current datetime>" or provide an artifact name template in the Executable config
$artifact->setFilename(pathinfo($artifactPath, PATHINFO_FILENAME));
// TODO: add an event listener which sets Artifact=null (or deletes the Process) if the user deletes this asset
$parent = Asset\Service::createFolderByPath($artifactAssetPath);
$filename = pathinfo($artifactPath, PATHINFO_BASENAME);
$fullPath = sprintf('%s/%s', $parent->getFullPath(), $filename);

$artifact = Asset::getByPath($fullPath);
if (null === $artifact) {
$artifact = new Asset();
$artifact->setParent($parent);
// TODO: name the file something like "[$executableName] artifact [$currentDatetime]" or provide an artifact name template in the Executable config
$artifact->setFilename($filename);
}
$artifact->addMetadata(self::METADATA_MARKER, 'number', $process->getId());
$artifact->setStream($fileHandle);
$artifact->save();

fclose($fileHandle);
Expand Down

0 comments on commit 6dc325e

Please sign in to comment.