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
ac21544
commit 81e65d3
Showing
12 changed files
with
217 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\Gdpr\Controller\Adminhtml\Privacy; | ||
|
||
use Magento\Backend\App\Action\Context; | ||
use Magento\Customer\Controller\Adminhtml\Index\AbstractMassAction; | ||
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory; | ||
use Magento\Eav\Model\Entity\Collection\AbstractCollection; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Phrase; | ||
use Magento\Ui\Component\MassAction\Filter; | ||
use Opengento\Gdpr\Api\EraseCustomerManagementInterface; | ||
|
||
/** | ||
* Class MassErase | ||
*/ | ||
class MassErase extends AbstractMassAction | ||
{ | ||
/** | ||
* @var \Opengento\Gdpr\Api\EraseCustomerManagementInterface | ||
*/ | ||
private $eraseCustomerManagement; | ||
|
||
/** | ||
* @param \Magento\Backend\App\Action\Context $context | ||
* @param \Magento\Ui\Component\MassAction\Filter $filter | ||
* @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $collectionFactory | ||
* @param \Opengento\Gdpr\Api\EraseCustomerManagementInterface $eraseCustomerManagement | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Filter $filter, | ||
CollectionFactory $collectionFactory, | ||
EraseCustomerManagementInterface $eraseCustomerManagement | ||
) { | ||
$this->eraseCustomerManagement = $eraseCustomerManagement; | ||
parent::__construct($context, $filter, $collectionFactory); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function massAction(AbstractCollection $collection) | ||
{ | ||
$customerErased = 0; | ||
|
||
foreach ($collection->getAllIds() as $customerId) { | ||
try { | ||
$this->eraseCustomerManagement->process($this->eraseCustomerManagement->create((int) $customerId)); | ||
$customerErased++; | ||
} catch (LocalizedException $e) { | ||
$this->messageManager->addErrorMessage( | ||
new Phrase('Customer with id "%1": %2', [$customerId, $e->getMessage()]) | ||
); | ||
} catch (\Exception $e) { | ||
$this->messageManager->addExceptionMessage($e, new Phrase('An error occurred on the server.')); | ||
} | ||
} | ||
|
||
if ($customerErased) { | ||
$this->messageManager->addSuccessMessage( | ||
new Phrase('A total of %1 record(s) were erased.', [$customerErased]) | ||
); | ||
} | ||
|
||
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ | ||
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); | ||
$resultRedirect->setPath('customer/index/index'); | ||
|
||
return $resultRedirect; | ||
} | ||
} |
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,14 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> | ||
<router id="admin"> | ||
<route id="customer"> | ||
<module name="Opengento_Gdpr" after="Magento_Customer"/> | ||
</route> | ||
</router> | ||
</config> |
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,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
--> | ||
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> | ||
<listingToolbar name="listing_top"> | ||
<massaction name="listing_massaction"> | ||
<action name="erase"> | ||
<settings> | ||
<confirm> | ||
<message translate="true">Are you sure you want to erase the selected customers?</message> | ||
<title translate="true">Erase items</title> | ||
</confirm> | ||
<url path="customer/privacy/massErase"/> | ||
<type>erase</type> | ||
<label translate="true">Erase (GDPR)</label> | ||
</settings> | ||
</action> | ||
</massaction> | ||
</listingToolbar> | ||
</listing> |