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 23, 2018
1 parent 06f9ebb commit 7d65884
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/ProcessManagerBundle/EventListener/ArtifactListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace ProcessManagerBundle\EventListener;

use Pimcore\Model\Asset;
use ProcessManagerBundle\Monolog\ProcessLogEvent;

/**
* Class ArtifactListener.
*/
class ArtifactListener
{
/**
* @param ImportDefinitionEvent $event
*/
public function onProcessLogEvent(ProcessLogEvent $event)
{
// receives it via the logger from self::onArtifactEvent()
$record = $event->getRecord();

if (false === array_key_exists('artifact', $record['context'])) {
return;
}

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

$artifactPath = $record['context']['artifact'];

// TODO: copy $artifactPath in place of this asset
$artifact = new Asset();

$process->setArtifact($artifact);
$process->save();
}
}
15 changes: 15 additions & 0 deletions src/ProcessManagerBundle/Model/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Pimcore\Logger;
use Pimcore\Model\AbstractModel;
use Pimcore\Model\Asset;

class Process extends AbstractModel implements ProcessInterface
{
Expand Down Expand Up @@ -273,4 +274,18 @@ public function getPercentage() {

return ((100 / $this->getTotal()) * $this->getProgress()) / 100;
}

/**
* @param Asset $artifact
*/
public function setArtifact(Asset $artifact)
{
}

/**
* @return null|Asset
*/
public function getArtifact()
{
}
}
13 changes: 12 additions & 1 deletion src/ProcessManagerBundle/Model/ProcessInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace ProcessManagerBundle\Model;

use CoreShop\Component\Resource\Model\ResourceInterface;
use Pimcore\Model\Asset;

interface ProcessInterface extends ResourceInterface
{
Expand Down Expand Up @@ -90,4 +91,14 @@ public function setTotal($total);
* @return float
*/
public function getPercentage();
}

/**
* @param Asset $artifact
*/
public function setArtifact(Asset $artifact);

/**
* @return null|Asset
*/
public function getArtifact();
}
6 changes: 6 additions & 0 deletions src/ProcessManagerBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ services:
- { name: process_manager.process, type: pimcore, form-type: ProcessManagerBundle\Form\Type\Processes\PimcoreType }

### Event listeners
process_manager.event_listener.artifact:
class: ProcessManagerBundle\EventListener\ArtifactListener
tags:
- { name: kernel.event_listener, event: process_manager.process.log_event, method: onProcessLogEvent }
arguments:
- '@process_manager.registry.processes'
process_manager.event_listener.cron:
class: ProcessManagerBundle\EventListener\CronListener
tags:
Expand Down

0 comments on commit 7d65884

Please sign in to comment.