-
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
0 parents
commit c385d6e
Showing
17 changed files
with
1,072 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
/* | ||
* Copyright © Ghost Unicorns snc. All rights reserved. | ||
* See LICENSE for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GhostUnicorns\CrtEntity\Api\Data; | ||
|
||
use DateTime; | ||
use Exception; | ||
use Magento\Framework\Api\ExtensibleDataInterface; | ||
use Magento\Framework\DataObject; | ||
|
||
interface EntityInterface extends ExtensibleDataInterface | ||
{ | ||
/** | ||
* @return int | ||
*/ | ||
public function getActivityId(): int; | ||
|
||
/** | ||
* @param int $activityId | ||
* @return void | ||
*/ | ||
public function setActivityId(int $activityId); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string; | ||
|
||
/** | ||
* @param string $type | ||
* @return void | ||
*/ | ||
public function setType(string $type); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getIdentifier(): string; | ||
|
||
/** | ||
* @param string $identifier | ||
* @return void | ||
*/ | ||
public function setIdentifier(string $identifier); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDataOriginal(): string; | ||
|
||
/** | ||
* @param string $value | ||
* @return void | ||
*/ | ||
public function setDataOriginal(string $value); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDataRefined(): string; | ||
|
||
/** | ||
* @param string|null $value | ||
* @return void | ||
*/ | ||
public function setDataRefined(?string $value); | ||
|
||
/** | ||
* @return DataObject | ||
*/ | ||
public function getExtra(): DataObject; | ||
|
||
/** | ||
* @param DataObject $value | ||
* @return void | ||
*/ | ||
public function setExtra(DataObject $value); | ||
|
||
/** | ||
* @param array $value | ||
* @return void | ||
*/ | ||
public function addExtraArray(array $value); | ||
|
||
/** | ||
* @return DateTime | ||
* @throws Exception | ||
*/ | ||
public function getCreatedAt(): DateTime; | ||
|
||
/** | ||
* @return DateTime | ||
* @throws Exception | ||
*/ | ||
public function getUpdatedAt(): DateTime; | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isSkip(): bool; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function skip(); | ||
} |
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,25 @@ | ||
<?php | ||
/* | ||
* Copyright © Ghost Unicorns snc. All rights reserved. | ||
* See LICENSE for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GhostUnicorns\CrtEntity\Api\Data; | ||
|
||
use Magento\Framework\Api\SearchResultsInterface; | ||
|
||
interface EntitySearchResultInterface extends SearchResultsInterface | ||
{ | ||
/** | ||
* @return EntityInterface[] | ||
*/ | ||
public function getItems(); | ||
|
||
/** | ||
* @param EntityInterface[] $items | ||
* @return void | ||
*/ | ||
public function setItems(array $items); | ||
} |
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,98 @@ | ||
<?php | ||
/* | ||
* Copyright © Ghost Unicorns snc. All rights reserved. | ||
* See LICENSE for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GhostUnicorns\CrtEntity\Api; | ||
|
||
use Exception; | ||
use GhostUnicorns\CrtEntity\Api\Data\EntityInterface; | ||
use GhostUnicorns\CrtEntity\Api\Data\EntitySearchResultInterface; | ||
use Magento\Framework\Api\SearchCriteriaInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
|
||
interface EntityRepositoryInterface | ||
{ | ||
/** | ||
* @param int $id | ||
* @return EntityInterface | ||
* @throws NoSuchEntityException | ||
*/ | ||
public function getById(int $id): EntityInterface; | ||
|
||
/** | ||
* @param EntityInterface $entity | ||
* @return EntityInterface | ||
*/ | ||
public function save(EntityInterface $entity); | ||
|
||
/** | ||
* @param EntityInterface $entity | ||
* @return void | ||
*/ | ||
public function delete(EntityInterface $entity); | ||
|
||
/** | ||
* @param SearchCriteriaInterface $searchCriteria | ||
* @return EntitySearchResultInterface | ||
*/ | ||
public function getList(SearchCriteriaInterface $searchCriteria): EntitySearchResultInterface; | ||
|
||
/** | ||
* @param int $activityId | ||
* @return EntityInterface[] | ||
* @throws Exception | ||
*/ | ||
public function getAllByActivityId(int $activityId): array; | ||
|
||
/** | ||
* @param int $activityId | ||
* @param string $identifier | ||
* @return EntityInterface[] | ||
* @throws Exception | ||
*/ | ||
public function getAllByActivityIdAndIdentifier(int $activityId, string $identifier): array; | ||
|
||
/** | ||
* @param int $activityId | ||
* @param string $identifier | ||
* @param string $type | ||
* @return EntityInterface | ||
* @throws Exception | ||
*/ | ||
public function getByActivityIdAndIdentifierAndType( | ||
int $activityId, | ||
string $identifier, | ||
string $type | ||
): EntityInterface; | ||
|
||
/** | ||
* @param int $activityId | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public function getAllByActivityIdGroupedByIdentifier(int $activityId): array; | ||
|
||
/** | ||
* @param int $activityId | ||
* @return array | ||
* @throws Exception | ||
*/ | ||
public function getAllIdentifiersByActivityId(int $activityId): array; | ||
|
||
/** | ||
* @param int $activityId | ||
* @param string $identifier | ||
* @return array | ||
*/ | ||
public function getAllByActivityIdAndIdentifierGroupedByIdentifier(int $activityId, string $identifier): array; | ||
|
||
/** | ||
* @param int $activityId | ||
* @return array | ||
*/ | ||
public function getAllDataRefinedByActivityIdGroupedByIdentifier(int $activityId): array; | ||
} |
Empty file.
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,45 @@ | ||
<?php | ||
/* | ||
* Copyright © Ghost Unicorns snc. All rights reserved. | ||
* See LICENSE for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GhostUnicorns\CrtEntity\Model; | ||
|
||
use Exception; | ||
use GhostUnicorns\CrtEntity\Api\EntityRepositoryInterface; | ||
|
||
class AddExtraDataToEntitiesByActivityId | ||
{ | ||
/** | ||
* @var EntityRepositoryInterface | ||
*/ | ||
private $entityRepository; | ||
|
||
/** | ||
* @param EntityRepositoryInterface $entityRepository | ||
*/ | ||
public function __construct( | ||
EntityRepositoryInterface $entityRepository | ||
) { | ||
$this->entityRepository = $entityRepository; | ||
} | ||
|
||
/** | ||
* @param int $activityId | ||
* @param string $identifier | ||
* @param array $extraData | ||
* @throws Exception | ||
*/ | ||
public function execute(int $activityId, string $identifier, array $extraData) | ||
{ | ||
$entities = $this->entityRepository->getAllByActivityIdAndIdentifier($activityId, $identifier); | ||
|
||
foreach ($entities as $entity) { | ||
$entity->addExtraArray($extraData); | ||
$this->entityRepository->save($entity); | ||
} | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
/* | ||
* Copyright © Ghost Unicorns snc. All rights reserved. | ||
* See LICENSE for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GhostUnicorns\CrtEntity\Model; | ||
|
||
use GhostUnicorns\CrtEntity\Api\EntityRepositoryInterface; | ||
use GhostUnicorns\CrtEntity\Model\ResourceModel\EntityResourceModel; | ||
use Magento\Framework\Exception\AlreadyExistsException; | ||
|
||
class ClearDataRefinedByActivityId | ||
{ | ||
/** | ||
* @var EntityRepositoryInterface | ||
*/ | ||
private EntityRepositoryInterface $entityRepository; | ||
|
||
/** | ||
* @var EntityResourceModel | ||
*/ | ||
private $entityResourceModel; | ||
|
||
/** | ||
* @param EntityRepositoryInterface $entityRepository | ||
* @param EntityResourceModel $entityResourceModel | ||
*/ | ||
public function __construct( | ||
EntityRepositoryInterface $entityRepository, | ||
EntityResourceModel $entityResourceModel | ||
) { | ||
$this->entityRepository = $entityRepository; | ||
$this->entityResourceModel = $entityResourceModel; | ||
} | ||
|
||
/** | ||
* @param int $activityId | ||
* @throws AlreadyExistsException | ||
*/ | ||
public function execute(int $activityId) | ||
{ | ||
$entities = $this->entityRepository->getAllByActivityId($activityId); | ||
foreach ($entities as $entity) { | ||
$entity->setDataRefined(null); | ||
$this->entityResourceModel->save($entity); | ||
} | ||
} | ||
} |
Oops, something went wrong.