Skip to content

Commit 3814a0d

Browse files
committed
[FEATURE] Make migration of inventories possible
I had to drop support for non-stable prefered TYPO3 versions in migration. That would mean in such a case they are listed as single <inventroy> tags
1 parent 51f63ac commit 3814a0d

File tree

8 files changed

+161
-21
lines changed

8 files changed

+161
-21
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.. include:: /Includes.rst.txt
2+
3+
.. _redirects:
4+
5+
=========
6+
Redirects
7+
=========
8+
9+
* :ref:`mod <t3tsconfig:pagemod>
10+
* :ref:`mod <t3tsconfig/main:pagemod>
11+
* :ref:`mod <t3tsconfig/13.4:pagemod>
12+
* :ref:`mod <t3tsconfig/12.4:pagemod>
13+
14+
15+
* :ref:`Create a menu with TypoScript <t3ts45:menu>`

packages/typo3-docs-theme/resources/config/typo3-docs-theme.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use T3Docs\Typo3DocsTheme\Api\Typo3ApiService;
2121
use T3Docs\Typo3DocsTheme\Compiler\NodeTransformers\CollectPrefixLinkTargetsTransformer;
2222
use T3Docs\Typo3DocsTheme\Compiler\NodeTransformers\ConfvalMenuNodeTransformer;
23+
use T3Docs\Typo3DocsTheme\Compiler\NodeTransformers\RedirectsNodeTransformer;
2324
use T3Docs\Typo3DocsTheme\Compiler\NodeTransformers\RemoveInterlinkSelfReferencesFromCrossReferenceNodeTransformer;
2425
use T3Docs\Typo3DocsTheme\Compiler\NodeTransformers\ReplacePermalinksNodeTransformer;
2526
use T3Docs\Typo3DocsTheme\Directives\ConfvalMenuDirective;
@@ -84,6 +85,8 @@
8485
->bind('$startingRule', service(DirectiveContentRule::class))
8586
->instanceof(BaseDirective::class)
8687
->tag('phpdoc.guides.directive')
88+
->set(RedirectsNodeTransformer::class)
89+
->tag('phpdoc.guides.compiler.nodeTransformers')
8790
->set(ReplacePermalinksNodeTransformer::class)
8891
->tag('phpdoc.guides.compiler.nodeTransformers')
8992
->set(CollectPrefixLinkTargetsTransformer::class)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace T3Docs\Typo3DocsTheme\Compiler\NodeTransformers;
15+
16+
use phpDocumentor\Guides\Compiler\CompilerContextInterface;
17+
use phpDocumentor\Guides\Compiler\NodeTransformer;
18+
use phpDocumentor\Guides\Nodes\Inline\CrossReferenceNode;
19+
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
20+
use phpDocumentor\Guides\Nodes\Node;
21+
use phpDocumentor\Guides\Nodes\PrefixedLinkTargetNode;
22+
use T3Docs\Typo3DocsTheme\Inventory\Typo3VersionService;
23+
24+
use function assert;
25+
26+
/** @implements NodeTransformer<CrossReferenceNode> */
27+
final class RedirectsNodeTransformer implements NodeTransformer
28+
{
29+
public function __construct(
30+
private readonly Typo3VersionService $typo3VersionService
31+
) {}
32+
33+
public function enterNode(Node $node, CompilerContextInterface $compilerContext): Node
34+
{
35+
return $node;
36+
}
37+
38+
public function leaveNode(Node $node, CompilerContextInterface $compilerContext): Node|null
39+
{
40+
assert($node instanceof CrossReferenceNode);
41+
if ($node->getInterlinkDomain() === '') {
42+
return $node;
43+
}
44+
if ($node->getInterlinkDomain() === 't3ts45') {
45+
$version = $this->typo3VersionService->getPreferredVersion();
46+
if (!in_array($version, ['12.4', '13.4', 'main'], true)) {
47+
return $node;
48+
}
49+
$prefix = '';
50+
if ($node instanceof PrefixedLinkTargetNode) {
51+
$prefix = $node->getPrefix();
52+
}
53+
assert(is_string($node->getValue()));
54+
return new ReferenceNode('guide-' . $node->getTargetReference(), $node->getValue(), $node->getInterlinkDomain(), $node->getInterlinkGroup(), $prefix);
55+
}
56+
return $node;
57+
}
58+
59+
public function supports(Node $node): bool
60+
{
61+
return $node instanceof CrossReferenceNode;
62+
}
63+
64+
public function getPriority(): int
65+
{
66+
return 900;
67+
}
68+
}

packages/typo3-docs-theme/src/Inventory/Typo3InventoryRepository.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,16 @@ public function __construct(
4646
}
4747
foreach (DefaultInventories::cases() as $defaultInventory) {
4848
$id = $this->anchorNormalizer->reduceAnchor($defaultInventory->name);
49-
$url = $defaultInventory->getUrl();
50-
if (!str_contains($url, '{typo3_version}')) {
51-
$this->addInventory($id, $url, false);
49+
if (!$defaultInventory->isVersioned()) {
50+
$this->addInventory($id, $defaultInventory->getUrl(''), false);
5251
continue;
5352
}
5453
foreach (Typo3VersionMapping::cases() as $versionMapping) {
55-
$mappedUrl = str_replace('{typo3_version}', $versionMapping->getVersion(), $url);
54+
$mappedUrl = $defaultInventory->getUrl($versionMapping->getVersion());
5655
$this->addInventory($id . '-' . $versionMapping->value, $mappedUrl, false);
5756
}
5857
$preferred = $this->typo3VersionService->getPreferredVersion();
59-
$this->addInventory($id, str_replace('{typo3_version}', $preferred, $url), false);
58+
$this->addInventory($id, $defaultInventory->getUrl($preferred), false);
6059
}
6160
}
6261

@@ -109,7 +108,7 @@ private function loadInventoryFromComposerExtension(string $reducedKey, string $
109108
} elseif ($defaultInventory = DefaultInventories::tryFrom($match1)) {
110109
// we do not have a composer name here but a default inventory with a version, for example "t3coreapi/12.4"
111110
$version = $this->typo3VersionService->resolveCoreVersion($match2);
112-
$inventoryUrl = str_replace('{typo3_version}', $version, $defaultInventory->getUrl());
111+
$inventoryUrl = $defaultInventory->getUrl($version);
113112
} else {
114113
$version ??= 'main';
115114
$version = $this->typo3VersionService->resolveVersion($version);

packages/typo3-guides-cli/src/Migration/SettingsMigrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private function createInventorySection(): array
133133
$this->convertedSettings++;
134134

135135
if ($defaultInventory = DefaultInventories::tryFrom($id)) {
136-
$defaultUrl = $defaultInventory->getUrl();
136+
$defaultUrl = $defaultInventory->getUrl(Typo3VersionMapping::Stable->getVersion());
137137
if ($url === $defaultUrl) {
138138
continue;
139139
} else {

packages/typo3-guides-cli/tests/unit/Migration/SettingsMigratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class="\T3Docs\Typo3DocsTheme\DependencyInjection\Typo3DocsThemeExtension"
195195
</guides>
196196
EXPECTED,
197197
];
198-
yield 'with intersphinx default id, non-stable preferred TYPO3 version' => [
198+
yield 'with intersphinx default id, first version is not preferred TYPO3 version' => [
199199
'legacySettings' => [
200200
'intersphinx_mapping' => [
201201
't3viewhelper' => 'https://docs.typo3.org/other/typo3/view-helper-reference/12.4/en-us/',
@@ -204,8 +204,8 @@ class="\T3Docs\Typo3DocsTheme\DependencyInjection\Typo3DocsThemeExtension"
204204
],
205205
'expected' => <<<EXPECTED
206206
<guides xmlns="https://www.phpdoc.org/guides" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" links-are-relative="true" xsi:schemaLocation="https://www.phpdoc.org/guides ../vendor/phpdocumentor/guides-cli/resources/schema/guides.xsd">
207-
<extension class="\T3Docs\Typo3DocsTheme\DependencyInjection\Typo3DocsThemeExtension" typo3-core-preferred="12.4"/>
208-
<inventory id="t3coreapi" url="https://docs.typo3.org/m/typo3/reference-coreapi/13.4/en-us/"/>
207+
<extension class="\T3Docs\Typo3DocsTheme\DependencyInjection\Typo3DocsThemeExtension" typo3-core-preferred="stable"/>
208+
<inventory id="t3viewhelper" url="https://docs.typo3.org/other/typo3/view-helper-reference/12.4/en-us/"/>
209209
</guides>
210210
EXPECTED,
211211
];

packages/typo3-version-handling/src/DefaultInventories.php

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ enum DefaultInventories: string
88
// also add them to `Documentation/Developer/InterlinkInventories.rst`.
99
case t3docs = 't3docs';
1010
case changelog = 'changelog';
11+
case t3ts45 = 't3ts45';
1112
case t3coreapi = 't3coreapi';
1213
case t3tca = 't3tca';
1314
case t3tsconfig = 't3tsconfig';
@@ -27,9 +28,59 @@ enum DefaultInventories: string
2728
case t3exceptions = 't3exceptions';
2829
case api = 'api';
2930

31+
public function isVersioned(): bool
32+
{
33+
34+
return match ($this) {
35+
// Main doc page, it is only deployed to main
36+
DefaultInventories::t3docs => false,
3037

31-
public function getUrl(): string
38+
// Changelog, it is only deployed to main
39+
DefaultInventories::changelog => false,
40+
41+
42+
// Team Guides, they are commonly not versioned
43+
DefaultInventories::h2document => false,
44+
DefaultInventories::t3content => false,
45+
DefaultInventories::t3contribute => false,
46+
DefaultInventories::t3writing => false,
47+
DefaultInventories::t3org => false,
48+
49+
// Other
50+
DefaultInventories::fluid => false,
51+
DefaultInventories::t3renderguides => false,
52+
DefaultInventories::t3exceptions => false,
53+
54+
default => true,
55+
};
56+
}
57+
58+
public function getUrl(string $version): string
3259
{
60+
if ($version === 'main') {
61+
switch ($this) {
62+
case DefaultInventories::t3tsconfig:
63+
return DefaultInventories::t3tsref->getUrl($version);
64+
case DefaultInventories::t3ts45:
65+
return DefaultInventories::t3tsref->getUrl($version);
66+
}
67+
}
68+
if ($version === '13.4') {
69+
switch ($this) {
70+
case DefaultInventories::t3tsconfig:
71+
return DefaultInventories::t3tsref->getUrl($version);
72+
case DefaultInventories::t3ts45:
73+
return DefaultInventories::t3tsref->getUrl($version);
74+
}
75+
}
76+
if ($version === '12.4') {
77+
switch ($this) {
78+
case DefaultInventories::t3tsconfig:
79+
return DefaultInventories::t3tsref->getUrl($version);
80+
case DefaultInventories::t3ts45:
81+
return DefaultInventories::t3tsref->getUrl($version);
82+
}
83+
}
3384
return match ($this) {
3485
// Main doc page, it is only deployed to main
3586
DefaultInventories::t3docs => 'https://docs.typo3.org/',
@@ -38,17 +89,20 @@ public function getUrl(): string
3889
DefaultInventories::changelog => 'https://docs.typo3.org/c/typo3/cms-core/main/en-us/',
3990

4091
// Core Manuals
41-
DefaultInventories::t3coreapi => 'https://docs.typo3.org/m/typo3/reference-coreapi/{typo3_version}/en-us/',
42-
DefaultInventories::t3tca => 'https://docs.typo3.org/m/typo3/reference-tca/{typo3_version}/en-us/',
43-
DefaultInventories::t3tsconfig => 'https://docs.typo3.org/m/typo3/reference-tsconfig/{typo3_version}/en-us/',
44-
DefaultInventories::t3tsref => 'https://docs.typo3.org/m/typo3/reference-typoscript/{typo3_version}/en-us/',
45-
DefaultInventories::t3viewhelper => 'https://docs.typo3.org/other/typo3/view-helper-reference/{typo3_version}/en-us/',
92+
DefaultInventories::t3coreapi => 'https://docs.typo3.org/m/typo3/reference-coreapi/' . $version . '/en-us/',
93+
DefaultInventories::t3tca => 'https://docs.typo3.org/m/typo3/reference-tca/' . $version . '/en-us/',
94+
DefaultInventories::t3tsref => 'https://docs.typo3.org/m/typo3/reference-typoscript/' . $version . '/en-us/',
95+
DefaultInventories::t3viewhelper => 'https://docs.typo3.org/other/typo3/view-helper-reference/' . $version . '/en-us/',
4696

4797
// Official Core Tutorials and Guides
48-
DefaultInventories::t3editors => 'https://docs.typo3.org/m/typo3/tutorial-editors/{typo3_version}/en-us/',
49-
DefaultInventories::t3sitepackage => 'https://docs.typo3.org/m/typo3/tutorial-sitepackage/{typo3_version}/en-us/',
50-
DefaultInventories::t3start => 'https://docs.typo3.org/m/typo3/tutorial-getting-started/{typo3_version}/en-us/',
51-
DefaultInventories::t3translate => 'https://docs.typo3.org/m/typo3/guide-frontendlocalization/{typo3_version}/en-us/',
98+
DefaultInventories::t3editors => 'https://docs.typo3.org/m/typo3/tutorial-editors/' . $version . '/en-us/',
99+
DefaultInventories::t3sitepackage => 'https://docs.typo3.org/m/typo3/tutorial-sitepackage/' . $version . '/en-us/',
100+
DefaultInventories::t3start => 'https://docs.typo3.org/m/typo3/tutorial-getting-started/' . $version . '/en-us/',
101+
DefaultInventories::t3translate => 'https://docs.typo3.org/m/typo3/guide-frontendlocalization/' . $version . '/en-us/',
102+
103+
// Former Official manuals, redirected starting 12.4
104+
DefaultInventories::t3tsconfig => 'https://docs.typo3.org/m/typo3/reference-tsconfig/' . $version . '/en-us/',
105+
DefaultInventories::t3ts45 => 'https://docs.typo3.org/m/typo3/tutorial-typoscript-in-45-minutes/' . $version . '/en-us/',
52106

53107

54108
// Team Guides, they are commonly not versioned
@@ -63,7 +117,7 @@ public function getUrl(): string
63117
DefaultInventories::t3renderguides => 'https://docs.typo3.org/other/t3docs/render-guides/main/en-us/',
64118
DefaultInventories::t3exceptions => 'https://docs.typo3.org/m/typo3/reference-exceptions/main/en-us/',
65119

66-
DefaultInventories::api => 'https://api.typo3.org/{typo3_version}/',
120+
DefaultInventories::api => 'https://api.typo3.org/' . $version . '/',
67121
};
68122
}
69123

tests/Integration/tests/guides-inventories/expected/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ <h1>Title<a class="headerlink" href="#title" data-bs-toggle="modal" data-bs-targ
1818
<li>t3start</li>
1919
<li>t3tca</li>
2020
<li>t3translate</li>
21+
<li>t3ts45</li>
2122
<li>t3tsconfig</li>
2223
<li>t3tsref</li>
2324
<li>t3viewhelper</li>

0 commit comments

Comments
 (0)