Failed Conditions
Pull Request — newinternal (#527)
by Simon
16:02 queued 05:59
created
includes/Tasks/InternalPageBase.php 1 patch
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -22,225 +22,225 @@
 block discarded – undo
22 22
 
23 23
 abstract class InternalPageBase extends PageBase
24 24
 {
25
-    use NavigationMenuAccessControl;
26
-
27
-    /** @var IdentificationVerifier */
28
-    private $identificationVerifier;
29
-    /** @var ITypeAheadHelper */
30
-    private $typeAheadHelper;
31
-    /** @var SecurityManager */
32
-    private $securityManager;
33
-    /** @var IBlacklistHelper */
34
-    private $blacklistHelper;
35
-
36
-    /**
37
-     * @return ITypeAheadHelper
38
-     */
39
-    public function getTypeAheadHelper()
40
-    {
41
-        return $this->typeAheadHelper;
42
-    }
43
-
44
-    /**
45
-     * Sets up the internal IdentificationVerifier instance.  Intended to be called from WebStart::setupHelpers().
46
-     *
47
-     * @param IdentificationVerifier $identificationVerifier
48
-     *
49
-     * @return void
50
-     */
51
-    public function setIdentificationVerifier(IdentificationVerifier $identificationVerifier)
52
-    {
53
-        $this->identificationVerifier = $identificationVerifier;
54
-    }
55
-
56
-    /**
57
-     * @param ITypeAheadHelper $typeAheadHelper
58
-     */
59
-    public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper)
60
-    {
61
-        $this->typeAheadHelper = $typeAheadHelper;
62
-    }
63
-
64
-    /**
65
-     * Runs the page code
66
-     *
67
-     * @throws Exception
68
-     * @category Security-Critical
69
-     */
70
-    final public function execute()
71
-    {
72
-        if ($this->getRouteName() === null) {
73
-            throw new Exception("Request is unrouted.");
74
-        }
75
-
76
-        if ($this->getSiteConfiguration() === null) {
77
-            throw new Exception("Page has no configuration!");
78
-        }
79
-
80
-        $this->setupPage();
81
-
82
-        $this->touchUserLastActive();
83
-
84
-        $currentUser = User::getCurrent($this->getDatabase());
85
-
86
-        // Hey, this is also a security barrier, in addition to the below. Separated out for readability.
87
-        if (!$this->isProtectedPage()) {
88
-            // This page is /not/ a protected page, as such we can just run it.
89
-            $this->runPage();
90
-
91
-            return;
92
-        }
93
-
94
-        // Security barrier.
95
-        //
96
-        // This code essentially doesn't care if the user is logged in or not, as the security manager hides all that
97
-        // away for us
98
-        $securityResult = $this->getSecurityManager()->allows(get_called_class(), $this->getRouteName(), $currentUser);
99
-        if ($securityResult === SecurityManager::ALLOWED) {
100
-            // We're allowed to run the page, so let's run it.
101
-            $this->runPage();
102
-        }
103
-        else {
104
-            $this->handleAccessDenied($securityResult);
105
-
106
-            // Send the headers
107
-            $this->sendResponseHeaders();
108
-        }
109
-    }
110
-
111
-    /**
112
-     * Performs final tasks needed before rendering the page.
113
-     */
114
-    final public function finalisePage()
115
-    {
116
-        parent::finalisePage();
117
-
118
-        $this->assign('typeAheadBlock', $this->getTypeAheadHelper()->getTypeAheadScriptBlock());
119
-
120
-        $database = $this->getDatabase();
121
-
122
-        $currentUser = User::getCurrent($database);
123
-        if (!$currentUser->isCommunityUser()) {
124
-            $sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);';
125
-            $statement = $database->query($sql);
126
-            $activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class);
127
-            $this->assign('onlineusers', $activeUsers);
128
-        }
129
-
130
-        $this->setupNavMenuAccess($currentUser);
131
-    }
132
-
133
-    /**
134
-     * Configures whether the page respects roles or not. You probably want this to return true.
135
-     *
136
-     * Set to false for public pages. You probably want this to return true.
137
-     *
138
-     * This defaults to true unless you explicitly set it to false. Setting it to false means anybody can do anything
139
-     * on this page, so you probably want this to return true.
140
-     *
141
-     * @return bool
142
-     * @category Security-Critical
143
-     */
144
-    protected function isProtectedPage()
145
-    {
146
-        return true;
147
-    }
148
-
149
-    protected function handleAccessDenied($denyReason)
150
-    {
151
-        $currentUser = User::getCurrent($this->getDatabase());
152
-
153
-        // Not allowed to access this resource.
154
-        // Firstly, let's check if we're even logged in.
155
-        if ($currentUser->isCommunityUser()) {
156
-            // Not logged in, redirect to login page
157
-            WebRequest::setPostLoginRedirect();
158
-            $this->redirect("login");
159
-
160
-            return;
161
-        }
162
-        else {
163
-            // Decide whether this was a rights failure, or an identification failure.
164
-
165
-            if ($denyReason === SecurityManager::ERROR_NOT_IDENTIFIED) {
166
-                // Not identified
167
-                throw new NotIdentifiedException($this->getSecurityManager());
168
-            }
169
-            elseif ($denyReason === SecurityManager::ERROR_DENIED) {
170
-                // Nope, plain old access denied
171
-                throw new AccessDeniedException($this->getSecurityManager());
172
-            }
173
-            else {
174
-                throw new Exception('Unknown response from security manager.');
175
-            }
176
-        }
177
-    }
178
-
179
-    /**
180
-     * Tests the security barrier for a specified action.
181
-     *
182
-     * Don't use within templates
183
-     *
184
-     * @param string      $action
185
-     *
186
-     * @param User        $user
187
-     * @param null|string $pageName
188
-     *
189
-     * @return bool
190
-     * @category Security-Critical
191
-     */
192
-    final public function barrierTest($action, User $user, $pageName = null)
193
-    {
194
-        $page = get_called_class();
195
-        if ($pageName !== null) {
196
-            $page = $pageName;
197
-        }
198
-
199
-        $securityResult = $this->getSecurityManager()->allows($page, $action, $user);
200
-
201
-        return $securityResult === SecurityManager::ALLOWED;
202
-    }
203
-
204
-    /**
205
-     * Updates the lastactive timestamp
206
-     */
207
-    private function touchUserLastActive()
208
-    {
209
-        if (WebRequest::getSessionUserId() !== null) {
210
-            $query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;';
211
-            $this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId()));
212
-        }
213
-    }
214
-
215
-    /**
216
-     * @return SecurityManager
217
-     */
218
-    public function getSecurityManager()
219
-    {
220
-        return $this->securityManager;
221
-    }
222
-
223
-    /**
224
-     * @param SecurityManager $securityManager
225
-     */
226
-    public function setSecurityManager(SecurityManager $securityManager)
227
-    {
228
-        $this->securityManager = $securityManager;
229
-    }
230
-
231
-    /**
232
-     * @return IBlacklistHelper
233
-     */
234
-    public function getBlacklistHelper()
235
-    {
236
-        return $this->blacklistHelper;
237
-    }
238
-
239
-    /**
240
-     * @param IBlacklistHelper $blacklistHelper
241
-     */
242
-    public function setBlacklistHelper(IBlacklistHelper $blacklistHelper)
243
-    {
244
-        $this->blacklistHelper = $blacklistHelper;
245
-    }
25
+	use NavigationMenuAccessControl;
26
+
27
+	/** @var IdentificationVerifier */
28
+	private $identificationVerifier;
29
+	/** @var ITypeAheadHelper */
30
+	private $typeAheadHelper;
31
+	/** @var SecurityManager */
32
+	private $securityManager;
33
+	/** @var IBlacklistHelper */
34
+	private $blacklistHelper;
35
+
36
+	/**
37
+	 * @return ITypeAheadHelper
38
+	 */
39
+	public function getTypeAheadHelper()
40
+	{
41
+		return $this->typeAheadHelper;
42
+	}
43
+
44
+	/**
45
+	 * Sets up the internal IdentificationVerifier instance.  Intended to be called from WebStart::setupHelpers().
46
+	 *
47
+	 * @param IdentificationVerifier $identificationVerifier
48
+	 *
49
+	 * @return void
50
+	 */
51
+	public function setIdentificationVerifier(IdentificationVerifier $identificationVerifier)
52
+	{
53
+		$this->identificationVerifier = $identificationVerifier;
54
+	}
55
+
56
+	/**
57
+	 * @param ITypeAheadHelper $typeAheadHelper
58
+	 */
59
+	public function setTypeAheadHelper(ITypeAheadHelper $typeAheadHelper)
60
+	{
61
+		$this->typeAheadHelper = $typeAheadHelper;
62
+	}
63
+
64
+	/**
65
+	 * Runs the page code
66
+	 *
67
+	 * @throws Exception
68
+	 * @category Security-Critical
69
+	 */
70
+	final public function execute()
71
+	{
72
+		if ($this->getRouteName() === null) {
73
+			throw new Exception("Request is unrouted.");
74
+		}
75
+
76
+		if ($this->getSiteConfiguration() === null) {
77
+			throw new Exception("Page has no configuration!");
78
+		}
79
+
80
+		$this->setupPage();
81
+
82
+		$this->touchUserLastActive();
83
+
84
+		$currentUser = User::getCurrent($this->getDatabase());
85
+
86
+		// Hey, this is also a security barrier, in addition to the below. Separated out for readability.
87
+		if (!$this->isProtectedPage()) {
88
+			// This page is /not/ a protected page, as such we can just run it.
89
+			$this->runPage();
90
+
91
+			return;
92
+		}
93
+
94
+		// Security barrier.
95
+		//
96
+		// This code essentially doesn't care if the user is logged in or not, as the security manager hides all that
97
+		// away for us
98
+		$securityResult = $this->getSecurityManager()->allows(get_called_class(), $this->getRouteName(), $currentUser);
99
+		if ($securityResult === SecurityManager::ALLOWED) {
100
+			// We're allowed to run the page, so let's run it.
101
+			$this->runPage();
102
+		}
103
+		else {
104
+			$this->handleAccessDenied($securityResult);
105
+
106
+			// Send the headers
107
+			$this->sendResponseHeaders();
108
+		}
109
+	}
110
+
111
+	/**
112
+	 * Performs final tasks needed before rendering the page.
113
+	 */
114
+	final public function finalisePage()
115
+	{
116
+		parent::finalisePage();
117
+
118
+		$this->assign('typeAheadBlock', $this->getTypeAheadHelper()->getTypeAheadScriptBlock());
119
+
120
+		$database = $this->getDatabase();
121
+
122
+		$currentUser = User::getCurrent($database);
123
+		if (!$currentUser->isCommunityUser()) {
124
+			$sql = 'SELECT * FROM user WHERE lastactive > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);';
125
+			$statement = $database->query($sql);
126
+			$activeUsers = $statement->fetchAll(PDO::FETCH_CLASS, User::class);
127
+			$this->assign('onlineusers', $activeUsers);
128
+		}
129
+
130
+		$this->setupNavMenuAccess($currentUser);
131
+	}
132
+
133
+	/**
134
+	 * Configures whether the page respects roles or not. You probably want this to return true.
135
+	 *
136
+	 * Set to false for public pages. You probably want this to return true.
137
+	 *
138
+	 * This defaults to true unless you explicitly set it to false. Setting it to false means anybody can do anything
139
+	 * on this page, so you probably want this to return true.
140
+	 *
141
+	 * @return bool
142
+	 * @category Security-Critical
143
+	 */
144
+	protected function isProtectedPage()
145
+	{
146
+		return true;
147
+	}
148
+
149
+	protected function handleAccessDenied($denyReason)
150
+	{
151
+		$currentUser = User::getCurrent($this->getDatabase());
152
+
153
+		// Not allowed to access this resource.
154
+		// Firstly, let's check if we're even logged in.
155
+		if ($currentUser->isCommunityUser()) {
156
+			// Not logged in, redirect to login page
157
+			WebRequest::setPostLoginRedirect();
158
+			$this->redirect("login");
159
+
160
+			return;
161
+		}
162
+		else {
163
+			// Decide whether this was a rights failure, or an identification failure.
164
+
165
+			if ($denyReason === SecurityManager::ERROR_NOT_IDENTIFIED) {
166
+				// Not identified
167
+				throw new NotIdentifiedException($this->getSecurityManager());
168
+			}
169
+			elseif ($denyReason === SecurityManager::ERROR_DENIED) {
170
+				// Nope, plain old access denied
171
+				throw new AccessDeniedException($this->getSecurityManager());
172
+			}
173
+			else {
174
+				throw new Exception('Unknown response from security manager.');
175
+			}
176
+		}
177
+	}
178
+
179
+	/**
180
+	 * Tests the security barrier for a specified action.
181
+	 *
182
+	 * Don't use within templates
183
+	 *
184
+	 * @param string      $action
185
+	 *
186
+	 * @param User        $user
187
+	 * @param null|string $pageName
188
+	 *
189
+	 * @return bool
190
+	 * @category Security-Critical
191
+	 */
192
+	final public function barrierTest($action, User $user, $pageName = null)
193
+	{
194
+		$page = get_called_class();
195
+		if ($pageName !== null) {
196
+			$page = $pageName;
197
+		}
198
+
199
+		$securityResult = $this->getSecurityManager()->allows($page, $action, $user);
200
+
201
+		return $securityResult === SecurityManager::ALLOWED;
202
+	}
203
+
204
+	/**
205
+	 * Updates the lastactive timestamp
206
+	 */
207
+	private function touchUserLastActive()
208
+	{
209
+		if (WebRequest::getSessionUserId() !== null) {
210
+			$query = 'UPDATE user SET lastactive = CURRENT_TIMESTAMP() WHERE id = :id;';
211
+			$this->getDatabase()->prepare($query)->execute(array(":id" => WebRequest::getSessionUserId()));
212
+		}
213
+	}
214
+
215
+	/**
216
+	 * @return SecurityManager
217
+	 */
218
+	public function getSecurityManager()
219
+	{
220
+		return $this->securityManager;
221
+	}
222
+
223
+	/**
224
+	 * @param SecurityManager $securityManager
225
+	 */
226
+	public function setSecurityManager(SecurityManager $securityManager)
227
+	{
228
+		$this->securityManager = $securityManager;
229
+	}
230
+
231
+	/**
232
+	 * @return IBlacklistHelper
233
+	 */
234
+	public function getBlacklistHelper()
235
+	{
236
+		return $this->blacklistHelper;
237
+	}
238
+
239
+	/**
240
+	 * @param IBlacklistHelper $blacklistHelper
241
+	 */
242
+	public function setBlacklistHelper(IBlacklistHelper $blacklistHelper)
243
+	{
244
+		$this->blacklistHelper = $blacklistHelper;
245
+	}
246 246
 }
Please login to merge, or discard this patch.
includes/Exceptions/NotIdentifiedException.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -15,52 +15,52 @@
 block discarded – undo
15 15
 
16 16
 class NotIdentifiedException extends ReadableException
17 17
 {
18
-    use NavigationMenuAccessControl;
19
-    /**
20
-     * @var SecurityManager
21
-     */
22
-    private $securityManager;
18
+	use NavigationMenuAccessControl;
19
+	/**
20
+	 * @var SecurityManager
21
+	 */
22
+	private $securityManager;
23 23
 
24
-    /**
25
-     * NotIdentifiedException constructor.
26
-     *
27
-     * @param SecurityManager $securityManager
28
-     */
29
-    public function __construct(SecurityManager $securityManager = null)
30
-    {
31
-        $this->securityManager = $securityManager;
32
-    }
24
+	/**
25
+	 * NotIdentifiedException constructor.
26
+	 *
27
+	 * @param SecurityManager $securityManager
28
+	 */
29
+	public function __construct(SecurityManager $securityManager = null)
30
+	{
31
+		$this->securityManager = $securityManager;
32
+	}
33 33
 
34
-    /**
35
-     * Returns a readable HTML error message that's displayable to the user using templates.
36
-     * @return string
37
-     */
38
-    public function getReadableError()
39
-    {
40
-        if (!headers_sent()) {
41
-            header("HTTP/1.1 403 Forbidden");
42
-        }
34
+	/**
35
+	 * Returns a readable HTML error message that's displayable to the user using templates.
36
+	 * @return string
37
+	 */
38
+	public function getReadableError()
39
+	{
40
+		if (!headers_sent()) {
41
+			header("HTTP/1.1 403 Forbidden");
42
+		}
43 43
 
44
-        $this->setUpSmarty();
44
+		$this->setUpSmarty();
45 45
 
46
-        // uck. We should still be able to access the database in this situation though.
47
-        $database = PdoDatabase::getDatabaseConnection('acc');
48
-        $currentUser = User::getCurrent($database);
49
-        $this->assign('currentUser', $currentUser);
50
-        $this->assign("loggedIn", (!$currentUser->isCommunityUser()));
46
+		// uck. We should still be able to access the database in this situation though.
47
+		$database = PdoDatabase::getDatabaseConnection('acc');
48
+		$currentUser = User::getCurrent($database);
49
+		$this->assign('currentUser', $currentUser);
50
+		$this->assign("loggedIn", (!$currentUser->isCommunityUser()));
51 51
 
52
-        if($this->securityManager !== null) {
53
-            $this->setupNavMenuAccess($currentUser);
54
-        }
52
+		if($this->securityManager !== null) {
53
+			$this->setupNavMenuAccess($currentUser);
54
+		}
55 55
 
56
-        return $this->fetchTemplate("exception/not-identified.tpl");
57
-    }
56
+		return $this->fetchTemplate("exception/not-identified.tpl");
57
+	}
58 58
 
59
-    /**
60
-     * @return SecurityManager
61
-     */
62
-    protected function getSecurityManager()
63
-    {
64
-        return $this->securityManager;
65
-    }
59
+	/**
60
+	 * @return SecurityManager
61
+	 */
62
+	protected function getSecurityManager()
63
+	{
64
+		return $this->securityManager;
65
+	}
66 66
 }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
         $this->assign('currentUser', $currentUser);
58 58
         $this->assign("loggedIn", (!$currentUser->isCommunityUser()));
59 59
 
60
-        if($this->securityManager !== null) {
60
+        if ($this->securityManager !== null) {
61 61
             $this->setupNavMenuAccess($currentUser);
62 62
         }
63 63
 
Please login to merge, or discard this patch.
includes/ConsoleTasks/MigrateToRoles.php 3 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -16,55 +16,55 @@
 block discarded – undo
16 16
 
17 17
 class MigrateToRoles extends ConsoleTaskBase
18 18
 {
19
-    public function execute()
20
-    {
21
-        $communityUser = User::getCommunity();
19
+	public function execute()
20
+	{
21
+		$communityUser = User::getCommunity();
22 22
 
23
-        $database = $this->getDatabase();
24
-        $statement = $database->query('SELECT id, status, checkuser FROM user;');
25
-        $update = $database->prepare("UPDATE user SET status = 'Active' WHERE id = :id;");
23
+		$database = $this->getDatabase();
24
+		$statement = $database->query('SELECT id, status, checkuser FROM user;');
25
+		$update = $database->prepare("UPDATE user SET status = 'Active' WHERE id = :id;");
26 26
 
27
-        $users = $statement->fetchAll(PDO::FETCH_ASSOC);
27
+		$users = $statement->fetchAll(PDO::FETCH_ASSOC);
28 28
 
29
-        foreach ($users as $user) {
30
-            $toAdd = array('user');
29
+		foreach ($users as $user) {
30
+			$toAdd = array('user');
31 31
 
32
-            if($user['status'] === 'Admin'){
33
-                $toAdd[] = 'admin';
34
-            }
32
+			if($user['status'] === 'Admin'){
33
+				$toAdd[] = 'admin';
34
+			}
35 35
 
36
-            if($user['checkuser'] == 1){
37
-                $toAdd[] = 'checkuser';
38
-            }
36
+			if($user['checkuser'] == 1){
37
+				$toAdd[] = 'checkuser';
38
+			}
39 39
 
40
-            foreach ($toAdd as $x) {
41
-                $a = new UserRole();
42
-                $a->setUser($user['id']);
43
-                $a->setRole($x);
44
-                $a->setDatabase($database);
45
-                $a->save();
46
-            }
40
+			foreach ($toAdd as $x) {
41
+				$a = new UserRole();
42
+				$a->setUser($user['id']);
43
+				$a->setRole($x);
44
+				$a->setDatabase($database);
45
+				$a->save();
46
+			}
47 47
 
48
-            $logData = serialize(array(
49
-                'added' => $toAdd,
50
-                'removed' => array(),
51
-                'reason' => 'Initial migration'
52
-            ));
48
+			$logData = serialize(array(
49
+				'added' => $toAdd,
50
+				'removed' => array(),
51
+				'reason' => 'Initial migration'
52
+			));
53 53
 
54
-            $log = new Log();
55
-            $log->setDatabase($database);
56
-            $log->setAction('RoleChange');
57
-            $log->setObjectId($user['id']);
58
-            $log->setObjectType('User');
59
-            $log->setUser($communityUser);
60
-            $log->setComment($logData);
61
-            $log->save();
54
+			$log = new Log();
55
+			$log->setDatabase($database);
56
+			$log->setAction('RoleChange');
57
+			$log->setObjectId($user['id']);
58
+			$log->setObjectType('User');
59
+			$log->setUser($communityUser);
60
+			$log->setComment($logData);
61
+			$log->save();
62 62
 
63
-            if($user['status'] === 'Admin' || $user['status'] === 'User'){
64
-                $update->execute(array('id' => $user['id']));
65
-            }
66
-        }
63
+			if($user['status'] === 'Admin' || $user['status'] === 'User'){
64
+				$update->execute(array('id' => $user['id']));
65
+			}
66
+		}
67 67
 
68
-        $database->exec("UPDATE schemaversion SET version = 25;");
69
-    }
68
+		$database->exec("UPDATE schemaversion SET version = 25;");
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
         foreach ($users as $user) {
30 30
             $toAdd = array('user');
31 31
 
32
-            if($user['status'] === 'Admin'){
32
+            if ($user['status'] === 'Admin') {
33 33
                 $toAdd[] = 'admin';
34 34
             }
35 35
 
36
-            if($user['checkuser'] == 1){
36
+            if ($user['checkuser'] == 1) {
37 37
                 $toAdd[] = 'checkuser';
38 38
             }
39 39
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             $log->setComment($logData);
61 61
             $log->save();
62 62
 
63
-            if($user['status'] === 'Admin' || $user['status'] === 'User'){
63
+            if ($user['status'] === 'Admin' || $user['status'] === 'User') {
64 64
                 $update->execute(array('id' => $user['id']));
65 65
             }
66 66
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
         foreach ($users as $user) {
30 30
             $toAdd = array('user');
31 31
 
32
-            if($user['status'] === 'Admin'){
32
+            if($user['status'] === 'Admin') {
33 33
                 $toAdd[] = 'admin';
34 34
             }
35 35
 
36
-            if($user['checkuser'] == 1){
36
+            if($user['checkuser'] == 1) {
37 37
                 $toAdd[] = 'checkuser';
38 38
             }
39 39
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             $log->setComment($logData);
61 61
             $log->save();
62 62
 
63
-            if($user['status'] === 'Admin' || $user['status'] === 'User'){
63
+            if($user['status'] === 'Admin' || $user['status'] === 'User') {
64 64
                 $update->execute(array('id' => $user['id']));
65 65
             }
66 66
         }
Please login to merge, or discard this patch.
includes/DataObjects/UserRole.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -15,95 +15,95 @@
 block discarded – undo
15 15
 
16 16
 class UserRole extends DataObject
17 17
 {
18
-    /** @var int */
19
-    private $user;
20
-    /** @var string */
21
-    private $role;
18
+	/** @var int */
19
+	private $user;
20
+	/** @var string */
21
+	private $role;
22 22
 
23
-    /**
24
-     * @param int         $userId
25
-     * @param PdoDatabase $database
26
-     *
27
-     * @return UserRole[]
28
-     */
29
-    public static function getForUser($userId, PdoDatabase $database)
30
-    {
31
-        $sql = 'SELECT * FROM userrole WHERE user = :user';
32
-        $statement = $database->prepare($sql);
33
-        $statement->bindValue(':user', $userId);
23
+	/**
24
+	 * @param int         $userId
25
+	 * @param PdoDatabase $database
26
+	 *
27
+	 * @return UserRole[]
28
+	 */
29
+	public static function getForUser($userId, PdoDatabase $database)
30
+	{
31
+		$sql = 'SELECT * FROM userrole WHERE user = :user';
32
+		$statement = $database->prepare($sql);
33
+		$statement->bindValue(':user', $userId);
34 34
 
35
-        $statement->execute();
35
+		$statement->execute();
36 36
 
37
-        $result = array();
37
+		$result = array();
38 38
 
39
-        /** @var Ban $v */
40
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
41
-            $v->setDatabase($database);
42
-            $result[] = $v;
43
-        }
39
+		/** @var Ban $v */
40
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
41
+			$v->setDatabase($database);
42
+			$result[] = $v;
43
+		}
44 44
 
45
-        return $result;
46
-    }
45
+		return $result;
46
+	}
47 47
 
48
-    /**
49
-     * Saves a data object to the database, either updating or inserting a record.
50
-     *
51
-     * @throws Exception
52
-     */
53
-    public function save()
54
-    {
55
-        if ($this->isNew()) {
56
-            // insert
57
-            $statement = $this->dbObject->prepare('INSERT INTO `userrole` (user, role) VALUES (:user, :role);'
58
-            );
59
-            $statement->bindValue(":user", $this->user);
60
-            $statement->bindValue(":role", $this->role);
48
+	/**
49
+	 * Saves a data object to the database, either updating or inserting a record.
50
+	 *
51
+	 * @throws Exception
52
+	 */
53
+	public function save()
54
+	{
55
+		if ($this->isNew()) {
56
+			// insert
57
+			$statement = $this->dbObject->prepare('INSERT INTO `userrole` (user, role) VALUES (:user, :role);'
58
+			);
59
+			$statement->bindValue(":user", $this->user);
60
+			$statement->bindValue(":role", $this->role);
61 61
 
62
-            if ($statement->execute()) {
63
-                $this->id = (int)$this->dbObject->lastInsertId();
64
-            }
65
-            else {
66
-                throw new Exception($statement->errorInfo());
67
-            }
68
-        }
69
-        else {
70
-            // update
71
-            throw new Exception('Updating roles is not available');
72
-        }
73
-    }
62
+			if ($statement->execute()) {
63
+				$this->id = (int)$this->dbObject->lastInsertId();
64
+			}
65
+			else {
66
+				throw new Exception($statement->errorInfo());
67
+			}
68
+		}
69
+		else {
70
+			// update
71
+			throw new Exception('Updating roles is not available');
72
+		}
73
+	}
74 74
 
75
-    #region Properties
75
+	#region Properties
76 76
 
77
-    /**
78
-     * @return int
79
-     */
80
-    public function getUser()
81
-    {
82
-        return $this->user;
83
-    }
77
+	/**
78
+	 * @return int
79
+	 */
80
+	public function getUser()
81
+	{
82
+		return $this->user;
83
+	}
84 84
 
85
-    /**
86
-     * @param int $user
87
-     */
88
-    public function setUser($user)
89
-    {
90
-        $this->user = $user;
91
-    }
85
+	/**
86
+	 * @param int $user
87
+	 */
88
+	public function setUser($user)
89
+	{
90
+		$this->user = $user;
91
+	}
92 92
 
93
-    /**
94
-     * @return string
95
-     */
96
-    public function getRole()
97
-    {
98
-        return $this->role;
99
-    }
93
+	/**
94
+	 * @return string
95
+	 */
96
+	public function getRole()
97
+	{
98
+		return $this->role;
99
+	}
100 100
 
101
-    /**
102
-     * @param string $role
103
-     */
104
-    public function setRole($role)
105
-    {
106
-        $this->role = $role;
107
-    }
108
-    #endregion
101
+	/**
102
+	 * @param string $role
103
+	 */
104
+	public function setRole($role)
105
+	{
106
+		$this->role = $role;
107
+	}
108
+	#endregion
109 109
 }
Please login to merge, or discard this patch.
includes/DataObjects/Comment.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -20,172 +20,172 @@
 block discarded – undo
20 20
  */
21 21
 class Comment extends DataObject
22 22
 {
23
-    private $time;
24
-    private $user;
25
-    private $comment;
26
-    private $visibility = "user";
27
-    private $request;
28
-
29
-    /**
30
-     * Retrieves all comments for a request, optionally filtered
31
-     *
32
-     * @param integer     $id      Request ID to search by
33
-     * @param PdoDatabase $database
34
-     * @param bool        $showAll True to show all comments, False to show only unprotected comments, and protected
35
-     *                             comments visible to $userId
36
-     * @param null|int    $userId  User to filter by
37
-     *
38
-     * @return Comment[]
39
-     */
40
-    public static function getForRequest($id, PdoDatabase $database, $showAll = false, $userId = null)
41
-    {
42
-        if ($showAll) {
43
-            $statement = $database->prepare('SELECT * FROM comment WHERE request = :target;');
44
-        }
45
-        else {
46
-            $statement = $database->prepare(<<<SQL
23
+	private $time;
24
+	private $user;
25
+	private $comment;
26
+	private $visibility = "user";
27
+	private $request;
28
+
29
+	/**
30
+	 * Retrieves all comments for a request, optionally filtered
31
+	 *
32
+	 * @param integer     $id      Request ID to search by
33
+	 * @param PdoDatabase $database
34
+	 * @param bool        $showAll True to show all comments, False to show only unprotected comments, and protected
35
+	 *                             comments visible to $userId
36
+	 * @param null|int    $userId  User to filter by
37
+	 *
38
+	 * @return Comment[]
39
+	 */
40
+	public static function getForRequest($id, PdoDatabase $database, $showAll = false, $userId = null)
41
+	{
42
+		if ($showAll) {
43
+			$statement = $database->prepare('SELECT * FROM comment WHERE request = :target;');
44
+		}
45
+		else {
46
+			$statement = $database->prepare(<<<SQL
47 47
 SELECT * FROM comment
48 48
 WHERE request = :target AND (visibility = 'user' OR user = :userid);
49 49
 SQL
50
-            );
51
-            $statement->bindValue(':userid', $userId);
52
-        }
53
-
54
-        $statement->bindValue(':target', $id);
55
-
56
-        $statement->execute();
57
-
58
-        $result = array();
59
-        /** @var Comment $v */
60
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
61
-            $v->setDatabase($database);
62
-            $result[] = $v;
63
-        }
64
-
65
-        return $result;
66
-    }
67
-
68
-    /**
69
-     * @throws Exception
70
-     */
71
-    public function save()
72
-    {
73
-        if ($this->isNew()) {
74
-            // insert
75
-            $statement = $this->dbObject->prepare(<<<SQL
50
+			);
51
+			$statement->bindValue(':userid', $userId);
52
+		}
53
+
54
+		$statement->bindValue(':target', $id);
55
+
56
+		$statement->execute();
57
+
58
+		$result = array();
59
+		/** @var Comment $v */
60
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
61
+			$v->setDatabase($database);
62
+			$result[] = $v;
63
+		}
64
+
65
+		return $result;
66
+	}
67
+
68
+	/**
69
+	 * @throws Exception
70
+	 */
71
+	public function save()
72
+	{
73
+		if ($this->isNew()) {
74
+			// insert
75
+			$statement = $this->dbObject->prepare(<<<SQL
76 76
 INSERT INTO comment ( time, user, comment, visibility, request )
77 77
 VALUES ( CURRENT_TIMESTAMP(), :user, :comment, :visibility, :request );
78 78
 SQL
79
-            );
80
-            $statement->bindValue(":user", $this->user);
81
-            $statement->bindValue(":comment", $this->comment);
82
-            $statement->bindValue(":visibility", $this->visibility);
83
-            $statement->bindValue(":request", $this->request);
84
-
85
-            if ($statement->execute()) {
86
-                $this->id = (int)$this->dbObject->lastInsertId();
87
-            }
88
-            else {
89
-                throw new Exception($statement->errorInfo());
90
-            }
91
-        }
92
-        else {
93
-            // update
94
-            $statement = $this->dbObject->prepare(<<<SQL
79
+			);
80
+			$statement->bindValue(":user", $this->user);
81
+			$statement->bindValue(":comment", $this->comment);
82
+			$statement->bindValue(":visibility", $this->visibility);
83
+			$statement->bindValue(":request", $this->request);
84
+
85
+			if ($statement->execute()) {
86
+				$this->id = (int)$this->dbObject->lastInsertId();
87
+			}
88
+			else {
89
+				throw new Exception($statement->errorInfo());
90
+			}
91
+		}
92
+		else {
93
+			// update
94
+			$statement = $this->dbObject->prepare(<<<SQL
95 95
 UPDATE comment
96 96
 SET comment = :comment, visibility = :visibility, updateversion = updateversion + 1
97 97
 WHERE id = :id AND updateversion = :updateversion
98 98
 LIMIT 1;
99 99
 SQL
100
-            );
101
-
102
-            $statement->bindValue(':id', $this->id);
103
-            $statement->bindValue(':updateversion', $this->updateversion);
104
-
105
-            $statement->bindValue(':comment', $this->comment);
106
-            $statement->bindValue(':visibility', $this->visibility);
107
-
108
-            if (!$statement->execute()) {
109
-                throw new Exception($statement->errorInfo());
110
-            }
111
-
112
-            if ($statement->rowCount() !== 1) {
113
-                throw new OptimisticLockFailedException();
114
-            }
115
-
116
-            $this->updateversion++;
117
-        }
118
-    }
119
-
120
-    /**
121
-     * @return DateTimeImmutable
122
-     */
123
-    public function getTime()
124
-    {
125
-        return new DateTimeImmutable($this->time);
126
-    }
127
-
128
-    /**
129
-     * @return int
130
-     */
131
-    public function getUser()
132
-    {
133
-        return $this->user;
134
-    }
135
-
136
-    /**
137
-     * @param int $user
138
-     */
139
-    public function setUser($user)
140
-    {
141
-        $this->user = $user;
142
-    }
143
-
144
-    /**
145
-     * @return string
146
-     */
147
-    public function getComment()
148
-    {
149
-        return $this->comment;
150
-    }
151
-
152
-    /**
153
-     * @param string $comment
154
-     */
155
-    public function setComment($comment)
156
-    {
157
-        $this->comment = $comment;
158
-    }
159
-
160
-    /**
161
-     * @return string
162
-     */
163
-    public function getVisibility()
164
-    {
165
-        return $this->visibility;
166
-    }
167
-
168
-    /**
169
-     * @param string $visibility
170
-     */
171
-    public function setVisibility($visibility)
172
-    {
173
-        $this->visibility = $visibility;
174
-    }
175
-
176
-    /**
177
-     * @return int
178
-     */
179
-    public function getRequest()
180
-    {
181
-        return $this->request;
182
-    }
183
-
184
-    /**
185
-     * @param int $request
186
-     */
187
-    public function setRequest($request)
188
-    {
189
-        $this->request = $request;
190
-    }
100
+			);
101
+
102
+			$statement->bindValue(':id', $this->id);
103
+			$statement->bindValue(':updateversion', $this->updateversion);
104
+
105
+			$statement->bindValue(':comment', $this->comment);
106
+			$statement->bindValue(':visibility', $this->visibility);
107
+
108
+			if (!$statement->execute()) {
109
+				throw new Exception($statement->errorInfo());
110
+			}
111
+
112
+			if ($statement->rowCount() !== 1) {
113
+				throw new OptimisticLockFailedException();
114
+			}
115
+
116
+			$this->updateversion++;
117
+		}
118
+	}
119
+
120
+	/**
121
+	 * @return DateTimeImmutable
122
+	 */
123
+	public function getTime()
124
+	{
125
+		return new DateTimeImmutable($this->time);
126
+	}
127
+
128
+	/**
129
+	 * @return int
130
+	 */
131
+	public function getUser()
132
+	{
133
+		return $this->user;
134
+	}
135
+
136
+	/**
137
+	 * @param int $user
138
+	 */
139
+	public function setUser($user)
140
+	{
141
+		$this->user = $user;
142
+	}
143
+
144
+	/**
145
+	 * @return string
146
+	 */
147
+	public function getComment()
148
+	{
149
+		return $this->comment;
150
+	}
151
+
152
+	/**
153
+	 * @param string $comment
154
+	 */
155
+	public function setComment($comment)
156
+	{
157
+		$this->comment = $comment;
158
+	}
159
+
160
+	/**
161
+	 * @return string
162
+	 */
163
+	public function getVisibility()
164
+	{
165
+		return $this->visibility;
166
+	}
167
+
168
+	/**
169
+	 * @param string $visibility
170
+	 */
171
+	public function setVisibility($visibility)
172
+	{
173
+		$this->visibility = $visibility;
174
+	}
175
+
176
+	/**
177
+	 * @return int
178
+	 */
179
+	public function getRequest()
180
+	{
181
+		return $this->request;
182
+	}
183
+
184
+	/**
185
+	 * @param int $request
186
+	 */
187
+	public function setRequest($request)
188
+	{
189
+		$this->request = $request;
190
+	}
191 191
 }
Please login to merge, or discard this patch.
includes/Helpers/IrcNotificationHelper.php 2 patches
Indentation   +449 added lines, -449 removed lines patch added patch discarded remove patch
@@ -26,455 +26,455 @@
 block discarded – undo
26 26
  */
27 27
 class IrcNotificationHelper
28 28
 {
29
-    /** @var PdoDatabase $notificationsDatabase */
30
-    private $notificationsDatabase;
31
-    /** @var PdoDatabase $primaryDatabase */
32
-    private $primaryDatabase;
33
-    /** @var bool $notificationsEnabled */
34
-    private $notificationsEnabled;
35
-    /** @var int $notificationType */
36
-    private $notificationType;
37
-    /** @var User $currentUser */
38
-    private $currentUser;
39
-    /** @var string $instanceName */
40
-    private $instanceName;
41
-    /** @var string */
42
-    private $baseUrl;
43
-    /** @var array */
44
-    private $requestStates;
45
-
46
-    /**
47
-     * IrcNotificationHelper constructor.
48
-     *
49
-     * @param SiteConfiguration $siteConfiguration
50
-     * @param PdoDatabase       $primaryDatabase
51
-     * @param PdoDatabase       $notificationsDatabase
52
-     */
53
-    public function __construct(
54
-        SiteConfiguration $siteConfiguration,
55
-        PdoDatabase $primaryDatabase,
56
-        PdoDatabase $notificationsDatabase = null
57
-    ) {
58
-        $this->primaryDatabase = $primaryDatabase;
59
-
60
-        if ($this->notificationsDatabase !== null) {
61
-            $this->notificationsDatabase = $notificationsDatabase;
62
-            $this->notificationsEnabled = $siteConfiguration->getIrcNotificationsEnabled();
63
-        }
64
-        else {
65
-            $this->notificationsEnabled = false;
66
-        }
67
-
68
-        $this->notificationType = $siteConfiguration->getIrcNotificationType();
69
-        $this->instanceName = $siteConfiguration->getIrcNotificationsInstance();
70
-        $this->baseUrl = $siteConfiguration->getBaseUrl();
71
-        $this->requestStates = $siteConfiguration->getRequestStates();
72
-
73
-        $this->currentUser = User::getCurrent($primaryDatabase);
74
-    }
75
-
76
-    /**
77
-     * Send a notification
78
-     *
79
-     * @param string $message The text to send
80
-     */
81
-    protected function send($message)
82
-    {
83
-        $instanceName = $this->instanceName;
84
-
85
-        if (!$this->notificationsEnabled) {
86
-            return;
87
-        }
88
-
89
-        $blacklist = array("DCC", "CCTP", "PRIVMSG");
90
-        $message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc
91
-
92
-        $msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message";
93
-
94
-        try {
95
-            $notification = new Notification();
96
-            $notification->setDatabase($this->notificationsDatabase);
97
-            $notification->setType($this->notificationType);
98
-            $notification->setText($msg);
99
-
100
-            $notification->save();
101
-        }
102
-        catch (Exception $ex) {
103
-            // OK, so we failed to send the notification - that db might be down?
104
-            // This is non-critical, so silently fail.
105
-
106
-            // Disable notifications for remainder of request.
107
-            $this->notificationsEnabled = false;
108
-        }
109
-    }
110
-
111
-    #region user management
112
-
113
-    /**
114
-     * send a new user notification
115
-     *
116
-     * @param User $user
117
-     */
118
-    public function userNew(User $user)
119
-    {
120
-        $this->send("New user: {$user->getUsername()}");
121
-    }
122
-
123
-    /**
124
-     * send an approved notification
125
-     *
126
-     * @param User $user
127
-     */
128
-    public function userApproved(User $user)
129
-    {
130
-        $this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername());
131
-    }
132
-
133
-    /**
134
-     * send a promoted notification
135
-     *
136
-     * @param User $user
137
-     */
138
-    public function userPromoted(User $user)
139
-    {
140
-        $this->send("{$user->getUsername()} promoted to tool admin by " . $this->currentUser->getUsername());
141
-    }
142
-
143
-    /**
144
-     * send a declined notification
145
-     *
146
-     * @param User   $user
147
-     * @param string $reason the reason the user was declined
148
-     */
149
-    public function userDeclined(User $user, $reason)
150
-    {
151
-        $this->send("{$user->getUsername()} declined by " . $this->currentUser->getUsername() . " ($reason)");
152
-    }
153
-
154
-    /**
155
-     * send a demotion notification
156
-     *
157
-     * @param User   $user
158
-     * @param string $reason the reason the user was demoted
159
-     */
160
-    public function userDemoted(User $user, $reason)
161
-    {
162
-        $this->send("{$user->getUsername()} demoted by " . $this->currentUser->getUsername() . " ($reason)");
163
-    }
164
-
165
-    /**
166
-     * send a suspended notification
167
-     *
168
-     * @param User   $user
169
-     * @param string $reason The reason the user has been suspended
170
-     */
171
-    public function userSuspended(User $user, $reason)
172
-    {
173
-        $this->send("{$user->getUsername()} suspended by " . $this->currentUser->getUsername() . " ($reason)");
174
-    }
175
-
176
-    /**
177
-     * Send a preference change notification
178
-     *
179
-     * @param User $user
180
-     */
181
-    public function userPrefChange(User $user)
182
-    {
183
-        $this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername());
184
-    }
185
-
186
-    /**
187
-     * Send a user renamed notification
188
-     *
189
-     * @param User   $user
190
-     * @param string $old
191
-     */
192
-    public function userRenamed(User $user, $old)
193
-    {
194
-        $this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}");
195
-    }
196
-
197
-    /**
198
-     * @param User   $user
199
-     * @param string $reason
200
-     */
201
-    public function userRolesEdited(User $user, $reason)
202
-    {
203
-        $currentUser = $this->currentUser->getUsername();
204
-        $this->send("Active roles for {$user->getUsername()} changed by " . $currentUser . " ($reason)");
205
-    }
206
-
207
-    #endregion
208
-
209
-    #region Site Notice
210
-
211
-    /**
212
-     * Summary of siteNoticeEdited
213
-     */
214
-    public function siteNoticeEdited()
215
-    {
216
-        $this->send("Site notice edited by " . $this->currentUser->getUsername());
217
-    }
218
-    #endregion
219
-
220
-    #region Welcome Templates
221
-    /**
222
-     * Summary of welcomeTemplateCreated
223
-     *
224
-     * @param WelcomeTemplate $template
225
-     */
226
-    public function welcomeTemplateCreated(WelcomeTemplate $template)
227
-    {
228
-        $this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername());
229
-    }
230
-
231
-    /**
232
-     * Summary of welcomeTemplateDeleted
233
-     *
234
-     * @param int $templateid
235
-     */
236
-    public function welcomeTemplateDeleted($templateid)
237
-    {
238
-        $this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername());
239
-    }
240
-
241
-    /**
242
-     * Summary of welcomeTemplateEdited
243
-     *
244
-     * @param WelcomeTemplate $template
245
-     */
246
-    public function welcomeTemplateEdited(WelcomeTemplate $template)
247
-    {
248
-        $this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername());
249
-    }
250
-
251
-    #endregion
252
-
253
-    #region bans
254
-    /**
255
-     * Summary of banned
256
-     *
257
-     * @param Ban $ban
258
-     */
259
-    public function banned(Ban $ban)
260
-    {
261
-        if ($ban->getDuration() == -1) {
262
-            $duration = "indefinitely";
263
-        }
264
-        else {
265
-            $duration = "until " . date("F j, Y, g:i a", $ban->getDuration());
266
-        }
267
-
268
-        $username = $this->currentUser->getUsername();
269
-
270
-        $this->send("{$ban->getTarget()} banned by {$username} for '{$ban->getReason()}' {$duration}");
271
-    }
272
-
273
-    /**
274
-     * Summary of unbanned
275
-     *
276
-     * @param Ban    $ban
277
-     * @param string $unbanreason
278
-     */
279
-    public function unbanned(Ban $ban, $unbanreason)
280
-    {
281
-        $this->send($ban->getTarget() . " unbanned by " . $this->currentUser
282
-                ->getUsername() . " (" . $unbanreason . ")");
283
-    }
284
-
285
-    #endregion
286
-
287
-    #region request management
288
-
289
-    /**
290
-     * Summary of requestReceived
291
-     *
292
-     * @param Request $request
293
-     */
294
-    public function requestReceived(Request $request)
295
-    {
296
-        $this->send(
297
-            IrcColourCode::DARK_GREY . "[["
298
-            . IrcColourCode::DARK_GREEN . "acc:"
299
-            . IrcColourCode::ORANGE . $request->getId()
300
-            . IrcColourCode::DARK_GREY . "]]"
301
-            . IrcColourCode::RED . " N "
302
-            . IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} "
303
-            . IrcColourCode::DARK_RED . "* "
304
-            . IrcColourCode::DARK_GREEN . $request->getName()
305
-            . IrcColourCode::DARK_RED . " * "
306
-            . IrcColourCode::RESET
307
-        );
308
-    }
309
-
310
-    /**
311
-     * Summary of requestDeferred
312
-     *
313
-     * @param Request $request
314
-     */
315
-    public function requestDeferred(Request $request)
316
-    {
317
-        $availableRequestStates = $this->requestStates;
318
-
319
-        $deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
320
-        $username = $this->currentUser->getUsername();
321
-
322
-        $this->send("Request {$request->getId()} ({$request->getName()}) deferred to {$deferTo} by {$username}");
323
-    }
324
-
325
-    /**
326
-     *
327
-     * Summary of requestDeferredWithMail
328
-     *
329
-     * @param Request $request
330
-     */
331
-    public function requestDeferredWithMail(Request $request)
332
-    {
333
-        $availableRequestStates = $this->requestStates;
334
-
335
-        $deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
336
-        $username = $this->currentUser->getUsername();
337
-        $id = $request->getId();
338
-        $name = $request->getName();
339
-
340
-        $this->send("Request {$id} ({$name}) deferred to {$deferTo} with an email by {$username}");
341
-    }
342
-
343
-    /**
344
-     * Summary of requestClosed
345
-     *
346
-     * @param Request $request
347
-     * @param string  $closetype
348
-     */
349
-    public function requestClosed(Request $request, $closetype)
350
-    {
351
-        $username = $this->currentUser->getUsername();
352
-
353
-        $this->send("Request {$request->getId()} ({$request->getName()}) closed ($closetype) by {$username}");
354
-    }
355
-
356
-    /**
357
-     * Summary of sentMail
358
-     *
359
-     * @param Request $request
360
-     */
361
-    public function sentMail(Request $request)
362
-    {
363
-        $this->send($this->currentUser->getUsername()
364
-            . " sent an email related to Request {$request->getId()} ({$request->getName()})");
365
-    }
366
-
367
-    #endregion
368
-
369
-    #region reservations
370
-
371
-    /**
372
-     * Summary of requestReserved
373
-     *
374
-     * @param Request $request
375
-     */
376
-    public function requestReserved(Request $request)
377
-    {
378
-        $username = $this->currentUser->getUsername();
379
-
380
-        $this->send("Request {$request->getId()} ({$request->getName()}) reserved by {$username}");
381
-    }
382
-
383
-    /**
384
-     * Summary of requestReserveBroken
385
-     *
386
-     * @param Request $request
387
-     */
388
-    public function requestReserveBroken(Request $request)
389
-    {
390
-        $username = $this->currentUser->getUsername();
391
-
392
-        $this->send("Reservation on request {$request->getId()} ({$request->getName()}) broken by {$username}");
393
-    }
394
-
395
-    /**
396
-     * Summary of requestUnreserved
397
-     *
398
-     * @param Request $request
399
-     */
400
-    public function requestUnreserved(Request $request)
401
-    {
402
-        $this->send("Request {$request->getId()} ({$request->getName()}) is no longer being handled.");
403
-    }
404
-
405
-    /**
406
-     * Summary of requestReservationSent
407
-     *
408
-     * @param Request $request
409
-     * @param User    $target
410
-     */
411
-    public function requestReservationSent(Request $request, User $target)
412
-    {
413
-        $username = $this->currentUser->getUsername();
414
-
415
-        $this->send(
416
-            "Reservation of request {$request->getId()} ({$request->getName()}) sent to {$target->getUsername()} by "
417
-            . $username);
418
-    }
419
-
420
-    #endregion
421
-
422
-    #region comments
423
-
424
-    /**
425
-     * Summary of commentCreated
426
-     *
427
-     * @param Comment $comment
428
-     * @param Request $request
429
-     */
430
-    public function commentCreated(Comment $comment, Request $request)
431
-    {
432
-        $username = $this->currentUser->getUsername();
433
-        $visibility = ($comment->getVisibility() == "admin" ? "private " : "");
434
-
435
-        $this->send("{$username} posted a {$visibility}comment on request {$request->getId()} ({$request->getName()})");
436
-    }
437
-
438
-    /**
439
-     * Summary of commentEdited
440
-     *
441
-     * @param Comment $comment
442
-     * @param Request $request
443
-     */
444
-    public function commentEdited(Comment $comment, Request $request)
445
-    {
446
-        $username = $this->currentUser->getUsername();
447
-
448
-        $this->send(<<<TAG
29
+	/** @var PdoDatabase $notificationsDatabase */
30
+	private $notificationsDatabase;
31
+	/** @var PdoDatabase $primaryDatabase */
32
+	private $primaryDatabase;
33
+	/** @var bool $notificationsEnabled */
34
+	private $notificationsEnabled;
35
+	/** @var int $notificationType */
36
+	private $notificationType;
37
+	/** @var User $currentUser */
38
+	private $currentUser;
39
+	/** @var string $instanceName */
40
+	private $instanceName;
41
+	/** @var string */
42
+	private $baseUrl;
43
+	/** @var array */
44
+	private $requestStates;
45
+
46
+	/**
47
+	 * IrcNotificationHelper constructor.
48
+	 *
49
+	 * @param SiteConfiguration $siteConfiguration
50
+	 * @param PdoDatabase       $primaryDatabase
51
+	 * @param PdoDatabase       $notificationsDatabase
52
+	 */
53
+	public function __construct(
54
+		SiteConfiguration $siteConfiguration,
55
+		PdoDatabase $primaryDatabase,
56
+		PdoDatabase $notificationsDatabase = null
57
+	) {
58
+		$this->primaryDatabase = $primaryDatabase;
59
+
60
+		if ($this->notificationsDatabase !== null) {
61
+			$this->notificationsDatabase = $notificationsDatabase;
62
+			$this->notificationsEnabled = $siteConfiguration->getIrcNotificationsEnabled();
63
+		}
64
+		else {
65
+			$this->notificationsEnabled = false;
66
+		}
67
+
68
+		$this->notificationType = $siteConfiguration->getIrcNotificationType();
69
+		$this->instanceName = $siteConfiguration->getIrcNotificationsInstance();
70
+		$this->baseUrl = $siteConfiguration->getBaseUrl();
71
+		$this->requestStates = $siteConfiguration->getRequestStates();
72
+
73
+		$this->currentUser = User::getCurrent($primaryDatabase);
74
+	}
75
+
76
+	/**
77
+	 * Send a notification
78
+	 *
79
+	 * @param string $message The text to send
80
+	 */
81
+	protected function send($message)
82
+	{
83
+		$instanceName = $this->instanceName;
84
+
85
+		if (!$this->notificationsEnabled) {
86
+			return;
87
+		}
88
+
89
+		$blacklist = array("DCC", "CCTP", "PRIVMSG");
90
+		$message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc
91
+
92
+		$msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message";
93
+
94
+		try {
95
+			$notification = new Notification();
96
+			$notification->setDatabase($this->notificationsDatabase);
97
+			$notification->setType($this->notificationType);
98
+			$notification->setText($msg);
99
+
100
+			$notification->save();
101
+		}
102
+		catch (Exception $ex) {
103
+			// OK, so we failed to send the notification - that db might be down?
104
+			// This is non-critical, so silently fail.
105
+
106
+			// Disable notifications for remainder of request.
107
+			$this->notificationsEnabled = false;
108
+		}
109
+	}
110
+
111
+	#region user management
112
+
113
+	/**
114
+	 * send a new user notification
115
+	 *
116
+	 * @param User $user
117
+	 */
118
+	public function userNew(User $user)
119
+	{
120
+		$this->send("New user: {$user->getUsername()}");
121
+	}
122
+
123
+	/**
124
+	 * send an approved notification
125
+	 *
126
+	 * @param User $user
127
+	 */
128
+	public function userApproved(User $user)
129
+	{
130
+		$this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername());
131
+	}
132
+
133
+	/**
134
+	 * send a promoted notification
135
+	 *
136
+	 * @param User $user
137
+	 */
138
+	public function userPromoted(User $user)
139
+	{
140
+		$this->send("{$user->getUsername()} promoted to tool admin by " . $this->currentUser->getUsername());
141
+	}
142
+
143
+	/**
144
+	 * send a declined notification
145
+	 *
146
+	 * @param User   $user
147
+	 * @param string $reason the reason the user was declined
148
+	 */
149
+	public function userDeclined(User $user, $reason)
150
+	{
151
+		$this->send("{$user->getUsername()} declined by " . $this->currentUser->getUsername() . " ($reason)");
152
+	}
153
+
154
+	/**
155
+	 * send a demotion notification
156
+	 *
157
+	 * @param User   $user
158
+	 * @param string $reason the reason the user was demoted
159
+	 */
160
+	public function userDemoted(User $user, $reason)
161
+	{
162
+		$this->send("{$user->getUsername()} demoted by " . $this->currentUser->getUsername() . " ($reason)");
163
+	}
164
+
165
+	/**
166
+	 * send a suspended notification
167
+	 *
168
+	 * @param User   $user
169
+	 * @param string $reason The reason the user has been suspended
170
+	 */
171
+	public function userSuspended(User $user, $reason)
172
+	{
173
+		$this->send("{$user->getUsername()} suspended by " . $this->currentUser->getUsername() . " ($reason)");
174
+	}
175
+
176
+	/**
177
+	 * Send a preference change notification
178
+	 *
179
+	 * @param User $user
180
+	 */
181
+	public function userPrefChange(User $user)
182
+	{
183
+		$this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername());
184
+	}
185
+
186
+	/**
187
+	 * Send a user renamed notification
188
+	 *
189
+	 * @param User   $user
190
+	 * @param string $old
191
+	 */
192
+	public function userRenamed(User $user, $old)
193
+	{
194
+		$this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}");
195
+	}
196
+
197
+	/**
198
+	 * @param User   $user
199
+	 * @param string $reason
200
+	 */
201
+	public function userRolesEdited(User $user, $reason)
202
+	{
203
+		$currentUser = $this->currentUser->getUsername();
204
+		$this->send("Active roles for {$user->getUsername()} changed by " . $currentUser . " ($reason)");
205
+	}
206
+
207
+	#endregion
208
+
209
+	#region Site Notice
210
+
211
+	/**
212
+	 * Summary of siteNoticeEdited
213
+	 */
214
+	public function siteNoticeEdited()
215
+	{
216
+		$this->send("Site notice edited by " . $this->currentUser->getUsername());
217
+	}
218
+	#endregion
219
+
220
+	#region Welcome Templates
221
+	/**
222
+	 * Summary of welcomeTemplateCreated
223
+	 *
224
+	 * @param WelcomeTemplate $template
225
+	 */
226
+	public function welcomeTemplateCreated(WelcomeTemplate $template)
227
+	{
228
+		$this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername());
229
+	}
230
+
231
+	/**
232
+	 * Summary of welcomeTemplateDeleted
233
+	 *
234
+	 * @param int $templateid
235
+	 */
236
+	public function welcomeTemplateDeleted($templateid)
237
+	{
238
+		$this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername());
239
+	}
240
+
241
+	/**
242
+	 * Summary of welcomeTemplateEdited
243
+	 *
244
+	 * @param WelcomeTemplate $template
245
+	 */
246
+	public function welcomeTemplateEdited(WelcomeTemplate $template)
247
+	{
248
+		$this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername());
249
+	}
250
+
251
+	#endregion
252
+
253
+	#region bans
254
+	/**
255
+	 * Summary of banned
256
+	 *
257
+	 * @param Ban $ban
258
+	 */
259
+	public function banned(Ban $ban)
260
+	{
261
+		if ($ban->getDuration() == -1) {
262
+			$duration = "indefinitely";
263
+		}
264
+		else {
265
+			$duration = "until " . date("F j, Y, g:i a", $ban->getDuration());
266
+		}
267
+
268
+		$username = $this->currentUser->getUsername();
269
+
270
+		$this->send("{$ban->getTarget()} banned by {$username} for '{$ban->getReason()}' {$duration}");
271
+	}
272
+
273
+	/**
274
+	 * Summary of unbanned
275
+	 *
276
+	 * @param Ban    $ban
277
+	 * @param string $unbanreason
278
+	 */
279
+	public function unbanned(Ban $ban, $unbanreason)
280
+	{
281
+		$this->send($ban->getTarget() . " unbanned by " . $this->currentUser
282
+				->getUsername() . " (" . $unbanreason . ")");
283
+	}
284
+
285
+	#endregion
286
+
287
+	#region request management
288
+
289
+	/**
290
+	 * Summary of requestReceived
291
+	 *
292
+	 * @param Request $request
293
+	 */
294
+	public function requestReceived(Request $request)
295
+	{
296
+		$this->send(
297
+			IrcColourCode::DARK_GREY . "[["
298
+			. IrcColourCode::DARK_GREEN . "acc:"
299
+			. IrcColourCode::ORANGE . $request->getId()
300
+			. IrcColourCode::DARK_GREY . "]]"
301
+			. IrcColourCode::RED . " N "
302
+			. IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} "
303
+			. IrcColourCode::DARK_RED . "* "
304
+			. IrcColourCode::DARK_GREEN . $request->getName()
305
+			. IrcColourCode::DARK_RED . " * "
306
+			. IrcColourCode::RESET
307
+		);
308
+	}
309
+
310
+	/**
311
+	 * Summary of requestDeferred
312
+	 *
313
+	 * @param Request $request
314
+	 */
315
+	public function requestDeferred(Request $request)
316
+	{
317
+		$availableRequestStates = $this->requestStates;
318
+
319
+		$deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
320
+		$username = $this->currentUser->getUsername();
321
+
322
+		$this->send("Request {$request->getId()} ({$request->getName()}) deferred to {$deferTo} by {$username}");
323
+	}
324
+
325
+	/**
326
+	 *
327
+	 * Summary of requestDeferredWithMail
328
+	 *
329
+	 * @param Request $request
330
+	 */
331
+	public function requestDeferredWithMail(Request $request)
332
+	{
333
+		$availableRequestStates = $this->requestStates;
334
+
335
+		$deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
336
+		$username = $this->currentUser->getUsername();
337
+		$id = $request->getId();
338
+		$name = $request->getName();
339
+
340
+		$this->send("Request {$id} ({$name}) deferred to {$deferTo} with an email by {$username}");
341
+	}
342
+
343
+	/**
344
+	 * Summary of requestClosed
345
+	 *
346
+	 * @param Request $request
347
+	 * @param string  $closetype
348
+	 */
349
+	public function requestClosed(Request $request, $closetype)
350
+	{
351
+		$username = $this->currentUser->getUsername();
352
+
353
+		$this->send("Request {$request->getId()} ({$request->getName()}) closed ($closetype) by {$username}");
354
+	}
355
+
356
+	/**
357
+	 * Summary of sentMail
358
+	 *
359
+	 * @param Request $request
360
+	 */
361
+	public function sentMail(Request $request)
362
+	{
363
+		$this->send($this->currentUser->getUsername()
364
+			. " sent an email related to Request {$request->getId()} ({$request->getName()})");
365
+	}
366
+
367
+	#endregion
368
+
369
+	#region reservations
370
+
371
+	/**
372
+	 * Summary of requestReserved
373
+	 *
374
+	 * @param Request $request
375
+	 */
376
+	public function requestReserved(Request $request)
377
+	{
378
+		$username = $this->currentUser->getUsername();
379
+
380
+		$this->send("Request {$request->getId()} ({$request->getName()}) reserved by {$username}");
381
+	}
382
+
383
+	/**
384
+	 * Summary of requestReserveBroken
385
+	 *
386
+	 * @param Request $request
387
+	 */
388
+	public function requestReserveBroken(Request $request)
389
+	{
390
+		$username = $this->currentUser->getUsername();
391
+
392
+		$this->send("Reservation on request {$request->getId()} ({$request->getName()}) broken by {$username}");
393
+	}
394
+
395
+	/**
396
+	 * Summary of requestUnreserved
397
+	 *
398
+	 * @param Request $request
399
+	 */
400
+	public function requestUnreserved(Request $request)
401
+	{
402
+		$this->send("Request {$request->getId()} ({$request->getName()}) is no longer being handled.");
403
+	}
404
+
405
+	/**
406
+	 * Summary of requestReservationSent
407
+	 *
408
+	 * @param Request $request
409
+	 * @param User    $target
410
+	 */
411
+	public function requestReservationSent(Request $request, User $target)
412
+	{
413
+		$username = $this->currentUser->getUsername();
414
+
415
+		$this->send(
416
+			"Reservation of request {$request->getId()} ({$request->getName()}) sent to {$target->getUsername()} by "
417
+			. $username);
418
+	}
419
+
420
+	#endregion
421
+
422
+	#region comments
423
+
424
+	/**
425
+	 * Summary of commentCreated
426
+	 *
427
+	 * @param Comment $comment
428
+	 * @param Request $request
429
+	 */
430
+	public function commentCreated(Comment $comment, Request $request)
431
+	{
432
+		$username = $this->currentUser->getUsername();
433
+		$visibility = ($comment->getVisibility() == "admin" ? "private " : "");
434
+
435
+		$this->send("{$username} posted a {$visibility}comment on request {$request->getId()} ({$request->getName()})");
436
+	}
437
+
438
+	/**
439
+	 * Summary of commentEdited
440
+	 *
441
+	 * @param Comment $comment
442
+	 * @param Request $request
443
+	 */
444
+	public function commentEdited(Comment $comment, Request $request)
445
+	{
446
+		$username = $this->currentUser->getUsername();
447
+
448
+		$this->send(<<<TAG
449 449
 Comment {$comment->getId()} on request {$request->getId()} ({$request->getName()}) edited by {$username}
450 450
 TAG
451
-        );
452
-    }
453
-
454
-    #endregion
455
-
456
-    #region email management (close reasons)
457
-
458
-    /**
459
-     * Summary of emailCreated
460
-     *
461
-     * @param EmailTemplate $template
462
-     */
463
-    public function emailCreated(EmailTemplate $template)
464
-    {
465
-        $username = $this->currentUser->getUsername();
466
-        $this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username);
467
-    }
468
-
469
-    /**
470
-     * Summary of emailEdited
471
-     *
472
-     * @param EmailTemplate $template
473
-     */
474
-    public function emailEdited(EmailTemplate $template)
475
-    {
476
-        $username = $this->currentUser->getUsername();
477
-        $this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username);
478
-    }
479
-    #endregion
451
+		);
452
+	}
453
+
454
+	#endregion
455
+
456
+	#region email management (close reasons)
457
+
458
+	/**
459
+	 * Summary of emailCreated
460
+	 *
461
+	 * @param EmailTemplate $template
462
+	 */
463
+	public function emailCreated(EmailTemplate $template)
464
+	{
465
+		$username = $this->currentUser->getUsername();
466
+		$this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username);
467
+	}
468
+
469
+	/**
470
+	 * Summary of emailEdited
471
+	 *
472
+	 * @param EmailTemplate $template
473
+	 */
474
+	public function emailEdited(EmailTemplate $template)
475
+	{
476
+		$username = $this->currentUser->getUsername();
477
+		$this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username);
478
+	}
479
+	#endregion
480 480
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
         $blacklist = array("DCC", "CCTP", "PRIVMSG");
90 90
         $message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc
91 91
 
92
-        $msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message";
92
+        $msg = IrcColourCode::RESET.IrcColourCode::BOLD."[$instanceName]".IrcColourCode::RESET.": $message";
93 93
 
94 94
         try {
95 95
             $notification = new Notification();
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function userApproved(User $user)
129 129
     {
130
-        $this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername());
130
+        $this->send("{$user->getUsername()} approved by ".$this->currentUser->getUsername());
131 131
     }
132 132
 
133 133
     /**
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      */
138 138
     public function userPromoted(User $user)
139 139
     {
140
-        $this->send("{$user->getUsername()} promoted to tool admin by " . $this->currentUser->getUsername());
140
+        $this->send("{$user->getUsername()} promoted to tool admin by ".$this->currentUser->getUsername());
141 141
     }
142 142
 
143 143
     /**
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      */
149 149
     public function userDeclined(User $user, $reason)
150 150
     {
151
-        $this->send("{$user->getUsername()} declined by " . $this->currentUser->getUsername() . " ($reason)");
151
+        $this->send("{$user->getUsername()} declined by ".$this->currentUser->getUsername()." ($reason)");
152 152
     }
153 153
 
154 154
     /**
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public function userDemoted(User $user, $reason)
161 161
     {
162
-        $this->send("{$user->getUsername()} demoted by " . $this->currentUser->getUsername() . " ($reason)");
162
+        $this->send("{$user->getUsername()} demoted by ".$this->currentUser->getUsername()." ($reason)");
163 163
     }
164 164
 
165 165
     /**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      */
171 171
     public function userSuspended(User $user, $reason)
172 172
     {
173
-        $this->send("{$user->getUsername()} suspended by " . $this->currentUser->getUsername() . " ($reason)");
173
+        $this->send("{$user->getUsername()} suspended by ".$this->currentUser->getUsername()." ($reason)");
174 174
     }
175 175
 
176 176
     /**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function userPrefChange(User $user)
182 182
     {
183
-        $this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername());
183
+        $this->send("{$user->getUsername()}'s preferences were changed by ".$this->currentUser->getUsername());
184 184
     }
185 185
 
186 186
     /**
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      */
192 192
     public function userRenamed(User $user, $old)
193 193
     {
194
-        $this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}");
194
+        $this->send($this->currentUser->getUsername()." renamed $old to {$user->getUsername()}");
195 195
     }
196 196
 
197 197
     /**
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     public function userRolesEdited(User $user, $reason)
202 202
     {
203 203
         $currentUser = $this->currentUser->getUsername();
204
-        $this->send("Active roles for {$user->getUsername()} changed by " . $currentUser . " ($reason)");
204
+        $this->send("Active roles for {$user->getUsername()} changed by ".$currentUser." ($reason)");
205 205
     }
206 206
 
207 207
     #endregion
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
      */
214 214
     public function siteNoticeEdited()
215 215
     {
216
-        $this->send("Site notice edited by " . $this->currentUser->getUsername());
216
+        $this->send("Site notice edited by ".$this->currentUser->getUsername());
217 217
     }
218 218
     #endregion
219 219
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
      */
226 226
     public function welcomeTemplateCreated(WelcomeTemplate $template)
227 227
     {
228
-        $this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername());
228
+        $this->send("Welcome template {$template->getId()} created by ".$this->currentUser->getUsername());
229 229
     }
230 230
 
231 231
     /**
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      */
236 236
     public function welcomeTemplateDeleted($templateid)
237 237
     {
238
-        $this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername());
238
+        $this->send("Welcome template {$templateid} deleted by ".$this->currentUser->getUsername());
239 239
     }
240 240
 
241 241
     /**
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      */
246 246
     public function welcomeTemplateEdited(WelcomeTemplate $template)
247 247
     {
248
-        $this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername());
248
+        $this->send("Welcome template {$template->getId()} edited by ".$this->currentUser->getUsername());
249 249
     }
250 250
 
251 251
     #endregion
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
             $duration = "indefinitely";
263 263
         }
264 264
         else {
265
-            $duration = "until " . date("F j, Y, g:i a", $ban->getDuration());
265
+            $duration = "until ".date("F j, Y, g:i a", $ban->getDuration());
266 266
         }
267 267
 
268 268
         $username = $this->currentUser->getUsername();
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
      */
279 279
     public function unbanned(Ban $ban, $unbanreason)
280 280
     {
281
-        $this->send($ban->getTarget() . " unbanned by " . $this->currentUser
282
-                ->getUsername() . " (" . $unbanreason . ")");
281
+        $this->send($ban->getTarget()." unbanned by ".$this->currentUser
282
+                ->getUsername()." (".$unbanreason.")");
283 283
     }
284 284
 
285 285
     #endregion
@@ -294,15 +294,15 @@  discard block
 block discarded – undo
294 294
     public function requestReceived(Request $request)
295 295
     {
296 296
         $this->send(
297
-            IrcColourCode::DARK_GREY . "[["
298
-            . IrcColourCode::DARK_GREEN . "acc:"
299
-            . IrcColourCode::ORANGE . $request->getId()
300
-            . IrcColourCode::DARK_GREY . "]]"
301
-            . IrcColourCode::RED . " N "
302
-            . IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} "
303
-            . IrcColourCode::DARK_RED . "* "
304
-            . IrcColourCode::DARK_GREEN . $request->getName()
305
-            . IrcColourCode::DARK_RED . " * "
297
+            IrcColourCode::DARK_GREY."[["
298
+            . IrcColourCode::DARK_GREEN."acc:"
299
+            . IrcColourCode::ORANGE.$request->getId()
300
+            . IrcColourCode::DARK_GREY."]]"
301
+            . IrcColourCode::RED." N "
302
+            . IrcColourCode::DARK_BLUE.$this->baseUrl."/internal.php/viewRequest?id={$request->getId()} "
303
+            . IrcColourCode::DARK_RED."* "
304
+            . IrcColourCode::DARK_GREEN.$request->getName()
305
+            . IrcColourCode::DARK_RED." * "
306 306
             . IrcColourCode::RESET
307 307
         );
308 308
     }
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
     public function emailCreated(EmailTemplate $template)
464 464
     {
465 465
         $username = $this->currentUser->getUsername();
466
-        $this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username);
466
+        $this->send("Email {$template->getId()} ({$template->getName()}) created by ".$username);
467 467
     }
468 468
 
469 469
     /**
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
     public function emailEdited(EmailTemplate $template)
475 475
     {
476 476
         $username = $this->currentUser->getUsername();
477
-        $this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username);
477
+        $this->send("Email {$template->getId()} ({$template->getName()}) edited by ".$username);
478 478
     }
479 479
     #endregion
480 480
 }
Please login to merge, or discard this patch.
includes/Pages/Statistics/StatsTopCreators.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
 
14 14
 class StatsTopCreators extends InternalPageBase
15 15
 {
16
-    public function main()
17
-    {
18
-        $this->setHtmlTitle('Top Creators :: Statistics');
16
+	public function main()
17
+	{
18
+		$this->setHtmlTitle('Top Creators :: Statistics');
19 19
 
20
-        // Retrieve all-time stats
21
-        $queryAllTime = <<<SQL
20
+		// Retrieve all-time stats
21
+		$queryAllTime = <<<SQL
22 22
 SELECT
23 23
 	/* StatsTopCreators::execute()/queryAllTime */
24 24
     COUNT(*) count,
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
 ORDER BY COUNT(*) DESC;
36 36
 SQL;
37 37
 
38
-        // Retrieve all-time stats for active users only
39
-        $queryAllTimeActive = <<<SQL
38
+		// Retrieve all-time stats for active users only
39
+		$queryAllTimeActive = <<<SQL
40 40
 SELECT
41 41
 	/* StatsTopCreators::execute()/queryAllTimeActive */
42 42
     COUNT(*) count,
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
 ORDER BY COUNT(*) DESC;
54 54
 SQL;
55 55
 
56
-        // Retrieve today's stats (so far)
57
-        $queryToday = <<<SQL
56
+		// Retrieve today's stats (so far)
57
+		$queryToday = <<<SQL
58 58
 SELECT
59 59
 	/* StatsTopCreators::execute()/top5out */
60 60
     COUNT(*) count,
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 ORDER BY COUNT(*) DESC;
71 71
 SQL;
72 72
 
73
-        // Retrieve Yesterday's stats
74
-        $queryYesterday = <<<SQL
73
+		// Retrieve Yesterday's stats
74
+		$queryYesterday = <<<SQL
75 75
 SELECT
76 76
 	/* StatsTopCreators::execute()/top5yout */
77 77
     COUNT(*) count,
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 ORDER BY COUNT(*) DESC;
88 88
 SQL;
89 89
 
90
-        // Retrieve last 7 days
91
-        $queryLast7Days = <<<SQL
90
+		// Retrieve last 7 days
91
+		$queryLast7Days = <<<SQL
92 92
 SELECT
93 93
 	/* StatsTopCreators::execute()/top5wout */
94 94
     COUNT(*) count,
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 ORDER BY COUNT(*) DESC;
105 105
 SQL;
106 106
 
107
-        // Retrieve last month's stats
108
-        $queryLast28Days = <<<SQL
107
+		// Retrieve last month's stats
108
+		$queryLast28Days = <<<SQL
109 109
 SELECT
110 110
 	/* StatsTopCreators::execute()/top5mout */
111 111
     COUNT(*) count,
@@ -121,24 +121,24 @@  discard block
 block discarded – undo
121 121
 ORDER BY COUNT(*) DESC;
122 122
 SQL;
123 123
 
124
-        // Put it all together
125
-        $queries = array(
126
-            'queryAllTime'       => $queryAllTime,
127
-            'queryAllTimeActive' => $queryAllTimeActive,
128
-            'queryToday'         => $queryToday,
129
-            'queryYesterday'     => $queryYesterday,
130
-            'queryLast7Days'     => $queryLast7Days,
131
-            'queryLast28Days'    => $queryLast28Days,
132
-        );
124
+		// Put it all together
125
+		$queries = array(
126
+			'queryAllTime'       => $queryAllTime,
127
+			'queryAllTimeActive' => $queryAllTimeActive,
128
+			'queryToday'         => $queryToday,
129
+			'queryYesterday'     => $queryYesterday,
130
+			'queryLast7Days'     => $queryLast7Days,
131
+			'queryLast28Days'    => $queryLast28Days,
132
+		);
133 133
 
134
-        $database = $this->getDatabase();
135
-        foreach ($queries as $name => $sql) {
136
-            $statement = $database->query($sql);
137
-            $data = $statement->fetchAll(PDO::FETCH_ASSOC);
138
-            $this->assign($name, $data);
139
-        }
134
+		$database = $this->getDatabase();
135
+		foreach ($queries as $name => $sql) {
136
+			$statement = $database->query($sql);
137
+			$data = $statement->fetchAll(PDO::FETCH_ASSOC);
138
+			$this->assign($name, $data);
139
+		}
140 140
 
141
-        $this->assign('statsPageTitle', 'Top Account Creators');
142
-        $this->setTemplate('statistics/top-creators.tpl');
143
-    }
141
+		$this->assign('statsPageTitle', 'Top Account Creators');
142
+		$this->setTemplate('statistics/top-creators.tpl');
143
+	}
144 144
 }
Please login to merge, or discard this patch.
includes/Pages/Statistics/StatsInactiveUsers.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -17,31 +17,31 @@
 block discarded – undo
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("-45 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("-45 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
 }
Please login to merge, or discard this patch.
includes/Pages/Statistics/StatsMonthlyStats.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
 
14 14
 class StatsMonthlyStats extends InternalPageBase
15 15
 {
16
-    public function main()
17
-    {
18
-        $this->setHtmlTitle('Monthly Stats :: Statistics');
16
+	public function main()
17
+	{
18
+		$this->setHtmlTitle('Monthly Stats :: Statistics');
19 19
 
20
-        $query = <<<SQL
20
+		$query = <<<SQL
21 21
 SELECT
22 22
     COUNT(DISTINCT id) AS closed,
23 23
     YEAR(timestamp) AS year,
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
 ORDER BY YEAR(timestamp) , MONTH(timestamp) ASC;
29 29
 SQL;
30 30
 
31
-        $database = $this->getDatabase();
32
-        $statement = $database->query($query);
33
-        $data = $statement->fetchAll(PDO::FETCH_ASSOC);
31
+		$database = $this->getDatabase();
32
+		$statement = $database->query($query);
33
+		$data = $statement->fetchAll(PDO::FETCH_ASSOC);
34 34
 
35
-        $this->assign('dataTable', $data);
36
-        $this->assign('statsPageTitle', 'Monthly Statistics');
37
-        $this->setTemplate('statistics/monthly-stats.tpl');
38
-    }
35
+		$this->assign('dataTable', $data);
36
+		$this->assign('statsPageTitle', 'Monthly Statistics');
37
+		$this->setTemplate('statistics/monthly-stats.tpl');
38
+	}
39 39
 }
Please login to merge, or discard this patch.