![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/framework/Setup/Declaration/Schema/DataSavior/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Framework\Setup\Declaration\Schema\DataSavior; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Db\Select; /** * Yields data from database by select objects */ class SelectGenerator { /** * @var int */ private $batchSize = 30000; /** * @var int */ private $baseBatchSize; /** * @var ResourceConnection */ private $resourceConnection; /** * TableDump constructor. * @param ResourceConnection $resourceConnection * @param int $baseBatchSize */ public function __construct( ResourceConnection $resourceConnection, $baseBatchSize = 30000 ) { $this->baseBatchSize = $baseBatchSize; $this->resourceConnection = $resourceConnection; } /** * It retrieves data by batches * * Select generator do not know what data he will fetch, so you need to pass builded Select statement in it * * @param Select $select * @param string $connectionName * @return \Generator */ public function generator(Select $select, $connectionName) { $page = 0; $select->limit($this->batchSize, $page * $this->batchSize); $adapter = $this->resourceConnection->getConnection($connectionName); $data = $adapter->fetchAll($select); yield $data; while (count($data)) { ++$page; $select->limit($this->batchSize, $page * $this->batchSize + 1); $data = $adapter->fetchAll($select); yield $data; } } }