Skip to content

Commit

Permalink
Update Export.php
Browse files Browse the repository at this point in the history
Fix error causing line not be terminated every each INTERNAL_BATCH_SIZE
  • Loading branch information
Kuba Płaskonka authored Oct 27, 2020
1 parent 8e1885f commit 7b9eb32
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/ScheduledExportBundle/Export/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ class Export

/**
* Export constructor.
* @param string $gridConfig
* @param string $objectsFolder
* @param string $assetFolder
* @param ContainerInterface $container
* @param $input
* @param $output
* @param string|null $condition
* @param string|null $fileName
* @param string $timestamp
* @param string $onlyChanges
* @throws \Exception
*/
public function __construct(
Expand Down Expand Up @@ -101,9 +106,6 @@ public function __construct(
$this->types = str_replace(' ', '', (string) $input->getOption("types"));
}

/**
* @return WebsiteSetting
*/
public function getExportSetting() : WebsiteSetting
{
$settings = WebsiteSetting::getByName($this->gridConfig->getId() .
Expand Down Expand Up @@ -237,7 +239,7 @@ public function getTimestampFormat(): string
}

/**
* @param string $timestampFormat
* @param mixed $timestampFormat
*/
public function setTimestampFormat(string $timestampFormat): void
{
Expand Down Expand Up @@ -285,13 +287,11 @@ public function export(): void
}
}
$this->process->progress(count($objectIdBatch));
$this->process->setMessage(
sprintf("Running (%d/%d)", $this->process->getProgress(), $this->process->getTotal())
);
$this->process->setMessage(sprintf("Running (%d/%d)", $this->process->getProgress(), $this->process->getTotal()));
$this->process->save();
\Pimcore::collectGarbage();
}

}
$this->process->setMessage("Saving results");
$this->process->save();
$this->saveFileInAssets($filenames);
Expand All @@ -305,8 +305,6 @@ public function export(): void
}

/**
* @param array $objectIds
* @param string $filename
* @return Request
*/
protected function prepareRequest(array $objectIds, string $filename): Request
Expand Down Expand Up @@ -362,7 +360,7 @@ protected function prepareListing(): void
protected function getObjectIds(): array
{
$objectIds = [];
for ($i = 0; $i <= $this->process->getTotal(); $i = $i + self::INTERNAL_BATCH_SIZE) {
for($i = 0; $i <= $this->process->getTotal(); $i = $i + self::INTERNAL_BATCH_SIZE) {
$this->listing->setOffset($i);
$this->listing->setLimit(self::INTERNAL_BATCH_SIZE);
$objectIds[] = $this->listing->loadIdList();
Expand Down Expand Up @@ -409,9 +407,7 @@ protected function setHelperColumnsInSession($fieldsRaw): void
}

/**
* @param array $filenames
* @return void
* @throws \Exception
*/
protected function saveFileInAssets(array $filenames): void
{
Expand All @@ -423,22 +419,22 @@ protected function saveFileInAssets(array $filenames): void
$tmpFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $filename . ".csv";
$fileContent = file_get_contents($tmpFile);
if (!$firstFile) {
$content .= preg_replace('/^.+\n/', '', $fileContent);
$content .= $separator . preg_replace('/^.+\n/', '', $fileContent);
} else {
$content .= $fileContent;
}
unlink($tmpFile);
$firstFile = false;
}

if ($this->input->getOption('divide_file')) {
if($this->input->getOption('divide_file')) {
$line = strtok($content, $separator);
$header = $line;
$counter = 0;
$fileCounter = 0;
$subContent = "";
while ($line !== false) {
$line = strtok($separator);
$line = strtok( $separator );
$subContent .= $line . "\r\n";
$counter++;
if ($counter % $this->input->getOption('divide_file') == 0) {
Expand All @@ -460,14 +456,14 @@ protected function saveFileInAssets(array $filenames): void
$assetFile->setData($content);
$assetFile->save();
}

}

/**
* @param string $assetFolder
* @param int|null $index
* @return Asset
*/
protected function prepareAssetFile(string $assetFolder, ?int $index = null): Asset
protected function prepareAssetFile($assetFolder, ?int $index = null): Asset
{
$assetFile = new Asset();

Expand Down

0 comments on commit 7b9eb32

Please sign in to comment.