Skip to content

Commit

Permalink
Merge pull request #23 from DivanteLtd/feature/export-event
Browse files Browse the repository at this point in the history
Batch exported event
  • Loading branch information
t-zilla authored Dec 3, 2020
2 parents 60faec7 + 8cf7ca9 commit 1ac0658
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/ScheduledExportBundle/Event/BatchExportedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Divante\ScheduledExportBundle\Event;

use Pimcore\Model\DataObject\Concrete;

class BatchExportedEvent extends \Symfony\Component\EventDispatcher\Event
{
const NAME = 'divante.scheduled_export.batch_exported';

/** @var string[] */
private $objectsIds;

/**
* BatchExportedEvent constructor.
* @param string[] $objectsIds
*/
public function __construct(array $objectsIds)
{
$this->objectsIds = $objectsIds;
}

/**
* @return string[]
*/
public function getObjectsIds(): array
{
return $this->objectsIds;
}

}
7 changes: 6 additions & 1 deletion src/ScheduledExportBundle/Export/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Divante\ScheduledExportBundle\Export;

use Divante\ScheduledExportBundle\Event\BatchExportedEvent;
use Pimcore\Bundle\AdminBundle\Controller\Admin\DataObject\DataObjectHelperController;
use Pimcore\Localization\LocaleService;
use Pimcore\Logger;
Expand All @@ -23,6 +24,7 @@
use Symfony\Component\Console\Input\Input;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;

Expand Down Expand Up @@ -495,15 +497,18 @@ protected function exportToFilenames(array $objectIds): array
{
$filenames = [];
$localeService = new LocaleService();
$dispatcher = $this->container->get('event_dispatcher');
foreach ($objectIds as $objectIdBatch) {
$filename = uniqid();
$request = $this->prepareRequest($objectIdBatch, $filename);
if (!count($request->request->get('ids'))) {
break;
}


$this->controller->doExportAction($request, $localeService);
$event = new BatchExportedEvent($objectIdBatch ?? []);
$dispatcher->dispatch(BatchExportedEvent::NAME, $event);

$filenames[] = $filename;
$this->process = $this->processRepository->find($this->process->getId());
$this->process->progress(count($objectIdBatch));
Expand Down

0 comments on commit 1ac0658

Please sign in to comment.