Skip to content
This repository was archived by the owner on Nov 6, 2021. It is now read-only.

Commit afbe696

Browse files
author
Florian Horn
committed
Extended backup UI in administration area to allow exporting database dump matchin GDPR compliance
1 parent 8c5bfd5 commit afbe696

File tree

15 files changed

+270
-0
lines changed

15 files changed

+270
-0
lines changed

Block/Adminhtml/Backup.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* This file is part of the Content Fuzzyfyr module for Magento2.
4+
*
5+
* (c) All.In Data GmbH
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace AllInData\ContentFuzzyfyr\Block\Adminhtml;
12+
13+
use Magento\Backend\Block\AbstractBlock;
14+
15+
/**
16+
* Class Backup
17+
* @package AllInData\ContentFuzzyfyr\Block\Adminhtml
18+
*/
19+
class Backup extends \Magento\Backup\Block\Adminhtml\Backup
20+
{
21+
/**
22+
* @return AbstractBlock|void
23+
*/
24+
protected function _prepareLayout()
25+
{
26+
parent::_prepareLayout();
27+
28+
$this->getToolbar()->addChild(
29+
'createGdprConformDatabaseBackupButton',
30+
\Magento\Backend\Block\Widget\Button::class,
31+
[
32+
'label' => __('GDPR conform Database Backup (Content Fuzzyfyr)'),
33+
'onclick' => "return backup.backup('" . \AllInData\ContentFuzzyfyr\Model\Backup\Factory::TYPE_GDPR_DB . "')",
34+
'class' => 'task primary aid-content-export'
35+
]
36+
);
37+
}
38+
}

Handler/Backup/DatabaseHandler.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* This file is part of the Content Fuzzyfyr module for Magento2.
4+
*
5+
* (c) All.In Data GmbH
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace AllInData\ContentFuzzyfyr\Handler\Backup;
12+
13+
use AllInData\ContentFuzzyfyr\Console\Command\ExportCommand;
14+
use AllInData\ContentFuzzyfyr\Handler\BackupHandler;
15+
use Magento\Framework\Backup\Db\BackupFactory;
16+
use Magento\Framework\EntityManager\EventManager;
17+
use AllInData\ContentFuzzyfyr\Model\Configuration;
18+
use AllInData\ContentFuzzyfyr\Model\ConfigurationFactory;
19+
20+
/**
21+
* Class Db
22+
* @package AllInData\ContentFuzzyfyr\Handler\Backup
23+
*/
24+
class DatabaseHandler extends \Magento\Framework\Backup\Db
25+
{
26+
/**
27+
* @var EventManager
28+
*/
29+
private $eventManager;
30+
/**
31+
* @var ConfigurationFactory
32+
*/
33+
private $configurationFactory;
34+
/**
35+
* @var BackupHandler
36+
*/
37+
private $backupHandler;
38+
39+
/**
40+
* DatabaseHandler constructor.
41+
* @param BackupFactory $backupFactory
42+
* @param EventManager $eventManager
43+
* @param ConfigurationFactory $configurationFactory
44+
* @param BackupHandler $backupHandler
45+
*/
46+
public function __construct(
47+
BackupFactory $backupFactory,
48+
EventManager $eventManager,
49+
ConfigurationFactory $configurationFactory,
50+
BackupHandler $backupHandler
51+
) {
52+
parent::__construct($backupFactory);
53+
54+
$this->eventManager = $eventManager;
55+
$this->configurationFactory = $configurationFactory;
56+
$this->backupHandler = $backupHandler;
57+
}
58+
59+
/**
60+
* {@inheritdoc}
61+
*/
62+
public function create()
63+
{
64+
/*
65+
* Processing
66+
*/
67+
$this->backupHandler->beginTransaction();
68+
69+
try {
70+
$this->eventManager->dispatch(ExportCommand::EVENT_NAME, [
71+
'configuration' => $this->loadConfiguration()
72+
]);
73+
74+
if (!parent::create()) {
75+
throw new \RuntimeException('Failed to create database backup');
76+
}
77+
} catch (\Exception $e) {
78+
$this->backupHandler->endTransaction();
79+
return ExportCommand::ERROR_EXPORT_FAILED;
80+
}
81+
82+
$this->backupHandler->endTransaction();
83+
84+
return true;
85+
}
86+
87+
/**
88+
* Add path that should be ignoring when creating or rolling back backup
89+
*
90+
* @param string|array $paths
91+
* @return $this
92+
*/
93+
public function addIgnorePaths($paths)
94+
{
95+
return $this;
96+
}
97+
98+
/**
99+
* @return Configuration
100+
*/
101+
protected function loadConfiguration()
102+
{
103+
$configuration = $this->configurationFactory->create();
104+
// --- Flags
105+
$configuration->setApplyToUsers(true);
106+
$configuration->setApplyToCustomers(true);
107+
// --- Options
108+
$configuration->setDummyContentText(ExportCommand::DEFAULT_DUMMY_CONTENT_TEXT);
109+
$configuration->setDummyContentEmail(ExportCommand::DEFAULT_DUMMY_CONTENT_EMAIL);
110+
$configuration->setDummyContentUrl(ExportCommand::DEFAULT_DUMMY_CONTENT_URL);
111+
$configuration->setDummyPhoneNumber(ExportCommand::DEFAULT_DUMMY_CONTENT_PHONE);
112+
113+
return $configuration;
114+
}
115+
}

Model/Backup/Factory.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* This file is part of the Content Fuzzyfyr module for Magento2.
4+
*
5+
* (c) All.In Data GmbH
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace AllInData\ContentFuzzyfyr\Model\Backup;
12+
13+
use AllInData\ContentFuzzyfyr\Handler\Backup\DatabaseHandler;
14+
use Magento\Framework\Backup\BackupInterface;
15+
16+
/**
17+
* Class Factory
18+
* @package AllInData\ContentFuzzyfyr\Model\Backup
19+
*/
20+
class Factory extends \Magento\Framework\Backup\Factory
21+
{
22+
/*
23+
* Types
24+
*/
25+
const TYPE_GDPR_DB = 'aid_content_export_db';
26+
27+
/**
28+
* @var DatabaseHandler
29+
*/
30+
protected $dbBackupHandler;
31+
32+
/**
33+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
34+
* @param DatabaseHandler $dbBackupHandler
35+
*/
36+
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, DatabaseHandler $dbBackupHandler)
37+
{
38+
parent::__construct($objectManager);
39+
40+
$this->_allowedTypes = array_merge($this->_allowedTypes, [
41+
self::TYPE_GDPR_DB
42+
]);
43+
44+
$this->dbBackupHandler = $dbBackupHandler;
45+
}
46+
47+
/**
48+
* Create new backup instance
49+
*
50+
* @param string $type
51+
* @return BackupInterface
52+
* @throws \Magento\Framework\Exception\LocalizedException
53+
*/
54+
public function create($type)
55+
{
56+
switch ($type) {
57+
case self::TYPE_GDPR_DB:
58+
return $this->dbBackupHandler;
59+
}
60+
61+
return parent::create($type);
62+
}
63+
}

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,30 @@ in the *Observer* data:
134134

135135
'configuration' => \AllInData\ContentFuzzyfyr\Model\Configuration
136136

137+
138+
### Administration
139+
#### Content Export
140+
141+
The **Content Fuzzyfyr** Module for *Magento® 2* extends the *Magento® 2* administration backup area with an additional
142+
option to trigger the export of a GDPR compliant database dump. The database dump will have fuzzyfied customers and user
143+
data.
144+
145+
Navigate through the main navigation and selecting *System > Backup*:
146+
147+
![alt text](./resources/aid-content-fuzzyfyr-export-1.png "Dashboard - Menu - Backup")
148+
149+
The backup area is extended by the new button *GDPR conform Database Backup (Content Fuzzyfyr)*:
150+
151+
![alt text](./resources/aid-content-fuzzyfyr-export-2.png "Extended backup area")
152+
153+
By clicking on this button, a wizard is opened to configure the backup - mainly the name of the backup file:
154+
155+
![alt text](./resources/aid-content-fuzzyfyr-export-3.png "Backup wizard")
156+
157+
If the wizard is confirmed, the GDPR compliant backup will be created and visibile in the existing backup list:
158+
159+
![alt text](./resources/aid-content-fuzzyfyr-export-4.png "GDPR compliant backup")
160+
137161
## Contribution
138162
Feel free to contribute to this module by reporting issues or create some pull requests for improvements.
139163

build.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,15 @@ fi
391391
info "Prepare important files"
392392
cp -pPR "${SRC}/Api" "${TMP}/Api"
393393
cp -pPR "${SRC}/assets" "${TMP}/assets"
394+
cp -pPR "${SRC}/Block" "${TMP}/Block"
394395
cp -pPR "${SRC}/Console" "${TMP}/Console"
395396
cp -pPR "${SRC}/docs" "${TMP}/docs"
396397
cp -pPR "${SRC}/etc" "${TMP}/etc"
397398
cp -pPR "${SRC}/Handler" "${TMP}/Handler"
399+
cp -pPR "${SRC}/i18n" "${TMP}/i18n"
398400
cp -pPR "${SRC}/Model" "${TMP}/Model"
399401
cp -pPR "${SRC}/Observer" "${TMP}/Observer"
402+
cp -pPR "${SRC}/resources" "${TMP}/resources"
400403
cp -pP "${SRC}/Changelog.md" "${TMP}/Changelog.md"
401404
cp -pP "${SRC}/composer.json" "${TMP}/composer.json"
402405
cp -pP "${SRC}/composer.lock" "${TMP}/composer.lock"

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ services:
1717
- ~/.composer:/var/www/.composer:delegated
1818
- ./Api:/var/www/html/app/code/AllInData/ContentFuzzyfyr/Api:cached
1919
- ./assets:/var/www/html/app/code/AllInData/ContentFuzzyfyr/assets:cached
20+
- ./Block:/var/www/html/app/code/AllInData/ContentFuzzyfyr/Block:cached
2021
- ./Console:/var/www/html/app/code/AllInData/ContentFuzzyfyr/Console:cached
2122
- ./etc:/var/www/html/app/code/AllInData/ContentFuzzyfyr/etc
2223
- ./Handler:/var/www/html/app/code/AllInData/ContentFuzzyfyr/Handler:cached
24+
- ./i18n:/var/www/html/app/code/AllInData/ContentFuzzyfyr/i18n:cached
2325
- ./Model:/var/www/html/app/code/AllInData/ContentFuzzyfyr/Model:cached
2426
- ./Observer:/var/www/html/app/code/AllInData/ContentFuzzyfyr/Observer:cached
2527
- ./Test:/var/www/html/app/code/AllInData/ContentFuzzyfyr/Test:cached

etc/adminhtml/di.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* This file is part of the Content Fuzzyfyr module for Magento2.
5+
*
6+
* (c) All.In Data GmbH
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
-->
12+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
13+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
14+
15+
<preference for="Magento\Backup\Block\Adminhtml\Backup"
16+
type="AllInData\ContentFuzzyfyr\Block\Adminhtml\Backup"/>
17+
18+
<preference for="Magento\Framework\Backup\Factory"
19+
type="AllInData\ContentFuzzyfyr\Model\Backup\Factory"/>
20+
21+
</config>

etc/module.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
1414
<module name="AllInData_ContentFuzzyfyr" setup_version="1.4.0">
1515
<sequence>
16+
<module name="Magento_Backup"/>
1617
<module name="Magento_Catalog"/>
1718
<module name="Magento_Cms"/>
1819
<module name="Magento_Customer"/>

i18n/de_DE.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"GDPR conform Database Backup (Content Fuzzyfyr)","DSGVO-konformes Datenbank-Backup (Content Fuzzyfyr)"

i18n/en_GB.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"GDPR conform Database Backup (Content Fuzzyfyr)","GDPR conform Database Backup (Content Fuzzyfyr)"

0 commit comments

Comments
 (0)