Skip to content

Commit

Permalink
export entity persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Sep 13, 2019
1 parent 984c11a commit 91e6330
Show file tree
Hide file tree
Showing 38 changed files with 933 additions and 328 deletions.
113 changes: 113 additions & 0 deletions Api/Data/ExportEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,137 @@
*/
interface ExportEntityInterface
{
/**#@+
* Constants for fields keys
*/
public const ID = 'export_id';
public const ENTITY_ID = 'entity_id';
public const ENTITY_TYPE = 'entity_type';
public const FILE_NAME = 'file_name';
public const FILE_PATH = 'file_path';
public const CREATED_AT = 'created_at';
public const EXPORTED_AT = 'exported_at';
public const EXPIRED_AT = 'expired_at';
/**#@-*/

/**
* Retrieve the export ID
*
* @return int
*/
public function getExportId(): int;

/**
* Set the export ID
*
* @param int $exportId
* @return ExportEntityInterface
*/
public function setExportId(int $exportId): ExportEntityInterface;

/**
* Retrieve the entity ID to export
*
* @return int
*/
public function getEntityId(): int;

/**
* Set the entity ID to export
*
* @param int $entityId
* @return ExportEntityInterface
*/
public function setEntityId($entityId): ExportEntityInterface;

/**
* Retrieve the entity type to export
*
* @return string
*/
public function getEntityType(): string;

/**
* Set the entity type to export
*
* @param string $entityType
* @return ExportEntityInterface
* @todo force type in php7.4
*/
public function setEntityType(string $entityType): ExportEntityInterface;

/**
* Retrieve the file name to export the data to
*
* @return string
*/
public function getFileName(): string;

/**
* Set the file name to export the data to
*
* @param string $filename
* @return ExportEntityInterface
*/
public function setFileName(string $filename): ExportEntityInterface;

/**
* Retrieve the export file absolute path
*
* @return string|null
*/
public function getFilePath(): ?string;

/**
* Set the export file absolute path
*
* @param string $filePath
* @return ExportEntityInterface
*/
public function setFilePath(string $filePath): ExportEntityInterface;

/**
* Retrieve the created at date of the export
*
* @return string
*/
public function getCreatedAt(): string;

/**
* Set the created at date of the export
*
* @param string $createdAt
* @return ExportEntityInterface
*/
public function setCreatedAt(string $createdAt): ExportEntityInterface;

/**
* Retrieve the last exported at date
*
* @return string|null
*/
public function getExportedAt(): ?string;

/**
* Set the last exported at date
*
* @param string $exportedAt
* @return ExportEntityInterface
*/
public function setExportedAt(string $exportedAt): ExportEntityInterface;

/**
* Retrieve the date expiration of the export
*
* @return string
*/
public function getExpiredAt(): string;

/**
* Set the expiration date of the export
*
* @param string $expiredAt
* @return ExportEntityInterface
*/
public function setExpiredAt(string $expiredAt): ExportEntityInterface;
}
32 changes: 32 additions & 0 deletions Api/Data/ExportEntitySearchResultsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace Opengento\Gdpr\Api\Data;

use Magento\Framework\Api\SearchResultsInterface;

/**
* Interface ExportEntitySearchResultsInterface
* @api
*/
interface ExportEntitySearchResultsInterface extends SearchResultsInterface
{
/**
* Retrieve the export entities list
*
* @return \Opengento\Gdpr\Api\Data\ExportEntityInterface[]
*/
public function getItems(): array;

/**
* Set the export entities list
*
* @param \Opengento\Gdpr\Api\Data\ExportEntityInterface[] $items
* @return \Opengento\Gdpr\Api\Data\ExportEntitySearchResultsInterface
*/
public function setItems(array $items): ExportEntitySearchResultsInterface;
}
12 changes: 12 additions & 0 deletions Api/ExportEntityManagementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
*/
interface ExportEntityManagementInterface
{
/**
* Initialize and save a new export for an entity
*
* @param int $entityId
* @param string $entityType
* @param null|string $fileName [optional]
* @return ExportEntityInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function create(int $entityId, string $entityType, ?string $fileName = null): ExportEntityInterface;

/**
* Export all data related to a given entity to the file
*
Expand Down
66 changes: 66 additions & 0 deletions Api/ExportEntityRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);

namespace Opengento\Gdpr\Api;

use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\SearchResultsInterface;
use Opengento\Gdpr\Api\Data\ExportEntityInterface;

/**
* Interface ExportEntityRepositoryInterface
* @api
*/
interface ExportEntityRepositoryInterface
{
/**
* Save export entity
*
* @param \Opengento\Gdpr\Api\Data\ExportEntityInterface $entity
* @return \Opengento\Gdpr\Api\Data\ExportEntityInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(ExportEntityInterface $entity): ExportEntityInterface;

/**
* Retrieve export entity by ID
*
* @param int $entityId
* @return \Opengento\Gdpr\Api\Data\ExportEntityInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getById(int $entityId): ExportEntityInterface;

/**
* Retrieve export by entity
*
* @param int $entityId
* @param string $entityType
* @return \Opengento\Gdpr\Api\Data\ExportEntityInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getByEntity(int $entityId, string $entityType): ExportEntityInterface;

/**
* Retrieve export entity list by search filter criteria
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Opengento\Gdpr\Api\Data\ExportEntitySearchResultsInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getList(SearchCriteriaInterface $searchCriteria): SearchResultsInterface;

/**
* Delete export entity
*
* @param \Opengento\Gdpr\Api\Data\ExportEntityInterface $entity
* @return bool true on success
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function delete(ExportEntityInterface $entity): bool;
}
2 changes: 1 addition & 1 deletion Console/Command/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
try {
foreach ($entityIds as $entityId) {
$out = $this->exportManagement->export(
new ExportEntity((int) $entityId, $entityType, $fileName . '_' . $entityId)
$this->exportManagement->create((int) $entityId, $entityType, $fileName . '_' . $entityId)
);
$output->writeln('<info>Entity\'s related data have been exported to: ' . $out . '.</info>');
}
Expand Down
13 changes: 2 additions & 11 deletions Controller/Adminhtml/Guest/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Opengento\Gdpr\Controller\Adminhtml\AbstractAction;
use Opengento\Gdpr\Model\Archive\MoveToArchive;
use Opengento\Gdpr\Model\Config;
use Opengento\Gdpr\Model\Export\ExportEntityFactory;

/**
* Class Export
Expand All @@ -41,31 +40,23 @@ class Export extends AbstractAction
*/
private $exportManagement;

/**
* @var \Opengento\Gdpr\Model\Export\ExportEntityFactory
*/
private $exportEntityFactory;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Opengento\Gdpr\Model\Config $config
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
* @param \Opengento\Gdpr\Model\Archive\MoveToArchive $moveToArchive
* @param \Opengento\Gdpr\Api\ExportEntityManagementInterface $exportManagement
* @param \Opengento\Gdpr\Model\Export\ExportEntityFactory $exportEntityFactory
*/
public function __construct(
Context $context,
Config $config,
FileFactory $fileFactory,
MoveToArchive $moveToArchive,
ExportEntityManagementInterface $exportManagement,
ExportEntityFactory $exportEntityFactory
ExportEntityManagementInterface $exportManagement
) {
$this->fileFactory = $fileFactory;
$this->moveToArchive = $moveToArchive;
$this->exportManagement = $exportManagement;
$this->exportEntityFactory = $exportEntityFactory;
parent::__construct($context, $config);
}

Expand All @@ -76,7 +67,7 @@ protected function executeAction()
{
try {
$entityId = (int) $this->getRequest()->getParam('id');
$fileName = $this->exportManagement->export($this->exportEntityFactory->create($entityId));
$fileName = $this->exportManagement->export($this->exportManagement->create($entityId, 'order'));
$archiveFileName = 'guest_privacy_data_' . $entityId . '.zip';

return $this->fileFactory->create(
Expand Down
13 changes: 2 additions & 11 deletions Controller/Adminhtml/Privacy/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Opengento\Gdpr\Controller\Adminhtml\AbstractAction;
use Opengento\Gdpr\Model\Archive\MoveToArchive;
use Opengento\Gdpr\Model\Config;
use Opengento\Gdpr\Model\Export\ExportEntityFactory;

/**
* Class Export
Expand All @@ -41,31 +40,23 @@ class Export extends AbstractAction
*/
private $exportManagement;

/**
* @var \Opengento\Gdpr\Model\Export\ExportEntityFactory
*/
private $exportEntityFactory;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Opengento\Gdpr\Model\Config $config
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
* @param \Opengento\Gdpr\Model\Archive\MoveToArchive $moveToArchive
* @param \Opengento\Gdpr\Api\ExportEntityManagementInterface $exportManagement
* @param \Opengento\Gdpr\Model\Export\ExportEntityFactory $exportEntityFactory
*/
public function __construct(
Context $context,
Config $config,
FileFactory $fileFactory,
MoveToArchive $moveToArchive,
ExportEntityManagementInterface $exportManagement,
ExportEntityFactory $exportEntityFactory
ExportEntityManagementInterface $exportManagement
) {
$this->fileFactory = $fileFactory;
$this->moveToArchive = $moveToArchive;
$this->exportManagement = $exportManagement;
$this->exportEntityFactory = $exportEntityFactory;
parent::__construct($context, $config);
}

Expand All @@ -76,7 +67,7 @@ protected function executeAction()
{
try {
$customerId = (int) $this->getRequest()->getParam('id');
$fileName = $this->exportManagement->export($this->exportEntityFactory->create($customerId));
$fileName = $this->exportManagement->export($this->exportManagement->create($customerId, 'customer'));
$archiveFileName = 'customer_privacy_data_' . $customerId . '.zip';

return $this->fileFactory->create(
Expand Down
Loading

0 comments on commit 91e6330

Please sign in to comment.