|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* Wikipedia Account Creation Assistance tool * |
|
4
|
|
|
* * |
|
5
|
|
|
* All code in this file is released into the public domain by the ACC * |
|
6
|
|
|
* Development Team. Please see team.json for a list of contributors. * |
|
7
|
|
|
******************************************************************************/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Waca\Pages\RequestAction; |
|
10
|
|
|
|
|
11
|
|
|
use DateTime; |
|
12
|
|
|
use Waca\DataObjects\JobQueue; |
|
13
|
|
|
use Waca\DataObjects\RequestQueue; |
|
14
|
|
|
use Waca\DataObjects\User; |
|
15
|
|
|
use Waca\Exceptions\ApplicationLogicException; |
|
16
|
|
|
use Waca\Helpers\Logger; |
|
17
|
|
|
use Waca\Helpers\SearchHelpers\JobQueueSearchHelper; |
|
18
|
|
|
use Waca\RequestStatus; |
|
19
|
|
|
use Waca\SessionAlert; |
|
20
|
|
|
use Waca\WebRequest; |
|
21
|
|
|
|
|
22
|
|
|
class PageDeferRequest extends RequestActionBase |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Main function for this page, when no specific actions are called. |
|
26
|
|
|
* @throws ApplicationLogicException |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function main() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->checkPosted(); |
|
31
|
|
|
$database = $this->getDatabase(); |
|
32
|
|
|
$request = $this->getRequest($database); |
|
33
|
|
|
$currentUser = User::getCurrent($database); |
|
34
|
|
|
|
|
35
|
|
|
$target = WebRequest::postString('target'); |
|
36
|
|
|
|
|
37
|
|
|
// FIXME: domains! |
|
38
|
|
|
$requestQueue = RequestQueue::getByApiName($database, $target, 1); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
if ($requestQueue === false) { |
|
41
|
|
|
throw new ApplicationLogicException('Defer target not valid'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if ($request->getQueue() == $requestQueue->getId() && $request->getStatus() == RequestStatus::OPEN) { |
|
45
|
|
|
SessionAlert::warning('This request is already in the specified queue.'); |
|
46
|
|
|
$this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
47
|
|
|
|
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$closureDate = $request->getClosureDate(); |
|
52
|
|
|
$date = new DateTime(); |
|
53
|
|
|
$date->modify("-7 days"); |
|
54
|
|
|
|
|
55
|
|
|
if ($request->getStatus() == RequestStatus::CLOSED && $closureDate < $date) { |
|
56
|
|
|
if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
57
|
|
|
throw new ApplicationLogicException( |
|
58
|
|
|
"You are not allowed to re-open a request that has been closed for over a week."); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
63
|
|
|
if (!$this->barrierTest('reopenClearedRequest', $currentUser, 'RequestData')) { |
|
64
|
|
|
throw new ApplicationLogicException( |
|
65
|
|
|
"You are not allowed to re-open a request for which the private data has been purged."); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ($request->getStatus() === RequestStatus::JOBQUEUE) { |
|
70
|
|
|
/** @var JobQueue[] $pendingJobs */ |
|
71
|
|
|
$pendingJobs = JobQueueSearchHelper::get($database)->byRequest($request->getId())->statusIn([ |
|
72
|
|
|
JobQueue::STATUS_QUEUED, |
|
73
|
|
|
JobQueue::STATUS_READY, |
|
74
|
|
|
JobQueue::STATUS_WAITING, |
|
75
|
|
|
])->fetch(); |
|
76
|
|
|
|
|
77
|
|
|
foreach ($pendingJobs as $job) { |
|
78
|
|
|
$job->setStatus(JobQueue::STATUS_CANCELLED); |
|
79
|
|
|
$job->setError('Cancelled by request deferral'); |
|
80
|
|
|
$job->save(); |
|
81
|
|
|
|
|
82
|
|
|
Logger::backgroundJobCancelled($database, $job); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$request->setReserved(null); |
|
87
|
|
|
$request->setStatus(RequestStatus::OPEN); |
|
88
|
|
|
$request->setQueue($requestQueue->getId()); |
|
89
|
|
|
$request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
90
|
|
|
$request->save(); |
|
91
|
|
|
|
|
92
|
|
|
Logger::deferRequest($database, $request, $requestQueue->getLogName()); |
|
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
$this->getNotificationHelper()->requestDeferred($request); |
|
95
|
|
|
|
|
96
|
|
|
$deto = htmlentities($requestQueue->getDisplayName(), ENT_COMPAT, 'UTF-8'); |
|
97
|
|
|
SessionAlert::success("Request {$request->getId()} deferred to {$deto}"); |
|
98
|
|
|
|
|
99
|
|
|
$this->redirect(); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|