Is any one have idea about below error when i am trying to import data by custom importer.
Fatal error: Uncaught Error: Call to undefined method IMI\SVGProductImages\AllowSVGUploader::skipDbProcessing() in /vendor/magento/module-import-export/Model/Import.php on line 486
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_ImportExport:etc/import.xsd">
<entity name="fancybox_import" label="Fancy box" model="Vendor\FancyBox\Model\Import\FancyboxImport" behaviorModel="Magento\ImportExport\Model\Source\Import\Behavior\Basic" />
</config>
Here is the main import file.
<?php
namespace Vendor\FancyBox\Model\Import;
use Vendor\FancyBox\Model\Import\FancyBoxImport\RowValidatorInterface as ValidatorInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
use Vendor\FancyBoxPicker\Api\Data\FancyBoxInterface as FancyBoxInterface;
/**
* Class FancyboxImport
* @package Vendor\FancyBox\Model\Import
*/
class FancyboxImport extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
{
const TABLE_ENTITY = 'vendor_fancybox';
/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = [
ValidatorInterface::ERROR_EMPTY => 'Empty',
];
/**
* @var array
*/
protected $_permanentAttributes = [FancyBoxInterface::SKU];
/**
* If we should check column names
*
* @var bool
*/
protected $needColumnCheck = true;
/**
* Valid column names
*
* @array
*/
protected $validColumnNames = [
FancyBoxInterface::SKU,
FancyBoxInterface::USE_THEME,
FancyBoxInterface::PURPOSE,
FancyBoxInterface::RESULT
];
/**
* Need to log in import history
*
* @var bool
*/
protected $logInHistory = true;
/**
* @var array
*/
protected $_validators = [];
/**
* @var \Magento\Framework\Stdlib\DateTime\DateTime
*/
protected $_connection;
/**
* @var
*/
protected $_resource;
/**
* @var \Vendor\FancyBoxInterface\Helper\Data
*/
protected $helper;
/**
* FancyBoxImport constructor.
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
* @param \Magento\ImportExport\Helper\Data $importExportData
* @param \Magento\ImportExport\Model\ResourceModel\Import\Data $importData
* @param ResourceConnection $resource
* @param \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper
* @param \Magento\Framework\Stdlib\StringUtils $string
* @param ProcessingErrorAggregatorInterface $errorAggregator
* @param \Vendor\FancyBox\Helper\Data $helper
*/
public function __construct(
\Magento\Framework\Json\Helper\Data $jsonHelper,
\Magento\ImportExport\Helper\Data $importExportData,
\Magento\ImportExport\Model\ResourceModel\Import\Data $importData,
\Magento\Framework\App\ResourceConnection $resource,
\Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper,
\Magento\Framework\Stdlib\StringUtils $string,
ProcessingErrorAggregatorInterface $errorAggregator,
\Vendor\FancyBox\Helper\Data $helper
) {
$this->jsonHelper = $jsonHelper;
$this->_importExportData = $importExportData;
$this->_resourceHelper = $resourceHelper;
$this->_dataSourceModel = $importData;
$this->_resource = $resource;
$this->_connection = $resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);
$this->errorAggregator = $errorAggregator;
$this->helper = $helper;
}
/**
* @return array
*/
public function getValidColumnNames()
{
return $this->validColumnNames;
}
/**
* Entity type code getter.
*
* @return string
*/
public function getEntityTypeCode()
{
return 'fancyname_import';
}
/**
* Row validation.
*
* @param array $rowData
* @param int $rowNum
* @return bool
*/
public function validateRow(array $rowData, $rowNum)
{
if (isset($this->_validatedRows[$rowNum])) {
return !$this->getErrorAggregator()->isRowInvalid($rowNum);
}
$this->_validatedRows[$rowNum] = true;
if (!isset($rowData[FancyBoxInterface::USE_THEME]) || empty($rowData[FancyBoxInterface::USE_THEME])) {
$this->addRowError(ValidatorInterface::ERROR_EMPTY, $rowNum);
return false;
}
if (!isset($rowData[FancyBoxInterface::PURPOSE]) || empty($rowData[FancyBoxInterface::PURPOSE])) {
$this->addRowError(ValidatorInterface::ERROR_EMPTY, $rowNum);
return false;
}
if (!isset($rowData[FancyBoxInterface::RESULT]) || empty($rowData[FancyBoxInterface::RESULT])) {
$this->addRowError(ValidatorInterface::ERROR_EMPTY, $rowNum);
return false;
}
return !$this->getErrorAggregator()->isRowInvalid($rowNum);
}
/**
* Create Fancy name picker data from raw data.
*
* @throws \Exception
* @return bool Result of operation.
*/
protected function _importData()
{
if (\Magento\ImportExport\Model\Import::BEHAVIOR_DELETE == $this->getBehavior()) {
$this->deleteEntity();
} elseif (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $this->getBehavior()) {
$this->replaceEntity();
} elseif (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $this->getBehavior()) {
$this->saveEntity();
}
return true;
}
/**
* Save Message
*
* @return $this
*/
public function saveEntity()
{
$this->saveAndReplaceEntity();
return $this;
}
/**
* Replace newsletter subscriber
*
* @return $this
*/
public function replaceEntity()
{
$this->saveAndReplaceEntity();
return $this;
}
/**
* Deletes Fancy name data from raw data.
*
* @return $this
*/
public function deleteEntity()
{
$listTitle = [];
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
foreach ($bunch as $rowNum => $rowData) {
$this->validateRow($rowData, $rowNum);
if (!$this->getErrorAggregator()->isRowInvalid($rowNum)) {
$rowTtile = $rowData[FancyBoxInterface::SKU];
$listTitle[] = $rowTtile;
}
if ($this->getErrorAggregator()->hasToBeTerminated()) {
$this->getErrorAggregator()->addRowToSkip($rowNum);
}
}
}
if ($listTitle) {
$this->deleteEntityFinish(array_unique($listTitle), self::TABLE_ENTITY);
}
return $this;
}
/**
* Save and replace fancy name data
*
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function saveAndReplaceEntity()
{
$behavior = $this->getBehavior();
$listTitle = [];
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
$entityList = [];
foreach ($bunch as $rowNum => $rowData) {
if (!$this->validateRow($rowData, $rowNum)) {
$this->addRowError(ValidatorInterface::ERROR_EMPTY, $rowNum);
continue;
}
if ($this->getErrorAggregator()->hasToBeTerminated()) {
$this->getErrorAggregator()->addRowToSkip($rowNum);
continue;
}
$rowTtile= $rowData[FancyBoxInterface::SKU];
$listTitle[] = $rowTtile;
$sku = $rowData[FancyBoxInterface::SKU];
$usetheme = $rowData[FancyBoxInterface::USE_THEME];
$purpose = $rowData[FancyBoxInterface::PURPOSE];
$result = $rowData[FancyBoxInterface::RESULT];
$status = (isset($rowData[FancyBoxInterface::STATUS]) && !empty($rowData[FancyBoxInterface::STATUS])) ? $rowData[FancyBoxInterface::STATUS] : 0;
$createdat = (isset($rowData[FancyBoxInterface::CREATED_AT]) && !empty($rowData[FancyBoxInterface::CREATED_AT])) ? $rowData[FancyBoxInterface::CREATED_AT] : null;
$updatedat = (isset($rowData[FancyBoxInterface::UPDATED_AT]) && !empty($rowData[FancyBoxInterface::UPDATED_AT])) ? $rowData[FancyBoxInterface::UPDATED_AT] : null;
$entityList[$rowTtile][] = [
FancyBoxInterface::SKU => (isset($sku) && !empty($sku)) ? trim($sku) : null,
FancyBoxInterface::USE_THEME => (isset($usetheme) && !empty($usetheme)) ? trim($usetheme) : null,
FancyBoxInterface::PURPOSE => (isset($purpose) && !empty($purpose)) ? trim($purpose) : null,
FancyBoxInterface::RESULT => (isset($result) && !empty($result)) ? trim($result) : null,
FancyBoxInterface::CHARACTER => $this->helper->setCsvImportCharacter($rowData[FancyBoxInterface::RESULT]),
FancyBoxInterface::STATUS => $status,
FancyBoxInterface::CREATED_AT => $createdat,
FancyBoxInterface::UPDATED_AT => $updatedat
];
}
if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
if ($listTitle) {
if ($this->deleteEntityFinish(array_unique($listTitle), self::TABLE_ENTITY)) {
$this->saveEntityFinish($entityList, self::TABLE_ENTITY);
}
}
} elseif (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
$this->saveEntityFinish($entityList, self::TABLE_ENTITY);
}
}
return $this;
}
/**
* Save fancyname to table.
*
* @param array $entityData
* @param string $table
* @return $this
*/
protected function saveEntityFinish(array $entityData, $table)
{
if ($entityData) {
$tableName = $this->_connection->getTableName($table);
$entityIn = [];
foreach ($entityData as $id => $entityRows) {
foreach ($entityRows as $row) {
$entityIn[] = $row;
}
}
if ($entityIn) {
$this->_connection->insertOnDuplicate($tableName, $entityIn, [
FancyBoxInterface::SKU,
FancyBoxInterface::USE_THEME,
FancyBoxInterface::PURPOSE,
FancyBoxInterface::RESULT,
FancyBoxInterface::CHARACTER,
FancyBoxInterface::STATUS,
FancyBoxInterface::CREATED_AT,
FancyBoxInterface::UPDATED_AT,
]);
}
}
return $this;
}
/**
* Delete fancy table entity
* @param array $ids
* @param $table
* @return bool
*/
protected function deleteEntityFinish(array $ids, $table)
{
if ($table && $ids) {
try {
$this->countItemsDeleted += $this->_connection->delete(
$this->_connection->getTableName($table),
$this->_connection->quoteInto('sku IN (?)', $ids)
);
return true;
} catch (\Exception $e) {
return false;
}
} else {
return false;
}
}
}