-
Notifications
You must be signed in to change notification settings - Fork 49
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
Showing
21 changed files
with
514 additions
and
152 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
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,77 @@ | ||
--- | ||
tables: | ||
sylius_address_log_entries: | ||
truncate: true | ||
|
||
sylius_address: | ||
converters: | ||
first_name: | ||
converter: 'randomizeText' | ||
last_name: | ||
converter: 'randomizeText' | ||
phone_number: | ||
converter: 'randomizeNumber' | ||
street: | ||
converter: 'randomizeText' | ||
company: | ||
converter: 'randomizeText' | ||
city: | ||
converter: 'randomizeText' | ||
postcode: | ||
converter: 'randomizeNumber' | ||
|
||
sylius_admin_user: | ||
converters: | ||
username: | ||
converter: 'randomizeText' | ||
unique: true | ||
username_canonical: | ||
converter: 'fromContext' | ||
parameters: | ||
key: 'processed_data.username' | ||
email: | ||
converter: 'randomizeEmail' | ||
unique: true | ||
email_canonical: | ||
converter: 'fromContext' | ||
parameters: | ||
key: 'processed_data.email' | ||
first_name: | ||
converter: 'randomizeText' | ||
last_name: | ||
converter: 'randomizeText' | ||
|
||
sylius_customer: | ||
converters: | ||
email: | ||
converter: 'randomizeEmail' | ||
unique: true | ||
email_canonical: | ||
converter: 'fromContext' | ||
parameters: | ||
key: 'processed_data.email' | ||
first_name: | ||
converter: 'randomizeText' | ||
last_name: | ||
converter: 'randomizeText' | ||
birthday: | ||
converter: 'anonymizeDateTime' | ||
phone_number: | ||
converter: 'randomizeNumber' | ||
|
||
sylius_shop_user: | ||
converters: | ||
username: | ||
converter: 'randomizeText' | ||
unique: true | ||
username_canonical: | ||
converter: 'fromContext' | ||
parameters: | ||
key: 'processed_data.username' | ||
email: | ||
converter: 'randomizeEmail' | ||
unique: true | ||
email_canonical: | ||
converter: 'fromContext' | ||
parameters: | ||
key: 'processed_data.email' |
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
74 changes: 74 additions & 0 deletions
74
src/Config/Compiler/Processor/DefaultSettingsProcessor.php
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,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Smile\GdprDump\Config\Compiler\Processor; | ||
|
||
use Smile\GdprDump\Config\ConfigInterface; | ||
|
||
final class DefaultSettingsProcessor implements ProcessorInterface | ||
{ | ||
public function process(ConfigInterface $config): void | ||
{ | ||
$data = $config->toArray(); | ||
$data += [ | ||
'database' => [], | ||
'dump' => [], | ||
'faker' => [], | ||
'filter_propagation' => [], | ||
'tables_whitelist' => [], | ||
'tables_blacklist' => [], | ||
'tables' => [], | ||
'variables' => [], | ||
]; | ||
|
||
foreach ($this->getDefaultSettings() as $key => $value) { | ||
$data[$key] += $value; | ||
} | ||
|
||
$config->reset($data); | ||
} | ||
|
||
/** | ||
* Get default settings. | ||
*/ | ||
private function getDefaultSettings(): array | ||
{ | ||
return [ | ||
'dump' => [ | ||
'output' => 'php://stdout', | ||
'add_drop_database' => false, | ||
'add_drop_table' => true, // false in MySQLDump-PHP | ||
'add_drop_trigger' => true, | ||
'add_locks' => true, | ||
'complete_insert' => false, | ||
'compress' => 'none', | ||
'default_character_set' => 'utf8', | ||
'disable_keys' => true, | ||
'events' => false, | ||
'extended_insert' => true, | ||
'hex_blob' => false, // true in MySQLDump-PHP | ||
'init_commands' => [], | ||
'insert_ignore' => false, | ||
'lock_tables' => false, // true in MySQLDump-PHP | ||
'net_buffer_length' => 1000000, | ||
'no_autocommit' => true, | ||
'no_create_info' => false, | ||
'routines' => false, | ||
'single_transaction' => true, | ||
'skip_comments' => false, | ||
'skip_definer' => false, | ||
'skip_dump_date' => false, | ||
'skip_triggers' => false, | ||
'skip_tz_utc' => false, | ||
], | ||
'filter_propagation' => [ | ||
'enabled' => true, | ||
'ignored_foreign_keys' => [], | ||
], | ||
'faker' => [ | ||
'locale' => '', | ||
], | ||
]; | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
src/Config/Compiler/Processor/QueryValidationProcessor.php
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Smile\GdprDump\Config\Compiler\Processor; | ||
|
||
use Exception; | ||
use Smile\GdprDump\Config\ConfigException; | ||
use Smile\GdprDump\Config\ConfigInterface; | ||
use Smile\GdprDump\Util\QueryValidator; | ||
|
||
final class QueryValidationProcessor implements ProcessorInterface | ||
{ | ||
/** | ||
* Assert that SQL queries don't include forbidden keywords. | ||
*/ | ||
public function process(ConfigInterface $config): void | ||
{ | ||
try { | ||
$this->validateVarQueries($config); | ||
$this->validateInitCommands($config); | ||
} catch (Exception $e) { | ||
throw new ConfigException($e->getMessage(), $e); | ||
} | ||
} | ||
|
||
/** | ||
* Validate SQL queries found in the "variables" section of the config. | ||
*/ | ||
private function validateVarQueries(ConfigInterface $config): void | ||
{ | ||
$selectQueryValidator = new QueryValidator(['select']); | ||
$varQueries = (array) $config->get('variables'); | ||
|
||
foreach ($varQueries as $query) { | ||
$selectQueryValidator->validate($query); | ||
} | ||
} | ||
|
||
/** | ||
* Validate SQL queries found in the "dump.init_commands" section of the config. | ||
*/ | ||
private function validateInitCommands(ConfigInterface $config): void | ||
{ | ||
$selectQueryValidator = new QueryValidator(['set']); | ||
$dumpSettings = (array) $config->get('dump'); | ||
|
||
foreach ($dumpSettings['init_commands'] as $query) { | ||
$selectQueryValidator->validate($query); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.