-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # Classes/Command/NodeIndexQueueCommandController.php
- Loading branch information
Showing
9 changed files
with
346 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
namespace Flowpack\ElasticSearch\ContentRepositoryQueueIndexer; | ||
|
||
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Indexer\NodeIndexer; | ||
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\Domain\Repository\NodeDataRepository; | ||
use Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\Domain\Service\FakeNodeDataFactory; | ||
use Flowpack\JobQueue\Common\Job\JobInterface; | ||
use Neos\ContentRepository\Domain\Factory\NodeFactory; | ||
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Utility\Algorithms; | ||
|
||
/** | ||
* Elasticsearch Node Abstract Job | ||
*/ | ||
abstract class AbstractIndexingJob implements JobInterface | ||
{ | ||
use LoggerTrait; | ||
|
||
/** | ||
* @var NodeIndexer | ||
* @Flow\Inject | ||
*/ | ||
protected $nodeIndexer; | ||
|
||
/** | ||
* @var NodeDataRepository | ||
* @Flow\Inject | ||
*/ | ||
protected $nodeDataRepository; | ||
|
||
/** | ||
* @var NodeFactory | ||
* @Flow\Inject | ||
*/ | ||
protected $nodeFactory; | ||
|
||
/** | ||
* @var ContextFactoryInterface | ||
* @Flow\Inject | ||
*/ | ||
protected $contextFactory; | ||
|
||
/** | ||
* @var FakeNodeDataFactory | ||
* @Flow\Inject | ||
*/ | ||
protected $fakeNodeDataFactory; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $identifier; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $targetWorkspaceName; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $indexPostfix; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $nodes = []; | ||
|
||
/** | ||
* @param string $indexPostfix | ||
* @param string $targetWorkspaceName In case indexing is triggered during publishing, a target workspace name will be passed in | ||
* @param array $nodes | ||
*/ | ||
public function __construct($indexPostfix, $targetWorkspaceName, array $nodes) | ||
{ | ||
$this->identifier = Algorithms::generateRandomString(24); | ||
$this->targetWorkspaceName = $targetWorkspaceName; | ||
$this->indexPostfix = $indexPostfix; | ||
$this->nodes = $nodes; | ||
} | ||
|
||
/** | ||
* Get an optional identifier for the job | ||
* | ||
* @return string A job identifier | ||
*/ | ||
public function getIdentifier() | ||
{ | ||
return $this->identifier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
namespace Flowpack\ElasticSearch\ContentRepositoryQueueIndexer\Domain\Service; | ||
|
||
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception; | ||
use Neos\ContentRepository\Domain\Model\NodeData; | ||
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository; | ||
use Neos\ContentRepository\Domain\Service\NodeTypeManager; | ||
use Neos\ContentRepository\Exception\NodeTypeNotFoundException; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* @Flow\Scope("singleton") | ||
*/ | ||
class FakeNodeDataFactory | ||
{ | ||
/** | ||
* @var WorkspaceRepository | ||
* @Flow\Inject | ||
*/ | ||
protected $workspaceRepository; | ||
|
||
/** | ||
* @var NodeTypeManager | ||
* @Flow\Inject | ||
*/ | ||
protected $nodeTypeManager; | ||
|
||
/** | ||
* This creates a "fake" removed NodeData instance from the given payload | ||
* | ||
* @param array $payload | ||
* @return NodeData | ||
* @throws Exception | ||
*/ | ||
public function createFromPayload(array $payload) | ||
{ | ||
if (!isset($payload['workspace']) || empty($payload['workspace'])) { | ||
throw new Exception('Unable to create fake node data, missing workspace value', 1508448007); | ||
} | ||
if (!isset($payload['path']) || empty($payload['path'])) { | ||
throw new Exception('Unable to create fake node data, missing path value', 1508448008); | ||
} | ||
if (!isset($payload['identifier']) || empty($payload['identifier'])) { | ||
throw new Exception('Unable to create fake node data, missing identifier value', 1508448009); | ||
} | ||
if (!isset($payload['nodeType']) || empty($payload['nodeType'])) { | ||
throw new Exception('Unable to create fake node data, missing nodeType value', 1508448011); | ||
} | ||
|
||
$workspace = $this->workspaceRepository->findOneByName($payload['workspace']); | ||
if ($workspace === null) { | ||
throw new Exception('Unable to create fake node data, workspace not found', 1508448028); | ||
} | ||
|
||
$nodeData = new NodeData($payload['path'], $workspace, $payload['identifier'], isset($payload['dimensions']) ? $payload['dimensions'] : null); | ||
try { | ||
$nodeData->setNodeType($this->nodeTypeManager->getNodeType($payload['nodeType'])); | ||
} catch (NodeTypeNotFoundException $e) { | ||
throw new Exception('Unable to create fake node data, node type not found', 1509362172); | ||
} | ||
|
||
$nodeData->setProperty('title', 'Fake node'); | ||
$nodeData->setProperty('uriPathSegment', 'fake-node'); | ||
|
||
$nodeData->setRemoved(true); | ||
|
||
return $nodeData; | ||
} | ||
} |
Oops, something went wrong.