diff --git a/application/Espo/Core/Export/Csv.php b/application/Espo/Core/Export/Csv.php index ebb350e028..1ddeaae91e 100644 --- a/application/Espo/Core/Export/Csv.php +++ b/application/Espo/Core/Export/Csv.php @@ -52,7 +52,7 @@ class Csv extends \Espo\Core\Injectable } } - public function process($entityType, $params, $dataList) + public function process(string $entityType, array $params, ?array $dataList, $dataFp = null) { if (!is_array($params['attributeList'])) { throw new Error(); @@ -67,10 +67,20 @@ class Csv extends \Espo\Core\Injectable $fp = fopen('php://temp', 'w'); fputcsv($fp, $attributeList, $delimiter); - foreach ($dataList as $row) { - $preparedRow = $this->prepareRow($row); - fputcsv($fp, $preparedRow, $delimiter); + + if ($dataFp) { + while (($line = fgets($dataFp)) !== false) { + $row = unserialize(base64_decode($line)); + $preparedRow = $this->prepareRow($row); + fputcsv($fp, $preparedRow, $delimiter); + } + } else { + foreach ($dataList as $row) { + $preparedRow = $this->prepareRow($row); + fputcsv($fp, $preparedRow, $delimiter); + } } + rewind($fp); $csv = stream_get_contents($fp); fclose($fp); diff --git a/application/Espo/Core/Export/Xlsx.php b/application/Espo/Core/Export/Xlsx.php index 221acedaf8..62886be6dd 100644 --- a/application/Espo/Core/Export/Xlsx.php +++ b/application/Espo/Core/Export/Xlsx.php @@ -146,7 +146,7 @@ class Xlsx extends \Espo\Core\Injectable } } - public function process($entityType, $params, $dataList) + public function process(string $entityType, array $params, ?array $dataList = null, $dataFp = null) { if (!is_array($params['fieldList'])) { throw new Error(); @@ -258,7 +258,24 @@ class Xlsx extends \Espo\Core\Injectable $typesCache = array(); $rowNumber++; - foreach ($dataList as $row) { + + $lineIndex = -1; + if ($dataList) { + $lineCount = count($dataList); + } + + while (true) { + $lineIndex++; + + if ($dataFp) { + $line = fgets($dataFp); + if ($line === false) break; + $row = unserialize(base64_decode($line)); + } else { + if ($lineIndex >= $lineCount) break; + $row = $dataList[$lineIndex]; + } + $i = 0; foreach ($fieldList as $i => $name) { $col = $azRange[$i]; @@ -611,4 +628,4 @@ class Xlsx extends \Espo\Core\Injectable return $xlsx; } -} \ No newline at end of file +} diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index de3990fc41..0991fcc23b 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -2042,8 +2042,6 @@ class Record extends \Espo\Core\Services\Base $sth->execute(); } - $dataList = []; - $attributeListToSkip = [ 'deleted' ]; @@ -2089,6 +2087,8 @@ class Record extends \Espo\Core\Services\Base $fieldList = $exportObj->filterFieldList($this->entityType, $fieldList, $exportAllFields); } + $fp = null; + if (is_null($attributeList)) { $attributeList = []; $seed = $this->getEntityManager()->getEntity($this->entityType); @@ -2109,6 +2109,8 @@ class Record extends \Espo\Core\Services\Base $exportObj->addAdditionalAttributes($this->entityType, $attributeList, $fieldList); } + $fp = fopen('php://temp', 'w'); + if ($collection) { foreach ($collection as $entity) { $this->loadAdditionalFieldsForExport($entity); @@ -2120,8 +2122,10 @@ class Record extends \Espo\Core\Services\Base $value = $this->getAttributeFromEntityForExport($entity, $attribute); $row[$attribute] = $value; } - $dataList[] = $row; + $line = base64_encode(serialize($row)) . \PHP_EOL; + fwrite($fp, $line); } + rewind($fp); } else { while ($dataRow = $sth->fetch(\PDO::FETCH_ASSOC)) { $entity = $this->getEntityManager()->getEntityFactory()->create($this->getEntityType()); @@ -2137,8 +2141,11 @@ class Record extends \Espo\Core\Services\Base $value = $this->getAttributeFromEntityForExport($entity, $attribute); $row[$attribute] = $value; } - $dataList[] = $row; + + $line = base64_encode(serialize($row)) . \PHP_EOL; + fwrite($fp, $line); } + rewind($fp); } if (is_null($attributeList)) { @@ -2168,7 +2175,9 @@ class Record extends \Espo\Core\Services\Base if (array_key_exists('exportName', $params)) { $exportParams['exportName'] = $params['exportName']; } - $contents = $exportObj->process($this->entityType, $exportParams, $dataList); + $contents = $exportObj->process($this->entityType, $exportParams, null, $fp); + + fclose($fp); $attachment = $this->getEntityManager()->getEntity('Attachment'); $attachment->set('name', $fileName);