17 private $resourceConnection;
22 private $dbConnection;
27 private $insertIntoTable;
42 private $currentStorageIndex = 0;
55 $this->insertIntoTable = $insertIntoTable;
56 $this->batchSize = $batchSize;
57 $this->dataStorage = new \SplFixedArray($batchSize);
67 public function insert(array $dataToInsert)
69 $this->dataStorage[$this->currentStorageIndex] = $dataToInsert;
70 $this->currentStorageIndex++;
72 if ($this->currentStorageIndex >= $this->batchSize) {
84 if ($this->currentStorageIndex > 0) {
85 if ($this->currentStorageIndex < $this->batchSize) {
86 $this->dataStorage->setSize($this->currentStorageIndex);
89 $this->getDbConnection()
91 $this->insertIntoTable,
92 array_keys(reset($this->dataStorage)),
93 $this->dataStorage->toArray()
96 $this->dataStorage = new \SplFixedArray($this->batchSize);
97 $this->currentStorageIndex = 0;
108 private function getDbConnection()
110 if ($this->dbConnection ===
null) {
111 $this->dbConnection = $this->resourceConnection->getConnection();
114 return $this->dbConnection;
__construct(\Magento\Framework\App\ResourceConnection $resourceConnection, $insertIntoTable, $batchSize)
insert(array $dataToInsert)