Skip to content

Commit

Permalink
Fix #92 null pointer exception
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed May 8, 2021
1 parent f3c5dac commit edfc1c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
24 changes: 13 additions & 11 deletions Observer/DeleteExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SearchResultsInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractModel;
use Opengento\Gdpr\Api\Data\ExportEntityInterface;
use Opengento\Gdpr\Api\Data\ExportEntitySearchResultsInterface;
use Opengento\Gdpr\Api\ExportEntityRepositoryInterface;
Expand Down Expand Up @@ -65,27 +65,29 @@ public function __construct(

public function execute(Observer $observer): void
{
/** @var AbstractModel $entity */
/** @var DataObject $entity */
$entity = $observer->getData('data_object');

try {
foreach ($this->fetchExportEntities($entity)->getItems() as $exportEntity) {
$this->exportRepository->delete($exportEntity);
if ($entity instanceof DataObject) {
try {
foreach ($this->fetchExportEntities($entity)->getItems() as $exportEntity) {
$this->exportRepository->delete($exportEntity);
}
} catch (LocalizedException $e) {
$this->logger->error($e->getLogMessage(), $e->getTrace());
} catch (Exception $e) {
$this->logger->error($e->getMessage(), $e->getTrace());
}
} catch (LocalizedException $e) {
$this->logger->error($e->getLogMessage(), $e->getTrace());
} catch (Exception $e) {
$this->logger->error($e->getMessage(), $e->getTrace());
}
}

/**
* @param AbstractModel $entity
* @param DataObject $entity
* @return ExportEntitySearchResultsInterface
* @throws LocalizedException
* @throws Exception
*/
private function fetchExportEntities(AbstractModel $entity): SearchResultsInterface
private function fetchExportEntities(DataObject $entity): SearchResultsInterface
{
$entityTypes = $this->entityTypeResolver->resolve($entity);

Expand Down
8 changes: 4 additions & 4 deletions Observer/InvalidateExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SearchResultsInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\AbstractModel;
use Opengento\Gdpr\Api\Data\ExportEntityInterface;
use Opengento\Gdpr\Api\Data\ExportEntitySearchResultsInterface;
use Opengento\Gdpr\Api\ExportEntityManagementInterface;
Expand Down Expand Up @@ -75,7 +75,7 @@ public function execute(Observer $observer): void
{
$entity = $observer->getData('data_object');

if ($entity instanceof AbstractModel) {
if ($entity instanceof DataObject) {
try {
foreach ($this->fetchExportEntities($entity)->getItems() as $exportEntity) {
$this->exportManagement->invalidate($exportEntity);
Expand All @@ -89,12 +89,12 @@ public function execute(Observer $observer): void
}

/**
* @param AbstractModel $entity
* @param DataObject $entity
* @return ExportEntitySearchResultsInterface
* @throws LocalizedException
* @throws Exception
*/
private function fetchExportEntities(AbstractModel $entity): SearchResultsInterface
private function fetchExportEntities(DataObject $entity): SearchResultsInterface
{
$entityTypes = $this->entityTypeResolver->resolve($entity);

Expand Down

0 comments on commit edfc1c3

Please sign in to comment.