enwikipedia-acc /
waca
| 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\Pages\RequestAction; |
||
| 11 | |||
| 12 | use Waca\Background\Task\WelcomeUserTask; |
||
| 13 | use Waca\DataObjects\JobQueue; |
||
| 14 | use Waca\DataObjects\Request; |
||
| 15 | use Waca\DataObjects\User; |
||
| 16 | use Waca\Exceptions\ApplicationLogicException; |
||
| 17 | use Waca\PdoDatabase; |
||
| 18 | use Waca\Tasks\InternalPageBase; |
||
| 19 | use Waca\WebRequest; |
||
| 20 | |||
| 21 | abstract class RequestActionBase extends InternalPageBase |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @param PdoDatabase $database |
||
| 25 | * |
||
| 26 | * @return Request |
||
| 27 | * @throws ApplicationLogicException |
||
| 28 | */ |
||
| 29 | protected function getRequest(PdoDatabase $database) |
||
| 30 | { |
||
| 31 | $requestId = WebRequest::postInt('request'); |
||
| 32 | if ($requestId === null) { |
||
| 33 | throw new ApplicationLogicException('Request ID not found'); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** @var Request $request */ |
||
| 37 | $request = Request::getById($requestId, $database); |
||
| 38 | |||
| 39 | if ($request === false) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 40 | throw new ApplicationLogicException('Request not found'); |
||
| 41 | } |
||
| 42 | |||
| 43 | return $request; |
||
| 44 | } |
||
| 45 | |||
| 46 | final protected function checkPosted() |
||
| 47 | { |
||
| 48 | // if the request was not posted, send the user away. |
||
| 49 | if (!WebRequest::wasPosted()) { |
||
| 50 | throw new ApplicationLogicException('This page does not support GET methods.'); |
||
| 51 | } |
||
| 52 | |||
| 53 | // validate the CSRF token |
||
| 54 | $this->validateCSRFToken(); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param Request $request |
||
| 59 | * @param $parentTaskId |
||
| 60 | * @param User $user |
||
| 61 | * @param PdoDatabase $database |
||
| 62 | */ |
||
| 63 | protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database) |
||
| 64 | { |
||
| 65 | $welcomeTask = new JobQueue(); |
||
| 66 | $welcomeTask->setDomain(1); // FIXME: domains! |
||
| 67 | $welcomeTask->setTask(WelcomeUserTask::class); |
||
| 68 | $welcomeTask->setRequest($request->getId()); |
||
| 69 | $welcomeTask->setParent($parentTaskId); |
||
| 70 | $welcomeTask->setTriggerUserId($user->getId()); |
||
| 71 | $welcomeTask->setDatabase($database); |
||
| 72 | $welcomeTask->save(); |
||
| 73 | } |
||
| 74 | } |