Skip to content

Commit

Permalink
TASK: Persist entities every 1000 records
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehoffmann30 committed Jan 9, 2019
1 parent 29ba5de commit 0bb0089
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion Classes/Synchronization/Synchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Doctrine\Common\Collections\ArrayCollection;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Media\Domain\Model\Asset;
use Neos\Media\Domain\Model\Tag;
Expand Down Expand Up @@ -88,6 +89,12 @@ class Synchronizer
*/
protected $syncCounter = [];

/**
* @Flow\Inject
* @var PersistenceManager
*/
protected $persistenceManager;

/**
* @Flow\Inject
* @var SystemLoggerInterface
Expand All @@ -99,15 +106,29 @@ class Synchronizer
*/
public function syncAssetsBySourceIdentifier(string $sourceIdentifier)
{
$syncedFileCount = 0;

$this->reset();
$this->source = $this->sourceFactory->createSource($sourceIdentifier);

$this->logger->log('Generating file list for source ' . $sourceIdentifier);
$sourceFileCollection = $this->source->generateSourceFileCollection();
$this->logger->log(sprintf('Found %s files to consider.', $sourceFileCollection->count()));

/** @var SourceFile $sourceFile */
foreach ($sourceFileCollection as $sourceFile) {
$this->syncAsset($sourceFile);

try {
$this->syncAsset($sourceFile);
} catch (\Exception $exception) {
$this->logger->log(sprintf('Exception %s (%s) while trying to import asset %s', $exception->getMessage(), $exception->getCode(), $sourceFile->getFileIdentifier()), LOG_WARNING);
}

$syncedFileCount++;

if($syncedFileCount % 1000 === 0) {
$this->persistenceManager->persistAll();
}
}

if ($this->source->isRemoveAssetsNotInSource() === true) {
Expand Down

0 comments on commit 0bb0089

Please sign in to comment.