From f5e2c631f3af059bf1f3634851e794d2ad5bf95b Mon Sep 17 00:00:00 2001 From: Chihiro Adachi <8196725+chihiro-adachi@users.noreply.github.com> Date: Wed, 23 Dec 2020 10:36:56 +0900 Subject: [PATCH 1/4] =?UTF-8?q?CSV=E5=87=BA=E5=8A=9B=E6=99=82=E3=81=ABdepr?= =?UTF-8?q?ecated=E3=82=92=E7=99=BA=E7=94=9F=E3=81=95=E3=81=9B=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Service/CsvExportService.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Eccube/Service/CsvExportService.php b/src/Eccube/Service/CsvExportService.php index a83688011af..565424d46bf 100644 --- a/src/Eccube/Service/CsvExportService.php +++ b/src/Eccube/Service/CsvExportService.php @@ -282,7 +282,7 @@ public function exportData(\Closure $closure) $query = $this->qb->getQuery(); foreach ($query->getResult() as $iterableResult) { $closure($iterableResult, $this); - $this->entityManager->detach($iterableResult); + $this->entityManager->clear(); $query->free(); flush(); } @@ -317,16 +317,12 @@ public function getData(Csv $Csv, $entity) // one to one の場合は, dtb_csv.reference_field_name, 合致する結果を取得する. if ($data instanceof \Eccube\Entity\AbstractEntity) { - if (EntityUtil::isNotEmpty($data)) { - return $data->offsetGet($Csv->getReferenceFieldName()); - } + return $data->offsetGet($Csv->getReferenceFieldName()); } elseif ($data instanceof \Doctrine\Common\Collections\Collection) { // one to manyの場合は, カンマ区切りに変換する. $array = []; foreach ($data as $elem) { - if (EntityUtil::isNotEmpty($elem)) { - $array[] = $elem->offsetGet($Csv->getReferenceFieldName()); - } + $array[] = $elem->offsetGet($Csv->getReferenceFieldName()); } return implode($this->eccubeConfig['eccube_csv_export_multidata_separator'], $array); From f179120a149753ac58ded048055f3583c8410d90 Mon Sep 17 00:00:00 2001 From: Chihiro Adachi <8196725+chihiro-adachi@users.noreply.github.com> Date: Wed, 23 Dec 2020 10:37:38 +0900 Subject: [PATCH 2/4] =?UTF-8?q?scrutinizer=E3=81=AE=E6=8C=87=E6=91=98?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Service/CsvExportService.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Eccube/Service/CsvExportService.php b/src/Eccube/Service/CsvExportService.php index 565424d46bf..357ca77faed 100644 --- a/src/Eccube/Service/CsvExportService.php +++ b/src/Eccube/Service/CsvExportService.php @@ -333,8 +333,6 @@ public function getData(Csv $Csv, $entity) // スカラ値の場合はそのまま. return $data; } - - return null; } /** From 01d6b1543247dea1fccfc10a9a185018bd8abc8d Mon Sep 17 00:00:00 2001 From: Chihiro Adachi <8196725+chihiro-adachi@users.noreply.github.com> Date: Wed, 23 Dec 2020 11:26:57 +0900 Subject: [PATCH 3/4] =?UTF-8?q?ManyToOne=E3=81=AE=E5=87=BA=E5=8A=9B?= =?UTF-8?q?=E3=81=8C=E4=B8=8D=E5=AE=8C=E5=85=A8=E3=81=AB=E3=81=AA=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=80=81detach=E3=82=92=E4=BD=BF=E3=81=86?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Service/CsvExportService.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Eccube/Service/CsvExportService.php b/src/Eccube/Service/CsvExportService.php index 357ca77faed..df678229fe8 100644 --- a/src/Eccube/Service/CsvExportService.php +++ b/src/Eccube/Service/CsvExportService.php @@ -282,7 +282,9 @@ public function exportData(\Closure $closure) $query = $this->qb->getQuery(); foreach ($query->getResult() as $iterableResult) { $closure($iterableResult, $this); - $this->entityManager->clear(); + // https://github.com/EC-CUBE/ec-cube/issues/4775 + // entityManager::detach内のtrigger errorを避けるため、UnitOfWork::detachを直接呼び出す + $this->entityManager->getUnitOfWork()->detach($iterableResult); $query->free(); flush(); } From 0da7c07755505ce96eaa2e279ec550dd84165c4f Mon Sep 17 00:00:00 2001 From: Chihiro Adachi <8196725+chihiro-adachi@users.noreply.github.com> Date: Wed, 6 Jan 2021 09:34:39 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E3=83=9A=E3=83=BC=E3=82=B8=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E3=81=97=E3=81=A6=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Service/CsvExportService.php | 35 ++++++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/Eccube/Service/CsvExportService.php b/src/Eccube/Service/CsvExportService.php index df678229fe8..9e3ba6b3647 100644 --- a/src/Eccube/Service/CsvExportService.php +++ b/src/Eccube/Service/CsvExportService.php @@ -28,8 +28,8 @@ use Eccube\Repository\OrderRepository; use Eccube\Repository\ProductRepository; use Eccube\Repository\ShippingRepository; -use Eccube\Util\EntityUtil; use Eccube\Util\FormUtil; +use Knp\Component\Pager\PaginatorInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\Request; @@ -110,6 +110,9 @@ class CsvExportService */ protected $formFactory; + /** @var PaginatorInterface */ + protected $paginator; + /** * CsvExportService constructor. * @@ -117,8 +120,12 @@ class CsvExportService * @param CsvRepository $csvRepository * @param CsvTypeRepository $csvTypeRepository * @param OrderRepository $orderRepository + * @param ShippingRepository $shippingRepository * @param CustomerRepository $customerRepository + * @param ProductRepository $productRepository * @param EccubeConfig $eccubeConfig + * @param FormFactoryInterface $formFactory + * @param PaginatorInterface $paginator */ public function __construct( EntityManagerInterface $entityManager, @@ -129,7 +136,8 @@ public function __construct( CustomerRepository $customerRepository, ProductRepository $productRepository, EccubeConfig $eccubeConfig, - FormFactoryInterface $formFactory + FormFactoryInterface $formFactory, + PaginatorInterface $paginator ) { $this->entityManager = $entityManager; $this->csvRepository = $csvRepository; @@ -140,6 +148,7 @@ public function __construct( $this->eccubeConfig = $eccubeConfig; $this->productRepository = $productRepository; $this->formFactory = $formFactory; + $this->paginator = $paginator; } /** @@ -279,14 +288,20 @@ public function exportData(\Closure $closure) $this->fopen(); - $query = $this->qb->getQuery(); - foreach ($query->getResult() as $iterableResult) { - $closure($iterableResult, $this); - // https://github.com/EC-CUBE/ec-cube/issues/4775 - // entityManager::detach内のtrigger errorを避けるため、UnitOfWork::detachを直接呼び出す - $this->entityManager->getUnitOfWork()->detach($iterableResult); - $query->free(); - flush(); + $page = 1; + $limit = 100; + while ($results = $this->paginator->paginate($this->qb, $page, $limit)) { + if (!$results->valid()) { + break; + } + + foreach ($results as $result) { + $closure($result, $this); + flush(); + } + + $this->entityManager->clear(); + $page++; } $this->fclose();