1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\Econda\Business\Collector; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\LocaleTransfer; |
|
|
|
|
11
|
|
|
use Spryker\Service\UtilDataReader\Model\BatchIterator\CountableIteratorInterface; |
|
|
|
|
12
|
|
|
use Spryker\Service\UtilDataReader\Model\BatchIterator\PdoBatchIterator; |
|
|
|
|
13
|
|
|
use Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderInterface; |
|
|
|
|
14
|
|
|
use Spryker\Zed\Kernel\Persistence\QueryContainer\QueryContainerInterface; |
|
|
|
|
15
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\Writer\WriterInterface; |
16
|
|
|
use SprykerEco\Zed\Econda\Business\Model\BatchResultInterface; |
17
|
|
|
use SprykerEco\Zed\Econda\Persistence\Econda\AbstractPdoEcondaQuery; |
18
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
|
|
|
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
20
|
|
|
|
21
|
|
|
abstract class AbstractDatabaseCollector extends AbstractCollector implements DatabaseCollectorInterface |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var \SprykerEco\Zed\Econda\Persistence\Econda\AbstractPdoEcondaQuery |
26
|
|
|
*/ |
27
|
|
|
protected $queryBuilder; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderInterface |
31
|
|
|
*/ |
32
|
|
|
protected $criteriaBuilder; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param \Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderInterface $criteria |
36
|
|
|
* @param \SprykerEco\Zed\Econda\Persistence\Econda\AbstractPdoEcondaQuery $query |
37
|
|
|
*/ |
38
|
|
|
public function __construct( |
39
|
|
|
CriteriaBuilderInterface $criteria, |
40
|
|
|
AbstractPdoEcondaQuery $query |
41
|
|
|
) { |
42
|
|
|
$this->criteriaBuilder = $criteria; |
43
|
|
|
$this->queryBuilder = $query; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param \Generated\Shared\Transfer\LocaleTransfer $locale |
48
|
|
|
* @param \Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderInterface $criteriaBuilder |
49
|
|
|
* @param \Spryker\Zed\Kernel\Persistence\QueryContainer\QueryContainerInterface $connection |
50
|
|
|
* @param int $chunkSize |
51
|
|
|
* |
52
|
|
|
* @return \Spryker\Service\UtilDataReader\Model\BatchIterator\CountableIteratorInterface |
53
|
|
|
*/ |
54
|
|
|
public function createIteratorAndPrepareQuery( |
55
|
|
|
LocaleTransfer $locale, |
56
|
|
|
CriteriaBuilderInterface $criteriaBuilder, |
57
|
|
|
QueryContainerInterface $connection, |
58
|
|
|
$chunkSize = 100 |
59
|
|
|
) { |
60
|
|
|
$this->queryBuilder |
61
|
|
|
->setCriteriaBuilder($criteriaBuilder) |
62
|
|
|
->setLocale($locale) |
63
|
|
|
->prepare(); |
64
|
|
|
|
65
|
|
|
return new PdoBatchIterator($criteriaBuilder, $connection, $chunkSize); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param \Spryker\Service\UtilDataReader\Model\BatchIterator\CountableIteratorInterface $batchCollection |
70
|
|
|
* @param \SprykerEco\Zed\Econda\Business\Model\BatchResultInterface $batchResult |
71
|
|
|
* @param \SprykerEco\Zed\Econda\Business\Exporter\Writer\WriterInterface $storeWriter |
72
|
|
|
* @param \Generated\Shared\Transfer\LocaleTransfer $locale |
73
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
74
|
|
|
* @param \Symfony\Component\Console\Helper\ProgressBar $progressBar |
75
|
|
|
* |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
public function exportDataToStore( |
79
|
|
|
CountableIteratorInterface $batchCollection, |
80
|
|
|
BatchResultInterface $batchResult, |
81
|
|
|
WriterInterface $storeWriter, |
82
|
|
|
LocaleTransfer $locale, |
83
|
|
|
OutputInterface $output, |
84
|
|
|
ProgressBar $progressBar |
85
|
|
|
) { |
86
|
|
|
|
87
|
|
|
$totalCount = $batchCollection->count(); |
88
|
|
|
$batchResult->setTotalCount($totalCount); |
89
|
|
|
|
90
|
|
|
$progressBar->setMessage($this->collectResourceType(), 'barTitle'); |
91
|
|
|
|
92
|
|
|
foreach ($batchCollection as $batch) { |
93
|
|
|
$this->processBatchForExport( |
94
|
|
|
$batch, |
95
|
|
|
$progressBar, |
96
|
|
|
$locale, |
97
|
|
|
$batchResult, |
98
|
|
|
$storeWriter |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$progressBar->finish(); |
103
|
|
|
$output->writeln(''); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param array $batch |
108
|
|
|
* @param \Symfony\Component\Console\Helper\ProgressBar $progressBar |
109
|
|
|
* @param \Generated\Shared\Transfer\LocaleTransfer $locale |
110
|
|
|
* @param \SprykerEco\Zed\Econda\Business\Model\BatchResultInterface $batchResult |
111
|
|
|
* @param \SprykerEco\Zed\Econda\Business\Exporter\Writer\WriterInterface $storeWriter |
112
|
|
|
* |
113
|
|
|
* @return void |
114
|
|
|
*/ |
115
|
|
|
protected function processBatchForExport( |
116
|
|
|
array $batch, |
117
|
|
|
ProgressBar $progressBar, |
118
|
|
|
LocaleTransfer $locale, |
119
|
|
|
BatchResultInterface $batchResult, |
120
|
|
|
WriterInterface $storeWriter |
121
|
|
|
) { |
122
|
|
|
$batchSize = count($batch); |
123
|
|
|
$progressBar->advance($batchSize); |
124
|
|
|
|
125
|
|
|
$collectedData = $this->collectData($batch, $locale); |
126
|
|
|
$collectedDataCount = count($collectedData); |
127
|
|
|
|
128
|
|
|
$storeWriter->write($collectedData); |
129
|
|
|
|
130
|
|
|
$batchResult->increaseProcessedCount($collectedDataCount); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths