Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
AnonymizeStatisticDataByCron
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
 startAnonymizing
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace BO\Zmsdb\Helper;
4
5use BO\Zmsdb\ProcessStatusArchived;
6use BO\Zmsdb\Config as ConfigRepository;
7
8class AnonymizeStatisticDataByCron
9{
10    protected $verbose = false;
11
12    protected $timespan = '-90 days';
13
14    public function __construct($verbose = false)
15    {
16        $this->verbose = $verbose;
17
18        // Fetching the configuration setting
19        $config = (new ConfigRepository())->readEntity();
20
21        // Extracting the retention setting and converting it to an integer
22        $retentionSetting = explode(',', $config->getPreference('buergerarchiv', 'setRetentionPeriodDays'));
23        if ($retentionSetting[0] !== "none") {
24            // Ensure it's a positive integer and assign it to timespan
25            print("Using retention period set in admin system config {$retentionSetting[0]} days.\n\n");
26            $this->timespan = (int)$retentionSetting[0];
27        } else {
28            // Default to 90 days if the setting is not set or not numeric
29            print("Using default retention period 90 days.\n\n");
30            $this->timespan = 90;
31        }
32    }
33
34    public function startAnonymizing(\DateTimeImmutable $currentDate, $commit = false)
35    {
36        // Adjust the currentDate based on the numeric timespan
37        $targetDate = $currentDate->modify("-{$this->timespan} days");
38        print("Beginning anonymization for entries older than {$targetDate->format('Y-m-d')}.\n\n");
39
40        if ($commit) {
41            $processStatusArchived = new ProcessStatusArchived();
42            $success = $processStatusArchived->anonymizeNames($targetDate);
43            if ($success) {
44                print("Anonymization process completed successfully.\n\n");
45            } else {
46                print("An error occurred during the anonymization process.\n\n");
47            }
48        } else {
49            print("Dry run mode - no changes have been made to the database.\n\n");
50        }
51    }
52}