[TASK] Migrate linkvalidator results from serializable to json storage 31/62631/2
authorBenni Mack <benni@typo3.org>
Fri, 13 Dec 2019 22:14:25 +0000 (23:14 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Thu, 9 Jan 2020 07:35:25 +0000 (08:35 +0100)
LinkAnalyzer now stores the response as JSON instead of PHP serialize.

A fallback mechanism when unpacking uses unserialize() as fallback
to keep records in the database.

Resolves: #89944
Releases: master
Change-Id: Ic3a2ba058d916936cc5c46a0a8e279bc07bfe60c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62631
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Sybille Peters <sypets@gmx.de>
Tested-by: Jonas Eberle <flightvision@googlemail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Sybille Peters <sypets@gmx.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Jonas Eberle <flightvision@googlemail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php
typo3/sysext/linkvalidator/Classes/Report/LinkValidatorReport.php

index 21da1eb..66fef8e 100644 (file)
@@ -221,6 +221,7 @@ class LinkAnalyzer
                 $record['record_pid'] = $entryValue['row']['pid'];
                 $record['record_uid'] = $entryValue['uid'];
                 $record['table_name'] = $table;
+                $record['link_type'] = $key;
                 $record['link_title'] = $entryValue['link_title'];
                 $record['field'] = $entryValue['field'];
                 $record['last_check'] = time();
@@ -232,28 +233,25 @@ class LinkAnalyzer
                 } else {
                     $url = $entryValue['substr']['tokenValue'];
                 }
+                $record['url'] = $url;
                 $this->linkCounts[$table]++;
                 $checkUrl = $hookObj->checkLink($url, $entryValue, $this);
 
                 // Broken link found
                 if (!$checkUrl) {
-                    $response = [];
-                    $response['valid'] = false;
-                    $response['errorParams'] = $hookObj->getErrorParams();
+                    $response = [
+                        'valid' => false,
+                        'errorParams' => $hookObj->getErrorParams()
+                    ];
                     $this->brokenLinkCounts[$table]++;
-                    $record['link_type'] = $key;
-                    $record['url'] = $url;
-                    $record['url_response'] = serialize($response);
+                    $record['url_response'] = json_encode($response);
                     GeneralUtility::makeInstance(ConnectionPool::class)
                         ->getConnectionForTable('tx_linkvalidator_link')
                         ->insert('tx_linkvalidator_link', $record);
                 } elseif (GeneralUtility::_GP('showalllinks')) {
-                    $response = [];
-                    $response['valid'] = true;
+                    $response = ['valid' => true];
                     $this->brokenLinkCounts[$table]++;
-                    $record['url'] = $url;
-                    $record['link_type'] = $key;
-                    $record['url_response'] = serialize($response);
+                    $record['url_response'] = json_encode($response);
                     GeneralUtility::makeInstance(ConnectionPool::class)
                         ->getConnectionForTable('tx_linkvalidator_link')
                         ->insert('tx_linkvalidator_link', $record);
index 0efbf01..7f670e7 100644 (file)
@@ -667,7 +667,11 @@ class LinkValidatorReport
         $markerArray['element'] = $element;
         $markerArray['headlink'] = htmlspecialchars($row['link_title']);
         $markerArray['linktarget'] = htmlspecialchars($hookObj->getBrokenUrl($row));
-        $response = unserialize($row['url_response']);
+        $response = json_decode($row['url_response'], true);
+        // Fallback mechansim to still support the old serialized data, could be removed in TYPO3 v12 or later
+        if ($response === null) {
+            $response = unserialize($row['url_response'], ['allowed_classes' => false]);
+        }
         if ($response['valid']) {
             $linkMessage = '<span class="valid">' . htmlspecialchars($languageService->getLL('list.msg.ok')) . '</span>';
         } else {