Skip to content

Commit

Permalink
feature: artifact support
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarlovi committed Oct 24, 2018
1 parent 05b4bf4 commit 40ae28f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/ProcessManagerBundle/EventListener/ArtifactListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace ProcessManagerBundle\EventListener;

use Pimcore\File as FileHelper;
use Pimcore\Model\Asset;
use ProcessManagerBundle\Model\ProcessInterface;
use ProcessManagerBundle\Monolog\ProcessLogEvent;

/**
Expand All @@ -23,24 +25,28 @@ public function onProcessLogEvent(ProcessLogEvent $event)
if (false === array_key_exists('artifact', $record['context'])) {
return;
}

/** @var ProcessInterface $process */
$process = $record['extra']['process'];

// ProcessInterface instance must have a relation to its ExecutableInterface instance
// TODO: need asset path in Executable config, hardcoded for now
$artifactAssetPath = '/exports';

/** @var ProcessInterface $process */
$process = $record['extra']['process'];

$artifactPath = $record['context']['artifact'];
$artifact = new Asset();
$fileHandle = fopen($artifactPath, 'rb', false, FileHelper::getContext());

// TODO: how to do this better?
// this loads the entire file in memory instead of just moving the file using the filesystem
$artifact->setData(file_get_contents($artifactPath));
$artifact->setFilename(pathinfo($artifactPath, PATHINFO_FILENAME));
$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
$artifact->addMetadata('process_manager.process', 'number', $process->getId());
$artifact->save();

fclose($fileHandle);

$process->setArtifact($artifact);
$process->save();
}
Expand Down

0 comments on commit 40ae28f

Please sign in to comment.