Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/9.0' into task/4471-lint-distrib…
Browse files Browse the repository at this point in the history
…utionintegrity
  • Loading branch information
ahaeslich committed Sep 9, 2023
2 parents 19fabbf + 2f63e69 commit 3187aa8
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\ContentRepositoryRegistry\Migration\Factory\MigrationFactory;
use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\Service\NodeMigrationGeneratorService;
use Neos\Flow\Cli\CommandController;
use Neos\ContentRepository\NodeMigration\MigrationException;
use Neos\ContentRepository\NodeMigration\Command\MigrationConfiguration;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\Exception\StopCommandException;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Neos\Flow\Package\Exception\UnknownPackageException;
use Neos\Flow\Package\PackageManager;
use Neos\Utility\Exception\FilesException;

/**
* Command controller for tasks related to node migration.
Expand All @@ -34,7 +39,9 @@ class NodeMigrationCommandController extends CommandController
public function __construct(
private readonly MigrationFactory $migrationFactory,
private readonly ContentRepositoryRegistry $contentRepositoryRegistry,
private readonly ObjectManagerInterface $container
private readonly ObjectManagerInterface $container,
private readonly PackageManager $packageManager,
private readonly NodeMigrationGeneratorService $nodeMigrationGeneratorService
)
{
parent::__construct();
Expand Down Expand Up @@ -82,6 +89,34 @@ public function migrateCommand(string $version, $workspace = 'live', bool $force
}
}

/**
* Creates a node migration for the given package Key.
*
* @param string $packageKey The packageKey for the given package
* @return void
* @throws UnknownPackageException
* @throws FilesException
* @throws StopCommandException
* @see neos.contentrepositoryregistry:nodemigration:migrationcreate
*/
public function migrationCreateCommand(string $packageKey): void
{
if (!$this->packageManager->isPackageAvailable($packageKey)) {
$this->outputLine('Package "%s" is not available.', [$packageKey]);
$this->quit(1);
}

try {
$createdMigration = $this->nodeMigrationGeneratorService->generateBoilerplateMigrationFileInPackage($packageKey);
} catch (MigrationException $e) {
$this->outputLine();
$this->outputLine('Error ' . $e->getMessage());
$this->quit(1);
}
$this->outputLine($createdMigration);
$this->outputLine('Your node migration has been created successfully.');
}

/**
* Helper to output comments and warnings for the given configuration.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Neos\ContentRepository\Command;
namespace Neos\ContentRepositoryRegistry\Command;

/*
* This file is part of the Neos.ContentRepository package.
Expand All @@ -12,26 +12,34 @@
* source code.
*/

use Neos\ContentRepository\Domain\Service\NodeTypeManager;
use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Symfony\Component\Yaml\Yaml;

#[Flow\Scope("singleton")]
class NodeTypesCommandController extends CommandController
{
#[Flow\Inject]
protected NodeTypeManager $nodeTypeManager;
public function __construct(
private readonly ContentRepositoryRegistry $contentRepositoryRegistry
) {
parent::__construct();
}

/**
* Shows the merged configuration (including supertypes) of a NodeType
*
* @param string $nodeTypeName The name of the NodeType to show
* @param ?string $path Path of the NodeType-configuration which will be shown
* @param string $contentRepository Identifier of the Content Repository to determine the set of NodeTypes
*/
public function showCommand(string $nodeTypeName, ?string $path = null): void
public function showCommand(string $nodeTypeName, ?string $path = null, string $contentRepository = 'default'): void
{
$nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName);
$contentRepositoryId = ContentRepositoryId::fromString($contentRepository);
$nodeTypeManager = $this->contentRepositoryRegistry->get($contentRepositoryId)->getNodeTypeManager();

$nodeType = $nodeTypeManager->getNodeType($nodeTypeName);
if (!$nodeType) {
$this->outputLine('<b>NodeType "%s" was not found!</b>', [$nodeTypeName]);
$this->quit();
Expand All @@ -53,12 +61,16 @@ public function showCommand(string $nodeTypeName, ?string $path = null): void
*
* @param string|null $filter Only NodeType-names containing this string will be listed
* @param bool $includeAbstract List abstract NodeTypes
* @param string $contentRepository Identifier of the Content Repository to determine the set of NodeTypes
*/
public function listCommand(?string $filter = null, bool $includeAbstract = true): void
public function listCommand(?string $filter = null, bool $includeAbstract = true, string $contentRepository = 'default'): void
{
$contentRepositoryId = ContentRepositoryId::fromString($contentRepository);
$nodeTypeManager = $this->contentRepositoryRegistry->get($contentRepositoryId)->getNodeTypeManager();

$nodeTypesFound = 0;
$nodeTypeNameSpacesWithNodeTypeNames = [];
foreach ($this->nodeTypeManager->getNodeTypes($includeAbstract) as $nodeType) {
foreach ($nodeTypeManager->getNodeTypes($includeAbstract) as $nodeType) {
$nodeTypeName = $nodeType->getName();
if (!$filter || str_contains($nodeTypeName, $filter)) {
[$nameSpace] = explode(":", $nodeTypeName, 2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace Neos\ContentRepository\Migration\Service;
namespace Neos\ContentRepositoryRegistry\Service;

/*
* This file is part of the Neos.ContentRepository package.
* This file is part of the Neos.ContentRepositoryRegistry package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
Expand All @@ -11,22 +11,23 @@
* source code.
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Package\Exception\UnknownPackageException;
use Neos\Flow\Package\PackageManager;
use Neos\Utility\Exception\FilesException;
use Neos\Utility\Files;

/**
* Service for the Migration generator
* Service for the Node Migration generator
*
*/
class MigrationGeneratorService
class NodeMigrationGeneratorService
{
/**
* @Flow\Inject
*/
protected PackageManager $packageManager;

public function __construct(
private readonly PackageManager $packageManager
)
{
}

/**
* Creates a node migration for the given $packageKey
Expand All @@ -38,7 +39,7 @@ class MigrationGeneratorService
*/
public function generateBoilerplateMigrationFileInPackage(string $packageKey): string
{
$templatePath = 'resource://Neos.ContentRepository/Private/Generator/Migrations/ContentRepository/NodeMigrationTemplate.yaml.tmpl';
$templatePath = 'resource://Neos.ContentRepositoryRegistry/Private/Generator/Migrations/ContentRepository/NodeMigrationTemplate.yaml.tmpl';
$nodeMigrationPath = Files::concatenatePaths([$this->packageManager->getPackage($packageKey)->getPackagePath(), 'Migrations/ContentRepository']) . '/';

$timeStamp = (new \DateTimeImmutable())->format('YmdHis');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#############################################################################################################################################################################
# For more information about node migrations in Neos, checkout the documentation: https://neos.readthedocs.io/en/stable/References/NodeMigrations.html?highlight=migrations #
#############################################################################################################################################################################
up:
comments: 'Migration description'
migration:
-
filters:
-

down:
comments: 'No down migration available'
comments: 'Migration description'
migration:
-
filters:
-
transformations:
-
1 change: 1 addition & 0 deletions Neos.Neos/Classes/Domain/Model/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public function hasActiveDomains()
*/
public function getActiveDomains()
{
/** @var Collection<int, Domain> $activeDomains */
$activeDomains = $this->domains->filter(function (Domain $domain) {
return $domain->getActive();
});
Expand Down
9 changes: 3 additions & 6 deletions Neos.Neos/Classes/Fusion/Helper/NodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
*/
class NodeHelper implements ProtectedContextAwareInterface
{
/**
* @Flow\Inject
* @var ContentRepositoryRegistry
*/
protected $contentRepositoryRegistry;
#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* Check if the given node is already a collection, find collection by nodePath otherwise, throw exception
Expand Down Expand Up @@ -80,7 +77,7 @@ public function nearestContentCollection(Node $node, string $nodePath): Node
throw new Exception(sprintf(
'No content collection of type %s could be found in the current node (%s) or at the path "%s".'
. ' You might want to adjust your node type configuration and create the missing child node'
. ' through the "flow node:repair --node-type %s" command.',
. ' through the "flow structureadjustments:fix --node-type %s" command.',
$contentCollectionType,
$nodePathOfNode->value,
$nodePath->serializeToString(),
Expand Down
4 changes: 2 additions & 2 deletions Neos.Neos/Documentation/References/CommandReference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ Options
Package *NEOS.CONTENTREPOSITORY.MIGRATION*
-------------------

.. _`Neos Command Reference: NEOS.CONTENTREPOSITORY.MIGRATION neos.contentrepository.migration:node:migrationcreate`:
.. _`Neos Command Reference: NEOS.CONTENTREPOSITORYREGISTRY neos.contentrepositoryregistry:nodemigration:migrationcreate`:

``neos.contentrepository.migration:node:migrationcreate``
``neos.contentrepositoryregistry:nodemigration:migrationcreate``
*************************

**Create a node migration for the given package key**
Expand Down

0 comments on commit 3187aa8

Please sign in to comment.