Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Define storage node by identifier #25

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions Classes/Importer/AbstractImporter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Ttree\ContentRepositoryImporter\Importer;

use Neos\Cache\Frontend\VariableFrontend;
Expand Down Expand Up @@ -29,6 +30,12 @@
*/
abstract class AbstractImporter implements ImporterInterface
{
/**
* The unique identifier of the storage node
* @var string
*/
protected $storageNodeIdentifier;

/**
* Node path (can be absolute or relative to the current site node) where the "storage node" (ie. the parent
* document node for nodes imported by the concrete importer) will be located. You can also use the identifier of the node.
Expand Down Expand Up @@ -312,12 +319,26 @@ public function initialize(DataProviderInterface $dataProvider)
$context = $this->contextFactory->create($contextConfiguration);
$this->rootNode = $context->getRootNode();

$this->applyOption($this->storageNodeNodePath, 'storageNodeNodePath');
$this->applyOption($this->nodeTypeName, 'nodeTypeName');
$this->applyOption($this->storageNodeIdentifier, 'storageNodeIdentifier');
$this->applyOption($this->storageNodeNodePath, 'storageNodeNodePath');

if (isset($this->options['siteNodePath']) || isset($this->options['siteNodeIdentifier'])) {
$siteNodePath = isset($this->options['siteNodePath']) ? trim($this->options['siteNodePath']) : null;
$siteNodeIdentifier = isset($this->options['siteNodeIdentifier']) ? trim($this->options['siteNodeIdentifier']) : null;
$siteNodePath = isset($this->options['siteNodePath']) ? trim($this->options['siteNodePath']) : null;
$siteNodeIdentifier = isset($this->options['siteNodeIdentifier']) ? trim($this->options['siteNodeIdentifier']) : null;

if (isset($this->storageNodeIdentifier)) {
$this->storageNode = $context->getNodeByIdentifier($this->storageNodeIdentifier);
if (!($this->storageNode instanceof NodeInterface)) {
throw new Exception(sprintf('The storage node with identifier "%s" was not found', $this->storageNodeIdentifier));
}

$pathParts = explode('/', ltrim($this->storageNode->getPath(), '/'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dfeyer: This part is quite hacky - is there a better solution?

$siteNodePath = '/sites/' . $pathParts[1];

$this->storageNodeNodePath = $this->storageNode->getPath();
}

if (isset($siteNodePath) || isset($siteNodeIdentifier)) {
$this->siteNode = $this->rootNode->getNode($siteNodePath) ?: $context->getNodeByIdentifier($siteNodeIdentifier);
if ($this->siteNode === null) {
throw new Exception(sprintf('Site node not found (%s)', $siteNodePath ?: $siteNodeIdentifier), 1425077201);
Expand Down Expand Up @@ -373,6 +394,7 @@ protected function processBatch(NodeTemplate $nodeTemplate = null)
$this->postProcessing($records);
}


public function withStorageNode(NodeInterface $storageNode, \Closure $closure)
{
$previousStorageNode = $this->storageNode;
Expand Down Expand Up @@ -582,7 +604,7 @@ protected function getExternalIdentifierFromRecordData(array $data)
if ($externalIdentifier === null) {
throw new \Exception('Could not determine external identifier from record data. See ' . self::class . ' for more information.', 1462968317292);
}
return (string)$externalIdentifier;
return (string) $externalIdentifier;
}

/**
Expand Down Expand Up @@ -612,7 +634,7 @@ protected function getLabelFromRecordData(array $data)
if ($label === null) {
throw new \Exception('Could not determine label from record data (key: ' . $this->labelDataKey . '). See ' . self::class . ' for more information.', 1462968958372);
}
return (string)$label;
return (string) $label;
}


Expand Down