forked from opengento/magento2-gdpr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55fbcba
commit 487667b
Showing
22 changed files
with
126 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\Gdpr\Model\Export; | ||
|
||
use Magento\Framework\Exception\FileSystemException; | ||
use Magento\Framework\Exception\NotFoundException; | ||
use Opengento\Gdpr\Api\Data\ExportEntityInterface; | ||
use Opengento\Gdpr\Model\Archive\MoveToArchive; | ||
use Opengento\Gdpr\Model\Config; | ||
use Opengento\Gdpr\Service\Export\ProcessorFactory; | ||
use Opengento\Gdpr\Service\Export\RendererFactory; | ||
use function sha1; | ||
use const DIRECTORY_SEPARATOR; | ||
|
||
final class ExportToFile | ||
{ | ||
/** | ||
* @var ProcessorFactory | ||
*/ | ||
private $exportProcessorFactory; | ||
|
||
/** | ||
* @var RendererFactory | ||
*/ | ||
private $exportRendererFactory; | ||
|
||
/** | ||
* @var MoveToArchive | ||
*/ | ||
private $archive; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
public function __construct( | ||
ProcessorFactory $exportProcessorFactory, | ||
RendererFactory $exportRendererFactory, | ||
MoveToArchive $archive, | ||
Config $config | ||
) { | ||
$this->exportProcessorFactory = $exportProcessorFactory; | ||
$this->exportRendererFactory = $exportRendererFactory; | ||
$this->archive = $archive; | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* @param ExportEntityInterface $exportEntity | ||
* @return string|null | ||
* @throws FileSystemException | ||
* @throws NotFoundException | ||
*/ | ||
public function export(ExportEntityInterface $exportEntity): ?string | ||
{ | ||
$exporter = $this->exportProcessorFactory->get($exportEntity->getEntityType()); | ||
$fileName = $this->prepareFileName($exportEntity); | ||
$data = $exporter->execute($exportEntity->getEntityId(), []); | ||
foreach ($this->config->getExportRendererCodes() as $rendererCode) { | ||
$filePath = $this->archive->prepareArchive( | ||
$this->exportRendererFactory->get($rendererCode)->saveData($fileName, $data), | ||
$fileName . '.zip' | ||
); | ||
} | ||
|
||
return $filePath ?? null; | ||
} | ||
|
||
private function prepareFileName(ExportEntityInterface $exportEntity): string | ||
{ | ||
return 'gdpr' . | ||
DIRECTORY_SEPARATOR . | ||
sha1($exportEntity->getEntityType() . $exportEntity->getExportId()) . | ||
DIRECTORY_SEPARATOR . | ||
$exportEntity->getFileName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.