|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* Wikipedia Account Creation Assistance tool * |
|
4
|
|
|
* ACC Development Team. Please see team.json for a list of contributors. * |
|
5
|
|
|
* * |
|
6
|
|
|
* This is free and unencumbered software released into the public domain. * |
|
7
|
|
|
* Please see LICENSE.md for the full licencing statement. * |
|
8
|
|
|
******************************************************************************/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Waca\ConsoleTasks; |
|
11
|
|
|
|
|
12
|
|
|
use Exception; |
|
13
|
|
|
use Waca\Tasks\ConsoleTaskBase; |
|
14
|
|
|
|
|
15
|
|
|
class ClearOldDataTask extends ConsoleTaskBase |
|
16
|
|
|
{ |
|
17
|
|
|
public function execute() |
|
18
|
|
|
{ |
|
19
|
|
|
$dataClearInterval = $this->getSiteConfiguration()->getDataClearInterval(); |
|
20
|
|
|
$database = $this->getDatabase(); |
|
21
|
|
|
|
|
22
|
|
|
$query = $database->prepare(<<<SQL |
|
23
|
|
|
UPDATE request |
|
24
|
|
|
SET ip = :ip, forwardedip = null, email = :mail, useragent = '' |
|
25
|
|
|
WHERE date < DATE_SUB(curdate(), INTERVAL {$dataClearInterval}) |
|
26
|
|
|
AND status = 'Closed'; |
|
27
|
|
|
SQL |
|
28
|
|
|
); |
|
29
|
|
|
|
|
30
|
|
|
$success = $query->execute(array( |
|
31
|
|
|
":ip" => $this->getSiteConfiguration()->getDataClearIp(), |
|
32
|
|
|
":mail" => $this->getSiteConfiguration()->getDataClearEmail(), |
|
33
|
|
|
)); |
|
34
|
|
|
|
|
35
|
|
|
if (!$success) { |
|
36
|
|
|
throw new Exception("Error in transaction 1: Could not clear data."); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$dataQuery = $database->prepare(<<<SQL |
|
40
|
|
|
DELETE rd |
|
41
|
|
|
FROM requestdata rd |
|
42
|
|
|
INNER JOIN request r ON r.id = rd.request |
|
43
|
|
|
WHERE r.date < DATE_SUB(curdate(), INTERVAL {$dataClearInterval}) |
|
44
|
|
|
AND r.status = 'Closed'; |
|
45
|
|
|
SQL |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
$success = $dataQuery->execute(); |
|
49
|
|
|
|
|
50
|
|
|
if (!$success) { |
|
51
|
|
|
throw new Exception("Error in transaction 2: Could not clear data."); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// FIXME: domains! |
|
55
|
|
|
$flaggedCommentsQuery = $database->query(<<<SQL |
|
56
|
|
|
SELECT COUNT(1) FROM comment c INNER JOIN request r ON c.request = r.id WHERE c.flagged = 1 AND r.status = 'Closed' |
|
57
|
|
|
SQL |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
$flaggedCommentsCount = $flaggedCommentsQuery->fetchColumn(); |
|
61
|
|
|
$this->getNotificationHelper()->alertFlaggedComments($flaggedCommentsCount); |
|
62
|
|
|
} |
|
63
|
|
|
} |