blob: 7a1e908bf68a8e80c9c8a9d77dc898c4e962e7bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\PrivacyManager;
use Piwik\Plugins\PrivacyManager\Model\DataSubjects;
use Piwik\Plugins\PrivacyManager\Model\LogDataAnonymizations;
use Piwik\Plugins\SitesManager\API as SitesManagerAPI;
class Tasks extends \Piwik\Plugin\Tasks
{
/**
* @var LogDataAnonymizations
*/
private $logDataAnonymizations;
/**
* @var DataSubjects
*/
private $dataSubjects;
/**
* @var SitesManagerAPI
*/
private $sitesManagerAPI;
public function __construct(LogDataAnonymizations $logDataAnonymizations, DataSubjects $dataSubjects, SitesManagerAPI $sitesManagerAPI)
{
$this->logDataAnonymizations = $logDataAnonymizations;
$this->dataSubjects = $dataSubjects;
$this->sitesManagerAPI = $sitesManagerAPI;
}
public function schedule()
{
$this->daily('deleteReportData', null, self::LOW_PRIORITY);
$this->hourly('deleteLogData', null, self::LOW_PRIORITY);
$this->hourly('anonymizePastData', null, self::LOW_PRIORITY);
$this->weekly('deleteLogDataForDeletedSites', null, self::LOW_PRIORITY);
}
public function anonymizePastData()
{
$loop = 0;
do {
$loop++; // safety loop...
$id = $this->logDataAnonymizations->getNextScheduledAnonymizationId();
if (!empty($id)) {
$this->logDataAnonymizations->executeScheduledEntry($id);
}
} while (!empty($id) && $loop < 100);
}
public function deleteReportData()
{
$privacyManager = new PrivacyManager();
$privacyManager->deleteReportData();
}
/**
* To test execute the following command:
* `./console core:run-scheduled-tasks "Piwik\Plugins\PrivacyManager\Tasks.deleteLogData"`
*/
public function deleteLogData()
{
$privacyManager = new PrivacyManager();
$privacyManager->deleteLogData();
}
public function deleteLogDataForDeletedSites()
{
$allSiteIds = $this->sitesManagerAPI->getAllSitesId();
$this->dataSubjects->deleteDataSubjectsForDeletedSites($allSiteIds);
}
}
|