|
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 Exception; |
|
12
|
|
|
use Waca\DataObjects\User; |
|
13
|
|
|
use Waca\Exceptions\ApplicationLogicException; |
|
14
|
|
|
use Waca\Helpers\Logger; |
|
15
|
|
|
use Waca\SessionAlert; |
|
16
|
|
|
use Waca\WebRequest; |
|
17
|
|
|
|
|
18
|
|
|
class PageSendToUser extends RequestActionBase |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Main function for this page, when no specific actions are called. |
|
22
|
|
|
* @throws ApplicationLogicException |
|
23
|
|
|
* @throws Exception |
|
24
|
|
|
*/ |
|
|
|
|
|
|
25
|
|
|
protected function main() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->checkPosted(); |
|
28
|
|
|
$database = $this->getDatabase(); |
|
29
|
|
|
$request = $this->getRequest($database); |
|
30
|
|
|
|
|
31
|
|
|
if ($request->getReserved() !== User::getCurrent($database)->getId()) { |
|
32
|
|
|
throw new ApplicationLogicException('You don\'t have this request reserved!'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$username = WebRequest::postString('user'); |
|
36
|
|
|
if ($username === null) { |
|
37
|
|
|
throw new ApplicationLogicException('User must be specified'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$user = User::getByUsername($username, $database); |
|
41
|
|
|
if ($user === false) { |
|
42
|
|
|
throw new ApplicationLogicException('User not found'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if (!$user->isActive()) { |
|
46
|
|
|
throw new ApplicationLogicException('User is currently not active on the tool'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$request->setReserved($user->getId()); |
|
50
|
|
|
$request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
51
|
|
|
$request->save(); |
|
52
|
|
|
|
|
53
|
|
|
Logger::sendReservation($database, $request, $user); |
|
54
|
|
|
$this->getNotificationHelper()->requestReservationSent($request, $user); |
|
55
|
|
|
SessionAlert::success("Reservation sent successfully"); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
58
|
|
|
} |
|
|
|
|
|
|
59
|
|
|
} |
|
|
|
|
|
|
60
|
|
|
|