Skip to content

Commit

Permalink
Prevents deleting print addresses when doing GDPR removal
Browse files Browse the repository at this point in the history
remp/helpdesk#295
  • Loading branch information
miroc committed Feb 22, 2021
1 parent 05ef3ea commit 27550ae
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddDeletedAtToGdprRemovedAddresses extends AbstractMigration
{
public function up()
{
$sql = <<<SQL
UPDATE addresses SET deleted_at = updated_at
WHERE first_name = 'GDPR removal' AND last_name = 'GDPR removal' AND address = 'GDPR removal'
SQL;
$this->execute($sql);
}

public function down()
{
$this->output->writeln('Down migration is not available.');
}
}
42 changes: 25 additions & 17 deletions src/model/User/AddressesUserDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Crm\UsersModule\User;

use Crm\ApplicationModule\NowTrait;
use Crm\ApplicationModule\User\UserDataProviderInterface;
use Crm\UsersModule\Repository\AddressesRepository;

class AddressesUserDataProvider implements UserDataProviderInterface
{
use NowTrait;

private $addressesRepository;

public function __construct(
Expand All @@ -20,6 +23,26 @@ public static function identifier(): string
return 'addresses';
}

public static function gdprRemovalTemplate($deletedAt)
{
return [
'title' => 'GDPR removal',
'first_name' => 'GDPR removal',
'last_name' => 'GDPR removal',
'address' => 'GDPR removal',
'number' => 'GDPR removal',
'city' => 'GDPR removal',
'zip' => 'GDPR removal',
'country_id' => null,
'company_id' => 'GDPR removal',
'company_tax_id' => 'GDPR removal',
'company_vat_id' => 'GDPR removal',
'company_name' => 'GDPR removal',
'phone_number' => 'GDPR removal',
'deleted_at' => $deletedAt
];
}

public function data($userId)
{
return [];
Expand Down Expand Up @@ -91,24 +114,9 @@ public function delete($userId, $protectedData = [])
}

$addresses = $query->fetchAll();
$GDPRTemplateAddress = [
'title' => 'GDPR removal',
'first_name' => 'GDPR removal',
'last_name' => 'GDPR removal',
'address' => 'GDPR removal',
'number' => 'GDPR removal',
'city' => 'GDPR removal',
'zip' => 'GDPR removal',
'country_id' => null,
'company_id' => 'GDPR removal',
'company_tax_id' => 'GDPR removal',
'company_vat_id' => 'GDPR removal',
'company_name' => 'GDPR removal',
'phone_number' => 'GDPR removal',
];

$gdprRemovalTemplate = self::gdprRemovalTemplate($this->getNow());
foreach ($addresses as $address) {
$this->addressesRepository->update($address, $GDPRTemplateAddress);
$this->addressesRepository->update($address, $gdprRemovalTemplate);
}
}

Expand Down

0 comments on commit 27550ae

Please sign in to comment.