Skip to content

Commit 331c49d

Browse files
committed
Optionally use temporary table for validated import data
1 parent 76f1395 commit 331c49d

3 files changed

Lines changed: 62 additions & 3 deletions

File tree

ResourceModel/ImportData.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace FireGento\FastSimpleImport\ResourceModel;
4+
5+
use Magento\Framework\App\Config\ScopeConfigInterface;
6+
7+
/**
8+
* Overriden resource model for import data. Since we do not upload and validate CSV files, then process the uploaded
9+
* data in a second step, we can use a temporary table.
10+
*
11+
* This not only improves performance, it also allows for parallel import execution, because each process uses its own
12+
* temporary table.
13+
*
14+
* @package FireGento\FastSimpleImport\ResourceModel
15+
*/
16+
class ImportData extends \Magento\ImportExport\Model\ResourceModel\Import\Data
17+
{
18+
/**
19+
* @var ScopeConfigInterface
20+
*/
21+
private $scopeConfig;
22+
23+
public function __construct(
24+
\Magento\Framework\Model\ResourceModel\Db\Context $context,
25+
\Magento\Framework\Json\Helper\Data $jsonHelper,
26+
ScopeConfigInterface $scopeConfig,
27+
$connectionName = null
28+
)
29+
{
30+
$this->scopeConfig = $scopeConfig;
31+
parent::__construct($context, $jsonHelper, $connectionName);
32+
}
33+
34+
protected function _construct()
35+
{
36+
if ($this->scopeConfig->isSetFlag('fastsimpleimport/database/import_temp_table')) {
37+
$this->getConnection()->createTemporaryTableLike(
38+
'importexport_importdata_tmp',
39+
'importexport_importdata',
40+
true
41+
);
42+
$this->_init('importexport_importdata_tmp', 'id');
43+
} else {
44+
parent::_construct();
45+
}
46+
}
47+
48+
}

etc/adminhtml/system.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
<label>Category path seperator</label>
4141
</field>
4242
</group>
43+
<group id="database" translate="label" sortOrder="2" showInDefault="1" showInWebsite="0" showInStore="0">
44+
<label>Database settings</label>
45+
<field id="import_temp_table" type="select" sortOrder="10" showInDefault="1" translate="label,comment">
46+
<label>Create temporary table for validated import_data</label>
47+
<comment>This will create a temporary table instead of using the regular table. It allows parallel execution of imports without data loss. But it will not be possible anymore to upload CSV import files in the admin panel.</comment>
48+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
49+
</field>
50+
</group>
4351
</section>
4452
</system>
4553
</config>

etc/di.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
* See LICENSE.md bundled with this module for license details.
66
*/
77
-->
8-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9-
<preference for="\FireGento\FastSimpleImport\Model\Adapters\ImportAdapterFactoryInterface" type="FireGento\FastSimpleImport\Model\Adapters\ArrayAdapterFactory"/>
10-
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10+
<preference for="\FireGento\FastSimpleImport\Model\Adapters\ImportAdapterFactoryInterface"
11+
type="FireGento\FastSimpleImport\Model\Adapters\ArrayAdapterFactory"/>
12+
<preference for="Magento\ImportExport\Model\ResourceModel\Import\Data"
13+
type="FireGento\FastSimpleImport\ResourceModel\ImportData"/>
1114
</config>

0 commit comments

Comments
 (0)