Magento 2.3.2 - Export Error
Have you just upgraded to Magento version 2.3.2? Have an error on export?
Than you are at right place for a solution.
So without wasting time , let's roll the camera.
Error: Warning: DOMDocumentFragment::appendXML(): Entity: line 1: parser error : CData section too big found in vendor/magento/framework/View/TemplateEngine/Xhtml/Template.php on line 60
Preconditions (*)
Than you are at right place for a solution.
So without wasting time , let's roll the camera.
Error: Warning: DOMDocumentFragment::appendXML(): Entity: line 1: parser error : CData section too big found in vendor/magento/framework/View/TemplateEngine/Xhtml/Template.php on line 60
Preconditions (*)
- Magento version 2.3.2
- Too big files and number of files more (around > 20000)
Steps to reproduce (*)
You have error as described than below solution for your store.
1) export_grid.xml
vendor/magento/module-import-export/view/adminhtml/ui_component/export_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<listing
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">export_grid.export_grid_data_source</item>
</item>
</argument>
<settings>
<deps>
<dep>export_grid.export_grid_data_source</dep>
</deps>
<spinner>export_grid_columns</spinner>
</settings>
<dataSource name="export_grid_data_source" component="Magento_Ui/js/grid/provider">
<settings>
<storageConfig>
<param name="indexField" xsi:type="string">file_name</param>
</storageConfig>
<updateUrl path="mui/index/render"/>
</settings>
<aclResource>Magento_ImportExport::export</aclResource>
<dataProvider class="Magento\ImportExport\Ui\DataProvider\ExportFileDataProvider" name="export_grid_data_source">
<settings>
<requestFieldName>file_name</requestFieldName>
<primaryFieldName>file_name</primaryFieldName>
</settings>
</dataProvider>
</dataSource>
<listingToolbar name="listing_top">
<paging name="listing_paging"/>
</listingToolbar>
<columns name="export_grid_columns">
<column name="file_name">
<settings>
<sortable>false</sortable>
<label translate="true">File name</label>
</settings>
</column>
<actionsColumn name="actions" class="Magento\ImportExport\Ui\Component\Columns\ExportGridActions">
<settings>
<indexField>file_name</indexField>
</settings>
</actionsColumn>
</columns>
</listing>
2) ExportFileDataProvider.php
vendor/magento/module-import-export/Ui/DataProvider/ExportFileDataProvider.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\ImportExport\Ui\DataProvider;
use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Io\File;
/**
* Data provider for export grid.
*/
class ExportFileDataProvider extends DataProvider
{
/**
* @var DriverInterface
*/
private $file;
/**
* @var Filesystem
*/
private $fileSystem;
/**
* @var File
*/
private $fileio;
/**
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param \Magento\Framework\Api\Search\ReportingInterface $reporting
* @param \Magento\Framework\Api\Search\SearchCriteriaBuilder $searchCriteriaBuilder
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
* @param DriverInterface $file
* @param Filesystem $filesystem
* @param File $fileIO
* @param array $meta
* @param array $data
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
string $name,
string $primaryFieldName,
string $requestFieldName,
\Magento\Framework\Api\Search\ReportingInterface $reporting,
\Magento\Framework\Api\Search\SearchCriteriaBuilder $searchCriteriaBuilder,
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\Api\FilterBuilder $filterBuilder,
DriverInterface $file,
Filesystem $filesystem,
File $fileIO,
array $meta = [],
array $data = []
) {
$this->file = $file;
$this->fileSystem = $filesystem;
$this->fileio = $fileIO;
$this->request = $request;
parent::__construct(
$name,
$primaryFieldName,
$requestFieldName,
$reporting,
$searchCriteriaBuilder,
$request,
$filterBuilder,
$meta,
$data
);
}
/**
* Returns data for grid.
*
* @return array
* @throws \Magento\Framework\Exception\FileSystemException
*/
public function getData()
{
$directory = $this->fileSystem->getDirectoryRead(DirectoryList::VAR_DIR);
$emptyResponse = ['items' => [], 'totalRecords' => 0];
if (!$this->file->isExists($directory->getAbsolutePath() . 'export/')) {
return $emptyResponse;
}
$files = $this->file->readDirectoryRecursively($directory->getAbsolutePath() . 'export/');
if (empty($files)) {
return $emptyResponse;
}
$result = [];
foreach ($files as $file) {
// $result['items'][]['file_name'] = pathinfo($file, PATHINFO_BASENAME);
$result['items'][]['file_name'] = $this->fileio->getPathInfo($file)['basename'];
}
$pagesize = (int)($this->request->getParam('paging')['pageSize']);
$pageCurrent = (int)($this->request->getParam('paging')['current']);
$pageoffset = ($pageCurrent - 1)*$pagesize;
$result['totalRecords'] = count($result['items']);
$result['items'] = array_slice($result['items'],$pageoffset,$pagesize);
return $result;
}
}
That's it!!! You are done!! Yuriieeee!!
Pull request on github:
If like efforts, Please share, comment and subscribe for future posts and inspire more.
#magento2
Comments
Post a Comment