Skip to content

Commit

Permalink
Merge branch 'b-7.2.x-create-aggregate-service-OXDEV-8726' into b-7.2…
Browse files Browse the repository at this point in the history
….x-extral-all-user-data-OXDEV-805
  • Loading branch information
Sieg committed Sep 24, 2024
2 parents 4bd0002 + fd1e096 commit 0451423
Show file tree
Hide file tree
Showing 19 changed files with 345 additions and 24 deletions.
15 changes: 15 additions & 0 deletions src/UserData/DataType/ResultFileInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

namespace OxidEsales\GdprOptinModule\UserData\DataType;

interface ResultFileInterface
{
public function getFilename(): string;

public function getContent(): string;
}
32 changes: 32 additions & 0 deletions src/UserData/DataType/TableCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\GdprOptinModule\UserData\DataType;

class TableCollection implements TableCollectionInterface
{
/**
* @param array<string, array<array<string, string>>> $dataCollection
*/
public function __construct(
protected string $collectionName,
protected array $dataCollection
) {
}

public function getCollectionName(): string
{
return $this->collectionName;
}

public function getCollection(): array
{
return $this->dataCollection;
}
}
18 changes: 18 additions & 0 deletions src/UserData/DataType/TableCollectionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

namespace OxidEsales\GdprOptinModule\UserData\DataType;

interface TableCollectionInterface
{
public function getCollectionName(): string;

/**
* @return array<string, array<array<string, string>>>
*/
public function getCollection(): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

declare(strict_types=1);

namespace OxidEsales\GdprOptinModule\UserData\Service;
namespace OxidEsales\GdprOptinModule\UserData\Exception;

interface DataSerializerInterface
class AggregationTypeException extends \Exception
{
public function serialize(array $data): string;
}
7 changes: 7 additions & 0 deletions src/UserData/Infrastructure/DataSelectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@

interface DataSelectorInterface
{
public function getCollection(): string;

public function getSelectionTable(): string;

/**
* @return array<array<string, string>>
*/
public function getDataForColumnValue(string $columnValue): array;
}
13 changes: 12 additions & 1 deletion src/UserData/Infrastructure/GeneralTableDataSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,23 @@
class GeneralTableDataSelector implements DataSelectorInterface
{
public function __construct(
private string $collection,
private string $selectionTable,
private string $filterColumn,
private QueryBuilderFactoryInterface $queryBuilderFactory,
) {
}

public function getCollection(): string
{
return $this->collection;
}

public function getSelectionTable(): string
{
return $this->selectionTable;
}

public function getDataForColumnValue(string $columnValue): array
{
$queryBuilder = $this->queryBuilderFactory->create();
Expand All @@ -30,7 +41,7 @@ public function getDataForColumnValue(string $columnValue): array
->setParameter('filterValue', $columnValue);

/** @var Result $result */
$result = $queryBuilder->execute();
$result = $queryBuilder->execute(); /** @phpstan-ignore missingType.iterableValue */

return $result->fetchAllAssociative();
}
Expand Down
13 changes: 12 additions & 1 deletion src/UserData/Infrastructure/RelatedTableDataSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class RelatedTableDataSelector implements DataSelectorInterface
{
public function __construct(
private string $collection,
private string $primaryTable,
private string $selectionTable,
private string $relationCondition,
Expand All @@ -23,6 +24,16 @@ public function __construct(
) {
}

public function getCollection(): string
{
return $this->collection;
}

public function getSelectionTable(): string
{
return $this->selectionTable;
}

public function getDataForColumnValue(string $columnValue): array
{
$queryBuilder = $this->queryBuilderFactory->create();
Expand All @@ -33,7 +44,7 @@ public function getDataForColumnValue(string $columnValue): array
->setParameter('filterValue', $columnValue);

/** @var Result $result */
$result = $queryBuilder->execute();
$result = $queryBuilder->execute(); /** @phpstan-ignore missingType.iterableValue */

return $result->fetchAllAssociative();
}
Expand Down
54 changes: 54 additions & 0 deletions src/UserData/Service/CollectionAggregationService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\GdprOptinModule\UserData\Service;

use OxidEsales\GdprOptinModule\UserData\DataType\TableCollection;
use OxidEsales\GdprOptinModule\UserData\DataType\TableCollectionInterface;
use OxidEsales\GdprOptinModule\UserData\Exception\AggregationTypeException;
use OxidEsales\GdprOptinModule\UserData\Infrastructure\DataSelectorInterface;

class CollectionAggregationService implements CollectionAggregationServiceInterface
{
/** @var array<string, array<DataSelectorInterface>> */
protected array $groupedCollectors = [];

/**
* @param iterable<Object> $collectors
*/
public function __construct(
iterable $collectors
) {
foreach ($collectors as $collector) {
if (!$collector instanceof DataSelectorInterface) {
throw new AggregationTypeException();
}

$this->groupedCollectors[$collector->getCollection()][] = $collector;
}
}

/**
* @return array<TableCollectionInterface>
*/
public function collectUserData(string $userId): array
{
$resultCollections = [];

foreach ($this->groupedCollectors as $collectionName => $collectors) {
$collectionData = [];
foreach ($collectors as $oneCollector) {
$collectionData[$oneCollector->getSelectionTable()] = $oneCollector->getDataForColumnValue($userId);
}
$resultCollections[] = new TableCollection($collectionName, $collectionData);
}

return $resultCollections;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

namespace OxidEsales\GdprOptinModule\UserData\Service;

interface UserDataAggregationInterface
use OxidEsales\GdprOptinModule\UserData\DataType\TableCollectionInterface;

interface CollectionAggregationServiceInterface
{
/**
* @return array<TableCollectionInterface>
*/
public function collectUserData(string $userId): array;
}
18 changes: 18 additions & 0 deletions src/UserData/Service/CollectionSerializerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\GdprOptinModule\UserData\Service;

use OxidEsales\GdprOptinModule\UserData\DataType\ResultFileInterface;
use OxidEsales\GdprOptinModule\UserData\DataType\TableCollectionInterface;

interface CollectionSerializerInterface
{
public function serializeCollection(TableCollectionInterface $data): ResultFileInterface;
}
15 changes: 0 additions & 15 deletions src/UserData/Service/UserDataCollectorInterface.php

This file was deleted.

5 changes: 5 additions & 0 deletions src/UserData/Service/UserDataExportInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@

interface UserDataExportInterface
{
/**
* collects data from CollectionAggregationService as array of Collections
* iterate through collections and serialize them to ResultFileInterfaces array
* give this array of ResultFileInterfaces to the ZipCreatorInterface
*/
public function exportUserData(string $userId, string $outputPath): void;
}
7 changes: 6 additions & 1 deletion src/UserData/Service/ZipCreatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

namespace OxidEsales\GdprOptinModule\UserData\Service;

use OxidEsales\GdprOptinModule\UserData\DataType\ResultFileInterface;

interface ZipCreatorInterface
{
public function createZip(array $files, string $outputPath): string;
/**
* @param array<ResultFileInterface> $files
*/
public function createZip(array $files, string $outputFilePath): void;
}
Loading

0 comments on commit 0451423

Please sign in to comment.