@@ -12,98 +12,98 @@ |
||
12 | 12 | |
13 | 13 | class ValidationError |
14 | 14 | { |
15 | - const NAME_EMPTY = "name_empty"; |
|
16 | - const NAME_EXISTS = "name_exists"; |
|
17 | - const NAME_EXISTS_SUL = "name_exists_sul"; |
|
18 | - const NAME_NUMONLY = "name_numonly"; |
|
19 | - const NAME_INVALIDCHAR = "name_invalidchar"; |
|
20 | - const NAME_SANITISED = "name_sanitised"; |
|
21 | - const EMAIL_EMPTY = "email_empty"; |
|
22 | - const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
23 | - const EMAIL_INVALID = "email_invalid"; |
|
24 | - const EMAIL_MISMATCH = "email_mismatch"; |
|
25 | - const OPEN_REQUEST_NAME = "open_request_name"; |
|
26 | - const BANNED = "banned"; |
|
27 | - const BANNED_TOR = "banned_tor"; |
|
28 | - /** |
|
29 | - * @var array Error text for the above |
|
30 | - */ |
|
31 | - private static $errorText = array( |
|
32 | - self::NAME_EMPTY => 'You\'ve not chosen a username!', |
|
33 | - self::NAME_EXISTS => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
34 | - . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
35 | - . '[[User:example]] would become [[User:Example]].', |
|
36 | - self::NAME_EXISTS_SUL => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
37 | - . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
38 | - . '[[User:example]] would become [[User:Example]].', |
|
39 | - self::NAME_NUMONLY => 'The username you chose is invalid: it consists entirely of numbers. Please retry ' |
|
40 | - . 'with a valid username.', |
|
41 | - self::NAME_INVALIDCHAR => 'There appears to be an invalid character in your username. Please note that the ' |
|
42 | - . 'following characters are not allowed: <code># @ / < > [ ] | { }</code>', |
|
43 | - self::NAME_SANITISED => 'Your requested username has been automatically adjusted due to technical ' |
|
44 | - . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.', |
|
45 | - self::EMAIL_EMPTY => 'You need to supply an email address.', |
|
46 | - self::EMAIL_WIKIMEDIA => 'Please provide your email address here.', |
|
47 | - self::EMAIL_INVALID => 'Invalid E-mail address supplied. Please check you entered it correctly.', |
|
48 | - self::EMAIL_MISMATCH => 'The email addresses you entered do not match. Please try again.', |
|
49 | - self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.', |
|
50 | - self::BANNED => 'Sorry, you are currently banned from requesting accounts using this tool.', |
|
51 | - self::BANNED_TOR => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. ' |
|
52 | - . 'Please note that Tor is also currently banned from editing Wikipedia.', |
|
53 | - ); |
|
54 | - /** |
|
55 | - * Summary of $errorCode |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - private $errorCode; |
|
59 | - /** |
|
60 | - * Summary of $isError |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - private $isError; |
|
15 | + const NAME_EMPTY = "name_empty"; |
|
16 | + const NAME_EXISTS = "name_exists"; |
|
17 | + const NAME_EXISTS_SUL = "name_exists_sul"; |
|
18 | + const NAME_NUMONLY = "name_numonly"; |
|
19 | + const NAME_INVALIDCHAR = "name_invalidchar"; |
|
20 | + const NAME_SANITISED = "name_sanitised"; |
|
21 | + const EMAIL_EMPTY = "email_empty"; |
|
22 | + const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
23 | + const EMAIL_INVALID = "email_invalid"; |
|
24 | + const EMAIL_MISMATCH = "email_mismatch"; |
|
25 | + const OPEN_REQUEST_NAME = "open_request_name"; |
|
26 | + const BANNED = "banned"; |
|
27 | + const BANNED_TOR = "banned_tor"; |
|
28 | + /** |
|
29 | + * @var array Error text for the above |
|
30 | + */ |
|
31 | + private static $errorText = array( |
|
32 | + self::NAME_EMPTY => 'You\'ve not chosen a username!', |
|
33 | + self::NAME_EXISTS => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
34 | + . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
35 | + . '[[User:example]] would become [[User:Example]].', |
|
36 | + self::NAME_EXISTS_SUL => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
37 | + . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
38 | + . '[[User:example]] would become [[User:Example]].', |
|
39 | + self::NAME_NUMONLY => 'The username you chose is invalid: it consists entirely of numbers. Please retry ' |
|
40 | + . 'with a valid username.', |
|
41 | + self::NAME_INVALIDCHAR => 'There appears to be an invalid character in your username. Please note that the ' |
|
42 | + . 'following characters are not allowed: <code># @ / < > [ ] | { }</code>', |
|
43 | + self::NAME_SANITISED => 'Your requested username has been automatically adjusted due to technical ' |
|
44 | + . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.', |
|
45 | + self::EMAIL_EMPTY => 'You need to supply an email address.', |
|
46 | + self::EMAIL_WIKIMEDIA => 'Please provide your email address here.', |
|
47 | + self::EMAIL_INVALID => 'Invalid E-mail address supplied. Please check you entered it correctly.', |
|
48 | + self::EMAIL_MISMATCH => 'The email addresses you entered do not match. Please try again.', |
|
49 | + self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.', |
|
50 | + self::BANNED => 'Sorry, you are currently banned from requesting accounts using this tool.', |
|
51 | + self::BANNED_TOR => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. ' |
|
52 | + . 'Please note that Tor is also currently banned from editing Wikipedia.', |
|
53 | + ); |
|
54 | + /** |
|
55 | + * Summary of $errorCode |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + private $errorCode; |
|
59 | + /** |
|
60 | + * Summary of $isError |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + private $isError; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Summary of __construct |
|
67 | - * |
|
68 | - * @param string $errorCode |
|
69 | - * @param bool $isError |
|
70 | - */ |
|
71 | - public function __construct($errorCode, $isError = true) |
|
72 | - { |
|
73 | - $this->errorCode = $errorCode; |
|
74 | - $this->isError = $isError; |
|
75 | - } |
|
65 | + /** |
|
66 | + * Summary of __construct |
|
67 | + * |
|
68 | + * @param string $errorCode |
|
69 | + * @param bool $isError |
|
70 | + */ |
|
71 | + public function __construct($errorCode, $isError = true) |
|
72 | + { |
|
73 | + $this->errorCode = $errorCode; |
|
74 | + $this->isError = $isError; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Summary of getErrorCode |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getErrorCode() |
|
82 | - { |
|
83 | - return $this->errorCode; |
|
84 | - } |
|
77 | + /** |
|
78 | + * Summary of getErrorCode |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getErrorCode() |
|
82 | + { |
|
83 | + return $this->errorCode; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @return string |
|
88 | - * @throws Exception |
|
89 | - */ |
|
90 | - public function getErrorMessage() |
|
91 | - { |
|
92 | - $text = self::$errorText[$this->errorCode]; |
|
86 | + /** |
|
87 | + * @return string |
|
88 | + * @throws Exception |
|
89 | + */ |
|
90 | + public function getErrorMessage() |
|
91 | + { |
|
92 | + $text = self::$errorText[$this->errorCode]; |
|
93 | 93 | |
94 | - if ($text == null) { |
|
95 | - throw new Exception('Unknown validation error'); |
|
96 | - } |
|
94 | + if ($text == null) { |
|
95 | + throw new Exception('Unknown validation error'); |
|
96 | + } |
|
97 | 97 | |
98 | - return $text; |
|
99 | - } |
|
98 | + return $text; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Summary of isError |
|
103 | - * @return bool |
|
104 | - */ |
|
105 | - public function isError() |
|
106 | - { |
|
107 | - return $this->isError; |
|
108 | - } |
|
101 | + /** |
|
102 | + * Summary of isError |
|
103 | + * @return bool |
|
104 | + */ |
|
105 | + public function isError() |
|
106 | + { |
|
107 | + return $this->isError; |
|
108 | + } |
|
109 | 109 | } |
@@ -20,73 +20,73 @@ |
||
20 | 20 | |
21 | 21 | class WelcomeUserTask extends BackgroundTaskBase |
22 | 22 | { |
23 | - public static function enqueue(User $triggerUser, Request $request, PdoDatabase $database) |
|
24 | - { |
|
25 | - $job = new JobQueue(); |
|
26 | - $job->setDatabase($database); |
|
27 | - $job->setTask(WelcomeUserTask::class); |
|
28 | - $job->setRequest($request->getId()); |
|
29 | - $job->setTriggerUserId($triggerUser->getId()); |
|
30 | - $job->save(); |
|
31 | - } |
|
32 | - |
|
33 | - public function execute() |
|
34 | - { |
|
35 | - $database = $this->getDatabase(); |
|
36 | - $request = $this->getRequest(); |
|
37 | - $user = $this->getTriggerUser(); |
|
38 | - |
|
39 | - if ($user->getWelcomeTemplate() === null) { |
|
40 | - $this->markFailed('Welcome template not specified'); |
|
41 | - |
|
42 | - return; |
|
43 | - } |
|
44 | - |
|
45 | - /** @var WelcomeTemplate $template */ |
|
46 | - $template = WelcomeTemplate::getById($user->getWelcomeTemplate(), $database); |
|
47 | - |
|
48 | - if ($template === false) { |
|
49 | - $this->markFailed('Welcome template missing'); |
|
50 | - |
|
51 | - return; |
|
52 | - } |
|
53 | - |
|
54 | - $oauth = new OAuthUserHelper($user, $database, $this->getOauthProtocolHelper(), |
|
55 | - $this->getSiteConfiguration()); |
|
56 | - $mediaWikiHelper = new MediaWikiHelper($oauth, $this->getSiteConfiguration()); |
|
57 | - |
|
58 | - if ($request->getStatus() !== RequestStatus::CLOSED) { |
|
59 | - $this->markFailed('Request is currently open'); |
|
60 | - |
|
61 | - return; |
|
62 | - } |
|
63 | - |
|
64 | - if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
65 | - $this->markFailed('Account does not exist!'); |
|
66 | - |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - $this->performWelcome($template, $request, $mediaWikiHelper); |
|
71 | - $this->markComplete(); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Performs the welcome |
|
76 | - * |
|
77 | - * @param WelcomeTemplate $template |
|
78 | - * @param Request $request |
|
79 | - * @param MediaWikiHelper $mediaWikiHelper |
|
80 | - */ |
|
81 | - private function performWelcome( |
|
82 | - WelcomeTemplate $template, |
|
83 | - Request $request, |
|
84 | - MediaWikiHelper $mediaWikiHelper |
|
85 | - ) { |
|
86 | - $templateText = $template->getBotCode(); |
|
87 | - $templateText = str_replace('$signature', '~~~~', $templateText); |
|
88 | - $templateText = str_replace('$username', $request->getName(), $templateText); |
|
89 | - |
|
90 | - $mediaWikiHelper->addTalkPageMessage($request->getName(), 'Welcome!', 'Welcoming user created through [[WP:ACC]]', $templateText); |
|
91 | - } |
|
23 | + public static function enqueue(User $triggerUser, Request $request, PdoDatabase $database) |
|
24 | + { |
|
25 | + $job = new JobQueue(); |
|
26 | + $job->setDatabase($database); |
|
27 | + $job->setTask(WelcomeUserTask::class); |
|
28 | + $job->setRequest($request->getId()); |
|
29 | + $job->setTriggerUserId($triggerUser->getId()); |
|
30 | + $job->save(); |
|
31 | + } |
|
32 | + |
|
33 | + public function execute() |
|
34 | + { |
|
35 | + $database = $this->getDatabase(); |
|
36 | + $request = $this->getRequest(); |
|
37 | + $user = $this->getTriggerUser(); |
|
38 | + |
|
39 | + if ($user->getWelcomeTemplate() === null) { |
|
40 | + $this->markFailed('Welcome template not specified'); |
|
41 | + |
|
42 | + return; |
|
43 | + } |
|
44 | + |
|
45 | + /** @var WelcomeTemplate $template */ |
|
46 | + $template = WelcomeTemplate::getById($user->getWelcomeTemplate(), $database); |
|
47 | + |
|
48 | + if ($template === false) { |
|
49 | + $this->markFailed('Welcome template missing'); |
|
50 | + |
|
51 | + return; |
|
52 | + } |
|
53 | + |
|
54 | + $oauth = new OAuthUserHelper($user, $database, $this->getOauthProtocolHelper(), |
|
55 | + $this->getSiteConfiguration()); |
|
56 | + $mediaWikiHelper = new MediaWikiHelper($oauth, $this->getSiteConfiguration()); |
|
57 | + |
|
58 | + if ($request->getStatus() !== RequestStatus::CLOSED) { |
|
59 | + $this->markFailed('Request is currently open'); |
|
60 | + |
|
61 | + return; |
|
62 | + } |
|
63 | + |
|
64 | + if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
65 | + $this->markFailed('Account does not exist!'); |
|
66 | + |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + $this->performWelcome($template, $request, $mediaWikiHelper); |
|
71 | + $this->markComplete(); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Performs the welcome |
|
76 | + * |
|
77 | + * @param WelcomeTemplate $template |
|
78 | + * @param Request $request |
|
79 | + * @param MediaWikiHelper $mediaWikiHelper |
|
80 | + */ |
|
81 | + private function performWelcome( |
|
82 | + WelcomeTemplate $template, |
|
83 | + Request $request, |
|
84 | + MediaWikiHelper $mediaWikiHelper |
|
85 | + ) { |
|
86 | + $templateText = $template->getBotCode(); |
|
87 | + $templateText = str_replace('$signature', '~~~~', $templateText); |
|
88 | + $templateText = str_replace('$username', $request->getName(), $templateText); |
|
89 | + |
|
90 | + $mediaWikiHelper->addTalkPageMessage($request->getName(), 'Welcome!', 'Welcoming user created through [[WP:ACC]]', $templateText); |
|
91 | + } |
|
92 | 92 | } |
93 | 93 | \ No newline at end of file |
@@ -61,7 +61,7 @@ |
||
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
64 | + if (!$mediaWikiHelper->checkAccountExists($request->getName())) { |
|
65 | 65 | $this->markFailed('Account does not exist!'); |
66 | 66 | |
67 | 67 | return; |
@@ -61,7 +61,7 @@ |
||
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
64 | + if (!$mediaWikiHelper->checkAccountExists($request->getName())) { |
|
65 | 65 | $this->markFailed('Account does not exist!'); |
66 | 66 | |
67 | 67 | return; |
@@ -14,14 +14,14 @@ |
||
14 | 14 | |
15 | 15 | class UserCreationTask extends CreationTaskBase |
16 | 16 | { |
17 | - /** |
|
18 | - * @return IMediaWikiClient |
|
19 | - */ |
|
20 | - protected function getMediaWikiClient() |
|
21 | - { |
|
22 | - $oauth = new OAuthUserHelper($this->getTriggerUser(), $this->getDatabase(), $this->getOauthProtocolHelper(), |
|
23 | - $this->getSiteConfiguration()); |
|
17 | + /** |
|
18 | + * @return IMediaWikiClient |
|
19 | + */ |
|
20 | + protected function getMediaWikiClient() |
|
21 | + { |
|
22 | + $oauth = new OAuthUserHelper($this->getTriggerUser(), $this->getDatabase(), $this->getOauthProtocolHelper(), |
|
23 | + $this->getSiteConfiguration()); |
|
24 | 24 | |
25 | - return $oauth; |
|
26 | - } |
|
25 | + return $oauth; |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -16,16 +16,16 @@ |
||
16 | 16 | |
17 | 17 | class BotCreationTask extends CreationTaskBase |
18 | 18 | { |
19 | - /** |
|
20 | - * @return IMediaWikiClient |
|
21 | - */ |
|
22 | - protected function getMediaWikiClient() |
|
23 | - { |
|
24 | - return new BotMediaWikiClient($this->getSiteConfiguration()); |
|
25 | - } |
|
19 | + /** |
|
20 | + * @return IMediaWikiClient |
|
21 | + */ |
|
22 | + protected function getMediaWikiClient() |
|
23 | + { |
|
24 | + return new BotMediaWikiClient($this->getSiteConfiguration()); |
|
25 | + } |
|
26 | 26 | |
27 | - protected function getCreationReason(Request $request, User $user) |
|
28 | - { |
|
29 | - return parent::getCreationReason($request, $user) . ', on behalf of [[User:' . $user->getOnWikiName() . ']]'; |
|
30 | - } |
|
27 | + protected function getCreationReason(Request $request, User $user) |
|
28 | + { |
|
29 | + return parent::getCreationReason($request, $user) . ', on behalf of [[User:' . $user->getOnWikiName() . ']]'; |
|
30 | + } |
|
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -20,125 +20,125 @@ |
||
20 | 20 | |
21 | 21 | abstract class CreationTaskBase extends BackgroundTaskBase |
22 | 22 | { |
23 | - /** @var Request */ |
|
24 | - private $request; |
|
25 | - /** |
|
26 | - * @var MediaWikiHelper |
|
27 | - * Don't use this directly. |
|
28 | - */ |
|
29 | - private $mwHelper = null; |
|
30 | - |
|
31 | - public function execute() |
|
32 | - { |
|
33 | - $this->request = $this->getRequest(); |
|
34 | - $user = $this->getTriggerUser(); |
|
35 | - |
|
36 | - if ($this->request->getStatus() !== RequestStatus::JOBQUEUE) { |
|
37 | - $this->markCancelled('Request is not deferred to the job queue'); |
|
38 | - |
|
39 | - return; |
|
40 | - } |
|
23 | + /** @var Request */ |
|
24 | + private $request; |
|
25 | + /** |
|
26 | + * @var MediaWikiHelper |
|
27 | + * Don't use this directly. |
|
28 | + */ |
|
29 | + private $mwHelper = null; |
|
30 | + |
|
31 | + public function execute() |
|
32 | + { |
|
33 | + $this->request = $this->getRequest(); |
|
34 | + $user = $this->getTriggerUser(); |
|
35 | + |
|
36 | + if ($this->request->getStatus() !== RequestStatus::JOBQUEUE) { |
|
37 | + $this->markCancelled('Request is not deferred to the job queue'); |
|
38 | + |
|
39 | + return; |
|
40 | + } |
|
41 | 41 | |
42 | - if ($this->request->getEmailSent() != 0) { |
|
43 | - $this->markFailed('Request has already been sent an email'); |
|
44 | - |
|
45 | - return; |
|
46 | - } |
|
47 | - |
|
48 | - if ($this->getEmailTemplate() === null) { |
|
49 | - $this->markFailed('No email template specified'); |
|
50 | - |
|
51 | - return; |
|
52 | - } |
|
53 | - |
|
54 | - try { |
|
55 | - $this->performCreation($user); |
|
56 | - |
|
57 | - $this->request->setStatus(RequestStatus::CLOSED); |
|
58 | - $this->request->setReserved(null); |
|
59 | - $this->request->save(); |
|
60 | - |
|
61 | - // Log the closure as the user |
|
62 | - Logger::closeRequest($this->getDatabase(), $this->request, $this->getEmailTemplate()->getId(), null, |
|
63 | - $this->getTriggerUser()); |
|
64 | - |
|
65 | - $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
|
66 | - $requestEmailHelper->sendMail($this->request, $this->getEmailTemplate()->getText(), $this->getTriggerUser(), |
|
67 | - false); |
|
68 | - |
|
69 | - $this->getNotificationHelper()->requestClosed($this->request, $this->getEmailTemplate()->getName()); |
|
70 | - } |
|
71 | - catch (Exception $ex) { |
|
72 | - $this->markFailed($ex->getMessage()); |
|
73 | - |
|
74 | - return; |
|
75 | - } |
|
76 | - |
|
77 | - $this->markComplete(); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @return IMediaWikiClient |
|
82 | - */ |
|
83 | - protected abstract function getMediaWikiClient(); |
|
84 | - |
|
85 | - protected function getMediaWikiHelper(){ |
|
86 | - if($this->mwHelper === null) { |
|
87 | - $this->mwHelper = new MediaWikiHelper($this->getMediaWikiClient(), $this->getSiteConfiguration()); |
|
88 | - } |
|
89 | - |
|
90 | - return $this->mwHelper; |
|
91 | - } |
|
92 | - |
|
93 | - protected function getCreationReason(Request $request, User $user) |
|
94 | - { |
|
95 | - return 'Requested account at [[WP:ACC]], request #' . $request->getId(); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $name |
|
100 | - * |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - protected function checkAccountExists($name) |
|
104 | - { |
|
105 | - return $this->getMediaWikiHelper()->checkAccountExists($name); |
|
106 | - } |
|
107 | - |
|
108 | - protected function markFailed($reason = null) |
|
109 | - { |
|
110 | - $this->request->setStatus(RequestStatus::HOSPITAL); |
|
111 | - $this->request->save(); |
|
112 | - |
|
113 | - $this->getNotificationHelper()->requestCreationFailed($this->request); |
|
114 | - |
|
115 | - Logger::hospitalised($this->getDatabase(), $this->request); |
|
116 | - |
|
117 | - parent::markFailed($reason); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param $user |
|
122 | - * |
|
123 | - * @throws ApplicationLogicException |
|
124 | - */ |
|
125 | - protected function performCreation($user) |
|
126 | - { |
|
127 | - $mw = $this->getMediaWikiHelper(); |
|
42 | + if ($this->request->getEmailSent() != 0) { |
|
43 | + $this->markFailed('Request has already been sent an email'); |
|
44 | + |
|
45 | + return; |
|
46 | + } |
|
47 | + |
|
48 | + if ($this->getEmailTemplate() === null) { |
|
49 | + $this->markFailed('No email template specified'); |
|
50 | + |
|
51 | + return; |
|
52 | + } |
|
53 | + |
|
54 | + try { |
|
55 | + $this->performCreation($user); |
|
56 | + |
|
57 | + $this->request->setStatus(RequestStatus::CLOSED); |
|
58 | + $this->request->setReserved(null); |
|
59 | + $this->request->save(); |
|
60 | + |
|
61 | + // Log the closure as the user |
|
62 | + Logger::closeRequest($this->getDatabase(), $this->request, $this->getEmailTemplate()->getId(), null, |
|
63 | + $this->getTriggerUser()); |
|
64 | + |
|
65 | + $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
|
66 | + $requestEmailHelper->sendMail($this->request, $this->getEmailTemplate()->getText(), $this->getTriggerUser(), |
|
67 | + false); |
|
68 | + |
|
69 | + $this->getNotificationHelper()->requestClosed($this->request, $this->getEmailTemplate()->getName()); |
|
70 | + } |
|
71 | + catch (Exception $ex) { |
|
72 | + $this->markFailed($ex->getMessage()); |
|
73 | + |
|
74 | + return; |
|
75 | + } |
|
76 | + |
|
77 | + $this->markComplete(); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @return IMediaWikiClient |
|
82 | + */ |
|
83 | + protected abstract function getMediaWikiClient(); |
|
84 | + |
|
85 | + protected function getMediaWikiHelper(){ |
|
86 | + if($this->mwHelper === null) { |
|
87 | + $this->mwHelper = new MediaWikiHelper($this->getMediaWikiClient(), $this->getSiteConfiguration()); |
|
88 | + } |
|
89 | + |
|
90 | + return $this->mwHelper; |
|
91 | + } |
|
92 | + |
|
93 | + protected function getCreationReason(Request $request, User $user) |
|
94 | + { |
|
95 | + return 'Requested account at [[WP:ACC]], request #' . $request->getId(); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $name |
|
100 | + * |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + protected function checkAccountExists($name) |
|
104 | + { |
|
105 | + return $this->getMediaWikiHelper()->checkAccountExists($name); |
|
106 | + } |
|
107 | + |
|
108 | + protected function markFailed($reason = null) |
|
109 | + { |
|
110 | + $this->request->setStatus(RequestStatus::HOSPITAL); |
|
111 | + $this->request->save(); |
|
112 | + |
|
113 | + $this->getNotificationHelper()->requestCreationFailed($this->request); |
|
114 | + |
|
115 | + Logger::hospitalised($this->getDatabase(), $this->request); |
|
116 | + |
|
117 | + parent::markFailed($reason); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param $user |
|
122 | + * |
|
123 | + * @throws ApplicationLogicException |
|
124 | + */ |
|
125 | + protected function performCreation($user) |
|
126 | + { |
|
127 | + $mw = $this->getMediaWikiHelper(); |
|
128 | 128 | |
129 | - $reason = $this->getCreationReason($this->request, $user); |
|
129 | + $reason = $this->getCreationReason($this->request, $user); |
|
130 | 130 | |
131 | - if ($this->checkAccountExists($this->request->getName())) { |
|
132 | - throw new ApplicationLogicException('Account already exists'); |
|
133 | - } |
|
131 | + if ($this->checkAccountExists($this->request->getName())) { |
|
132 | + throw new ApplicationLogicException('Account already exists'); |
|
133 | + } |
|
134 | 134 | |
135 | - $mw->createAccount($this->request->getName(), $this->request->getEmail(), $reason); |
|
135 | + $mw->createAccount($this->request->getName(), $this->request->getEmail(), $reason); |
|
136 | 136 | |
137 | - if (!$this->checkAccountExists($this->request->getName())) { |
|
138 | - throw new ApplicationLogicException('Account creation appeared to succeed but account does not exist.'); |
|
139 | - } |
|
137 | + if (!$this->checkAccountExists($this->request->getName())) { |
|
138 | + throw new ApplicationLogicException('Account creation appeared to succeed but account does not exist.'); |
|
139 | + } |
|
140 | 140 | |
141 | - $this->request->setStatus(RequestStatus::CLOSED); |
|
142 | - $this->request->save(); |
|
143 | - } |
|
141 | + $this->request->setStatus(RequestStatus::CLOSED); |
|
142 | + $this->request->save(); |
|
143 | + } |
|
144 | 144 | } |
145 | 145 | \ No newline at end of file |
@@ -82,8 +82,8 @@ |
||
82 | 82 | */ |
83 | 83 | protected abstract function getMediaWikiClient(); |
84 | 84 | |
85 | - protected function getMediaWikiHelper(){ |
|
86 | - if($this->mwHelper === null) { |
|
85 | + protected function getMediaWikiHelper() { |
|
86 | + if ($this->mwHelper === null) { |
|
87 | 87 | $this->mwHelper = new MediaWikiHelper($this->getMediaWikiClient(), $this->getSiteConfiguration()); |
88 | 88 | } |
89 | 89 |
@@ -82,7 +82,8 @@ |
||
82 | 82 | */ |
83 | 83 | protected abstract function getMediaWikiClient(); |
84 | 84 | |
85 | - protected function getMediaWikiHelper(){ |
|
85 | + protected function getMediaWikiHelper() |
|
86 | + { |
|
86 | 87 | if($this->mwHelper === null) { |
87 | 88 | $this->mwHelper = new MediaWikiHelper($this->getMediaWikiClient(), $this->getSiteConfiguration()); |
88 | 89 | } |
@@ -23,267 +23,267 @@ |
||
23 | 23 | |
24 | 24 | abstract class BackgroundTaskBase |
25 | 25 | { |
26 | - /** @var JobQueue */ |
|
27 | - private $job; |
|
28 | - /** @var PdoDatabase */ |
|
29 | - private $database; |
|
30 | - /** @var IOAuthProtocolHelper */ |
|
31 | - private $oauthProtocolHelper; |
|
32 | - /** @var SiteConfiguration */ |
|
33 | - private $siteConfiguration; |
|
34 | - /** @var IEmailHelper */ |
|
35 | - private $emailHelper; |
|
36 | - /** @var HttpHelper */ |
|
37 | - private $httpHelper; |
|
38 | - /** @var IrcNotificationHelper */ |
|
39 | - private $notificationHelper; |
|
40 | - /** @var User */ |
|
41 | - private $triggerUser; |
|
42 | - /** @var Request */ |
|
43 | - private $request; |
|
44 | - /** @var EmailTemplate */ |
|
45 | - private $emailTemplate = null; |
|
46 | - /** @var mixed */ |
|
47 | - private $parameters; |
|
48 | - |
|
49 | - /** |
|
50 | - * @return JobQueue |
|
51 | - */ |
|
52 | - public function getJob() |
|
53 | - { |
|
54 | - return $this->job; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param JobQueue $job |
|
59 | - */ |
|
60 | - public function setJob(JobQueue $job) |
|
61 | - { |
|
62 | - $this->job = $job; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @return PdoDatabase |
|
67 | - */ |
|
68 | - public function getDatabase() |
|
69 | - { |
|
70 | - return $this->database; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param PdoDatabase $database |
|
75 | - */ |
|
76 | - public function setDatabase(PdoDatabase $database) |
|
77 | - { |
|
78 | - $this->database = $database; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @return IOAuthProtocolHelper |
|
83 | - */ |
|
84 | - public function getOauthProtocolHelper() |
|
85 | - { |
|
86 | - return $this->oauthProtocolHelper; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
91 | - */ |
|
92 | - public function setOauthProtocolHelper(IOAuthProtocolHelper $oauthProtocolHelper) |
|
93 | - { |
|
94 | - $this->oauthProtocolHelper = $oauthProtocolHelper; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @return SiteConfiguration |
|
99 | - */ |
|
100 | - public function getSiteConfiguration() |
|
101 | - { |
|
102 | - return $this->siteConfiguration; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param SiteConfiguration $siteConfiguration |
|
107 | - */ |
|
108 | - public function setSiteConfiguration(SiteConfiguration $siteConfiguration) |
|
109 | - { |
|
110 | - $this->siteConfiguration = $siteConfiguration; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @return HttpHelper |
|
115 | - */ |
|
116 | - public function getHttpHelper() |
|
117 | - { |
|
118 | - return $this->httpHelper; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @param HttpHelper $httpHelper |
|
123 | - */ |
|
124 | - public function setHttpHelper(HttpHelper $httpHelper) |
|
125 | - { |
|
126 | - $this->httpHelper = $httpHelper; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @return IEmailHelper |
|
131 | - */ |
|
132 | - public function getEmailHelper() |
|
133 | - { |
|
134 | - return $this->emailHelper; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @param IEmailHelper $emailHelper |
|
139 | - */ |
|
140 | - public function setEmailHelper(IEmailHelper $emailHelper) |
|
141 | - { |
|
142 | - $this->emailHelper = $emailHelper; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @return IrcNotificationHelper |
|
147 | - */ |
|
148 | - public function getNotificationHelper() |
|
149 | - { |
|
150 | - return $this->notificationHelper; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @param IrcNotificationHelper $notificationHelper |
|
155 | - */ |
|
156 | - public function setNotificationHelper($notificationHelper) |
|
157 | - { |
|
158 | - $this->notificationHelper = $notificationHelper; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - protected abstract function execute(); |
|
165 | - |
|
166 | - public function run() |
|
167 | - { |
|
168 | - $this->triggerUser = User::getById($this->job->getTriggerUserId(), $this->getDatabase()); |
|
169 | - |
|
170 | - if ($this->triggerUser === false) { |
|
171 | - throw new ApplicationLogicException('Cannot locate trigger user'); |
|
172 | - } |
|
173 | - |
|
174 | - $this->request = Request::getById($this->job->getRequest(), $this->getDatabase()); |
|
175 | - |
|
176 | - if ($this->request === false) { |
|
177 | - throw new ApplicationLogicException('Cannot locate request'); |
|
178 | - } |
|
179 | - |
|
180 | - if($this->job->getEmailTemplate() !== null){ |
|
181 | - $this->emailTemplate = EmailTemplate::getById($this->job->getEmailTemplate(), $this->getDatabase()); |
|
182 | - |
|
183 | - if ($this->emailTemplate === false) { |
|
184 | - throw new ApplicationLogicException('Cannot locate email template'); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - if($this->job->getParameters() !== null) { |
|
189 | - $this->parameters = json_decode($this->job->getParameters()); |
|
190 | - |
|
191 | - if (json_last_error() !== JSON_ERROR_NONE) { |
|
192 | - throw new ApplicationLogicException('JSON decode: ' . json_last_error_msg()); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - // Should we wait for a parent job? |
|
197 | - if($this->job->getParent() !== null) { |
|
198 | - /** @var JobQueue $parentJob */ |
|
199 | - $parentJob = JobQueue::getById($this->job->getParent(), $this->getDatabase()); |
|
200 | - |
|
201 | - if($parentJob === false) { |
|
202 | - $this->markFailed("Parent job could not be found"); |
|
203 | - return; |
|
204 | - } |
|
205 | - |
|
206 | - switch ($parentJob->getStatus()) { |
|
207 | - case JobQueue::STATUS_CANCELLED: |
|
208 | - case JobQueue::STATUS_FAILED: |
|
209 | - $this->markCancelled('Parent job failed/cancelled'); |
|
210 | - return; |
|
211 | - case JobQueue::STATUS_WAITING: |
|
212 | - case JobQueue::STATUS_READY: |
|
213 | - case JobQueue::STATUS_RUNNING: |
|
214 | - case JobQueue::STATUS_HELD: |
|
215 | - // Defer to next execution |
|
216 | - $this->job->setStatus(JobQueue::STATUS_READY); |
|
217 | - $this->job->save(); |
|
218 | - return; |
|
219 | - case JobQueue::STATUS_COMPLETE: |
|
220 | - // do nothing |
|
221 | - break; |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - $this->execute(); |
|
226 | - } |
|
227 | - |
|
228 | - protected function markComplete() |
|
229 | - { |
|
230 | - $this->job->setStatus(JobQueue::STATUS_COMPLETE); |
|
231 | - $this->job->setError(null); |
|
232 | - $this->job->setAcknowledged(null); |
|
233 | - $this->job->save(); |
|
234 | - |
|
235 | - Logger::backgroundJobComplete($this->getDatabase(), $this->getJob()); |
|
236 | - } |
|
237 | - |
|
238 | - protected function markCancelled($reason = null) |
|
239 | - { |
|
240 | - $this->job->setStatus(JobQueue::STATUS_CANCELLED); |
|
241 | - $this->job->setError($reason); |
|
242 | - $this->job->setAcknowledged(null); |
|
243 | - $this->job->save(); |
|
244 | - |
|
245 | - Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
246 | - } |
|
247 | - |
|
248 | - protected function markFailed($reason = null) |
|
249 | - { |
|
250 | - $this->job->setStatus(JobQueue::STATUS_FAILED); |
|
251 | - $this->job->setError($reason); |
|
252 | - $this->job->setAcknowledged(0); |
|
253 | - $this->job->save(); |
|
254 | - |
|
255 | - Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * @return User |
|
260 | - */ |
|
261 | - public function getTriggerUser() |
|
262 | - { |
|
263 | - return $this->triggerUser; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * @return Request |
|
268 | - */ |
|
269 | - public function getRequest() |
|
270 | - { |
|
271 | - return $this->request; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * @return EmailTemplate |
|
276 | - */ |
|
277 | - public function getEmailTemplate() |
|
278 | - { |
|
279 | - return $this->emailTemplate; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * @return mixed |
|
284 | - */ |
|
285 | - public function getParameters() |
|
286 | - { |
|
287 | - return $this->parameters; |
|
288 | - } |
|
26 | + /** @var JobQueue */ |
|
27 | + private $job; |
|
28 | + /** @var PdoDatabase */ |
|
29 | + private $database; |
|
30 | + /** @var IOAuthProtocolHelper */ |
|
31 | + private $oauthProtocolHelper; |
|
32 | + /** @var SiteConfiguration */ |
|
33 | + private $siteConfiguration; |
|
34 | + /** @var IEmailHelper */ |
|
35 | + private $emailHelper; |
|
36 | + /** @var HttpHelper */ |
|
37 | + private $httpHelper; |
|
38 | + /** @var IrcNotificationHelper */ |
|
39 | + private $notificationHelper; |
|
40 | + /** @var User */ |
|
41 | + private $triggerUser; |
|
42 | + /** @var Request */ |
|
43 | + private $request; |
|
44 | + /** @var EmailTemplate */ |
|
45 | + private $emailTemplate = null; |
|
46 | + /** @var mixed */ |
|
47 | + private $parameters; |
|
48 | + |
|
49 | + /** |
|
50 | + * @return JobQueue |
|
51 | + */ |
|
52 | + public function getJob() |
|
53 | + { |
|
54 | + return $this->job; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param JobQueue $job |
|
59 | + */ |
|
60 | + public function setJob(JobQueue $job) |
|
61 | + { |
|
62 | + $this->job = $job; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @return PdoDatabase |
|
67 | + */ |
|
68 | + public function getDatabase() |
|
69 | + { |
|
70 | + return $this->database; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param PdoDatabase $database |
|
75 | + */ |
|
76 | + public function setDatabase(PdoDatabase $database) |
|
77 | + { |
|
78 | + $this->database = $database; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @return IOAuthProtocolHelper |
|
83 | + */ |
|
84 | + public function getOauthProtocolHelper() |
|
85 | + { |
|
86 | + return $this->oauthProtocolHelper; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
91 | + */ |
|
92 | + public function setOauthProtocolHelper(IOAuthProtocolHelper $oauthProtocolHelper) |
|
93 | + { |
|
94 | + $this->oauthProtocolHelper = $oauthProtocolHelper; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @return SiteConfiguration |
|
99 | + */ |
|
100 | + public function getSiteConfiguration() |
|
101 | + { |
|
102 | + return $this->siteConfiguration; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param SiteConfiguration $siteConfiguration |
|
107 | + */ |
|
108 | + public function setSiteConfiguration(SiteConfiguration $siteConfiguration) |
|
109 | + { |
|
110 | + $this->siteConfiguration = $siteConfiguration; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @return HttpHelper |
|
115 | + */ |
|
116 | + public function getHttpHelper() |
|
117 | + { |
|
118 | + return $this->httpHelper; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @param HttpHelper $httpHelper |
|
123 | + */ |
|
124 | + public function setHttpHelper(HttpHelper $httpHelper) |
|
125 | + { |
|
126 | + $this->httpHelper = $httpHelper; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @return IEmailHelper |
|
131 | + */ |
|
132 | + public function getEmailHelper() |
|
133 | + { |
|
134 | + return $this->emailHelper; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @param IEmailHelper $emailHelper |
|
139 | + */ |
|
140 | + public function setEmailHelper(IEmailHelper $emailHelper) |
|
141 | + { |
|
142 | + $this->emailHelper = $emailHelper; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @return IrcNotificationHelper |
|
147 | + */ |
|
148 | + public function getNotificationHelper() |
|
149 | + { |
|
150 | + return $this->notificationHelper; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @param IrcNotificationHelper $notificationHelper |
|
155 | + */ |
|
156 | + public function setNotificationHelper($notificationHelper) |
|
157 | + { |
|
158 | + $this->notificationHelper = $notificationHelper; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + protected abstract function execute(); |
|
165 | + |
|
166 | + public function run() |
|
167 | + { |
|
168 | + $this->triggerUser = User::getById($this->job->getTriggerUserId(), $this->getDatabase()); |
|
169 | + |
|
170 | + if ($this->triggerUser === false) { |
|
171 | + throw new ApplicationLogicException('Cannot locate trigger user'); |
|
172 | + } |
|
173 | + |
|
174 | + $this->request = Request::getById($this->job->getRequest(), $this->getDatabase()); |
|
175 | + |
|
176 | + if ($this->request === false) { |
|
177 | + throw new ApplicationLogicException('Cannot locate request'); |
|
178 | + } |
|
179 | + |
|
180 | + if($this->job->getEmailTemplate() !== null){ |
|
181 | + $this->emailTemplate = EmailTemplate::getById($this->job->getEmailTemplate(), $this->getDatabase()); |
|
182 | + |
|
183 | + if ($this->emailTemplate === false) { |
|
184 | + throw new ApplicationLogicException('Cannot locate email template'); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + if($this->job->getParameters() !== null) { |
|
189 | + $this->parameters = json_decode($this->job->getParameters()); |
|
190 | + |
|
191 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
192 | + throw new ApplicationLogicException('JSON decode: ' . json_last_error_msg()); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + // Should we wait for a parent job? |
|
197 | + if($this->job->getParent() !== null) { |
|
198 | + /** @var JobQueue $parentJob */ |
|
199 | + $parentJob = JobQueue::getById($this->job->getParent(), $this->getDatabase()); |
|
200 | + |
|
201 | + if($parentJob === false) { |
|
202 | + $this->markFailed("Parent job could not be found"); |
|
203 | + return; |
|
204 | + } |
|
205 | + |
|
206 | + switch ($parentJob->getStatus()) { |
|
207 | + case JobQueue::STATUS_CANCELLED: |
|
208 | + case JobQueue::STATUS_FAILED: |
|
209 | + $this->markCancelled('Parent job failed/cancelled'); |
|
210 | + return; |
|
211 | + case JobQueue::STATUS_WAITING: |
|
212 | + case JobQueue::STATUS_READY: |
|
213 | + case JobQueue::STATUS_RUNNING: |
|
214 | + case JobQueue::STATUS_HELD: |
|
215 | + // Defer to next execution |
|
216 | + $this->job->setStatus(JobQueue::STATUS_READY); |
|
217 | + $this->job->save(); |
|
218 | + return; |
|
219 | + case JobQueue::STATUS_COMPLETE: |
|
220 | + // do nothing |
|
221 | + break; |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + $this->execute(); |
|
226 | + } |
|
227 | + |
|
228 | + protected function markComplete() |
|
229 | + { |
|
230 | + $this->job->setStatus(JobQueue::STATUS_COMPLETE); |
|
231 | + $this->job->setError(null); |
|
232 | + $this->job->setAcknowledged(null); |
|
233 | + $this->job->save(); |
|
234 | + |
|
235 | + Logger::backgroundJobComplete($this->getDatabase(), $this->getJob()); |
|
236 | + } |
|
237 | + |
|
238 | + protected function markCancelled($reason = null) |
|
239 | + { |
|
240 | + $this->job->setStatus(JobQueue::STATUS_CANCELLED); |
|
241 | + $this->job->setError($reason); |
|
242 | + $this->job->setAcknowledged(null); |
|
243 | + $this->job->save(); |
|
244 | + |
|
245 | + Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
246 | + } |
|
247 | + |
|
248 | + protected function markFailed($reason = null) |
|
249 | + { |
|
250 | + $this->job->setStatus(JobQueue::STATUS_FAILED); |
|
251 | + $this->job->setError($reason); |
|
252 | + $this->job->setAcknowledged(0); |
|
253 | + $this->job->save(); |
|
254 | + |
|
255 | + Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * @return User |
|
260 | + */ |
|
261 | + public function getTriggerUser() |
|
262 | + { |
|
263 | + return $this->triggerUser; |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * @return Request |
|
268 | + */ |
|
269 | + public function getRequest() |
|
270 | + { |
|
271 | + return $this->request; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * @return EmailTemplate |
|
276 | + */ |
|
277 | + public function getEmailTemplate() |
|
278 | + { |
|
279 | + return $this->emailTemplate; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * @return mixed |
|
284 | + */ |
|
285 | + public function getParameters() |
|
286 | + { |
|
287 | + return $this->parameters; |
|
288 | + } |
|
289 | 289 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | throw new ApplicationLogicException('Cannot locate request'); |
178 | 178 | } |
179 | 179 | |
180 | - if($this->job->getEmailTemplate() !== null){ |
|
180 | + if ($this->job->getEmailTemplate() !== null) { |
|
181 | 181 | $this->emailTemplate = EmailTemplate::getById($this->job->getEmailTemplate(), $this->getDatabase()); |
182 | 182 | |
183 | 183 | if ($this->emailTemplate === false) { |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - if($this->job->getParameters() !== null) { |
|
188 | + if ($this->job->getParameters() !== null) { |
|
189 | 189 | $this->parameters = json_decode($this->job->getParameters()); |
190 | 190 | |
191 | 191 | if (json_last_error() !== JSON_ERROR_NONE) { |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | // Should we wait for a parent job? |
197 | - if($this->job->getParent() !== null) { |
|
197 | + if ($this->job->getParent() !== null) { |
|
198 | 198 | /** @var JobQueue $parentJob */ |
199 | 199 | $parentJob = JobQueue::getById($this->job->getParent(), $this->getDatabase()); |
200 | 200 | |
201 | - if($parentJob === false) { |
|
201 | + if ($parentJob === false) { |
|
202 | 202 | $this->markFailed("Parent job could not be found"); |
203 | 203 | return; |
204 | 204 | } |
@@ -177,7 +177,7 @@ |
||
177 | 177 | throw new ApplicationLogicException('Cannot locate request'); |
178 | 178 | } |
179 | 179 | |
180 | - if($this->job->getEmailTemplate() !== null){ |
|
180 | + if($this->job->getEmailTemplate() !== null) { |
|
181 | 181 | $this->emailTemplate = EmailTemplate::getById($this->job->getEmailTemplate(), $this->getDatabase()); |
182 | 182 | |
183 | 183 | if ($this->emailTemplate === false) { |
@@ -23,124 +23,124 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class DataObject |
25 | 25 | { |
26 | - /** @var int ID of the object */ |
|
27 | - protected $id = null; |
|
28 | - /** @var int update version for optimistic locking */ |
|
29 | - protected $updateversion = 0; |
|
30 | - /** |
|
31 | - * @var PdoDatabase |
|
32 | - */ |
|
33 | - protected $dbObject; |
|
34 | - |
|
35 | - /** |
|
36 | - * Retrieves a data object by it's row ID. |
|
37 | - * |
|
38 | - * @param int $id |
|
39 | - * @param PdoDatabase $database |
|
40 | - * |
|
41 | - * @return DataObject|false |
|
42 | - */ |
|
43 | - public static function getById($id, PdoDatabase $database) |
|
44 | - { |
|
45 | - $array = explode('\\', get_called_class()); |
|
46 | - $realClassName = strtolower(end($array)); |
|
47 | - |
|
48 | - $statement = $database->prepare("SELECT * FROM {$realClassName} WHERE id = :id LIMIT 1;"); |
|
49 | - $statement->bindValue(":id", $id); |
|
50 | - |
|
51 | - $statement->execute(); |
|
52 | - |
|
53 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
54 | - |
|
55 | - if ($resultObject != false) { |
|
56 | - $resultObject->setDatabase($database); |
|
57 | - } |
|
58 | - |
|
59 | - return $resultObject; |
|
60 | - } |
|
61 | - |
|
62 | - public function setDatabase(PdoDatabase $db) |
|
63 | - { |
|
64 | - $this->dbObject = $db; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Gets the database associated with this data object. |
|
69 | - * @return PdoDatabase |
|
70 | - */ |
|
71 | - public function getDatabase() |
|
72 | - { |
|
73 | - return $this->dbObject; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Saves a data object to the database, either updating or inserting a record. |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - abstract public function save(); |
|
82 | - |
|
83 | - /** |
|
84 | - * Retrieves the ID attribute |
|
85 | - */ |
|
86 | - public function getId() |
|
87 | - { |
|
88 | - return (int)$this->id; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Deletes the object from the database |
|
93 | - */ |
|
94 | - public function delete() |
|
95 | - { |
|
96 | - if ($this->id === null) { |
|
97 | - // wtf? |
|
98 | - return; |
|
99 | - } |
|
100 | - |
|
101 | - $array = explode('\\', get_called_class()); |
|
102 | - $realClassName = strtolower(end($array)); |
|
103 | - |
|
104 | - $deleteQuery = "DELETE FROM {$realClassName} WHERE id = :id AND updateversion = :updateversion;"; |
|
105 | - $statement = $this->dbObject->prepare($deleteQuery); |
|
106 | - |
|
107 | - $statement->bindValue(":id", $this->id); |
|
108 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
109 | - $statement->execute(); |
|
110 | - |
|
111 | - if ($statement->rowCount() !== 1) { |
|
112 | - throw new OptimisticLockFailedException(); |
|
113 | - } |
|
114 | - |
|
115 | - $this->id = null; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function getUpdateVersion() |
|
122 | - { |
|
123 | - return $this->updateversion; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Sets the update version. |
|
128 | - * |
|
129 | - * You should never call this to change the value of the update version. You should only call it when passing user |
|
130 | - * input through. |
|
131 | - * |
|
132 | - * @param int $updateVersion |
|
133 | - */ |
|
134 | - public function setUpdateVersion($updateVersion) |
|
135 | - { |
|
136 | - $this->updateversion = $updateVersion; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return bool |
|
141 | - */ |
|
142 | - public function isNew() |
|
143 | - { |
|
144 | - return $this->id === null; |
|
145 | - } |
|
26 | + /** @var int ID of the object */ |
|
27 | + protected $id = null; |
|
28 | + /** @var int update version for optimistic locking */ |
|
29 | + protected $updateversion = 0; |
|
30 | + /** |
|
31 | + * @var PdoDatabase |
|
32 | + */ |
|
33 | + protected $dbObject; |
|
34 | + |
|
35 | + /** |
|
36 | + * Retrieves a data object by it's row ID. |
|
37 | + * |
|
38 | + * @param int $id |
|
39 | + * @param PdoDatabase $database |
|
40 | + * |
|
41 | + * @return DataObject|false |
|
42 | + */ |
|
43 | + public static function getById($id, PdoDatabase $database) |
|
44 | + { |
|
45 | + $array = explode('\\', get_called_class()); |
|
46 | + $realClassName = strtolower(end($array)); |
|
47 | + |
|
48 | + $statement = $database->prepare("SELECT * FROM {$realClassName} WHERE id = :id LIMIT 1;"); |
|
49 | + $statement->bindValue(":id", $id); |
|
50 | + |
|
51 | + $statement->execute(); |
|
52 | + |
|
53 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
54 | + |
|
55 | + if ($resultObject != false) { |
|
56 | + $resultObject->setDatabase($database); |
|
57 | + } |
|
58 | + |
|
59 | + return $resultObject; |
|
60 | + } |
|
61 | + |
|
62 | + public function setDatabase(PdoDatabase $db) |
|
63 | + { |
|
64 | + $this->dbObject = $db; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Gets the database associated with this data object. |
|
69 | + * @return PdoDatabase |
|
70 | + */ |
|
71 | + public function getDatabase() |
|
72 | + { |
|
73 | + return $this->dbObject; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Saves a data object to the database, either updating or inserting a record. |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + abstract public function save(); |
|
82 | + |
|
83 | + /** |
|
84 | + * Retrieves the ID attribute |
|
85 | + */ |
|
86 | + public function getId() |
|
87 | + { |
|
88 | + return (int)$this->id; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Deletes the object from the database |
|
93 | + */ |
|
94 | + public function delete() |
|
95 | + { |
|
96 | + if ($this->id === null) { |
|
97 | + // wtf? |
|
98 | + return; |
|
99 | + } |
|
100 | + |
|
101 | + $array = explode('\\', get_called_class()); |
|
102 | + $realClassName = strtolower(end($array)); |
|
103 | + |
|
104 | + $deleteQuery = "DELETE FROM {$realClassName} WHERE id = :id AND updateversion = :updateversion;"; |
|
105 | + $statement = $this->dbObject->prepare($deleteQuery); |
|
106 | + |
|
107 | + $statement->bindValue(":id", $this->id); |
|
108 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
109 | + $statement->execute(); |
|
110 | + |
|
111 | + if ($statement->rowCount() !== 1) { |
|
112 | + throw new OptimisticLockFailedException(); |
|
113 | + } |
|
114 | + |
|
115 | + $this->id = null; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function getUpdateVersion() |
|
122 | + { |
|
123 | + return $this->updateversion; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Sets the update version. |
|
128 | + * |
|
129 | + * You should never call this to change the value of the update version. You should only call it when passing user |
|
130 | + * input through. |
|
131 | + * |
|
132 | + * @param int $updateVersion |
|
133 | + */ |
|
134 | + public function setUpdateVersion($updateVersion) |
|
135 | + { |
|
136 | + $this->updateversion = $updateVersion; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return bool |
|
141 | + */ |
|
142 | + public function isNew() |
|
143 | + { |
|
144 | + return $this->id === null; |
|
145 | + } |
|
146 | 146 | } |
@@ -19,179 +19,179 @@ |
||
19 | 19 | |
20 | 20 | class PageEmailManagement extends InternalPageBase |
21 | 21 | { |
22 | - /** |
|
23 | - * Main function for this page, when no specific actions are called. |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - protected function main() |
|
27 | - { |
|
28 | - $this->setHtmlTitle('Close Emails'); |
|
29 | - |
|
30 | - // Get all active email templates |
|
31 | - $activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase()); |
|
32 | - $inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase()); |
|
33 | - |
|
34 | - $this->assign('activeTemplates', $activeTemplates); |
|
35 | - $this->assign('inactiveTemplates', $inactiveTemplates); |
|
36 | - |
|
37 | - $user = User::getCurrent($this->getDatabase()); |
|
38 | - $this->assign('canCreate', $this->barrierTest('create', $user)); |
|
39 | - $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
40 | - |
|
41 | - $this->setTemplate('email-management/main.tpl'); |
|
42 | - } |
|
43 | - |
|
44 | - protected function view() |
|
45 | - { |
|
46 | - $this->setHtmlTitle('Close Emails'); |
|
47 | - |
|
48 | - $database = $this->getDatabase(); |
|
49 | - $template = $this->getTemplate($database); |
|
50 | - |
|
51 | - $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
52 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
53 | - |
|
54 | - $this->assign('id', $template->getId()); |
|
55 | - $this->assign('emailTemplate', $template); |
|
56 | - $this->assign('createdid', $createdId); |
|
57 | - $this->assign('requeststates', $requestStates); |
|
58 | - |
|
59 | - $this->setTemplate('email-management/view.tpl'); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @param PdoDatabase $database |
|
64 | - * |
|
65 | - * @return EmailTemplate |
|
66 | - * @throws ApplicationLogicException |
|
67 | - */ |
|
68 | - protected function getTemplate(PdoDatabase $database) |
|
69 | - { |
|
70 | - $templateId = WebRequest::getInt('id'); |
|
71 | - if ($templateId === null) { |
|
72 | - throw new ApplicationLogicException('Template not specified'); |
|
73 | - } |
|
74 | - $template = EmailTemplate::getById($templateId, $database); |
|
75 | - if ($template === false || !is_a($template, EmailTemplate::class)) { |
|
76 | - throw new ApplicationLogicException('Template not found'); |
|
77 | - } |
|
78 | - |
|
79 | - return $template; |
|
80 | - } |
|
81 | - |
|
82 | - protected function edit() |
|
83 | - { |
|
84 | - $this->setHtmlTitle('Close Emails'); |
|
85 | - |
|
86 | - $database = $this->getDatabase(); |
|
87 | - $template = $this->getTemplate($database); |
|
88 | - |
|
89 | - $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
90 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
91 | - |
|
92 | - if (WebRequest::wasPosted()) { |
|
93 | - $this->validateCSRFToken(); |
|
94 | - |
|
95 | - $this->modifyTemplateData($template); |
|
96 | - |
|
97 | - $other = EmailTemplate::getByName($template->getName(), $database); |
|
98 | - if ($other !== false && $other->getId() !== $template->getId()) { |
|
99 | - throw new ApplicationLogicException('A template with this name already exists'); |
|
100 | - } |
|
101 | - |
|
102 | - if ($template->getId() === $createdId) { |
|
103 | - $template->setDefaultAction(EmailTemplate::CREATED); |
|
104 | - $template->setActive(true); |
|
105 | - $template->setPreloadOnly(false); |
|
106 | - } |
|
107 | - |
|
108 | - // optimistically lock on load of edit form |
|
109 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
110 | - $template->setUpdateVersion($updateVersion); |
|
111 | - |
|
112 | - $template->save(); |
|
113 | - Logger::editedEmail($database, $template); |
|
114 | - $this->getNotificationHelper()->emailEdited($template); |
|
115 | - SessionAlert::success("Email template has been saved successfully."); |
|
116 | - |
|
117 | - $this->redirect('emailManagement'); |
|
118 | - } |
|
119 | - else { |
|
120 | - $this->assignCSRFToken(); |
|
121 | - $this->assign('id', $template->getId()); |
|
122 | - $this->assign('emailTemplate', $template); |
|
123 | - $this->assign('createdid', $createdId); |
|
124 | - $this->assign('requeststates', $requestStates); |
|
125 | - |
|
126 | - $this->setTemplate('email-management/edit.tpl'); |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @param EmailTemplate $template |
|
132 | - * |
|
133 | - * @throws ApplicationLogicException |
|
134 | - */ |
|
135 | - private function modifyTemplateData(EmailTemplate $template) |
|
136 | - { |
|
137 | - $name = WebRequest::postString('name'); |
|
138 | - if ($name === null || $name === '') { |
|
139 | - throw new ApplicationLogicException('Name not specified'); |
|
140 | - } |
|
141 | - |
|
142 | - $template->setName($name); |
|
143 | - |
|
144 | - $text = WebRequest::postString('text'); |
|
145 | - if ($text === null || $text === '') { |
|
146 | - throw new ApplicationLogicException('Text not specified'); |
|
147 | - } |
|
148 | - |
|
149 | - $template->setText($text); |
|
150 | - |
|
151 | - $template->setJsquestion(WebRequest::postString('jsquestion')); |
|
152 | - |
|
153 | - $template->setDefaultAction(WebRequest::postString('defaultaction')); |
|
154 | - $template->setActive(WebRequest::postBoolean('active')); |
|
155 | - $template->setPreloadOnly(WebRequest::postBoolean('preloadonly')); |
|
156 | - } |
|
157 | - |
|
158 | - protected function create() |
|
159 | - { |
|
160 | - $this->setHtmlTitle('Close Emails'); |
|
161 | - |
|
162 | - $database = $this->getDatabase(); |
|
163 | - |
|
164 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
165 | - |
|
166 | - if (WebRequest::wasPosted()) { |
|
167 | - $this->validateCSRFToken(); |
|
168 | - $template = new EmailTemplate(); |
|
169 | - $template->setDatabase($database); |
|
170 | - |
|
171 | - $this->modifyTemplateData($template); |
|
172 | - |
|
173 | - $other = EmailTemplate::getByName($template->getName(), $database); |
|
174 | - if ($other !== false) { |
|
175 | - throw new ApplicationLogicException('A template with this name already exists'); |
|
176 | - } |
|
177 | - |
|
178 | - $template->save(); |
|
179 | - |
|
180 | - Logger::createEmail($database, $template); |
|
181 | - $this->getNotificationHelper()->emailCreated($template); |
|
182 | - |
|
183 | - SessionAlert::success("Email template has been saved successfully."); |
|
184 | - |
|
185 | - $this->redirect('emailManagement'); |
|
186 | - } |
|
187 | - else { |
|
188 | - $this->assignCSRFToken(); |
|
189 | - $this->assign('id', -1); |
|
190 | - $this->assign('emailTemplate', new EmailTemplate()); |
|
191 | - $this->assign('createdid', -2); |
|
192 | - |
|
193 | - $this->assign('requeststates', $requestStates); |
|
194 | - $this->setTemplate('email-management/edit.tpl'); |
|
195 | - } |
|
196 | - } |
|
22 | + /** |
|
23 | + * Main function for this page, when no specific actions are called. |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + protected function main() |
|
27 | + { |
|
28 | + $this->setHtmlTitle('Close Emails'); |
|
29 | + |
|
30 | + // Get all active email templates |
|
31 | + $activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase()); |
|
32 | + $inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase()); |
|
33 | + |
|
34 | + $this->assign('activeTemplates', $activeTemplates); |
|
35 | + $this->assign('inactiveTemplates', $inactiveTemplates); |
|
36 | + |
|
37 | + $user = User::getCurrent($this->getDatabase()); |
|
38 | + $this->assign('canCreate', $this->barrierTest('create', $user)); |
|
39 | + $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
40 | + |
|
41 | + $this->setTemplate('email-management/main.tpl'); |
|
42 | + } |
|
43 | + |
|
44 | + protected function view() |
|
45 | + { |
|
46 | + $this->setHtmlTitle('Close Emails'); |
|
47 | + |
|
48 | + $database = $this->getDatabase(); |
|
49 | + $template = $this->getTemplate($database); |
|
50 | + |
|
51 | + $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
52 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
53 | + |
|
54 | + $this->assign('id', $template->getId()); |
|
55 | + $this->assign('emailTemplate', $template); |
|
56 | + $this->assign('createdid', $createdId); |
|
57 | + $this->assign('requeststates', $requestStates); |
|
58 | + |
|
59 | + $this->setTemplate('email-management/view.tpl'); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @param PdoDatabase $database |
|
64 | + * |
|
65 | + * @return EmailTemplate |
|
66 | + * @throws ApplicationLogicException |
|
67 | + */ |
|
68 | + protected function getTemplate(PdoDatabase $database) |
|
69 | + { |
|
70 | + $templateId = WebRequest::getInt('id'); |
|
71 | + if ($templateId === null) { |
|
72 | + throw new ApplicationLogicException('Template not specified'); |
|
73 | + } |
|
74 | + $template = EmailTemplate::getById($templateId, $database); |
|
75 | + if ($template === false || !is_a($template, EmailTemplate::class)) { |
|
76 | + throw new ApplicationLogicException('Template not found'); |
|
77 | + } |
|
78 | + |
|
79 | + return $template; |
|
80 | + } |
|
81 | + |
|
82 | + protected function edit() |
|
83 | + { |
|
84 | + $this->setHtmlTitle('Close Emails'); |
|
85 | + |
|
86 | + $database = $this->getDatabase(); |
|
87 | + $template = $this->getTemplate($database); |
|
88 | + |
|
89 | + $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
90 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
91 | + |
|
92 | + if (WebRequest::wasPosted()) { |
|
93 | + $this->validateCSRFToken(); |
|
94 | + |
|
95 | + $this->modifyTemplateData($template); |
|
96 | + |
|
97 | + $other = EmailTemplate::getByName($template->getName(), $database); |
|
98 | + if ($other !== false && $other->getId() !== $template->getId()) { |
|
99 | + throw new ApplicationLogicException('A template with this name already exists'); |
|
100 | + } |
|
101 | + |
|
102 | + if ($template->getId() === $createdId) { |
|
103 | + $template->setDefaultAction(EmailTemplate::CREATED); |
|
104 | + $template->setActive(true); |
|
105 | + $template->setPreloadOnly(false); |
|
106 | + } |
|
107 | + |
|
108 | + // optimistically lock on load of edit form |
|
109 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
110 | + $template->setUpdateVersion($updateVersion); |
|
111 | + |
|
112 | + $template->save(); |
|
113 | + Logger::editedEmail($database, $template); |
|
114 | + $this->getNotificationHelper()->emailEdited($template); |
|
115 | + SessionAlert::success("Email template has been saved successfully."); |
|
116 | + |
|
117 | + $this->redirect('emailManagement'); |
|
118 | + } |
|
119 | + else { |
|
120 | + $this->assignCSRFToken(); |
|
121 | + $this->assign('id', $template->getId()); |
|
122 | + $this->assign('emailTemplate', $template); |
|
123 | + $this->assign('createdid', $createdId); |
|
124 | + $this->assign('requeststates', $requestStates); |
|
125 | + |
|
126 | + $this->setTemplate('email-management/edit.tpl'); |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @param EmailTemplate $template |
|
132 | + * |
|
133 | + * @throws ApplicationLogicException |
|
134 | + */ |
|
135 | + private function modifyTemplateData(EmailTemplate $template) |
|
136 | + { |
|
137 | + $name = WebRequest::postString('name'); |
|
138 | + if ($name === null || $name === '') { |
|
139 | + throw new ApplicationLogicException('Name not specified'); |
|
140 | + } |
|
141 | + |
|
142 | + $template->setName($name); |
|
143 | + |
|
144 | + $text = WebRequest::postString('text'); |
|
145 | + if ($text === null || $text === '') { |
|
146 | + throw new ApplicationLogicException('Text not specified'); |
|
147 | + } |
|
148 | + |
|
149 | + $template->setText($text); |
|
150 | + |
|
151 | + $template->setJsquestion(WebRequest::postString('jsquestion')); |
|
152 | + |
|
153 | + $template->setDefaultAction(WebRequest::postString('defaultaction')); |
|
154 | + $template->setActive(WebRequest::postBoolean('active')); |
|
155 | + $template->setPreloadOnly(WebRequest::postBoolean('preloadonly')); |
|
156 | + } |
|
157 | + |
|
158 | + protected function create() |
|
159 | + { |
|
160 | + $this->setHtmlTitle('Close Emails'); |
|
161 | + |
|
162 | + $database = $this->getDatabase(); |
|
163 | + |
|
164 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
165 | + |
|
166 | + if (WebRequest::wasPosted()) { |
|
167 | + $this->validateCSRFToken(); |
|
168 | + $template = new EmailTemplate(); |
|
169 | + $template->setDatabase($database); |
|
170 | + |
|
171 | + $this->modifyTemplateData($template); |
|
172 | + |
|
173 | + $other = EmailTemplate::getByName($template->getName(), $database); |
|
174 | + if ($other !== false) { |
|
175 | + throw new ApplicationLogicException('A template with this name already exists'); |
|
176 | + } |
|
177 | + |
|
178 | + $template->save(); |
|
179 | + |
|
180 | + Logger::createEmail($database, $template); |
|
181 | + $this->getNotificationHelper()->emailCreated($template); |
|
182 | + |
|
183 | + SessionAlert::success("Email template has been saved successfully."); |
|
184 | + |
|
185 | + $this->redirect('emailManagement'); |
|
186 | + } |
|
187 | + else { |
|
188 | + $this->assignCSRFToken(); |
|
189 | + $this->assign('id', -1); |
|
190 | + $this->assign('emailTemplate', new EmailTemplate()); |
|
191 | + $this->assign('createdid', -2); |
|
192 | + |
|
193 | + $this->assign('requeststates', $requestStates); |
|
194 | + $this->setTemplate('email-management/edit.tpl'); |
|
195 | + } |
|
196 | + } |
|
197 | 197 | } |
@@ -115,8 +115,7 @@ discard block |
||
115 | 115 | SessionAlert::success("Email template has been saved successfully."); |
116 | 116 | |
117 | 117 | $this->redirect('emailManagement'); |
118 | - } |
|
119 | - else { |
|
118 | + } else { |
|
120 | 119 | $this->assignCSRFToken(); |
121 | 120 | $this->assign('id', $template->getId()); |
122 | 121 | $this->assign('emailTemplate', $template); |
@@ -183,8 +182,7 @@ discard block |
||
183 | 182 | SessionAlert::success("Email template has been saved successfully."); |
184 | 183 | |
185 | 184 | $this->redirect('emailManagement'); |
186 | - } |
|
187 | - else { |
|
185 | + } else { |
|
188 | 186 | $this->assignCSRFToken(); |
189 | 187 | $this->assign('id', -1); |
190 | 188 | $this->assign('emailTemplate', new EmailTemplate()); |
@@ -17,31 +17,31 @@ |
||
17 | 17 | |
18 | 18 | class StatsInactiveUsers extends InternalPageBase |
19 | 19 | { |
20 | - public function main() |
|
21 | - { |
|
22 | - $this->setHtmlTitle('Inactive Users :: Statistics'); |
|
23 | - |
|
24 | - $date = new DateTime(); |
|
25 | - $date->modify("-90 days"); |
|
26 | - |
|
27 | - $inactiveUsers = UserSearchHelper::get($this->getDatabase()) |
|
28 | - ->byStatus('Active') |
|
29 | - ->lastActiveBefore($date) |
|
30 | - ->getRoleMap($roleMap) |
|
31 | - ->fetch(); |
|
32 | - |
|
33 | - $this->assign('inactiveUsers', $inactiveUsers); |
|
34 | - $this->assign('roles', $roleMap); |
|
35 | - $this->assign('canSuspend', |
|
36 | - $this->barrierTest('suspend', User::getCurrent($this->getDatabase()), PageUserManagement::class)); |
|
37 | - |
|
38 | - $immuneUsers = $this->getDatabase() |
|
39 | - ->query("SELECT user FROM userrole WHERE role IN ('toolRoot', 'checkuser') GROUP BY user;") |
|
40 | - ->fetchAll(PDO::FETCH_COLUMN); |
|
20 | + public function main() |
|
21 | + { |
|
22 | + $this->setHtmlTitle('Inactive Users :: Statistics'); |
|
23 | + |
|
24 | + $date = new DateTime(); |
|
25 | + $date->modify("-90 days"); |
|
26 | + |
|
27 | + $inactiveUsers = UserSearchHelper::get($this->getDatabase()) |
|
28 | + ->byStatus('Active') |
|
29 | + ->lastActiveBefore($date) |
|
30 | + ->getRoleMap($roleMap) |
|
31 | + ->fetch(); |
|
32 | + |
|
33 | + $this->assign('inactiveUsers', $inactiveUsers); |
|
34 | + $this->assign('roles', $roleMap); |
|
35 | + $this->assign('canSuspend', |
|
36 | + $this->barrierTest('suspend', User::getCurrent($this->getDatabase()), PageUserManagement::class)); |
|
37 | + |
|
38 | + $immuneUsers = $this->getDatabase() |
|
39 | + ->query("SELECT user FROM userrole WHERE role IN ('toolRoot', 'checkuser') GROUP BY user;") |
|
40 | + ->fetchAll(PDO::FETCH_COLUMN); |
|
41 | 41 | |
42 | - $this->assign('immune', array_fill_keys($immuneUsers, true)); |
|
42 | + $this->assign('immune', array_fill_keys($immuneUsers, true)); |
|
43 | 43 | |
44 | - $this->setTemplate('statistics/inactive-users.tpl'); |
|
45 | - $this->assign('statsPageTitle', 'Inactive tool users'); |
|
46 | - } |
|
44 | + $this->setTemplate('statistics/inactive-users.tpl'); |
|
45 | + $this->assign('statsPageTitle', 'Inactive tool users'); |
|
46 | + } |
|
47 | 47 | } |