Skip to content

Commit

Permalink
TASK: Adjust documentation and todos in legacy migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Nov 8, 2024
1 parent efb7fbd commit ea67195
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Export\Severity;
use Neos\ContentRepository\LegacyNodeMigration\LegacyExportServiceFactory;
use Neos\ContentRepository\LegacyNodeMigration\LegacyMigrationService;
use Neos\ContentRepository\LegacyNodeMigration\LegacyMigrationServiceFactory;
use Neos\ContentRepository\LegacyNodeMigration\RootNodeTypeMapping;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Cli\CommandController;
Expand All @@ -47,10 +45,13 @@ public function __construct(
/**
* Migrate from the Legacy CR
*
* Note that the dimension configuration and the node type schema must be migrated of the content repository to import to and it must be setup.
*
* @param string $contentRepository The target content repository that will be used for importing into
* @param string|null $config JSON encoded configuration, for example '{"dbal": {"dbname": "some-other-db"}, "resourcesPath": "/some/absolute/path", "rootNodes": {"/sites": "Neos.Neos:Sites", "/other": "My.Package:SomeOtherRoot"}}'
* @throws \Exception
*/
public function migrateLegacyDataCommand(string $contentRepository = 'default', bool $verbose = false, string $config = null): void
public function migrateLegacyDataCommand(string $contentRepository = 'default', string $config = null, bool $verbose = false, ): void
{
if ($config !== null) {
try {
Expand All @@ -69,7 +70,7 @@ public function migrateLegacyDataCommand(string $contentRepository = 'default',
$resourcesPath = $this->determineResourcesPath();
$rootNodes = $this->getDefaultRootNodes();
if (!$this->output->askConfirmation(sprintf('Do you want to migrate nodes from the current database "%s@%s" (y/n)? ', $this->connection->getParams()['dbname'] ?? '?', $this->connection->getParams()['host'] ?? '?'))) {
$connection = $this->adjustDataBaseConnection($this->connection);
$connection = $this->adjustDatabaseConnection($this->connection);
} else {
$connection = $this->connection;
}
Expand All @@ -96,6 +97,9 @@ public function migrateLegacyDataCommand(string $contentRepository = 'default',
$this->createOnMessageClosure($verbose)
);

$this->outputLine('Migrated data. Importing into new content repository ...');

// todo check if cr is setup before!!! do not fail here!!!
$this->siteImportService->importFromPath(
$contentRepositoryId,
$temporaryFilePath,
Expand All @@ -111,11 +115,14 @@ public function migrateLegacyDataCommand(string $contentRepository = 'default',
/**
* Export from the Legacy CR into a specified directory path
*
* Note that the dimension configuration and the node type schema must be migrated of the reference content repository
*
* @param string $contentRepository The reference content repository that can later be used for importing into
* @param string $path The path to the directory, will be created if missing
* @param string|null $config JSON encoded configuration, for example '{"dbal": {"dbname": "some-other-db"}, "resourcesPath": "/some/absolute/path", "rootNodes": {"/sites": "Neos.Neos:Sites", "/other": "My.Package:SomeOtherRoot"}}'
* @throws \Exception
*/
public function exportLegacyDataCommand(string $path, bool $verbose = false, string $config = null): void
public function exportLegacyDataCommand(string $path, string $contentRepository = 'default', string $config = null, bool $verbose = false): void
{
if ($config !== null) {
try {
Expand All @@ -134,7 +141,7 @@ public function exportLegacyDataCommand(string $path, bool $verbose = false, str
$resourcesPath = $this->determineResourcesPath();
$rootNodes = $this->getDefaultRootNodes();
if (!$this->output->askConfirmation(sprintf('Do you want to migrate nodes from the current database "%s@%s" (y/n)? ', $this->connection->getParams()['dbname'] ?? '?', $this->connection->getParams()['host'] ?? '?'))) {
$connection = $this->adjustDataBaseConnection($this->connection);
$connection = $this->adjustDatabaseConnection($this->connection);
} else {
$connection = $this->connection;
}
Expand All @@ -143,7 +150,7 @@ public function exportLegacyDataCommand(string $path, bool $verbose = false, str

Files::createDirectoryRecursively($path);
$legacyExportService = $this->contentRepositoryRegistry->buildService(
ContentRepositoryId::fromString('default'),
ContentRepositoryId::fromString($contentRepository),
new LegacyExportServiceFactory(
$connection,
$resourcesPath,
Expand All @@ -164,7 +171,7 @@ public function exportLegacyDataCommand(string $path, bool $verbose = false, str
/**
* @throws DBALException
*/
private function adjustDataBaseConnection(Connection $connection): Connection
private function adjustDatabaseConnection(Connection $connection): Connection
{
$connectionParams = $connection->getParams();
$connectionParams['driver'] = $this->output->select(sprintf('Driver? [%s] ', $connectionParams['driver'] ?? ''), ['pdo_mysql', 'pdo_sqlite', 'pdo_pgsql'], $connectionParams['driver'] ?? null);
Expand All @@ -189,7 +196,7 @@ private function verifyDatabaseConnection(Connection $connection): void
} catch (ConnectionException $exception) {
$this->outputLine('<error>Failed to connect to database "%s": %s</error>', [$connection->getDatabase(), $exception->getMessage()]);
$this->outputLine('Please verify connection parameters...');
$this->adjustDataBaseConnection($connection);
$this->adjustDatabaseConnection($connection);
}
} while (true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Neos\ContentRepository\Core\Factory\ContentRepositoryServiceInterface;
use Neos\ContentRepository\Core\Infrastructure\Property\PropertyConverter;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Export\Asset\Adapters\DbalAssetLoader;
use Neos\ContentRepository\Export\Asset\Adapters\FileSystemResourceLoader;
use Neos\ContentRepository\Export\Asset\AssetExporter;
Expand Down Expand Up @@ -62,7 +61,7 @@ public function exportToPath(string $path, \Closure $onProcessor, \Closure $onMe

$processors = Processors::fromArray([
'Exporting assets' => new AssetExportProcessor($this->nodeTypeManager, $assetExporter, new NodeDataLoader($this->connection)),
'Exporting node data' => new EventExportProcessor( $this->nodeTypeManager, $this->propertyMapper, $this->propertyConverter, $this->interDimensionalVariationGraph, $this->eventNormalizer, $this->rootNodeTypeMapping,new NodeDataLoader($this->connection)),
'Exporting node data' => new EventExportProcessor($this->nodeTypeManager, $this->propertyMapper, $this->propertyConverter, $this->interDimensionalVariationGraph, $this->eventNormalizer, $this->rootNodeTypeMapping, new NodeDataLoader($this->connection)),
'Exporting sites data' => new SitesExportProcessor(new SiteDataLoader($this->connection), new DomainDataLoader($this->connection)),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ public function run(ProcessingContext $context): void
continue;
}
}
try {
$this->processNodeData($context, $nodeDataRow);
} catch (MigrationException $e) {
throw new \RuntimeException($e->getMessage(), 1729506899, $e);
}
$this->processNodeData($context, $nodeDataRow);
}
// Set References, now when the full import is done.
foreach ($this->nodeReferencesWereSetEvents as $nodeReferencesWereSetEvent) {
Expand Down
6 changes: 3 additions & 3 deletions Neos.Neos/Classes/Command/SiteCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ public function createCommand($name, $packageKey, $nodeType, $nodeName = null, $
* This command allows importing sites from the given path/package. The format must
* be identical to that produced by the exportAll command.
*
* !!! The live workspace has to be empty prior to importing. !!!
*
* If a path is specified, this command expects the corresponding directory to contain the exported files
*
* If a package key is specified, this command expects the export files to be located in the private resources
* directory of the given package (Resources/Private/Content).
*
* **Note that the live workspace has to be empty prior to importing.**
*
* @param string|null $packageKey Package key specifying the package containing the sites content
* @param string|null $path relative or absolute path and filename to the export files
* @return void
Expand Down Expand Up @@ -199,7 +199,7 @@ public function importAllCommand(string $packageKey = null, string $path = null,
* Export sites
*
* This command exports all sites of the content repository.
**
*
* If a path is specified, this command creates the directory if needed and exports into that.
*
* If a package key is specified, this command exports to the private resources
Expand Down
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,14 @@ You can chose from one of the following options:
#### Migrating an existing (Neos < 9.0) Site

``` bash
# WORKAROUND: for now, you still need to create a site (which must match the root node name)
# !! in the future, you would want to import *INTO* a given site (and replace its root node)
./flow site:create neosdemo Neos.Demo Neos.Demo:Document.Homepage
# the following config points to a Neos 8.0 database (adjust to your needs), created by
# the legacy "./flow site:import Neos.Demo" command.
# the following config points to a Neos 8.0 database (adjust to your needs)
./flow site:migrateLegacyData --config '{"dbal": {"dbname": "neos80"}, "resourcesPath": "/path/to/neos-8.0/Data/Persistent/Resources"}'
```

#### Importing an existing (Neos >= 9.0) Site from an Export

``` bash
# make sure this cr is empty
./flow site:pruneAll
# import the event stream from the Neos.Demo package
./flow site:importAll Packages/Sites/Neos.Demo/Resources/Private/Content
./flow site:importAll --package-key Neos.Demo
```

### Running Neos
Expand Down

0 comments on commit ea67195

Please sign in to comment.