From 9e9feace80359a3b626c33d871943b763cd6f056 Mon Sep 17 00:00:00 2001
From: Vitaliy Honcharenko <vgoncharenko@magento.com>
Date: Wed, 11 Nov 2020 17:04:24 -0600
Subject: [PATCH] ISSUE-404: Sync with 2.4 - Product Feed index process unknown
 error

---
 .../Integration/AbstractProductTestHelper.php |  6 +--
 .../CatalogDataExporter/etc/db_schema.xml     |  6 +--
 .../Magento/CatalogDataExporter/etc/di.xml    |  6 +++
 app/code/Magento/DataExporter/etc/di.xml      |  7 +++
 .../Serialize/GzcompressDecorator.php         | 45 +++++++++++++++++++
 5 files changed, 64 insertions(+), 6 deletions(-)
 create mode 100644 lib/internal/Magento/Framework/Serialize/Serialize/GzcompressDecorator.php

diff --git a/app/code/Magento/CatalogDataExporter/Test/Integration/AbstractProductTestHelper.php b/app/code/Magento/CatalogDataExporter/Test/Integration/AbstractProductTestHelper.php
index 107ca1739..1d7d8a280 100644
--- a/app/code/Magento/CatalogDataExporter/Test/Integration/AbstractProductTestHelper.php
+++ b/app/code/Magento/CatalogDataExporter/Test/Integration/AbstractProductTestHelper.php
@@ -16,7 +16,7 @@
 use Magento\Framework\App\ResourceConnection;
 use Magento\Framework\Exception\LocalizedException;
 use Magento\Framework\Exception\NoSuchEntityException;
-use Magento\Framework\Serialize\Serializer\Json;
+use Magento\Framework\Serialize\Serializer\GzcompressDecorator;
 use Magento\Framework\UrlInterface;
 use Magento\Indexer\Model\Indexer;
 use Magento\Store\Model\StoreManagerInterface;
@@ -53,7 +53,7 @@ abstract class AbstractProductTestHelper extends \PHPUnit\Framework\TestCase
     protected $connection;
 
     /**
-     * @var Json
+     * @var GzcompressDecorator
      */
     protected $jsonSerializer;
 
@@ -104,7 +104,7 @@ protected function setUp(): void
         $this->storeManager = Bootstrap::getObjectManager()->create(StoreManagerInterface::class);
         $this->taxClassSource = Bootstrap::getObjectManager()->create(TaxClassSource::class);
 
-        $this->jsonSerializer = Bootstrap::getObjectManager()->create(Json::class);
+        $this->jsonSerializer = Bootstrap::getObjectManager()->create(GzcompressDecorator::class);
     }
 
     /**
diff --git a/app/code/Magento/CatalogDataExporter/etc/db_schema.xml b/app/code/Magento/CatalogDataExporter/etc/db_schema.xml
index f127827db..c75912da9 100644
--- a/app/code/Magento/CatalogDataExporter/etc/db_schema.xml
+++ b/app/code/Magento/CatalogDataExporter/etc/db_schema.xml
@@ -29,7 +29,7 @@
             comment="Store view code"
         />
         <column
-            xsi:type="mediumtext"
+            xsi:type="blob"
             name="feed_data"
             nullable="false"
             comment="Feed Data"
@@ -72,7 +72,7 @@
                 length="64"
                 comment="Store view code"
         />
-        <column xsi:type="mediumtext"
+        <column xsi:type="blob"
                 name="feed_data"
                 nullable="false"
                 comment="Feed Data"
@@ -111,7 +111,7 @@
                 comment="Store view code"
         />
         <column
-            xsi:type="mediumtext"
+            xsi:type="blob"
             name="feed_data"
             nullable="false"
             comment="Feed Data"
diff --git a/app/code/Magento/CatalogDataExporter/etc/di.xml b/app/code/Magento/CatalogDataExporter/etc/di.xml
index ca77f0599..3da8107cd 100644
--- a/app/code/Magento/CatalogDataExporter/etc/di.xml
+++ b/app/code/Magento/CatalogDataExporter/etc/di.xml
@@ -435,6 +435,12 @@
         </arguments>
     </virtualType>
 
+    <type name="Magento\DataExporter\Model\Feed">
+        <arguments>
+            <argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\GzcompressDecorator</argument>
+        </arguments>
+    </type>
+
     <type name="Magento\DataExporter\Model\FeedPool">
         <arguments>
             <argument name="classMap" xsi:type="array">
diff --git a/app/code/Magento/DataExporter/etc/di.xml b/app/code/Magento/DataExporter/etc/di.xml
index a38c8fb11..dd38db22f 100644
--- a/app/code/Magento/DataExporter/etc/di.xml
+++ b/app/code/Magento/DataExporter/etc/di.xml
@@ -33,6 +33,13 @@
             <argument name="data" xsi:type="object">Magento\DataExporter\Config\Data</argument>
         </arguments>
     </type>
+
+    <type name="Magento\DataExporter\Model\Indexer\DataSerializer">
+        <arguments>
+            <argument name="serializer" xsi:type="object">Magento\Framework\Serialize\Serializer\GzcompressDecorator</argument>
+        </arguments>
+    </type>
+
     <preference for="Magento\DataExporter\Config\ConfigInterface" type="Magento\DataExporter\Config\Config" />
 
     <preference for="Magento\DataExporter\Model\Indexer\FeedIndexerCallbackInterface"
diff --git a/lib/internal/Magento/Framework/Serialize/Serialize/GzcompressDecorator.php b/lib/internal/Magento/Framework/Serialize/Serialize/GzcompressDecorator.php
new file mode 100644
index 000000000..42d48fc4d
--- /dev/null
+++ b/lib/internal/Magento/Framework/Serialize/Serialize/GzcompressDecorator.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Copyright © Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+namespace Magento\Framework\Serialize\Serializer;
+
+use Magento\Framework\Serialize\SerializerInterface;
+
+/**
+ * Compress data.
+ */
+class GzcompressDecorator implements SerializerInterface
+{
+    /**
+     * Json serializer.
+     *
+     * @var Json
+     */
+    private $serializer;
+
+    /**
+     * @param Json $serializer
+     */
+    public function __construct(Json $serializer)
+    {
+        $this->serializer = $serializer;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function serialize($data)
+    {
+        return gzcompress($this->serializer->serialize($data), 9);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function unserialize($string)
+    {
+        return $this->serializer->unserialize(gzuncompress($string));
+    }
+}