Skip to content

Commit d243a37

Browse files
committed
Further WIP on document migration
1 parent d6b8e83 commit d243a37

37 files changed

+957
-56
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
/var/cache/*
33
!/var/cache/.gitkeep
44
rector.php
5-
.env
5+
.env.netglue-to-asset-target.env
6+
*.env
7+
config/**/*local.*

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
# Tooling to Clone Prismic Repositories
22

3-
WIP…
3+
This is a project that you should clone and run in an environment where you have PHP 8.4 installed.
4+
5+
It's not fancy, but it seems to work OK.
6+
7+
It's also still WIP…
8+
9+
## Things that definitely don't work
10+
11+
Cloning multiple locales hasn't been implemented. I currently have no need for it, so it's unlikely to be implemented unless someone else does it.
12+
13+
## Usage
14+
15+
### Clone
16+
17+
You know how to do this already right?
18+
19+
### Setup Environment
20+
21+
[Create a new repository at prismic.io](https://prismic.io/dashboard/new-repository) and go through the initial on-boarding until you can set the master locale. Use a master locale that matches the source locale, however, you can override the locale to match the target _(blindly)_ if you are confident that'd be OK. For example, copying from `en-us` to `en-gb` or vice versa would be fine. Look at [`./config/autoload/repository.global.php`](./config/autoload/repository.global.php) for more details.
22+
23+
Copy the [`./example.env.dist`](./example.env.dist) file to `./.env` and fill out the relevant details. You only need to supply _read_ tokens if your repository requires them. _Write_ tokens are mandatory for both source and target, but no writes happen on the source.
24+
25+
On your **source** repo, make sure that any documents you want to be cloned have been published. Un-published docs, or docs published to releases will not be copied.
26+
27+
### Run
28+
29+
```bash
30+
php bin/run.php
31+
```
32+
33+
## What happens
34+
35+
- _All_ assets are copied from source to target, not just the ones that are used in your documents. If an error occurs during asset copying, You can re-try safely. You won't end up with duplicated assets.
36+
- _All_ document type definitions are cloned from source to target along with any shared slices. Again, these are tracked, so can be retried if any errors occur during transfer.
37+
- _All_ source documents are downloaded at the **master ref**.
38+
- Works through source documents one at a time, adjusting image identifiers and sends the data to the target migration release.
39+
- TODO - Once all documents are processed, adjust all internal document links to point at the new equivalent document.

bin/run.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Prismic\Cloner\Asset\AssetMapper;
6+
use Prismic\Cloner\DocumentType\CloneDocumentTypes;
7+
use Prismic\Cloner\Migration\DocumentMigrator;
8+
use Psr\Container\ContainerInterface;
9+
10+
$container = require_once __DIR__ . '/../config/container.php';
11+
12+
assert($container instanceof ContainerInterface);
13+
14+
$assetMapper = $container->get(AssetMapper::class);
15+
$assetMapper(true);
16+
17+
$typeCloner = $container->get(CloneDocumentTypes::class);
18+
$typeCloner();
19+
20+
$documentMigrator = $container->get(DocumentMigrator::class);
21+
$documentMigrator->migrate();

composer.lock

Lines changed: 41 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/autoload/application.global.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@
2828

2929
// Where a map of migrated document id's is persisted
3030
'doc-migration-tracker-filename' => 'migrated-documents.json',
31+
32+
// Where cached document json is persisted per repository
33+
'document-cache-directory-name' => 'documents',
3134
],
3235
];

config/autoload/dependencies.global.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,52 @@
1717
use Prismic\Cloner\Factory\PathConfigFactory;
1818
use Prismic\Cloner\Migration\DefaultTitleResolver;
1919
use Prismic\Cloner\Migration\DocumentMigrationTracker;
20+
use Prismic\Cloner\Migration\DocumentMigrator;
2021
use Prismic\Cloner\Migration\Factory\DocumentMigrationTrackerFactory;
22+
use Prismic\Cloner\Migration\Factory\DocumentMigratorFactory;
23+
use Prismic\Cloner\Migration\Factory\TitleResolverFactory;
24+
use Prismic\Cloner\Migration\ResolveSinglesToTypeLabel;
2125
use Prismic\Cloner\Migration\TitleResolver;
2226
use Prismic\Cloner\PathConfig;
27+
use Prismic\Cloner\Transformer\AdjustInternalLinks;
28+
use Prismic\Cloner\Transformer\FixAssetIdentifiers;
29+
use Prismic\Cloner\Transformer\PostTransform;
30+
use Prismic\Cloner\Transformer\PostTransformFactory;
31+
use Prismic\Cloner\Transformer\PreTransform;
32+
use Prismic\Cloner\Transformer\PreTransformFactory;
2333

2434
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
2535

2636
return [
2737
'dependencies' => [
2838
'factories' => [
39+
// Utils, generic deps
2940
CurlClient::class => InvokableFactory::class,
3041
FinfoMimeTypeDetector::class => InvokableFactory::class,
31-
CopyAsset::class => ReflectionBasedAbstractFactory::class,
42+
43+
// Main tooling services
3244
PathConfig::class => PathConfigFactory::class,
45+
CopyAsset::class => ReflectionBasedAbstractFactory::class,
3346
AssetMapper::class => AssetMapperFactory::class,
3447
CloneDocumentTypes::class => CloneDocumentTypesFactory::class,
3548
DocumentTypes::class => DocumentTypesFactory::class,
3649
DocumentMigrationTracker::class => DocumentMigrationTrackerFactory::class,
50+
DocumentMigrator::class => DocumentMigratorFactory::class,
51+
52+
// Tools for figuring out the document title
3753
DefaultTitleResolver::class => ReflectionBasedAbstractFactory::class,
54+
ResolveSinglesToTypeLabel::class => ReflectionBasedAbstractFactory::class,
55+
TitleResolver::class => TitleResolverFactory::class,
56+
57+
// Tools for pre- and post-processing the documents
58+
FixAssetIdentifiers::class => ReflectionBasedAbstractFactory::class,
59+
AdjustInternalLinks::class => ReflectionBasedAbstractFactory::class,
60+
PreTransform::class => PreTransformFactory::class,
61+
PostTransform::class => PostTransformFactory::class,
3862
],
3963
'aliases' => [
4064
Psr\Http\Client\ClientInterface::class => CurlClient::class,
4165
MimeTypeDetector::class => FinfoMimeTypeDetector::class,
42-
TitleResolver::class => DefaultTitleResolver::class,
4366
],
4467
],
4568
];

config/autoload/repository.global.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
'name' => $_ENV['TARGET_REPO'],
3131
'writeToken' => $_ENV['TARGET_WRITE_TOKEN'],
3232
'readToken' => $_ENV['TARGET_READ_TOKEN'],
33+
/**
34+
* If you are copying from a repo in say 'en-us' and need the target to be 'en-gb', you can supply a
35+
* 'forceLanguage' option to override the language of the source document.
36+
* Bear in mind this is not going to be very helpful for multi-language repos
37+
*/
38+
//'forceLanguage' => 'en-gb',
3339
],
3440
],
3541

example.env.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copy this file to `.env` and change values to match your requirements
2+
3+
# Bare repository names, not URIs
4+
SOURCE_REPO=source-name
5+
TARGET_REPO=target-name
6+
7+
# You must supply write token for both source and target
8+
SOURCE_WRITE_TOKEN=
9+
TARGET_WRITE_TOKEN=
10+
11+
# Read tokens are optional, but required if your repos are setup to require one
12+
SOURCE_READ_TOKEN=
13+
TARGET_READ_TOKEN=

0 commit comments

Comments
 (0)