[BUGFIX] Upgrade linkhandler syntax to new link syntax 46/59046/2
authorJohannes Kasberger <johannes.kasberger@reelworx.at>
Tue, 27 Nov 2018 16:24:56 +0000 (17:24 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Thu, 6 Dec 2018 16:30:06 +0000 (17:30 +0100)
The \TYPO3\CMS\Core\LinkHandling\RecordLinkHandler::asString method
expects the parameters to hold the identifier and uid as top-level
array elements.
The legacy syntax converter now ensures that this nesting is correct.

Besides that we now also upgrade the very old linkhandler syntax
with no identifier.

Therefore we accept
 - record:<identifier>:<table>:<uid>
 - record:<table>:<uid>

Resolves: #80806
Releases: master, 8.7
Change-Id: I01c3d525de43a56d610dc882ef406de631a8762e
Reviewed-on: https://review.typo3.org/59046
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/LinkHandling/LegacyLinkNotationConverter.php
typo3/sysext/core/Tests/Unit/LinkHandling/LegacyLinkNotationConverterTest.php

index a811b64..776ca2b 100644 (file)
@@ -79,8 +79,17 @@ class LegacyLinkNotationConverter
             $result['url'] = $linkParameter;
             $result['value'] = $linkHandlerValue;
             if ($result['type'] === LinkService::TYPE_RECORD) {
-                list($a['identifier'], $a['table'], $a['uid']) = explode(':', $linkHandlerValue);
-                $result['url'] = $a;
+                list($a['identifier'], $tableAndUid) = explode(':', $linkHandlerValue, 2);
+                $tableAndUid = explode(':', $tableAndUid);
+                if (count($tableAndUid) > 1) {
+                    $a['table'] = $tableAndUid[0];
+                    $a['uid'] = $tableAndUid[1];
+                } else {
+                    // this case can happen if there is the very old linkhandler syntax, which was only record:<table>:<uid>
+                    $a['table'] = $a['identifier'];
+                    $a['uid'] = $tableAndUid[0];
+                }
+                $result = array_merge($result, $a);
             }
         } else {
             // special handling without a scheme
index 131105d..37bd851 100644 (file)
@@ -35,7 +35,7 @@ class LegacyLinkNotationConverterTest extends \TYPO3\TestingFramework\Core\Unit\
             'simple page - old style' => [
                 // original input value
                 '13',
-                // splitted values
+                // split values
                 [
                     'type' => LinkService::TYPE_PAGE,
                     'pageuid' => 13
@@ -80,7 +80,31 @@ class LegacyLinkNotationConverterTest extends \TYPO3\TestingFramework\Core\Unit\
                     'pagealias' => 'alias13'
                 ],
                 't3://page?alias=alias13'
-            ]
+            ],
+            'record of table - old 2-part identifier' => [
+                'record:tx_myext_entity:456',
+                [
+                    'type' => LinkService::TYPE_RECORD,
+                    'identifier' => 'tx_myext_entity',
+                    'table' => 'tx_myext_entity',
+                    'uid' => 456,
+                    'url' => 'record:tx_myext_entity:456',
+                    'value' => 'tx_myext_entity:456'
+                ],
+                't3://record?identifier=tx_myext_entity&uid=456'
+            ],
+            'record of table - old 3-part identifier' => [
+                'record:usage1:tx_myext_entity:456',
+                [
+                    'type' => LinkService::TYPE_RECORD,
+                    'identifier' => 'usage1',
+                    'table' => 'tx_myext_entity',
+                    'uid' => 456,
+                    'url' => 'record:usage1:tx_myext_entity:456',
+                    'value' => 'usage1:tx_myext_entity:456'
+                ],
+                't3://record?identifier=usage1&uid=456'
+            ],
         ];
     }
 
@@ -89,11 +113,10 @@ class LegacyLinkNotationConverterTest extends \TYPO3\TestingFramework\Core\Unit\
      *
      * @param string $input
      * @param array  $expected
-     * @param string $finalString
      *
      * @dataProvider resolveParametersForNonFilesDataProvider
      */
-    public function resolveReturnsSplitParameters($input, $expected, $finalString)
+    public function resolveReturnsSplitParameters($input, $expected)
     {
         $subject = new LegacyLinkNotationConverter();
         $this->assertEquals($expected, $subject->resolve($input));
@@ -103,9 +126,10 @@ class LegacyLinkNotationConverterTest extends \TYPO3\TestingFramework\Core\Unit\
      * @test
      *
      * @param string $input
-     * @param array  $parameters
+     * @param array $parameters
      * @param string $expected
      *
+     * @throws \TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException
      * @dataProvider resolveParametersForNonFilesDataProvider
      */
     public function splitParametersToUnifiedIdentifier($input, $parameters, $expected)
@@ -180,12 +204,12 @@ class LegacyLinkNotationConverterTest extends \TYPO3\TestingFramework\Core\Unit\
      *
      * @param string $input
      * @param array  $expected
-     * @param string $finalString
      *
      * @dataProvider resolveParametersForFilesDataProvider
      */
-    public function resolveFileReferencesToSplitParameters($input, $expected, $finalString)
+    public function resolveFileReferencesToSplitParameters($input, $expected)
     {
+        /** @var ResourceStorage|\PHPUnit_Framework_MockObject_MockObject $storage */
         $storage = $this->getMockBuilder(ResourceStorage::class)
             ->disableOriginalConstructor()
             ->getMock();
@@ -229,9 +253,10 @@ class LegacyLinkNotationConverterTest extends \TYPO3\TestingFramework\Core\Unit\
      * @test
      *
      * @param string $input
-     * @param array  $parameters
+     * @param array $parameters
      * @param string $expected
      *
+     * @throws \TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException
      * @dataProvider resolveParametersForFilesDataProvider
      */
     public function splitParametersToUnifiedIdentifierForFiles($input, $parameters, $expected)
@@ -267,8 +292,9 @@ class LegacyLinkNotationConverterTest extends \TYPO3\TestingFramework\Core\Unit\
             $folderData = explode(':', $parameters['folder']);
             /** @var ResourceStorage|\PHPUnit_Framework_MockObject_MockObject $storageMock */
             $storage = $this->getMockBuilder(ResourceStorage::class)
+                ->setMethods(['getUid'])
                 ->disableOriginalConstructor()
-                ->getMock(['getUid']);
+                ->getMock();
             $storage->method('getUid')->willReturn($folderData[0]);
             $folderObject->expects($this->any())->method('getStorage')->willReturn($storage);
             $folderObject->expects($this->any())->method('getIdentifier')->willReturn($folderData[1]);
@@ -302,6 +328,9 @@ class LegacyLinkNotationConverterTest extends \TYPO3\TestingFramework\Core\Unit\
 
     /**
      * @test
+     *
+     * @param string $pharUrl
+     *
      * @dataProvider resolveThrowExceptionWithPharReferencesDataProvider
      */
     public function resolveThrowExceptionWithPharReferences(string $pharUrl)