Passed
Push — dependabot/npm_and_yarn/sass-1... ( dd05dd )
by
unknown
05:21
created
includes/Fragments/NavigationMenuAccessControl.php 3 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -113,7 +113,8 @@
 block discarded – undo
113 113
      *
114 114
      * @return void
115 115
      */
116
-    public function setUpNavBarBadges(User $currentUser, PdoDatabase $database) {
116
+    public function setUpNavBarBadges(User $currentUser, PdoDatabase $database)
117
+    {
117 118
         // Set up some variables.
118 119
         // A size of 0 causes nothing to show up on the page (checked on navigation-menu.tpl) so leaving it 0 here is fine.
119 120
         $countOfFlagged = 0;
Please login to merge, or discard this patch.
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -37,108 +37,108 @@
 block discarded – undo
37 37
 
38 38
 trait NavigationMenuAccessControl
39 39
 {
40
-    protected abstract function assign($name, $value);
40
+	protected abstract function assign($name, $value);
41 41
 
42
-    protected abstract function getSecurityManager(): ISecurityManager;
42
+	protected abstract function getSecurityManager(): ISecurityManager;
43 43
 
44
-    public abstract function getDomainAccessManager(): IDomainAccessManager;
44
+	public abstract function getDomainAccessManager(): IDomainAccessManager;
45 45
 
46
-    /**
47
-     * @param $currentUser
48
-     */
49
-    protected function setupNavMenuAccess($currentUser)
50
-    {
51
-        $this->assign('nav__canRequests', $this->getSecurityManager()
52
-                ->allows(PageMain::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
46
+	/**
47
+	 * @param $currentUser
48
+	 */
49
+	protected function setupNavMenuAccess($currentUser)
50
+	{
51
+		$this->assign('nav__canRequests', $this->getSecurityManager()
52
+				->allows(PageMain::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
53 53
 
54
-        $this->assign('nav__canLogs', $this->getSecurityManager()
55
-                ->allows(PageLog::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
56
-        $this->assign('nav__canUsers', $this->getSecurityManager()
57
-                ->allows(StatsUsers::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
58
-        $this->assign('nav__canSearch', $this->getSecurityManager()
59
-                ->allows(PageSearch::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
60
-        $this->assign('nav__canStats', $this->getSecurityManager()
61
-                ->allows(StatsMain::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
54
+		$this->assign('nav__canLogs', $this->getSecurityManager()
55
+				->allows(PageLog::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
56
+		$this->assign('nav__canUsers', $this->getSecurityManager()
57
+				->allows(StatsUsers::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
58
+		$this->assign('nav__canSearch', $this->getSecurityManager()
59
+				->allows(PageSearch::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
60
+		$this->assign('nav__canStats', $this->getSecurityManager()
61
+				->allows(StatsMain::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
62 62
 
63
-        $this->assign('nav__canBan', $this->getSecurityManager()
64
-                ->allows(PageBan::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
65
-        $this->assign('nav__canEmailMgmt', $this->getSecurityManager()
66
-                ->allows(PageEmailManagement::class, RoleConfigurationBase::MAIN,
67
-                    $currentUser) === ISecurityManager::ALLOWED);
68
-        $this->assign('nav__canWelcomeMgmt', $this->getSecurityManager()
69
-                ->allows(PageWelcomeTemplateManagement::class, RoleConfigurationBase::MAIN,
70
-                    $currentUser) === ISecurityManager::ALLOWED);
71
-        $this->assign('nav__canSiteNoticeMgmt', $this->getSecurityManager()
72
-                ->allows(PageSiteNotice::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
73
-        $this->assign('nav__canUserMgmt', $this->getSecurityManager()
74
-                ->allows(PageUserManagement::class, RoleConfigurationBase::MAIN,
75
-                    $currentUser) === ISecurityManager::ALLOWED);
76
-        $this->assign('nav__canJobQueue', $this->getSecurityManager()
77
-                ->allows(PageJobQueue::class, RoleConfigurationBase::MAIN,
78
-                    $currentUser) === ISecurityManager::ALLOWED);
79
-        $this->assign('nav__canDomainMgmt', $this->getSecurityManager()
80
-                ->allows(PageDomainManagement::class, RoleConfigurationBase::MAIN,
81
-                    $currentUser) === ISecurityManager::ALLOWED);
82
-        $this->assign('nav__canFlaggedComments', $this->getSecurityManager()
83
-                ->allows(PageListFlaggedComments::class, RoleConfigurationBase::MAIN,
84
-                    $currentUser) === ISecurityManager::ALLOWED);
85
-        $this->assign('nav__canQueueMgmt', $this->getSecurityManager()
86
-                ->allows(PageQueueManagement::class, RoleConfigurationBase::MAIN,
87
-                    $currentUser) === ISecurityManager::ALLOWED);
88
-        $this->assign('nav__canFormMgmt', $this->getSecurityManager()
89
-                ->allows(PageRequestFormManagement::class, RoleConfigurationBase::MAIN,
90
-                    $currentUser) === ISecurityManager::ALLOWED);
91
-        $this->assign('nav__canErrorLog', $this->getSecurityManager()
92
-                ->allows(PageErrorLogViewer::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
63
+		$this->assign('nav__canBan', $this->getSecurityManager()
64
+				->allows(PageBan::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
65
+		$this->assign('nav__canEmailMgmt', $this->getSecurityManager()
66
+				->allows(PageEmailManagement::class, RoleConfigurationBase::MAIN,
67
+					$currentUser) === ISecurityManager::ALLOWED);
68
+		$this->assign('nav__canWelcomeMgmt', $this->getSecurityManager()
69
+				->allows(PageWelcomeTemplateManagement::class, RoleConfigurationBase::MAIN,
70
+					$currentUser) === ISecurityManager::ALLOWED);
71
+		$this->assign('nav__canSiteNoticeMgmt', $this->getSecurityManager()
72
+				->allows(PageSiteNotice::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
73
+		$this->assign('nav__canUserMgmt', $this->getSecurityManager()
74
+				->allows(PageUserManagement::class, RoleConfigurationBase::MAIN,
75
+					$currentUser) === ISecurityManager::ALLOWED);
76
+		$this->assign('nav__canJobQueue', $this->getSecurityManager()
77
+				->allows(PageJobQueue::class, RoleConfigurationBase::MAIN,
78
+					$currentUser) === ISecurityManager::ALLOWED);
79
+		$this->assign('nav__canDomainMgmt', $this->getSecurityManager()
80
+				->allows(PageDomainManagement::class, RoleConfigurationBase::MAIN,
81
+					$currentUser) === ISecurityManager::ALLOWED);
82
+		$this->assign('nav__canFlaggedComments', $this->getSecurityManager()
83
+				->allows(PageListFlaggedComments::class, RoleConfigurationBase::MAIN,
84
+					$currentUser) === ISecurityManager::ALLOWED);
85
+		$this->assign('nav__canQueueMgmt', $this->getSecurityManager()
86
+				->allows(PageQueueManagement::class, RoleConfigurationBase::MAIN,
87
+					$currentUser) === ISecurityManager::ALLOWED);
88
+		$this->assign('nav__canFormMgmt', $this->getSecurityManager()
89
+				->allows(PageRequestFormManagement::class, RoleConfigurationBase::MAIN,
90
+					$currentUser) === ISecurityManager::ALLOWED);
91
+		$this->assign('nav__canErrorLog', $this->getSecurityManager()
92
+				->allows(PageErrorLogViewer::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
93 93
 
94
-        $this->assign('nav__canViewRequest', $this->getSecurityManager()
95
-                ->allows(PageViewRequest::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
94
+		$this->assign('nav__canViewRequest', $this->getSecurityManager()
95
+				->allows(PageViewRequest::class, RoleConfigurationBase::MAIN, $currentUser) === ISecurityManager::ALLOWED);
96 96
 
97
-        $this->assign('nav__domainList', []);
98
-        if ($this->getDomainAccessManager() !== null) {
99
-            $this->assign('nav__domainList', $this->getDomainAccessManager()->getAllowedDomains($currentUser));
100
-        }
101
-    }
97
+		$this->assign('nav__domainList', []);
98
+		if ($this->getDomainAccessManager() !== null) {
99
+			$this->assign('nav__domainList', $this->getDomainAccessManager()->getAllowedDomains($currentUser));
100
+		}
101
+	}
102 102
 
103
-    /**
104
-     * Sets up the badges to draw attention to issues on various admin pages.
105
-     *
106
-     * This function checks to see if a user can access the pages, and if so checks the count of problem areas.
107
-     * If problem areas are found, a number greater than 0 will cause the badge to show up.
108
-     *
109
-     * @param User        $currentUser The current user
110
-     * @param PdoDatabase $database    Database instance
111
-     *
112
-     * @return void
113
-     */
114
-    public function setUpNavBarBadges(User $currentUser, PdoDatabase $database) {
115
-        // Set up some variables.
116
-        // A size of 0 causes nothing to show up on the page (checked on navigation-menu.tpl) so leaving it 0 here is fine.
117
-        $countOfFlagged = 0;
118
-        $countOfJobQueue = 0;
103
+	/**
104
+	 * Sets up the badges to draw attention to issues on various admin pages.
105
+	 *
106
+	 * This function checks to see if a user can access the pages, and if so checks the count of problem areas.
107
+	 * If problem areas are found, a number greater than 0 will cause the badge to show up.
108
+	 *
109
+	 * @param User        $currentUser The current user
110
+	 * @param PdoDatabase $database    Database instance
111
+	 *
112
+	 * @return void
113
+	 */
114
+	public function setUpNavBarBadges(User $currentUser, PdoDatabase $database) {
115
+		// Set up some variables.
116
+		// A size of 0 causes nothing to show up on the page (checked on navigation-menu.tpl) so leaving it 0 here is fine.
117
+		$countOfFlagged = 0;
118
+		$countOfJobQueue = 0;
119 119
 
120
-        // Count of flagged comments:
121
-        if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageListFlaggedComments::class)) {
122
-            // We want all flagged comments that haven't been acknowledged if we can visit the page.
123
-            $countOfFlagged = sizeof(Comment::getFlaggedComments($database, 1)); // FIXME: domains
124
-        }
120
+		// Count of flagged comments:
121
+		if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageListFlaggedComments::class)) {
122
+			// We want all flagged comments that haven't been acknowledged if we can visit the page.
123
+			$countOfFlagged = sizeof(Comment::getFlaggedComments($database, 1)); // FIXME: domains
124
+		}
125 125
 
126
-        // Count of failed job queue changes:
127
-        if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageJobQueue::class)) {
128
-            // We want all failed jobs that haven't been acknowledged if we can visit the page.
129
-            JobQueueSearchHelper::get($database, 1) // FIXME: domains
130
-                ->statusIn([JobQueue::STATUS_FAILED])
131
-                ->notAcknowledged()
132
-                ->getRecordCount($countOfJobQueue);
133
-        }
126
+		// Count of failed job queue changes:
127
+		if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageJobQueue::class)) {
128
+			// We want all failed jobs that haven't been acknowledged if we can visit the page.
129
+			JobQueueSearchHelper::get($database, 1) // FIXME: domains
130
+				->statusIn([JobQueue::STATUS_FAILED])
131
+				->notAcknowledged()
132
+				->getRecordCount($countOfJobQueue);
133
+		}
134 134
 
135
-        // To generate the main badge, add both up.
136
-        // If we add more badges in the future, don't forget to add them here!
137
-        $countOfAll = $countOfFlagged + $countOfJobQueue;
135
+		// To generate the main badge, add both up.
136
+		// If we add more badges in the future, don't forget to add them here!
137
+		$countOfAll = $countOfFlagged + $countOfJobQueue;
138 138
 
139
-        // Set badge variables
140
-        $this->assign("nav__numFlaggedComments", $countOfFlagged);
141
-        $this->assign("nav__numJobQueueFailed", $countOfJobQueue);
142
-        $this->assign("nav__numAdmin", $countOfAll);
143
-    }
139
+		// Set badge variables
140
+		$this->assign("nav__numFlaggedComments", $countOfFlagged);
141
+		$this->assign("nav__numJobQueueFailed", $countOfJobQueue);
142
+		$this->assign("nav__numAdmin", $countOfAll);
143
+	}
144 144
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -118,13 +118,13 @@
 block discarded – undo
118 118
         $countOfJobQueue = 0;
119 119
 
120 120
         // Count of flagged comments:
121
-        if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageListFlaggedComments::class)) {
121
+        if ($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageListFlaggedComments::class)) {
122 122
             // We want all flagged comments that haven't been acknowledged if we can visit the page.
123 123
             $countOfFlagged = sizeof(Comment::getFlaggedComments($database, 1)); // FIXME: domains
124 124
         }
125 125
 
126 126
         // Count of failed job queue changes:
127
-        if($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageJobQueue::class)) {
127
+        if ($this->barrierTest(RoleConfigurationBase::MAIN, $currentUser, PageJobQueue::class)) {
128 128
             // We want all failed jobs that haven't been acknowledged if we can visit the page.
129 129
             JobQueueSearchHelper::get($database, 1) // FIXME: domains
130 130
                 ->statusIn([JobQueue::STATUS_FAILED])
Please login to merge, or discard this patch.
includes/PdoDatabase.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -97,8 +97,7 @@
 block discarded – undo
97 97
         // all over the rest of the code
98 98
         if ($this->hasActiveTransaction) {
99 99
             return false;
100
-        }
101
-        else {
100
+        } else {
102 101
             $accessMode = 'READ WRITE';
103 102
 
104 103
             switch ($isolationLevel) {
Please login to merge, or discard this patch.
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -15,124 +15,124 @@
 block discarded – undo
15 15
 
16 16
 class PdoDatabase extends PDO
17 17
 {
18
-    public const ISOLATION_SERIALIZABLE = 'SERIALIZABLE';
19
-    public const ISOLATION_READ_COMMITTED = 'READ COMMITTED';
20
-    public const ISOLATION_READ_ONLY = 'READ ONLY';
21
-
22
-    private static PdoDatabase $connection;
23
-    /**
24
-     * @var bool True if a transaction is active
25
-     */
26
-    protected bool $hasActiveTransaction = false;
27
-
28
-    /**
29
-     * Unless you're doing low-level work, this is not the function you want.
30
-     *
31
-     * @throws Exception
32
-     */
33
-    public static function getDatabaseConnection(SiteConfiguration $configuration): PdoDatabase
34
-    {
35
-        if (!isset(self::$connection)) {
36
-            $dbConfig = $configuration->getDatabaseConfig();
37
-
38
-            try {
39
-                $databaseObject = new PdoDatabase(
40
-                    $dbConfig['datasource'],
41
-                    $dbConfig['username'],
42
-                    $dbConfig['password'],
43
-                    [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_520_ci']
44
-                );
45
-            }
46
-            catch (PDOException $ex) {
47
-                // wrap around any potential stack traces which may include passwords
48
-                throw new EnvironmentException('Error connecting to database: ' . $ex->getMessage());
49
-            }
50
-
51
-            $databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
52
-
53
-            // emulating prepared statements gives a performance boost on MySQL.
54
-            //
55
-            // however, our version of PDO doesn't seem to understand parameter types when emulating
56
-            // the prepared statements, so we're forced to turn this off for now.
57
-            // -- stw 2014-02-11
58
-            //
59
-            // and that's not the only problem with emulated prepares. We've now got code that relies
60
-            // on real prepares.
61
-            // -- stw 2023-09-30
62
-            $databaseObject->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
63
-
64
-            // Set the default transaction mode
65
-            $databaseObject->exec("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;");
66
-
67
-            self::$connection = $databaseObject;
68
-        }
69
-
70
-        return self::$connection;
71
-    }
72
-
73
-    /**
74
-     * Determines if this connection has a transaction in progress or not
75
-     * @return boolean true if there is a transaction in progress.
76
-     */
77
-    public function hasActiveTransaction(): bool
78
-    {
79
-        return $this->hasActiveTransaction;
80
-    }
81
-
82
-    public function beginTransaction(string $isolationLevel = self::ISOLATION_READ_COMMITTED): bool
83
-    {
84
-        // Override the pre-existing method, which doesn't stop you from
85
-        // starting transactions within transactions - which doesn't work and
86
-        // will throw an exception. This eliminates the need to catch exceptions
87
-        // all over the rest of the code
88
-        if ($this->hasActiveTransaction) {
89
-            return false;
90
-        }
91
-        else {
92
-            $accessMode = 'READ WRITE';
93
-
94
-            switch ($isolationLevel) {
95
-                case self::ISOLATION_SERIALIZABLE:
96
-                case self::ISOLATION_READ_COMMITTED:
97
-                    break;
98
-                case self::ISOLATION_READ_ONLY:
99
-                    $isolationLevel = self::ISOLATION_READ_COMMITTED;
100
-                    $accessMode = 'READ ONLY';
101
-                    break;
102
-                default:
103
-                    throw new Exception("Invalid transaction isolation level");
104
-            }
105
-
106
-            // set the transaction isolation level for every transaction.
107
-            // string substitution is safe here; values can only be one of the above constants
108
-            parent::exec("SET TRANSACTION ISOLATION LEVEL ${isolationLevel}, ${accessMode};");
109
-
110
-            // start a new transaction, and return whether the start was successful
111
-            $this->hasActiveTransaction = parent::beginTransaction();
112
-
113
-            return $this->hasActiveTransaction;
114
-        }
115
-    }
116
-
117
-    /**
118
-     * Commits the active transaction
119
-     */
120
-    public function commit(): void
121
-    {
122
-        if ($this->hasActiveTransaction) {
123
-            parent::commit();
124
-            $this->hasActiveTransaction = false;
125
-        }
126
-    }
127
-
128
-    /**
129
-     * Rolls back a transaction
130
-     */
131
-    public function rollBack(): void
132
-    {
133
-        if ($this->hasActiveTransaction) {
134
-            parent::rollback();
135
-            $this->hasActiveTransaction = false;
136
-        }
137
-    }
18
+	public const ISOLATION_SERIALIZABLE = 'SERIALIZABLE';
19
+	public const ISOLATION_READ_COMMITTED = 'READ COMMITTED';
20
+	public const ISOLATION_READ_ONLY = 'READ ONLY';
21
+
22
+	private static PdoDatabase $connection;
23
+	/**
24
+	 * @var bool True if a transaction is active
25
+	 */
26
+	protected bool $hasActiveTransaction = false;
27
+
28
+	/**
29
+	 * Unless you're doing low-level work, this is not the function you want.
30
+	 *
31
+	 * @throws Exception
32
+	 */
33
+	public static function getDatabaseConnection(SiteConfiguration $configuration): PdoDatabase
34
+	{
35
+		if (!isset(self::$connection)) {
36
+			$dbConfig = $configuration->getDatabaseConfig();
37
+
38
+			try {
39
+				$databaseObject = new PdoDatabase(
40
+					$dbConfig['datasource'],
41
+					$dbConfig['username'],
42
+					$dbConfig['password'],
43
+					[PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_520_ci']
44
+				);
45
+			}
46
+			catch (PDOException $ex) {
47
+				// wrap around any potential stack traces which may include passwords
48
+				throw new EnvironmentException('Error connecting to database: ' . $ex->getMessage());
49
+			}
50
+
51
+			$databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
52
+
53
+			// emulating prepared statements gives a performance boost on MySQL.
54
+			//
55
+			// however, our version of PDO doesn't seem to understand parameter types when emulating
56
+			// the prepared statements, so we're forced to turn this off for now.
57
+			// -- stw 2014-02-11
58
+			//
59
+			// and that's not the only problem with emulated prepares. We've now got code that relies
60
+			// on real prepares.
61
+			// -- stw 2023-09-30
62
+			$databaseObject->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
63
+
64
+			// Set the default transaction mode
65
+			$databaseObject->exec("SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;");
66
+
67
+			self::$connection = $databaseObject;
68
+		}
69
+
70
+		return self::$connection;
71
+	}
72
+
73
+	/**
74
+	 * Determines if this connection has a transaction in progress or not
75
+	 * @return boolean true if there is a transaction in progress.
76
+	 */
77
+	public function hasActiveTransaction(): bool
78
+	{
79
+		return $this->hasActiveTransaction;
80
+	}
81
+
82
+	public function beginTransaction(string $isolationLevel = self::ISOLATION_READ_COMMITTED): bool
83
+	{
84
+		// Override the pre-existing method, which doesn't stop you from
85
+		// starting transactions within transactions - which doesn't work and
86
+		// will throw an exception. This eliminates the need to catch exceptions
87
+		// all over the rest of the code
88
+		if ($this->hasActiveTransaction) {
89
+			return false;
90
+		}
91
+		else {
92
+			$accessMode = 'READ WRITE';
93
+
94
+			switch ($isolationLevel) {
95
+				case self::ISOLATION_SERIALIZABLE:
96
+				case self::ISOLATION_READ_COMMITTED:
97
+					break;
98
+				case self::ISOLATION_READ_ONLY:
99
+					$isolationLevel = self::ISOLATION_READ_COMMITTED;
100
+					$accessMode = 'READ ONLY';
101
+					break;
102
+				default:
103
+					throw new Exception("Invalid transaction isolation level");
104
+			}
105
+
106
+			// set the transaction isolation level for every transaction.
107
+			// string substitution is safe here; values can only be one of the above constants
108
+			parent::exec("SET TRANSACTION ISOLATION LEVEL ${isolationLevel}, ${accessMode};");
109
+
110
+			// start a new transaction, and return whether the start was successful
111
+			$this->hasActiveTransaction = parent::beginTransaction();
112
+
113
+			return $this->hasActiveTransaction;
114
+		}
115
+	}
116
+
117
+	/**
118
+	 * Commits the active transaction
119
+	 */
120
+	public function commit(): void
121
+	{
122
+		if ($this->hasActiveTransaction) {
123
+			parent::commit();
124
+			$this->hasActiveTransaction = false;
125
+		}
126
+	}
127
+
128
+	/**
129
+	 * Rolls back a transaction
130
+	 */
131
+	public function rollBack(): void
132
+	{
133
+		if ($this->hasActiveTransaction) {
134
+			parent::rollback();
135
+			$this->hasActiveTransaction = false;
136
+		}
137
+	}
138 138
 }
Please login to merge, or discard this patch.
includes/DataObjects/Ban.php 2 patches
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -155,12 +155,10 @@  discard block
 block discarded – undo
155 155
 
156 156
             if ($statement->execute()) {
157 157
                 $this->id = (int)$this->dbObject->lastInsertId();
158
-            }
159
-            else {
158
+            } else {
160 159
                 throw new Exception($statement->errorInfo());
161 160
             }
162
-        }
163
-        else {
161
+        } else {
164 162
             // update
165 163
             $statement = $this->dbObject->prepare(<<<SQL
166 164
 UPDATE `ban`
@@ -339,8 +337,7 @@  discard block
 block discarded – undo
339 337
     {
340 338
         if ($ip === null) {
341 339
             $this->ip = null;
342
-        }
343
-        else {
340
+        } else {
344 341
             $this->ip = inet_pton($ip);
345 342
         }
346 343
 
Please login to merge, or discard this patch.
Indentation   +363 added lines, -363 removed lines patch added patch discarded remove patch
@@ -19,66 +19,66 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class Ban extends DataObject
21 21
 {
22
-    const ACTION_BLOCK = 'block';
23
-    const ACTION_DROP = 'drop';
24
-    const ACTION_DEFER = 'defer';
25
-    const ACTION_NONE = 'none';
26
-
27
-    /** @var string|null */
28
-    private $name;
29
-    /** @var string|null */
30
-    private $ip;
31
-    /** @var int|null */
32
-    private $ipmask;
33
-    /** @var string|null */
34
-    private $email;
35
-    /** @var string|null */
36
-    private $useragent;
37
-
38
-    private $user;
39
-    private $reason;
40
-    private $date;
41
-    private $duration;
42
-    private $active;
43
-    private $action = self::ACTION_BLOCK;
44
-    private $targetqueue;
45
-    private $visibility = 'user';
46
-    private ?int $domain;
47
-
48
-    /**
49
-     * Gets all active bans, filtered by the optional target.
50
-     *
51
-     * @return Ban[]
52
-     */
53
-    public static function getActiveBans(PdoDatabase $database, int $domain)
54
-    {
55
-        $query = <<<SQL
22
+	const ACTION_BLOCK = 'block';
23
+	const ACTION_DROP = 'drop';
24
+	const ACTION_DEFER = 'defer';
25
+	const ACTION_NONE = 'none';
26
+
27
+	/** @var string|null */
28
+	private $name;
29
+	/** @var string|null */
30
+	private $ip;
31
+	/** @var int|null */
32
+	private $ipmask;
33
+	/** @var string|null */
34
+	private $email;
35
+	/** @var string|null */
36
+	private $useragent;
37
+
38
+	private $user;
39
+	private $reason;
40
+	private $date;
41
+	private $duration;
42
+	private $active;
43
+	private $action = self::ACTION_BLOCK;
44
+	private $targetqueue;
45
+	private $visibility = 'user';
46
+	private ?int $domain;
47
+
48
+	/**
49
+	 * Gets all active bans, filtered by the optional target.
50
+	 *
51
+	 * @return Ban[]
52
+	 */
53
+	public static function getActiveBans(PdoDatabase $database, int $domain)
54
+	{
55
+		$query = <<<SQL
56 56
 SELECT * FROM ban 
57 57
 WHERE (duration > UNIX_TIMESTAMP() OR duration is null) 
58 58
     AND active = 1
59 59
     AND (domain IS NULL OR domain = :domain);
60 60
 SQL;
61
-        $statement = $database->prepare($query);
62
-        $statement->execute([':domain' => $domain]);
63
-        $result = array();
64
-
65
-        /** @var Ban $v */
66
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
67
-            $v->setDatabase($database);
68
-            $result[] = $v;
69
-        }
70
-
71
-        return $result;
72
-    }
73
-
74
-    /**
75
-     * Gets a ban by its ID if it's currently active.
76
-     *
77
-     * @return Ban|false
78
-     */
79
-    public static function getActiveId($id, PdoDatabase $database, int $domain)
80
-    {
81
-        $statement = $database->prepare(<<<SQL
61
+		$statement = $database->prepare($query);
62
+		$statement->execute([':domain' => $domain]);
63
+		$result = array();
64
+
65
+		/** @var Ban $v */
66
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
67
+			$v->setDatabase($database);
68
+			$result[] = $v;
69
+		}
70
+
71
+		return $result;
72
+	}
73
+
74
+	/**
75
+	 * Gets a ban by its ID if it's currently active.
76
+	 *
77
+	 * @return Ban|false
78
+	 */
79
+	public static function getActiveId($id, PdoDatabase $database, int $domain)
80
+	{
81
+		$statement = $database->prepare(<<<SQL
82 82
 SELECT *
83 83
 FROM ban
84 84
 WHERE id = :id  
@@ -86,332 +86,332 @@  discard block
 block discarded – undo
86 86
   AND (duration > UNIX_TIMESTAMP() OR duration is null) 
87 87
   AND active = 1;
88 88
 SQL
89
-        );
90
-        $statement->bindValue(":id", $id);
91
-        $statement->bindValue(":domain", $domain);
89
+		);
90
+		$statement->bindValue(":id", $id);
91
+		$statement->bindValue(":domain", $domain);
92 92
 
93
-        $statement->execute();
93
+		$statement->execute();
94 94
 
95
-        $resultObject = $statement->fetchObject(get_called_class());
95
+		$resultObject = $statement->fetchObject(get_called_class());
96 96
 
97
-        if ($resultObject !== false) {
98
-            $resultObject->setDatabase($database);
99
-        }
97
+		if ($resultObject !== false) {
98
+			$resultObject->setDatabase($database);
99
+		}
100 100
 
101
-        return $resultObject;
102
-    }
101
+		return $resultObject;
102
+	}
103 103
 
104
-    public static function getByIdList($values, PdoDatabase $database, int $domain): array
105
-    {
106
-        if (count($values) === 0) {
107
-            return [];
108
-        }
104
+	public static function getByIdList($values, PdoDatabase $database, int $domain): array
105
+	{
106
+		if (count($values) === 0) {
107
+			return [];
108
+		}
109 109
 
110
-        // use the provided array to produce a list of question marks of the same length as the array.
111
-        $valueCount = count($values);
112
-        $inSection = str_repeat('?,', $valueCount - 1) . '?';
110
+		// use the provided array to produce a list of question marks of the same length as the array.
111
+		$valueCount = count($values);
112
+		$inSection = str_repeat('?,', $valueCount - 1) . '?';
113 113
 
114
-        // this is still parameterised! It's using positional parameters instead of named ones.
115
-        $query = 'SELECT * FROM ban WHERE id IN (' . $inSection . ')';
114
+		// this is still parameterised! It's using positional parameters instead of named ones.
115
+		$query = 'SELECT * FROM ban WHERE id IN (' . $inSection . ')';
116 116
 
117
-        $query .= ' AND (domain IS NULL OR domain = ?)';
118
-        $values[] = $domain;
117
+		$query .= ' AND (domain IS NULL OR domain = ?)';
118
+		$values[] = $domain;
119 119
 
120
-        $statement = $database->prepare($query);
120
+		$statement = $database->prepare($query);
121 121
 
122
-        // execute the statement with the provided parameter list.
123
-        $statement->execute($values);
122
+		// execute the statement with the provided parameter list.
123
+		$statement->execute($values);
124 124
 
125
-        $result = [];
126
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
127
-            $v->setDatabase($database);
128
-            $result[] = $v;
129
-        }
125
+		$result = [];
126
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
127
+			$v->setDatabase($database);
128
+			$result[] = $v;
129
+		}
130 130
 
131
-        return $result;
132
-    }
131
+		return $result;
132
+	}
133 133
 
134
-    /**
135
-     * @throws Exception
136
-     */
137
-    public function save()
138
-    {
139
-        if ($this->isNew()) {
140
-            // insert
141
-            $statement = $this->dbObject->prepare(<<<SQL
134
+	/**
135
+	 * @throws Exception
136
+	 */
137
+	public function save()
138
+	{
139
+		if ($this->isNew()) {
140
+			// insert
141
+			$statement = $this->dbObject->prepare(<<<SQL
142 142
 INSERT INTO `ban` (name, email, ip, ipmask, useragent, user, reason, date, duration, active, action, targetqueue, visibility, domain)
143 143
 VALUES (:name, :email, :ip, :ipmask, :useragent, :user, :reason, CURRENT_TIMESTAMP(), :duration, :active, :action, :targetqueue, :visibility, :domain);
144 144
 SQL
145
-            );
146
-
147
-            $statement->bindValue(":name", $this->name);
148
-            $statement->bindValue(":email", $this->email);
149
-            $statement->bindValue(":ip", $this->ip);
150
-            $statement->bindValue(":ipmask", $this->ipmask);
151
-            $statement->bindValue(":useragent", $this->useragent);
152
-
153
-            $statement->bindValue(":user", $this->user);
154
-            $statement->bindValue(":reason", $this->reason);
155
-            $statement->bindValue(":duration", $this->duration);
156
-            $statement->bindValue(":active", $this->active);
157
-            $statement->bindValue(":action", $this->action);
158
-            $statement->bindValue(":targetqueue", $this->targetqueue);
159
-            $statement->bindValue(":visibility", $this->visibility);
160
-            $statement->bindValue(":domain", $this->domain);
161
-
162
-            if ($statement->execute()) {
163
-                $this->id = (int)$this->dbObject->lastInsertId();
164
-            }
165
-            else {
166
-                throw new Exception($statement->errorInfo());
167
-            }
168
-        }
169
-        else {
170
-            // update
171
-            $statement = $this->dbObject->prepare(<<<SQL
145
+			);
146
+
147
+			$statement->bindValue(":name", $this->name);
148
+			$statement->bindValue(":email", $this->email);
149
+			$statement->bindValue(":ip", $this->ip);
150
+			$statement->bindValue(":ipmask", $this->ipmask);
151
+			$statement->bindValue(":useragent", $this->useragent);
152
+
153
+			$statement->bindValue(":user", $this->user);
154
+			$statement->bindValue(":reason", $this->reason);
155
+			$statement->bindValue(":duration", $this->duration);
156
+			$statement->bindValue(":active", $this->active);
157
+			$statement->bindValue(":action", $this->action);
158
+			$statement->bindValue(":targetqueue", $this->targetqueue);
159
+			$statement->bindValue(":visibility", $this->visibility);
160
+			$statement->bindValue(":domain", $this->domain);
161
+
162
+			if ($statement->execute()) {
163
+				$this->id = (int)$this->dbObject->lastInsertId();
164
+			}
165
+			else {
166
+				throw new Exception($statement->errorInfo());
167
+			}
168
+		}
169
+		else {
170
+			// update
171
+			$statement = $this->dbObject->prepare(<<<SQL
172 172
 UPDATE `ban`
173 173
 SET active = :active, updateversion = updateversion + 1
174 174
 WHERE id = :id AND updateversion = :updateversion;
175 175
 SQL
176
-            );
177
-            $statement->bindValue(':id', $this->id);
178
-            $statement->bindValue(':updateversion', $this->updateversion);
179
-
180
-            $statement->bindValue(':active', $this->active);
181
-
182
-            if (!$statement->execute()) {
183
-                throw new Exception($statement->errorInfo());
184
-            }
185
-
186
-            if ($statement->rowCount() !== 1) {
187
-                throw new OptimisticLockFailedException();
188
-            }
189
-
190
-            $this->updateversion++;
191
-        }
192
-    }
193
-
194
-    /**
195
-     * @return string
196
-     */
197
-    public function getReason()
198
-    {
199
-        return $this->reason;
200
-    }
201
-
202
-    /**
203
-     * @param string $reason
204
-     */
205
-    public function setReason($reason)
206
-    {
207
-        $this->reason = $reason;
208
-    }
209
-
210
-    /**
211
-     * @return mixed
212
-     */
213
-    public function getDate()
214
-    {
215
-        return $this->date;
216
-    }
217
-
218
-    /**
219
-     * @return mixed
220
-     */
221
-    public function getDuration()
222
-    {
223
-        return $this->duration;
224
-    }
225
-
226
-    /**
227
-     * @param mixed $duration
228
-     */
229
-    public function setDuration($duration)
230
-    {
231
-        $this->duration = $duration;
232
-    }
233
-
234
-    /**
235
-     * @return bool
236
-     */
237
-    public function isActive()
238
-    {
239
-        return $this->active == 1;
240
-    }
241
-
242
-    /**
243
-     * @param bool $active
244
-     */
245
-    public function setActive($active)
246
-    {
247
-        $this->active = $active ? 1 : 0;
248
-    }
249
-
250
-    /**
251
-     * @return int
252
-     */
253
-    public function getUser()
254
-    {
255
-        return $this->user;
256
-    }
257
-
258
-    /**
259
-     * @param int $user UserID of user who is setting the ban
260
-     */
261
-    public function setUser($user)
262
-    {
263
-        $this->user = $user;
264
-    }
265
-
266
-    /**
267
-     * @return string
268
-     */
269
-    public function getAction(): string
270
-    {
271
-        return $this->action;
272
-    }
273
-
274
-    /**
275
-     * @param string $action
276
-     */
277
-    public function setAction(string $action): void
278
-    {
279
-        $this->action = $action;
280
-    }
281
-
282
-    /**
283
-     * @return string
284
-     */
285
-    public function getVisibility() : string
286
-    {
287
-        return $this->visibility;
288
-    }
289
-
290
-    /**
291
-     * @param string $visibility
292
-     */
293
-    public function setVisibility(string $visibility): void
294
-    {
295
-        $this->visibility = $visibility;
296
-    }
297
-
298
-    /**
299
-     * @return string|null
300
-     */
301
-    public function getName(): ?string
302
-    {
303
-        return $this->name;
304
-    }
305
-
306
-    /**
307
-     * @param string|null $name
308
-     */
309
-    public function setName(?string $name): void
310
-    {
311
-        $this->name = $name;
312
-    }
313
-
314
-    /**
315
-     * @return string|null
316
-     */
317
-    public function getIp(): ?string
318
-    {
319
-        if ($this->ip === null) {
320
-            return null;
321
-        }
322
-
323
-        return inet_ntop($this->ip);
324
-    }
325
-
326
-    /**
327
-     * @return int|null
328
-     */
329
-    public function getIpMask(): ?int
330
-    {
331
-        return $this->ipmask;
332
-    }
333
-
334
-    /**
335
-     * @param string|null $ip
336
-     * @param int|null    $mask
337
-     */
338
-    public function setIp(?string $ip, ?int $mask): void
339
-    {
340
-        if ($ip === null) {
341
-            $this->ip = null;
342
-        }
343
-        else {
344
-            $this->ip = inet_pton($ip);
345
-        }
346
-
347
-        $this->ipmask = $mask;
348
-    }
349
-
350
-    /**
351
-     * @return string|null
352
-     */
353
-    public function getEmail(): ?string
354
-    {
355
-        return $this->email;
356
-    }
357
-
358
-    /**
359
-     * @param string|null $email
360
-     */
361
-    public function setEmail(?string $email): void
362
-    {
363
-        $this->email = $email;
364
-    }
365
-
366
-    /**
367
-     * @return string|null
368
-     */
369
-    public function getUseragent(): ?string
370
-    {
371
-        return $this->useragent;
372
-    }
373
-
374
-    /**
375
-     * @param string|null $useragent
376
-     */
377
-    public function setUseragent(?string $useragent): void
378
-    {
379
-        $this->useragent = $useragent;
380
-    }
381
-
382
-    /**
383
-     * @return int|null
384
-     */
385
-    public function getTargetQueue(): ?int
386
-    {
387
-        return $this->targetqueue;
388
-    }
389
-
390
-    /**
391
-     * @return RequestQueue|null
392
-     */
393
-    public function getTargetQueueObject(): ?RequestQueue
394
-    {
395
-        /** @var RequestQueue $queue */
396
-        $queue = RequestQueue::getById($this->targetqueue, $this->getDatabase());
397
-        return $queue === false ? null : $queue;
398
-    }
399
-
400
-    /**
401
-     * @param int|null $targetQueue
402
-     */
403
-    public function setTargetQueue(?int $targetQueue): void
404
-    {
405
-        $this->targetqueue = $targetQueue;
406
-    }
407
-
408
-    public function setDomain(?int $domain): void
409
-    {
410
-        $this->domain = $domain;
411
-    }
412
-
413
-    public function getDomain(): ?int
414
-    {
415
-        return $this->domain;
416
-    }
176
+			);
177
+			$statement->bindValue(':id', $this->id);
178
+			$statement->bindValue(':updateversion', $this->updateversion);
179
+
180
+			$statement->bindValue(':active', $this->active);
181
+
182
+			if (!$statement->execute()) {
183
+				throw new Exception($statement->errorInfo());
184
+			}
185
+
186
+			if ($statement->rowCount() !== 1) {
187
+				throw new OptimisticLockFailedException();
188
+			}
189
+
190
+			$this->updateversion++;
191
+		}
192
+	}
193
+
194
+	/**
195
+	 * @return string
196
+	 */
197
+	public function getReason()
198
+	{
199
+		return $this->reason;
200
+	}
201
+
202
+	/**
203
+	 * @param string $reason
204
+	 */
205
+	public function setReason($reason)
206
+	{
207
+		$this->reason = $reason;
208
+	}
209
+
210
+	/**
211
+	 * @return mixed
212
+	 */
213
+	public function getDate()
214
+	{
215
+		return $this->date;
216
+	}
217
+
218
+	/**
219
+	 * @return mixed
220
+	 */
221
+	public function getDuration()
222
+	{
223
+		return $this->duration;
224
+	}
225
+
226
+	/**
227
+	 * @param mixed $duration
228
+	 */
229
+	public function setDuration($duration)
230
+	{
231
+		$this->duration = $duration;
232
+	}
233
+
234
+	/**
235
+	 * @return bool
236
+	 */
237
+	public function isActive()
238
+	{
239
+		return $this->active == 1;
240
+	}
241
+
242
+	/**
243
+	 * @param bool $active
244
+	 */
245
+	public function setActive($active)
246
+	{
247
+		$this->active = $active ? 1 : 0;
248
+	}
249
+
250
+	/**
251
+	 * @return int
252
+	 */
253
+	public function getUser()
254
+	{
255
+		return $this->user;
256
+	}
257
+
258
+	/**
259
+	 * @param int $user UserID of user who is setting the ban
260
+	 */
261
+	public function setUser($user)
262
+	{
263
+		$this->user = $user;
264
+	}
265
+
266
+	/**
267
+	 * @return string
268
+	 */
269
+	public function getAction(): string
270
+	{
271
+		return $this->action;
272
+	}
273
+
274
+	/**
275
+	 * @param string $action
276
+	 */
277
+	public function setAction(string $action): void
278
+	{
279
+		$this->action = $action;
280
+	}
281
+
282
+	/**
283
+	 * @return string
284
+	 */
285
+	public function getVisibility() : string
286
+	{
287
+		return $this->visibility;
288
+	}
289
+
290
+	/**
291
+	 * @param string $visibility
292
+	 */
293
+	public function setVisibility(string $visibility): void
294
+	{
295
+		$this->visibility = $visibility;
296
+	}
297
+
298
+	/**
299
+	 * @return string|null
300
+	 */
301
+	public function getName(): ?string
302
+	{
303
+		return $this->name;
304
+	}
305
+
306
+	/**
307
+	 * @param string|null $name
308
+	 */
309
+	public function setName(?string $name): void
310
+	{
311
+		$this->name = $name;
312
+	}
313
+
314
+	/**
315
+	 * @return string|null
316
+	 */
317
+	public function getIp(): ?string
318
+	{
319
+		if ($this->ip === null) {
320
+			return null;
321
+		}
322
+
323
+		return inet_ntop($this->ip);
324
+	}
325
+
326
+	/**
327
+	 * @return int|null
328
+	 */
329
+	public function getIpMask(): ?int
330
+	{
331
+		return $this->ipmask;
332
+	}
333
+
334
+	/**
335
+	 * @param string|null $ip
336
+	 * @param int|null    $mask
337
+	 */
338
+	public function setIp(?string $ip, ?int $mask): void
339
+	{
340
+		if ($ip === null) {
341
+			$this->ip = null;
342
+		}
343
+		else {
344
+			$this->ip = inet_pton($ip);
345
+		}
346
+
347
+		$this->ipmask = $mask;
348
+	}
349
+
350
+	/**
351
+	 * @return string|null
352
+	 */
353
+	public function getEmail(): ?string
354
+	{
355
+		return $this->email;
356
+	}
357
+
358
+	/**
359
+	 * @param string|null $email
360
+	 */
361
+	public function setEmail(?string $email): void
362
+	{
363
+		$this->email = $email;
364
+	}
365
+
366
+	/**
367
+	 * @return string|null
368
+	 */
369
+	public function getUseragent(): ?string
370
+	{
371
+		return $this->useragent;
372
+	}
373
+
374
+	/**
375
+	 * @param string|null $useragent
376
+	 */
377
+	public function setUseragent(?string $useragent): void
378
+	{
379
+		$this->useragent = $useragent;
380
+	}
381
+
382
+	/**
383
+	 * @return int|null
384
+	 */
385
+	public function getTargetQueue(): ?int
386
+	{
387
+		return $this->targetqueue;
388
+	}
389
+
390
+	/**
391
+	 * @return RequestQueue|null
392
+	 */
393
+	public function getTargetQueueObject(): ?RequestQueue
394
+	{
395
+		/** @var RequestQueue $queue */
396
+		$queue = RequestQueue::getById($this->targetqueue, $this->getDatabase());
397
+		return $queue === false ? null : $queue;
398
+	}
399
+
400
+	/**
401
+	 * @param int|null $targetQueue
402
+	 */
403
+	public function setTargetQueue(?int $targetQueue): void
404
+	{
405
+		$this->targetqueue = $targetQueue;
406
+	}
407
+
408
+	public function setDomain(?int $domain): void
409
+	{
410
+		$this->domain = $domain;
411
+	}
412
+
413
+	public function getDomain(): ?int
414
+	{
415
+		return $this->domain;
416
+	}
417 417
 }
Please login to merge, or discard this patch.
includes/DataObjects/UserDomain.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -13,72 +13,72 @@
 block discarded – undo
13 13
 
14 14
 class UserDomain extends DataObject
15 15
 {
16
-    /** @var int */
17
-    private $user;
16
+	/** @var int */
17
+	private $user;
18 18
 
19
-    /** @var int */
20
-    private $domain;
19
+	/** @var int */
20
+	private $domain;
21 21
 
22
-    public function save()
23
-    {
24
-        if ($this->isNew()) {
25
-            // insert
26
-            $statement = $this->dbObject->prepare(<<<SQL
22
+	public function save()
23
+	{
24
+		if ($this->isNew()) {
25
+			// insert
26
+			$statement = $this->dbObject->prepare(<<<SQL
27 27
                 INSERT INTO userdomain (
28 28
                     user, domain
29 29
                 ) VALUES (
30 30
                     :user, :domain
31 31
                 );
32 32
 SQL
33
-            );
33
+			);
34 34
 
35
-            $statement->bindValue(":user", $this->user);
36
-            $statement->bindValue(":domain", $this->domain);
35
+			$statement->bindValue(":user", $this->user);
36
+			$statement->bindValue(":domain", $this->domain);
37 37
 
38
-            if ($statement->execute()) {
39
-                $this->id = (int)$this->dbObject->lastInsertId();
40
-            }
41
-            else {
42
-                throw new Exception($statement->errorInfo());
43
-            }
44
-        }
45
-        else {
46
-            // insert / delete only, no updates please.
47
-            throw new Exception('Updating domain membership is not available');
48
-        }
49
-    }
38
+			if ($statement->execute()) {
39
+				$this->id = (int)$this->dbObject->lastInsertId();
40
+			}
41
+			else {
42
+				throw new Exception($statement->errorInfo());
43
+			}
44
+		}
45
+		else {
46
+			// insert / delete only, no updates please.
47
+			throw new Exception('Updating domain membership is not available');
48
+		}
49
+	}
50 50
 
51
-    /**
52
-     * @return int
53
-     */
54
-    public function getUser(): int
55
-    {
56
-        return $this->user;
57
-    }
51
+	/**
52
+	 * @return int
53
+	 */
54
+	public function getUser(): int
55
+	{
56
+		return $this->user;
57
+	}
58 58
 
59
-    /**
60
-     * @param int $user
61
-     */
62
-    public function setUser(int $user): void
63
-    {
64
-        $this->user = $user;
65
-    }
59
+	/**
60
+	 * @param int $user
61
+	 */
62
+	public function setUser(int $user): void
63
+	{
64
+		$this->user = $user;
65
+	}
66 66
 
67
-    /**
68
-     * @return int
69
-     */
70
-    public function getDomain(): int
71
-    {
72
-        return $this->domain;
73
-    }
67
+	/**
68
+	 * @return int
69
+	 */
70
+	public function getDomain(): int
71
+	{
72
+		return $this->domain;
73
+	}
74 74
 
75
-    /**
76
-     * @param int $domain
77
-     */
78
-    public function setDomain(int $domain): void
79
-    {
80
-        $this->domain = $domain;
81
-    }
75
+	/**
76
+	 * @param int $domain
77
+	 */
78
+	public function setDomain(int $domain): void
79
+	{
80
+		$this->domain = $domain;
81
+	}
82 82
 
83 83
 
84 84
 }
85 85
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -37,12 +37,10 @@
 block discarded – undo
37 37
 
38 38
             if ($statement->execute()) {
39 39
                 $this->id = (int)$this->dbObject->lastInsertId();
40
-            }
41
-            else {
40
+            } else {
42 41
                 throw new Exception($statement->errorInfo());
43 42
             }
44
-        }
45
-        else {
43
+        } else {
46 44
             // insert / delete only, no updates please.
47 45
             throw new Exception('Updating domain membership is not available');
48 46
         }
Please login to merge, or discard this patch.
includes/DataObjects/RequestForm.php 2 patches
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -16,126 +16,126 @@  discard block
 block discarded – undo
16 16
 
17 17
 class RequestForm extends DataObject
18 18
 {
19
-    /** @var int */
20
-    private $enabled = 0;
21
-    /** @var int */
22
-    private $domain;
23
-    /** @var string */
24
-    private $name = '';
25
-    /** @var string */
26
-    private $publicendpoint = '';
27
-    /** @var string */
28
-    private $formcontent = '';
29
-    /** @var int|null */
30
-    private $overridequeue;
31
-    /** @var string */
32
-    private $usernamehelp;
33
-    /** @var string */
34
-    private $emailhelp;
35
-    /** @var string */
36
-    private $commentshelp;
37
-
38
-    /**
39
-     * @param PdoDatabase $database
40
-     * @param int         $domain
41
-     *
42
-     * @return RequestForm[]
43
-     */
44
-    public static function getAllForms(PdoDatabase $database, int $domain)
45
-    {
46
-        $statement = $database->prepare("SELECT * FROM requestform WHERE domain = :domain;");
47
-        $statement->execute([':domain' => $domain]);
48
-
49
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
50
-
51
-        if ($resultObject === false) {
52
-            return [];
53
-        }
54
-
55
-        /** @var RequestQueue $t */
56
-        foreach ($resultObject as $t) {
57
-            $t->setDatabase($database);
58
-        }
59
-
60
-        return $resultObject;
61
-    }
62
-
63
-    public static function getByName(PdoDatabase $database, string $name, int $domain)
64
-    {
65
-        $statement = $database->prepare(<<<SQL
19
+	/** @var int */
20
+	private $enabled = 0;
21
+	/** @var int */
22
+	private $domain;
23
+	/** @var string */
24
+	private $name = '';
25
+	/** @var string */
26
+	private $publicendpoint = '';
27
+	/** @var string */
28
+	private $formcontent = '';
29
+	/** @var int|null */
30
+	private $overridequeue;
31
+	/** @var string */
32
+	private $usernamehelp;
33
+	/** @var string */
34
+	private $emailhelp;
35
+	/** @var string */
36
+	private $commentshelp;
37
+
38
+	/**
39
+	 * @param PdoDatabase $database
40
+	 * @param int         $domain
41
+	 *
42
+	 * @return RequestForm[]
43
+	 */
44
+	public static function getAllForms(PdoDatabase $database, int $domain)
45
+	{
46
+		$statement = $database->prepare("SELECT * FROM requestform WHERE domain = :domain;");
47
+		$statement->execute([':domain' => $domain]);
48
+
49
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
50
+
51
+		if ($resultObject === false) {
52
+			return [];
53
+		}
54
+
55
+		/** @var RequestQueue $t */
56
+		foreach ($resultObject as $t) {
57
+			$t->setDatabase($database);
58
+		}
59
+
60
+		return $resultObject;
61
+	}
62
+
63
+	public static function getByName(PdoDatabase $database, string $name, int $domain)
64
+	{
65
+		$statement = $database->prepare(<<<SQL
66 66
             SELECT * FROM requestform WHERE name = :name AND domain = :domain;
67 67
 SQL
68
-        );
68
+		);
69 69
 
70
-        $statement->execute([
71
-            ':name' => $name,
72
-            ':domain'  => $domain,
73
-        ]);
70
+		$statement->execute([
71
+			':name' => $name,
72
+			':domain'  => $domain,
73
+		]);
74 74
 
75
-        /** @var RequestForm|false $result */
76
-        $result = $statement->fetchObject(get_called_class());
75
+		/** @var RequestForm|false $result */
76
+		$result = $statement->fetchObject(get_called_class());
77 77
 
78
-        if ($result !== false) {
79
-            $result->setDatabase($database);
80
-        }
78
+		if ($result !== false) {
79
+			$result->setDatabase($database);
80
+		}
81 81
 
82
-        return $result;
83
-    }
82
+		return $result;
83
+	}
84 84
 
85
-    public static function getByPublicEndpoint(PdoDatabase $database, string $endpoint, int $domain)
86
-    {
87
-        $statement = $database->prepare(<<<SQL
85
+	public static function getByPublicEndpoint(PdoDatabase $database, string $endpoint, int $domain)
86
+	{
87
+		$statement = $database->prepare(<<<SQL
88 88
             SELECT * FROM requestform WHERE publicendpoint = :endpoint and domain = :domain;
89 89
 SQL
90
-        );
90
+		);
91 91
 
92
-        $statement->execute([
93
-            ':endpoint' => $endpoint,
94
-            ':domain' => $domain,
95
-        ]);
92
+		$statement->execute([
93
+			':endpoint' => $endpoint,
94
+			':domain' => $domain,
95
+		]);
96 96
 
97
-        /** @var RequestForm|false $result */
98
-        $result = $statement->fetchObject(get_called_class());
97
+		/** @var RequestForm|false $result */
98
+		$result = $statement->fetchObject(get_called_class());
99 99
 
100
-        if ($result !== false) {
101
-            $result->setDatabase($database);
102
-        }
100
+		if ($result !== false) {
101
+			$result->setDatabase($database);
102
+		}
103 103
 
104
-        return $result;
105
-    }
104
+		return $result;
105
+	}
106 106
 
107
-    public function save()
108
-    {
109
-        if ($this->isNew()) {
110
-            // insert
111
-            $statement = $this->dbObject->prepare(<<<SQL
107
+	public function save()
108
+	{
109
+		if ($this->isNew()) {
110
+			// insert
111
+			$statement = $this->dbObject->prepare(<<<SQL
112 112
                 INSERT INTO requestform (
113 113
                     enabled, domain, name, publicendpoint, formcontent, overridequeue, usernamehelp, emailhelp, commentshelp
114 114
                 ) VALUES (
115 115
                     :enabled, :domain, :name, :publicendpoint, :formcontent, :overridequeue, :usernamehelp, :emailhelp, :commentshelp
116 116
                 );
117 117
 SQL
118
-            );
119
-
120
-            $statement->bindValue(":enabled", $this->enabled);
121
-            $statement->bindValue(":domain", $this->domain);
122
-            $statement->bindValue(":name", $this->name);
123
-            $statement->bindValue(":publicendpoint", $this->publicendpoint);
124
-            $statement->bindValue(":formcontent", $this->formcontent);
125
-            $statement->bindValue(":overridequeue", $this->overridequeue);
126
-            $statement->bindValue(":usernamehelp", $this->usernamehelp);
127
-            $statement->bindValue(":emailhelp", $this->emailhelp);
128
-            $statement->bindValue(":commentshelp", $this->commentshelp);
129
-
130
-            if ($statement->execute()) {
131
-                $this->id = (int)$this->dbObject->lastInsertId();
132
-            }
133
-            else {
134
-                throw new Exception($statement->errorInfo());
135
-            }
136
-        }
137
-        else {
138
-            $statement = $this->dbObject->prepare(<<<SQL
118
+			);
119
+
120
+			$statement->bindValue(":enabled", $this->enabled);
121
+			$statement->bindValue(":domain", $this->domain);
122
+			$statement->bindValue(":name", $this->name);
123
+			$statement->bindValue(":publicendpoint", $this->publicendpoint);
124
+			$statement->bindValue(":formcontent", $this->formcontent);
125
+			$statement->bindValue(":overridequeue", $this->overridequeue);
126
+			$statement->bindValue(":usernamehelp", $this->usernamehelp);
127
+			$statement->bindValue(":emailhelp", $this->emailhelp);
128
+			$statement->bindValue(":commentshelp", $this->commentshelp);
129
+
130
+			if ($statement->execute()) {
131
+				$this->id = (int)$this->dbObject->lastInsertId();
132
+			}
133
+			else {
134
+				throw new Exception($statement->errorInfo());
135
+			}
136
+		}
137
+		else {
138
+			$statement = $this->dbObject->prepare(<<<SQL
139 139
                 UPDATE requestform SET
140 140
                     enabled = :enabled,
141 141
                     domain = :domain,
@@ -150,186 +150,186 @@  discard block
 block discarded – undo
150 150
                     updateversion = updateversion + 1
151 151
 				WHERE id = :id AND updateversion = :updateversion;
152 152
 SQL
153
-            );
154
-
155
-            $statement->bindValue(":enabled", $this->enabled);
156
-            $statement->bindValue(":domain", $this->domain);
157
-            $statement->bindValue(":name", $this->name);
158
-            $statement->bindValue(":publicendpoint", $this->publicendpoint);
159
-            $statement->bindValue(":formcontent", $this->formcontent);
160
-            $statement->bindValue(":overridequeue", $this->overridequeue);
161
-            $statement->bindValue(":usernamehelp", $this->usernamehelp);
162
-            $statement->bindValue(":emailhelp", $this->emailhelp);
163
-            $statement->bindValue(":commentshelp", $this->commentshelp);
164
-
165
-
166
-            $statement->bindValue(':id', $this->id);
167
-            $statement->bindValue(':updateversion', $this->updateversion);
168
-
169
-            if (!$statement->execute()) {
170
-                throw new Exception($statement->errorInfo());
171
-            }
172
-
173
-            if ($statement->rowCount() !== 1) {
174
-                throw new OptimisticLockFailedException();
175
-            }
176
-
177
-            $this->updateversion++;
178
-        }
179
-    }
180
-
181
-    /**
182
-     * @return bool
183
-     */
184
-    public function isEnabled(): bool
185
-    {
186
-        return $this->enabled == 1;
187
-    }
188
-
189
-    /**
190
-     * @param bool $enabled
191
-     */
192
-    public function setEnabled(bool $enabled): void
193
-    {
194
-        $this->enabled = $enabled ? 1 : 0;
195
-    }
196
-
197
-    /**
198
-     * @return int
199
-     */
200
-    public function getDomain(): int
201
-    {
202
-        return $this->domain;
203
-    }
204
-
205
-    public function getDomainObject(): ?Domain
206
-    {
207
-        if ($this->domain !== null) {
208
-            /** @var Domain $domain */
209
-            $domain = Domain::getById($this->domain, $this->getDatabase());
210
-            return $domain;
211
-        }
212
-
213
-        return null;
214
-    }
215
-
216
-    /**
217
-     * @param int $domain
218
-     */
219
-    public function setDomain(int $domain): void
220
-    {
221
-        $this->domain = $domain;
222
-    }
223
-
224
-    /**
225
-     * @return string
226
-     */
227
-    public function getName(): string
228
-    {
229
-        return $this->name;
230
-    }
231
-
232
-    /**
233
-     * @param string $name
234
-     */
235
-    public function setName(string $name): void
236
-    {
237
-        $this->name = $name;
238
-    }
239
-
240
-    /**
241
-     * @return string
242
-     */
243
-    public function getPublicEndpoint(): string
244
-    {
245
-        return $this->publicendpoint;
246
-    }
247
-
248
-    /**
249
-     * @param string $publicEndpoint
250
-     */
251
-    public function setPublicEndpoint(string $publicEndpoint): void
252
-    {
253
-        $this->publicendpoint = $publicEndpoint;
254
-    }
255
-
256
-    /**
257
-     * @return string
258
-     */
259
-    public function getFormContent(): string
260
-    {
261
-        return $this->formcontent;
262
-    }
263
-
264
-    /**
265
-     * @param string $formContent
266
-     */
267
-    public function setFormContent(string $formContent): void
268
-    {
269
-        $this->formcontent = $formContent;
270
-    }
271
-
272
-    /**
273
-     * @return int|null
274
-     */
275
-    public function getOverrideQueue(): ?int
276
-    {
277
-        return $this->overridequeue;
278
-    }
279
-
280
-    /**
281
-     * @param int|null $overrideQueue
282
-     */
283
-    public function setOverrideQueue(?int $overrideQueue): void
284
-    {
285
-        $this->overridequeue = $overrideQueue;
286
-    }
287
-
288
-    /**
289
-     * @return string
290
-     */
291
-    public function getUsernameHelp(): ?string
292
-    {
293
-        return $this->usernamehelp;
294
-    }
295
-
296
-    /**
297
-     * @param string $usernamehelp
298
-     */
299
-    public function setUsernameHelp(string $usernamehelp): void
300
-    {
301
-        $this->usernamehelp = $usernamehelp;
302
-    }
303
-
304
-    /**
305
-     * @return string
306
-     */
307
-    public function getEmailHelp(): ?string
308
-    {
309
-        return $this->emailhelp;
310
-    }
311
-
312
-    /**
313
-     * @param string $emailhelp
314
-     */
315
-    public function setEmailHelp(string $emailhelp): void
316
-    {
317
-        $this->emailhelp = $emailhelp;
318
-    }
319
-
320
-    /**
321
-     * @return string
322
-     */
323
-    public function getCommentHelp(): ?string
324
-    {
325
-        return $this->commentshelp;
326
-    }
327
-
328
-    /**
329
-     * @param string $commenthelp
330
-     */
331
-    public function setCommentHelp(string $commenthelp): void
332
-    {
333
-        $this->commentshelp = $commenthelp;
334
-    }
153
+			);
154
+
155
+			$statement->bindValue(":enabled", $this->enabled);
156
+			$statement->bindValue(":domain", $this->domain);
157
+			$statement->bindValue(":name", $this->name);
158
+			$statement->bindValue(":publicendpoint", $this->publicendpoint);
159
+			$statement->bindValue(":formcontent", $this->formcontent);
160
+			$statement->bindValue(":overridequeue", $this->overridequeue);
161
+			$statement->bindValue(":usernamehelp", $this->usernamehelp);
162
+			$statement->bindValue(":emailhelp", $this->emailhelp);
163
+			$statement->bindValue(":commentshelp", $this->commentshelp);
164
+
165
+
166
+			$statement->bindValue(':id', $this->id);
167
+			$statement->bindValue(':updateversion', $this->updateversion);
168
+
169
+			if (!$statement->execute()) {
170
+				throw new Exception($statement->errorInfo());
171
+			}
172
+
173
+			if ($statement->rowCount() !== 1) {
174
+				throw new OptimisticLockFailedException();
175
+			}
176
+
177
+			$this->updateversion++;
178
+		}
179
+	}
180
+
181
+	/**
182
+	 * @return bool
183
+	 */
184
+	public function isEnabled(): bool
185
+	{
186
+		return $this->enabled == 1;
187
+	}
188
+
189
+	/**
190
+	 * @param bool $enabled
191
+	 */
192
+	public function setEnabled(bool $enabled): void
193
+	{
194
+		$this->enabled = $enabled ? 1 : 0;
195
+	}
196
+
197
+	/**
198
+	 * @return int
199
+	 */
200
+	public function getDomain(): int
201
+	{
202
+		return $this->domain;
203
+	}
204
+
205
+	public function getDomainObject(): ?Domain
206
+	{
207
+		if ($this->domain !== null) {
208
+			/** @var Domain $domain */
209
+			$domain = Domain::getById($this->domain, $this->getDatabase());
210
+			return $domain;
211
+		}
212
+
213
+		return null;
214
+	}
215
+
216
+	/**
217
+	 * @param int $domain
218
+	 */
219
+	public function setDomain(int $domain): void
220
+	{
221
+		$this->domain = $domain;
222
+	}
223
+
224
+	/**
225
+	 * @return string
226
+	 */
227
+	public function getName(): string
228
+	{
229
+		return $this->name;
230
+	}
231
+
232
+	/**
233
+	 * @param string $name
234
+	 */
235
+	public function setName(string $name): void
236
+	{
237
+		$this->name = $name;
238
+	}
239
+
240
+	/**
241
+	 * @return string
242
+	 */
243
+	public function getPublicEndpoint(): string
244
+	{
245
+		return $this->publicendpoint;
246
+	}
247
+
248
+	/**
249
+	 * @param string $publicEndpoint
250
+	 */
251
+	public function setPublicEndpoint(string $publicEndpoint): void
252
+	{
253
+		$this->publicendpoint = $publicEndpoint;
254
+	}
255
+
256
+	/**
257
+	 * @return string
258
+	 */
259
+	public function getFormContent(): string
260
+	{
261
+		return $this->formcontent;
262
+	}
263
+
264
+	/**
265
+	 * @param string $formContent
266
+	 */
267
+	public function setFormContent(string $formContent): void
268
+	{
269
+		$this->formcontent = $formContent;
270
+	}
271
+
272
+	/**
273
+	 * @return int|null
274
+	 */
275
+	public function getOverrideQueue(): ?int
276
+	{
277
+		return $this->overridequeue;
278
+	}
279
+
280
+	/**
281
+	 * @param int|null $overrideQueue
282
+	 */
283
+	public function setOverrideQueue(?int $overrideQueue): void
284
+	{
285
+		$this->overridequeue = $overrideQueue;
286
+	}
287
+
288
+	/**
289
+	 * @return string
290
+	 */
291
+	public function getUsernameHelp(): ?string
292
+	{
293
+		return $this->usernamehelp;
294
+	}
295
+
296
+	/**
297
+	 * @param string $usernamehelp
298
+	 */
299
+	public function setUsernameHelp(string $usernamehelp): void
300
+	{
301
+		$this->usernamehelp = $usernamehelp;
302
+	}
303
+
304
+	/**
305
+	 * @return string
306
+	 */
307
+	public function getEmailHelp(): ?string
308
+	{
309
+		return $this->emailhelp;
310
+	}
311
+
312
+	/**
313
+	 * @param string $emailhelp
314
+	 */
315
+	public function setEmailHelp(string $emailhelp): void
316
+	{
317
+		$this->emailhelp = $emailhelp;
318
+	}
319
+
320
+	/**
321
+	 * @return string
322
+	 */
323
+	public function getCommentHelp(): ?string
324
+	{
325
+		return $this->commentshelp;
326
+	}
327
+
328
+	/**
329
+	 * @param string $commenthelp
330
+	 */
331
+	public function setCommentHelp(string $commenthelp): void
332
+	{
333
+		$this->commentshelp = $commenthelp;
334
+	}
335 335
 }
336 336
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -129,12 +129,10 @@
 block discarded – undo
129 129
 
130 130
             if ($statement->execute()) {
131 131
                 $this->id = (int)$this->dbObject->lastInsertId();
132
-            }
133
-            else {
132
+            } else {
134 133
                 throw new Exception($statement->errorInfo());
135 134
             }
136
-        }
137
-        else {
135
+        } else {
138 136
             $statement = $this->dbObject->prepare(<<<SQL
139 137
                 UPDATE requestform SET
140 138
                     enabled = :enabled,
Please login to merge, or discard this patch.
includes/DataObjects/EmailTemplate.php 2 patches
Indentation   +348 added lines, -348 removed lines patch added patch discarded remove patch
@@ -21,188 +21,188 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class EmailTemplate extends DataObject
23 23
 {
24
-    const ACTION_CREATED = 'created';
25
-    const ACTION_NOT_CREATED = 'not created';
26
-    const ACTION_NONE = 'none';
27
-    const ACTION_DEFER = 'defer';
28
-
29
-    /** @var string the name of the template */
30
-    private $name;
31
-    private $text;
32
-    /** @var string|null */
33
-    private $jsquestion;
34
-    private $active = 1;
35
-    private $preloadonly = 0;
36
-    private $defaultaction = self::ACTION_NOT_CREATED;
37
-    private $queue;
38
-    /** @var int */
39
-    private $domain;
40
-
41
-    /**
42
-     * Gets active non-preload templates
43
-     *
44
-     * @param string      $defaultAction Default action to take (EmailTemplate::ACTION_CREATED or EmailTemplate::ACTION_NOT_CREATED)
45
-     * @param PdoDatabase $database
46
-     * @param int         $domain
47
-     * @param int|null    $filter        Template IDs to filter out
48
-     *
49
-     * @return array|false
50
-     */
51
-    public static function getActiveNonpreloadTemplates($defaultAction, PdoDatabase $database, int $domain, ?int $filter = null)
52
-    {
53
-        $statement = $database->prepare(<<<SQL
24
+	const ACTION_CREATED = 'created';
25
+	const ACTION_NOT_CREATED = 'not created';
26
+	const ACTION_NONE = 'none';
27
+	const ACTION_DEFER = 'defer';
28
+
29
+	/** @var string the name of the template */
30
+	private $name;
31
+	private $text;
32
+	/** @var string|null */
33
+	private $jsquestion;
34
+	private $active = 1;
35
+	private $preloadonly = 0;
36
+	private $defaultaction = self::ACTION_NOT_CREATED;
37
+	private $queue;
38
+	/** @var int */
39
+	private $domain;
40
+
41
+	/**
42
+	 * Gets active non-preload templates
43
+	 *
44
+	 * @param string      $defaultAction Default action to take (EmailTemplate::ACTION_CREATED or EmailTemplate::ACTION_NOT_CREATED)
45
+	 * @param PdoDatabase $database
46
+	 * @param int         $domain
47
+	 * @param int|null    $filter        Template IDs to filter out
48
+	 *
49
+	 * @return array|false
50
+	 */
51
+	public static function getActiveNonpreloadTemplates($defaultAction, PdoDatabase $database, int $domain, ?int $filter = null)
52
+	{
53
+		$statement = $database->prepare(<<<SQL
54 54
 SELECT * FROM `emailtemplate`
55 55
 WHERE defaultaction = :forcreated AND active = 1 AND preloadonly = 0 AND (:skipFilter = 1 OR id <> :filter) AND domain = :domain;
56 56
 SQL
57
-        );
58
-        $statement->bindValue(":forcreated", $defaultAction);
59
-        $statement->bindValue(":filter", $filter);
60
-        $statement->bindValue(":skipFilter", $filter === null ? 1 : 0);
61
-        $statement->bindValue(":domain", $domain);
62
-
63
-        $statement->execute();
64
-
65
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
66
-
67
-        /** @var EmailTemplate $t */
68
-        foreach ($resultObject as $t) {
69
-            $t->setDatabase($database);
70
-        }
71
-
72
-        return $resultObject;
73
-    }
74
-
75
-    /**
76
-     * Gets active non-preload and preload templates, optionally filtered by the default action.
77
-     *
78
-     * @param null|bool|string $defaultAction Default action to take (EmailTemplate::ACTION_CREATED,
79
-     *                                        EmailTemplate::ACTION_NOT_CREATED, or EmailTemplate::ACTION_NONE), or optionally null to
80
-     *                                        just get everything.
81
-     * @param PdoDatabase      $database
82
-     * @param int              $domain
83
-     *
84
-     * @return array|false
85
-     */
86
-    public static function getAllActiveTemplates($defaultAction, PdoDatabase $database, int $domain)
87
-    {
88
-        if ($defaultAction === false) {
89
-            $statement = $database->prepare(
90
-                "SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1 AND domain = :domain;");
91
-        }
92
-        elseif ($defaultAction === null) {
93
-            $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE active = 1 AND domain = :domain;");
94
-        }
95
-        else {
96
-            $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1 AND domain = :domain;");
97
-            $statement->bindValue(":forcreated", $defaultAction);
98
-        }
99
-
100
-        $statement->bindValue(":domain", $domain);
101
-
102
-        $statement->execute();
103
-
104
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
105
-
106
-        /** @var EmailTemplate $t */
107
-        foreach ($resultObject as $t) {
108
-            $t->setDatabase($database);
109
-        }
110
-
111
-        return $resultObject;
112
-    }
113
-
114
-    /**
115
-     * Gets all the inactive templates
116
-     *
117
-     * @param PdoDatabase $database
118
-     * @param int         $domain
119
-     *
120
-     * @return array
121
-     */
122
-    public static function getAllInactiveTemplates(PdoDatabase $database, int $domain)
123
-    {
124
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE active = 0 AND domain = :domain;");
125
-        $statement->execute([':domain' => $domain]);
126
-
127
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
128
-
129
-        /** @var EmailTemplate $t */
130
-        foreach ($resultObject as $t) {
131
-            $t->setDatabase($database);
132
-        }
133
-
134
-        return $resultObject;
135
-    }
136
-
137
-    /**
138
-     * @param string      $name
139
-     * @param PdoDatabase $database
140
-     * @param int         $domain
141
-     *
142
-     * @return EmailTemplate|false
143
-     */
144
-    public static function getByName($name, PdoDatabase $database, int $domain)
145
-    {
146
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE name = :name AND domain = :domain LIMIT 1;");
147
-        $statement->bindValue(":name", $name);
148
-        $statement->bindValue(":domain", $domain);
149
-
150
-        $statement->execute();
151
-
152
-        $resultObject = $statement->fetchObject(get_called_class());
153
-
154
-        if ($resultObject != false) {
155
-            $resultObject->setDatabase($database);
156
-        }
157
-
158
-        return $resultObject;
159
-    }
160
-
161
-    /**
162
-     * @return EmailTemplate
163
-     */
164
-    public static function getDroppedTemplate()
165
-    {
166
-        $t = new EmailTemplate();
167
-        $t->id = 0;
168
-        $t->active = 1;
169
-        $t->defaultaction = self::ACTION_NONE;
170
-        $t->name = 'Dropped';
171
-
172
-        return $t;
173
-    }
174
-
175
-    /**
176
-     * @throws Exception
177
-     */
178
-    public function save()
179
-    {
180
-        if ($this->isNew()) {
181
-            // insert
182
-            $statement = $this->dbObject->prepare(<<<SQL
57
+		);
58
+		$statement->bindValue(":forcreated", $defaultAction);
59
+		$statement->bindValue(":filter", $filter);
60
+		$statement->bindValue(":skipFilter", $filter === null ? 1 : 0);
61
+		$statement->bindValue(":domain", $domain);
62
+
63
+		$statement->execute();
64
+
65
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
66
+
67
+		/** @var EmailTemplate $t */
68
+		foreach ($resultObject as $t) {
69
+			$t->setDatabase($database);
70
+		}
71
+
72
+		return $resultObject;
73
+	}
74
+
75
+	/**
76
+	 * Gets active non-preload and preload templates, optionally filtered by the default action.
77
+	 *
78
+	 * @param null|bool|string $defaultAction Default action to take (EmailTemplate::ACTION_CREATED,
79
+	 *                                        EmailTemplate::ACTION_NOT_CREATED, or EmailTemplate::ACTION_NONE), or optionally null to
80
+	 *                                        just get everything.
81
+	 * @param PdoDatabase      $database
82
+	 * @param int              $domain
83
+	 *
84
+	 * @return array|false
85
+	 */
86
+	public static function getAllActiveTemplates($defaultAction, PdoDatabase $database, int $domain)
87
+	{
88
+		if ($defaultAction === false) {
89
+			$statement = $database->prepare(
90
+				"SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1 AND domain = :domain;");
91
+		}
92
+		elseif ($defaultAction === null) {
93
+			$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE active = 1 AND domain = :domain;");
94
+		}
95
+		else {
96
+			$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1 AND domain = :domain;");
97
+			$statement->bindValue(":forcreated", $defaultAction);
98
+		}
99
+
100
+		$statement->bindValue(":domain", $domain);
101
+
102
+		$statement->execute();
103
+
104
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
105
+
106
+		/** @var EmailTemplate $t */
107
+		foreach ($resultObject as $t) {
108
+			$t->setDatabase($database);
109
+		}
110
+
111
+		return $resultObject;
112
+	}
113
+
114
+	/**
115
+	 * Gets all the inactive templates
116
+	 *
117
+	 * @param PdoDatabase $database
118
+	 * @param int         $domain
119
+	 *
120
+	 * @return array
121
+	 */
122
+	public static function getAllInactiveTemplates(PdoDatabase $database, int $domain)
123
+	{
124
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE active = 0 AND domain = :domain;");
125
+		$statement->execute([':domain' => $domain]);
126
+
127
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
128
+
129
+		/** @var EmailTemplate $t */
130
+		foreach ($resultObject as $t) {
131
+			$t->setDatabase($database);
132
+		}
133
+
134
+		return $resultObject;
135
+	}
136
+
137
+	/**
138
+	 * @param string      $name
139
+	 * @param PdoDatabase $database
140
+	 * @param int         $domain
141
+	 *
142
+	 * @return EmailTemplate|false
143
+	 */
144
+	public static function getByName($name, PdoDatabase $database, int $domain)
145
+	{
146
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE name = :name AND domain = :domain LIMIT 1;");
147
+		$statement->bindValue(":name", $name);
148
+		$statement->bindValue(":domain", $domain);
149
+
150
+		$statement->execute();
151
+
152
+		$resultObject = $statement->fetchObject(get_called_class());
153
+
154
+		if ($resultObject != false) {
155
+			$resultObject->setDatabase($database);
156
+		}
157
+
158
+		return $resultObject;
159
+	}
160
+
161
+	/**
162
+	 * @return EmailTemplate
163
+	 */
164
+	public static function getDroppedTemplate()
165
+	{
166
+		$t = new EmailTemplate();
167
+		$t->id = 0;
168
+		$t->active = 1;
169
+		$t->defaultaction = self::ACTION_NONE;
170
+		$t->name = 'Dropped';
171
+
172
+		return $t;
173
+	}
174
+
175
+	/**
176
+	 * @throws Exception
177
+	 */
178
+	public function save()
179
+	{
180
+		if ($this->isNew()) {
181
+			// insert
182
+			$statement = $this->dbObject->prepare(<<<SQL
183 183
 INSERT INTO `emailtemplate` (name, text, jsquestion, defaultaction, active, preloadonly, queue, domain)
184 184
 VALUES (:name, :text, :jsquestion, :defaultaction, :active, :preloadonly, :queue, :domain);
185 185
 SQL
186
-            );
187
-            $statement->bindValue(":name", $this->name);
188
-            $statement->bindValue(":text", $this->text);
189
-            $statement->bindValue(":jsquestion", $this->jsquestion);
190
-            $statement->bindValue(":defaultaction", $this->defaultaction);
191
-            $statement->bindValue(":active", $this->active);
192
-            $statement->bindValue(":preloadonly", $this->preloadonly);
193
-            $statement->bindValue(":queue", $this->queue);
194
-            $statement->bindValue(":domain", $this->domain);
195
-
196
-            if ($statement->execute()) {
197
-                $this->id = (int)$this->dbObject->lastInsertId();
198
-            }
199
-            else {
200
-                throw new Exception($statement->errorInfo());
201
-            }
202
-        }
203
-        else {
204
-            // update
205
-            $statement = $this->dbObject->prepare(<<<SQL
186
+			);
187
+			$statement->bindValue(":name", $this->name);
188
+			$statement->bindValue(":text", $this->text);
189
+			$statement->bindValue(":jsquestion", $this->jsquestion);
190
+			$statement->bindValue(":defaultaction", $this->defaultaction);
191
+			$statement->bindValue(":active", $this->active);
192
+			$statement->bindValue(":preloadonly", $this->preloadonly);
193
+			$statement->bindValue(":queue", $this->queue);
194
+			$statement->bindValue(":domain", $this->domain);
195
+
196
+			if ($statement->execute()) {
197
+				$this->id = (int)$this->dbObject->lastInsertId();
198
+			}
199
+			else {
200
+				throw new Exception($statement->errorInfo());
201
+			}
202
+		}
203
+		else {
204
+			// update
205
+			$statement = $this->dbObject->prepare(<<<SQL
206 206
 UPDATE `emailtemplate`
207 207
 SET name = :name,
208 208
 	text = :text,
@@ -214,176 +214,176 @@  discard block
 block discarded – undo
214 214
 	updateversion = updateversion + 1
215 215
 WHERE id = :id AND updateversion = :updateversion;
216 216
 SQL
217
-            );
218
-            $statement->bindValue(':id', $this->id);
219
-            $statement->bindValue(':updateversion', $this->updateversion);
220
-
221
-            $statement->bindValue(':name', $this->name);
222
-            $statement->bindValue(":text", $this->text);
223
-            $statement->bindValue(":jsquestion", $this->jsquestion);
224
-            $statement->bindValue(":defaultaction", $this->defaultaction);
225
-            $statement->bindValue(":active", $this->active);
226
-            $statement->bindValue(":preloadonly", $this->preloadonly);
227
-            $statement->bindValue(":queue", $this->queue);
228
-
229
-            if (!$statement->execute()) {
230
-                throw new Exception($statement->errorInfo());
231
-            }
232
-
233
-            if ($statement->rowCount() !== 1) {
234
-                throw new OptimisticLockFailedException();
235
-            }
236
-
237
-            $this->updateversion++;
238
-        }
239
-    }
240
-
241
-    /**
242
-     * Override delete() from DataObject
243
-     */
244
-    public function delete()
245
-    {
246
-        throw new Exception("You shouldn't be doing that, you'll break logs.");
247
-    }
248
-
249
-    /**
250
-     * @return string
251
-     */
252
-    public function getName()
253
-    {
254
-        return $this->name;
255
-    }
256
-
257
-    /**
258
-     * @param string $name
259
-     */
260
-    public function setName($name)
261
-    {
262
-        $this->name = $name;
263
-    }
264
-
265
-    /**
266
-     * @return string
267
-     */
268
-    public function getText()
269
-    {
270
-        return $this->text;
271
-    }
272
-
273
-    /**
274
-     * @param string $text
275
-     */
276
-    public function setText($text)
277
-    {
278
-        $this->text = $text;
279
-    }
280
-
281
-    /**
282
-     * @return string|null
283
-     */
284
-    public function getJsquestion()
285
-    {
286
-        return $this->jsquestion;
287
-    }
288
-
289
-    /**
290
-     * @param string $jsquestion
291
-     */
292
-    public function setJsquestion($jsquestion)
293
-    {
294
-        $this->jsquestion = $jsquestion;
295
-    }
296
-
297
-    /**
298
-     * @return string
299
-     */
300
-    public function getDefaultAction()
301
-    {
302
-        return $this->defaultaction;
303
-    }
304
-
305
-    /**
306
-     * @param string $defaultAction
307
-     */
308
-    public function setDefaultAction($defaultAction)
309
-    {
310
-        $this->defaultaction = $defaultAction;
311
-    }
312
-
313
-    /**
314
-     * @return bool
315
-     */
316
-    public function getActive()
317
-    {
318
-        return $this->active == 1;
319
-    }
320
-
321
-    /**
322
-     * @param bool $active
323
-     */
324
-    public function setActive($active)
325
-    {
326
-        $this->active = $active ? 1 : 0;
327
-    }
328
-
329
-    /**
330
-     * @return bool
331
-     */
332
-    public function getPreloadOnly()
333
-    {
334
-        return $this->preloadonly == 1;
335
-    }
336
-
337
-    /**
338
-     * @param bool $preloadonly
339
-     */
340
-    public function setPreloadOnly($preloadonly)
341
-    {
342
-        $this->preloadonly = $preloadonly ? 1 : 0;
343
-    }
344
-
345
-    /**
346
-     * @return int|null
347
-     */
348
-    public function getQueue(): ?int
349
-    {
350
-        return $this->queue;
351
-    }
352
-
353
-    /**
354
-     * @return RequestQueue|null
355
-     */
356
-    public function getQueueObject(): ?RequestQueue
357
-    {
358
-        if ($this->queue === null) {
359
-            return null;
360
-        }
361
-
362
-        /** @var $dataObject RequestQueue|false */
363
-        $dataObject = RequestQueue::getById($this->queue, $this->getDatabase());
364
-
365
-        if ($dataObject === false) {
366
-            return null;
367
-        }
368
-
369
-        return $dataObject;
370
-    }
371
-
372
-    /**
373
-     * @param int|null $queue
374
-     */
375
-    public function setQueue(?int $queue): void
376
-    {
377
-        $this->queue = $queue;
378
-    }
379
-
380
-    public function getDomain(): int
381
-    {
382
-        return $this->domain;
383
-    }
384
-
385
-    public function setDomain(int $domain): void
386
-    {
387
-        $this->domain = $domain;
388
-    }
217
+			);
218
+			$statement->bindValue(':id', $this->id);
219
+			$statement->bindValue(':updateversion', $this->updateversion);
220
+
221
+			$statement->bindValue(':name', $this->name);
222
+			$statement->bindValue(":text", $this->text);
223
+			$statement->bindValue(":jsquestion", $this->jsquestion);
224
+			$statement->bindValue(":defaultaction", $this->defaultaction);
225
+			$statement->bindValue(":active", $this->active);
226
+			$statement->bindValue(":preloadonly", $this->preloadonly);
227
+			$statement->bindValue(":queue", $this->queue);
228
+
229
+			if (!$statement->execute()) {
230
+				throw new Exception($statement->errorInfo());
231
+			}
232
+
233
+			if ($statement->rowCount() !== 1) {
234
+				throw new OptimisticLockFailedException();
235
+			}
236
+
237
+			$this->updateversion++;
238
+		}
239
+	}
240
+
241
+	/**
242
+	 * Override delete() from DataObject
243
+	 */
244
+	public function delete()
245
+	{
246
+		throw new Exception("You shouldn't be doing that, you'll break logs.");
247
+	}
248
+
249
+	/**
250
+	 * @return string
251
+	 */
252
+	public function getName()
253
+	{
254
+		return $this->name;
255
+	}
256
+
257
+	/**
258
+	 * @param string $name
259
+	 */
260
+	public function setName($name)
261
+	{
262
+		$this->name = $name;
263
+	}
264
+
265
+	/**
266
+	 * @return string
267
+	 */
268
+	public function getText()
269
+	{
270
+		return $this->text;
271
+	}
272
+
273
+	/**
274
+	 * @param string $text
275
+	 */
276
+	public function setText($text)
277
+	{
278
+		$this->text = $text;
279
+	}
280
+
281
+	/**
282
+	 * @return string|null
283
+	 */
284
+	public function getJsquestion()
285
+	{
286
+		return $this->jsquestion;
287
+	}
288
+
289
+	/**
290
+	 * @param string $jsquestion
291
+	 */
292
+	public function setJsquestion($jsquestion)
293
+	{
294
+		$this->jsquestion = $jsquestion;
295
+	}
296
+
297
+	/**
298
+	 * @return string
299
+	 */
300
+	public function getDefaultAction()
301
+	{
302
+		return $this->defaultaction;
303
+	}
304
+
305
+	/**
306
+	 * @param string $defaultAction
307
+	 */
308
+	public function setDefaultAction($defaultAction)
309
+	{
310
+		$this->defaultaction = $defaultAction;
311
+	}
312
+
313
+	/**
314
+	 * @return bool
315
+	 */
316
+	public function getActive()
317
+	{
318
+		return $this->active == 1;
319
+	}
320
+
321
+	/**
322
+	 * @param bool $active
323
+	 */
324
+	public function setActive($active)
325
+	{
326
+		$this->active = $active ? 1 : 0;
327
+	}
328
+
329
+	/**
330
+	 * @return bool
331
+	 */
332
+	public function getPreloadOnly()
333
+	{
334
+		return $this->preloadonly == 1;
335
+	}
336
+
337
+	/**
338
+	 * @param bool $preloadonly
339
+	 */
340
+	public function setPreloadOnly($preloadonly)
341
+	{
342
+		$this->preloadonly = $preloadonly ? 1 : 0;
343
+	}
344
+
345
+	/**
346
+	 * @return int|null
347
+	 */
348
+	public function getQueue(): ?int
349
+	{
350
+		return $this->queue;
351
+	}
352
+
353
+	/**
354
+	 * @return RequestQueue|null
355
+	 */
356
+	public function getQueueObject(): ?RequestQueue
357
+	{
358
+		if ($this->queue === null) {
359
+			return null;
360
+		}
361
+
362
+		/** @var $dataObject RequestQueue|false */
363
+		$dataObject = RequestQueue::getById($this->queue, $this->getDatabase());
364
+
365
+		if ($dataObject === false) {
366
+			return null;
367
+		}
368
+
369
+		return $dataObject;
370
+	}
371
+
372
+	/**
373
+	 * @param int|null $queue
374
+	 */
375
+	public function setQueue(?int $queue): void
376
+	{
377
+		$this->queue = $queue;
378
+	}
379
+
380
+	public function getDomain(): int
381
+	{
382
+		return $this->domain;
383
+	}
384
+
385
+	public function setDomain(int $domain): void
386
+	{
387
+		$this->domain = $domain;
388
+	}
389 389
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -88,11 +88,9 @@  discard block
 block discarded – undo
88 88
         if ($defaultAction === false) {
89 89
             $statement = $database->prepare(
90 90
                 "SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1 AND domain = :domain;");
91
-        }
92
-        elseif ($defaultAction === null) {
91
+        } elseif ($defaultAction === null) {
93 92
             $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE active = 1 AND domain = :domain;");
94
-        }
95
-        else {
93
+        } else {
96 94
             $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1 AND domain = :domain;");
97 95
             $statement->bindValue(":forcreated", $defaultAction);
98 96
         }
@@ -195,12 +193,10 @@  discard block
 block discarded – undo
195 193
 
196 194
             if ($statement->execute()) {
197 195
                 $this->id = (int)$this->dbObject->lastInsertId();
198
-            }
199
-            else {
196
+            } else {
200 197
                 throw new Exception($statement->errorInfo());
201 198
             }
202
-        }
203
-        else {
199
+        } else {
204 200
             // update
205 201
             $statement = $this->dbObject->prepare(<<<SQL
206 202
 UPDATE `emailtemplate`
Please login to merge, or discard this patch.
includes/DataObjects/RequestData.php 2 patches
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -20,137 +20,137 @@
 block discarded – undo
20 20
  */
21 21
 class RequestData extends DataObject
22 22
 {
23
-    const TYPE_IPV4 = 'ipv4';
24
-    const TYPE_IPV6 = 'ipv6';
25
-    const TYPE_EMAIL = 'email';
26
-    const TYPE_USERAGENT = 'useragent';
27
-    const TYPE_CLIENTHINT = 'clienthint';
28
-
29
-    /** @var int */
30
-    private $request;
31
-    /** @var string */
32
-    private $type;
33
-    /** @var string|null */
34
-    private $name;
35
-    /** @var string */
36
-    private $value;
37
-
38
-    public static function getForRequest(int $requestId, PdoDatabase $database, ?string $type = null)
39
-    {
40
-        $statement = $database->prepare(<<<SQL
23
+	const TYPE_IPV4 = 'ipv4';
24
+	const TYPE_IPV6 = 'ipv6';
25
+	const TYPE_EMAIL = 'email';
26
+	const TYPE_USERAGENT = 'useragent';
27
+	const TYPE_CLIENTHINT = 'clienthint';
28
+
29
+	/** @var int */
30
+	private $request;
31
+	/** @var string */
32
+	private $type;
33
+	/** @var string|null */
34
+	private $name;
35
+	/** @var string */
36
+	private $value;
37
+
38
+	public static function getForRequest(int $requestId, PdoDatabase $database, ?string $type = null)
39
+	{
40
+		$statement = $database->prepare(<<<SQL
41 41
 SELECT * FROM requestdata
42 42
 WHERE request = :request AND type LIKE COALESCE(:type, '%');
43 43
 SQL
44
-        );
44
+		);
45 45
 
46
-        $statement->bindValue(":request", $requestId);
47
-        $statement->bindValue(":type", $type);
46
+		$statement->bindValue(":request", $requestId);
47
+		$statement->bindValue(":type", $type);
48 48
 
49
-        $statement->execute();
49
+		$statement->execute();
50 50
 
51
-        $result = array();
52
-        /** @var RequestData $v */
53
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
54
-            $v->setDatabase($database);
55
-            $result[] = $v;
56
-        }
51
+		$result = array();
52
+		/** @var RequestData $v */
53
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
54
+			$v->setDatabase($database);
55
+			$result[] = $v;
56
+		}
57 57
 
58
-        return $result;
59
-    }
58
+		return $result;
59
+	}
60 60
 
61 61
 
62
-    /**
63
-     * @throws Exception
64
-     */
65
-    public function save()
66
-    {
67
-        if ($this->isNew()) {
68
-            // insert
69
-            $statement = $this->dbObject->prepare(<<<SQL
62
+	/**
63
+	 * @throws Exception
64
+	 */
65
+	public function save()
66
+	{
67
+		if ($this->isNew()) {
68
+			// insert
69
+			$statement = $this->dbObject->prepare(<<<SQL
70 70
 INSERT INTO `requestdata` (request, type, name, value)
71 71
 VALUES (:request, :type, :name, :value);
72 72
 SQL
73
-            );
74
-
75
-            $statement->bindValue(":request", $this->request);
76
-            $statement->bindValue(":type", $this->type);
77
-            $statement->bindValue(":name", $this->name);
78
-            $statement->bindValue(":value", $this->value);
79
-
80
-            if ($statement->execute()) {
81
-                $this->id = (int)$this->dbObject->lastInsertId();
82
-            }
83
-            else {
84
-                throw new Exception($statement->errorInfo());
85
-            }
86
-        }
87
-        else {
88
-            // update
89
-            throw new ApplicationLogicException('Updates to RequestData are not supported.');
90
-        }
91
-    }
92
-
93
-    /**
94
-     * @return int
95
-     */
96
-    public function getRequest(): int
97
-    {
98
-        return $this->request;
99
-    }
100
-
101
-    /**
102
-     * @param int $request
103
-     */
104
-    public function setRequest(int $request): void
105
-    {
106
-        $this->request = $request;
107
-    }
108
-
109
-    /**
110
-     * @return string
111
-     */
112
-    public function getType(): string
113
-    {
114
-        return $this->type;
115
-    }
116
-
117
-    /**
118
-     * @param string $type
119
-     */
120
-    public function setType(string $type): void
121
-    {
122
-        $this->type = $type;
123
-    }
124
-
125
-    /**
126
-     * @return string|null
127
-     */
128
-    public function getName(): ?string
129
-    {
130
-        return $this->name;
131
-    }
132
-
133
-    /**
134
-     * @param string|null $name
135
-     */
136
-    public function setName(?string $name): void
137
-    {
138
-        $this->name = $name;
139
-    }
140
-
141
-    /**
142
-     * @return string
143
-     */
144
-    public function getValue(): string
145
-    {
146
-        return $this->value;
147
-    }
148
-
149
-    /**
150
-     * @param string $value
151
-     */
152
-    public function setValue(string $value): void
153
-    {
154
-        $this->value = $value;
155
-    }
73
+			);
74
+
75
+			$statement->bindValue(":request", $this->request);
76
+			$statement->bindValue(":type", $this->type);
77
+			$statement->bindValue(":name", $this->name);
78
+			$statement->bindValue(":value", $this->value);
79
+
80
+			if ($statement->execute()) {
81
+				$this->id = (int)$this->dbObject->lastInsertId();
82
+			}
83
+			else {
84
+				throw new Exception($statement->errorInfo());
85
+			}
86
+		}
87
+		else {
88
+			// update
89
+			throw new ApplicationLogicException('Updates to RequestData are not supported.');
90
+		}
91
+	}
92
+
93
+	/**
94
+	 * @return int
95
+	 */
96
+	public function getRequest(): int
97
+	{
98
+		return $this->request;
99
+	}
100
+
101
+	/**
102
+	 * @param int $request
103
+	 */
104
+	public function setRequest(int $request): void
105
+	{
106
+		$this->request = $request;
107
+	}
108
+
109
+	/**
110
+	 * @return string
111
+	 */
112
+	public function getType(): string
113
+	{
114
+		return $this->type;
115
+	}
116
+
117
+	/**
118
+	 * @param string $type
119
+	 */
120
+	public function setType(string $type): void
121
+	{
122
+		$this->type = $type;
123
+	}
124
+
125
+	/**
126
+	 * @return string|null
127
+	 */
128
+	public function getName(): ?string
129
+	{
130
+		return $this->name;
131
+	}
132
+
133
+	/**
134
+	 * @param string|null $name
135
+	 */
136
+	public function setName(?string $name): void
137
+	{
138
+		$this->name = $name;
139
+	}
140
+
141
+	/**
142
+	 * @return string
143
+	 */
144
+	public function getValue(): string
145
+	{
146
+		return $this->value;
147
+	}
148
+
149
+	/**
150
+	 * @param string $value
151
+	 */
152
+	public function setValue(string $value): void
153
+	{
154
+		$this->value = $value;
155
+	}
156 156
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -79,12 +79,10 @@
 block discarded – undo
79 79
 
80 80
             if ($statement->execute()) {
81 81
                 $this->id = (int)$this->dbObject->lastInsertId();
82
-            }
83
-            else {
82
+            } else {
84 83
                 throw new Exception($statement->errorInfo());
85 84
             }
86
-        }
87
-        else {
85
+        } else {
88 86
             // update
89 87
             throw new ApplicationLogicException('Updates to RequestData are not supported.');
90 88
         }
Please login to merge, or discard this patch.
includes/DataObjects/Comment.php 2 patches
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -20,228 +20,228 @@
 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
-    private $flagged = 0;
29
-    private $edited;
30
-
31
-    /**
32
-     * Retrieves all comments for a request, optionally filtered
33
-     *
34
-     * @param integer     $id             Request ID to search by
35
-     * @param PdoDatabase $database
36
-     * @param bool        $showRestricted True to show all comments, False to show only unprotected comments, and protected
37
-     *                                    comments visible to $userId
38
-     * @param bool        $showCheckuser
39
-     * @param null|int    $userId         User to filter by
40
-     *
41
-     * @return Comment[]
42
-     */
43
-    public static function getForRequest($id, PdoDatabase $database, $showRestricted = false, $showCheckuser = false, $userId = null)
44
-    {
45
-        $parameters = ['requester', 'user'];
46
-        if ($showCheckuser) {
47
-            $parameters[] = 'checkuser';
48
-        }
49
-        if ($showRestricted) {
50
-            $parameters[] = 'admin';
51
-        }
52
-
53
-        $visibilityPlaceholders = str_repeat('?,', count($parameters) - 1) . '?';
54
-
55
-        $statement = $database->prepare(<<<SQL
23
+	private $time;
24
+	private $user;
25
+	private $comment;
26
+	private $visibility = "user";
27
+	private $request;
28
+	private $flagged = 0;
29
+	private $edited;
30
+
31
+	/**
32
+	 * Retrieves all comments for a request, optionally filtered
33
+	 *
34
+	 * @param integer     $id             Request ID to search by
35
+	 * @param PdoDatabase $database
36
+	 * @param bool        $showRestricted True to show all comments, False to show only unprotected comments, and protected
37
+	 *                                    comments visible to $userId
38
+	 * @param bool        $showCheckuser
39
+	 * @param null|int    $userId         User to filter by
40
+	 *
41
+	 * @return Comment[]
42
+	 */
43
+	public static function getForRequest($id, PdoDatabase $database, $showRestricted = false, $showCheckuser = false, $userId = null)
44
+	{
45
+		$parameters = ['requester', 'user'];
46
+		if ($showCheckuser) {
47
+			$parameters[] = 'checkuser';
48
+		}
49
+		if ($showRestricted) {
50
+			$parameters[] = 'admin';
51
+		}
52
+
53
+		$visibilityPlaceholders = str_repeat('?,', count($parameters) - 1) . '?';
54
+
55
+		$statement = $database->prepare(<<<SQL
56 56
 SELECT * FROM comment
57 57
 WHERE (visibility in (${visibilityPlaceholders}) OR user = ?) AND request = ?;
58 58
 SQL
59
-        );
60
-
61
-        $parameters[] = $userId;
62
-        $parameters[] = $id;
63
-
64
-        $statement->execute($parameters);
65
-
66
-        $result = array();
67
-        /** @var Comment $v */
68
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
69
-            $v->setDatabase($database);
70
-            $result[] = $v;
71
-        }
72
-
73
-        return $result;
74
-    }
75
-
76
-    public static function getFlaggedComments(PdoDatabase $database, int $domain)
77
-    {
78
-        $statement = $database->prepare('SELECT c.* FROM comment c INNER JOIN request r ON c.request = r.id WHERE c.flagged = 1 AND r.domain = :domain;');
79
-        $statement->execute([':domain' => $domain]);
80
-
81
-        $result = array();
82
-        /** @var Comment $v */
83
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
84
-            $v->setDatabase($database);
85
-            $result[] = $v;
86
-        }
87
-
88
-        return $result;
89
-    }
90
-
91
-    /**
92
-     * @throws Exception
93
-     */
94
-    public function save()
95
-    {
96
-        if ($this->isNew()) {
97
-            // insert
98
-            $statement = $this->dbObject->prepare(<<<SQL
59
+		);
60
+
61
+		$parameters[] = $userId;
62
+		$parameters[] = $id;
63
+
64
+		$statement->execute($parameters);
65
+
66
+		$result = array();
67
+		/** @var Comment $v */
68
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
69
+			$v->setDatabase($database);
70
+			$result[] = $v;
71
+		}
72
+
73
+		return $result;
74
+	}
75
+
76
+	public static function getFlaggedComments(PdoDatabase $database, int $domain)
77
+	{
78
+		$statement = $database->prepare('SELECT c.* FROM comment c INNER JOIN request r ON c.request = r.id WHERE c.flagged = 1 AND r.domain = :domain;');
79
+		$statement->execute([':domain' => $domain]);
80
+
81
+		$result = array();
82
+		/** @var Comment $v */
83
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
84
+			$v->setDatabase($database);
85
+			$result[] = $v;
86
+		}
87
+
88
+		return $result;
89
+	}
90
+
91
+	/**
92
+	 * @throws Exception
93
+	 */
94
+	public function save()
95
+	{
96
+		if ($this->isNew()) {
97
+			// insert
98
+			$statement = $this->dbObject->prepare(<<<SQL
99 99
 INSERT INTO comment ( time, user, comment, visibility, request, flagged )
100 100
 VALUES ( CURRENT_TIMESTAMP(), :user, :comment, :visibility, :request, :flagged );
101 101
 SQL
102
-            );
103
-            $statement->bindValue(":user", $this->user);
104
-            $statement->bindValue(":comment", $this->comment);
105
-            $statement->bindValue(":visibility", $this->visibility);
106
-            $statement->bindValue(":request", $this->request);
107
-            $statement->bindValue(":flagged", $this->flagged);
108
-
109
-            if ($statement->execute()) {
110
-                $this->id = (int)$this->dbObject->lastInsertId();
111
-            }
112
-            else {
113
-                throw new Exception($statement->errorInfo());
114
-            }
115
-        }
116
-        else {
117
-            // update
118
-            $statement = $this->dbObject->prepare(<<<SQL
102
+			);
103
+			$statement->bindValue(":user", $this->user);
104
+			$statement->bindValue(":comment", $this->comment);
105
+			$statement->bindValue(":visibility", $this->visibility);
106
+			$statement->bindValue(":request", $this->request);
107
+			$statement->bindValue(":flagged", $this->flagged);
108
+
109
+			if ($statement->execute()) {
110
+				$this->id = (int)$this->dbObject->lastInsertId();
111
+			}
112
+			else {
113
+				throw new Exception($statement->errorInfo());
114
+			}
115
+		}
116
+		else {
117
+			// update
118
+			$statement = $this->dbObject->prepare(<<<SQL
119 119
 UPDATE comment
120 120
 SET comment = :comment, visibility = :visibility, flagged = :flagged, edited = :edited, updateversion = updateversion + 1
121 121
 WHERE id = :id AND updateversion = :updateversion;
122 122
 SQL
123
-            );
124
-
125
-            $statement->bindValue(':id', $this->id);
126
-            $statement->bindValue(':updateversion', $this->updateversion);
127
-
128
-            $statement->bindValue(':comment', $this->comment);
129
-            $statement->bindValue(':visibility', $this->visibility);
130
-            $statement->bindValue(":flagged", $this->flagged);
131
-            $statement->bindValue(":edited", $this->edited);
132
-
133
-            if (!$statement->execute()) {
134
-                throw new Exception($statement->errorInfo());
135
-            }
136
-
137
-            if ($statement->rowCount() !== 1) {
138
-                throw new OptimisticLockFailedException();
139
-            }
140
-
141
-            $this->updateversion++;
142
-        }
143
-    }
144
-
145
-    /**
146
-     * @return DateTimeImmutable
147
-     */
148
-    public function getTime()
149
-    {
150
-        return new DateTimeImmutable($this->time);
151
-    }
152
-
153
-    /**
154
-     * @return int
155
-     */
156
-    public function getUser()
157
-    {
158
-        return $this->user;
159
-    }
160
-
161
-    /**
162
-     * @param int $user
163
-     */
164
-    public function setUser($user)
165
-    {
166
-        $this->user = $user;
167
-    }
168
-
169
-    /**
170
-     * @return string
171
-     */
172
-    public function getComment()
173
-    {
174
-        return $this->comment;
175
-    }
176
-
177
-    /**
178
-     * @param string $comment
179
-     */
180
-    public function setComment($comment)
181
-    {
182
-        $this->comment = $comment;
183
-    }
184
-
185
-    /**
186
-     * @return string
187
-     */
188
-    public function getVisibility()
189
-    {
190
-        return $this->visibility;
191
-    }
192
-
193
-    /**
194
-     * @param string $visibility
195
-     */
196
-    public function setVisibility($visibility)
197
-    {
198
-        $this->visibility = $visibility;
199
-    }
200
-
201
-    /**
202
-     * @return int
203
-     */
204
-    public function getRequest()
205
-    {
206
-        return $this->request;
207
-    }
208
-
209
-    /**
210
-     * @param int $request
211
-     */
212
-    public function setRequest($request)
213
-    {
214
-        $this->request = $request;
215
-    }
216
-
217
-    /**
218
-     * @return bool
219
-     */
220
-    public function getFlagged() : bool
221
-    {
222
-        return $this->flagged == 1;
223
-    }
224
-
225
-    /**
226
-     * @param bool $flagged
227
-     */
228
-    public function setFlagged(bool $flagged): void
229
-    {
230
-        $this->flagged = $flagged ? 1 : 0;
231
-    }
232
-
233
-    public function touchEdited() : void
234
-    {
235
-        $dateTimeImmutable = new DateTimeImmutable("now");
236
-        $this->edited = $dateTimeImmutable->format('Y-m-d H:i:s');
237
-    }
238
-
239
-    public function getEdited() : ?DateTimeImmutable
240
-    {
241
-        if ($this->edited === null) {
242
-            return null;
243
-        }
244
-
245
-        return new DateTimeImmutable($this->edited);
246
-    }
123
+			);
124
+
125
+			$statement->bindValue(':id', $this->id);
126
+			$statement->bindValue(':updateversion', $this->updateversion);
127
+
128
+			$statement->bindValue(':comment', $this->comment);
129
+			$statement->bindValue(':visibility', $this->visibility);
130
+			$statement->bindValue(":flagged", $this->flagged);
131
+			$statement->bindValue(":edited", $this->edited);
132
+
133
+			if (!$statement->execute()) {
134
+				throw new Exception($statement->errorInfo());
135
+			}
136
+
137
+			if ($statement->rowCount() !== 1) {
138
+				throw new OptimisticLockFailedException();
139
+			}
140
+
141
+			$this->updateversion++;
142
+		}
143
+	}
144
+
145
+	/**
146
+	 * @return DateTimeImmutable
147
+	 */
148
+	public function getTime()
149
+	{
150
+		return new DateTimeImmutable($this->time);
151
+	}
152
+
153
+	/**
154
+	 * @return int
155
+	 */
156
+	public function getUser()
157
+	{
158
+		return $this->user;
159
+	}
160
+
161
+	/**
162
+	 * @param int $user
163
+	 */
164
+	public function setUser($user)
165
+	{
166
+		$this->user = $user;
167
+	}
168
+
169
+	/**
170
+	 * @return string
171
+	 */
172
+	public function getComment()
173
+	{
174
+		return $this->comment;
175
+	}
176
+
177
+	/**
178
+	 * @param string $comment
179
+	 */
180
+	public function setComment($comment)
181
+	{
182
+		$this->comment = $comment;
183
+	}
184
+
185
+	/**
186
+	 * @return string
187
+	 */
188
+	public function getVisibility()
189
+	{
190
+		return $this->visibility;
191
+	}
192
+
193
+	/**
194
+	 * @param string $visibility
195
+	 */
196
+	public function setVisibility($visibility)
197
+	{
198
+		$this->visibility = $visibility;
199
+	}
200
+
201
+	/**
202
+	 * @return int
203
+	 */
204
+	public function getRequest()
205
+	{
206
+		return $this->request;
207
+	}
208
+
209
+	/**
210
+	 * @param int $request
211
+	 */
212
+	public function setRequest($request)
213
+	{
214
+		$this->request = $request;
215
+	}
216
+
217
+	/**
218
+	 * @return bool
219
+	 */
220
+	public function getFlagged() : bool
221
+	{
222
+		return $this->flagged == 1;
223
+	}
224
+
225
+	/**
226
+	 * @param bool $flagged
227
+	 */
228
+	public function setFlagged(bool $flagged): void
229
+	{
230
+		$this->flagged = $flagged ? 1 : 0;
231
+	}
232
+
233
+	public function touchEdited() : void
234
+	{
235
+		$dateTimeImmutable = new DateTimeImmutable("now");
236
+		$this->edited = $dateTimeImmutable->format('Y-m-d H:i:s');
237
+	}
238
+
239
+	public function getEdited() : ?DateTimeImmutable
240
+	{
241
+		if ($this->edited === null) {
242
+			return null;
243
+		}
244
+
245
+		return new DateTimeImmutable($this->edited);
246
+	}
247 247
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -108,12 +108,10 @@
 block discarded – undo
108 108
 
109 109
             if ($statement->execute()) {
110 110
                 $this->id = (int)$this->dbObject->lastInsertId();
111
-            }
112
-            else {
111
+            } else {
113 112
                 throw new Exception($statement->errorInfo());
114 113
             }
115
-        }
116
-        else {
114
+        } else {
117 115
             // update
118 116
             $statement = $this->dbObject->prepare(<<<SQL
119 117
 UPDATE comment
Please login to merge, or discard this patch.
includes/DataObjects/UserPreference.php 3 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -16,165 +16,165 @@
 block discarded – undo
16 16
 class UserPreference extends DataObject
17 17
 {
18 18
 
19
-    /** @var int */
20
-    private $user;
21
-
22
-    /** @var ?int */
23
-    private $domain;
24
-
25
-    /** @var string */
26
-    private $preference;
27
-
28
-    /** @var ?mixed */
29
-    private $value;
30
-
31
-    public static function getLocalPreference(PdoDatabase $database, int $user, string $preference, int $domain) {
32
-        $statement = $database->prepare('SELECT * FROM userpreference WHERE preference = :preference AND USER = :user AND domain = :domain');
33
-        $statement->execute([
34
-            ':user' => $user,
35
-            ':preference' => $preference,
36
-            ':domain' => $domain
37
-        ]);
38
-
39
-        $resultObject = $statement->fetchObject(get_called_class());
40
-
41
-        if ($resultObject !== false) {
42
-            $resultObject->setDatabase($database);
43
-        }
44
-
45
-        return $resultObject;
46
-    }
47
-
48
-    public static function getGlobalPreference(PdoDatabase $database, int $user, string $preference) {
49
-        $statement = $database->prepare('SELECT * FROM userpreference WHERE preference = :preference AND USER = :user AND domain IS NULL');
50
-        $statement->execute([
51
-            ':user' => $user,
52
-            ':preference' => $preference
53
-        ]);
54
-
55
-        $resultObject = $statement->fetchObject(get_called_class());
56
-
57
-        if ($resultObject !== false) {
58
-            $resultObject->setDatabase($database);
59
-        }
60
-
61
-        return $resultObject;
62
-    }
63
-
64
-    /**
65
-     * @inheritDoc
66
-     * @throws Exception
67
-     */
68
-    public function save()
69
-    {
70
-        if($this->isNew()) {
71
-            // insert
72
-            $statement = $this->dbObject->prepare(<<<SQL
19
+	/** @var int */
20
+	private $user;
21
+
22
+	/** @var ?int */
23
+	private $domain;
24
+
25
+	/** @var string */
26
+	private $preference;
27
+
28
+	/** @var ?mixed */
29
+	private $value;
30
+
31
+	public static function getLocalPreference(PdoDatabase $database, int $user, string $preference, int $domain) {
32
+		$statement = $database->prepare('SELECT * FROM userpreference WHERE preference = :preference AND USER = :user AND domain = :domain');
33
+		$statement->execute([
34
+			':user' => $user,
35
+			':preference' => $preference,
36
+			':domain' => $domain
37
+		]);
38
+
39
+		$resultObject = $statement->fetchObject(get_called_class());
40
+
41
+		if ($resultObject !== false) {
42
+			$resultObject->setDatabase($database);
43
+		}
44
+
45
+		return $resultObject;
46
+	}
47
+
48
+	public static function getGlobalPreference(PdoDatabase $database, int $user, string $preference) {
49
+		$statement = $database->prepare('SELECT * FROM userpreference WHERE preference = :preference AND USER = :user AND domain IS NULL');
50
+		$statement->execute([
51
+			':user' => $user,
52
+			':preference' => $preference
53
+		]);
54
+
55
+		$resultObject = $statement->fetchObject(get_called_class());
56
+
57
+		if ($resultObject !== false) {
58
+			$resultObject->setDatabase($database);
59
+		}
60
+
61
+		return $resultObject;
62
+	}
63
+
64
+	/**
65
+	 * @inheritDoc
66
+	 * @throws Exception
67
+	 */
68
+	public function save()
69
+	{
70
+		if($this->isNew()) {
71
+			// insert
72
+			$statement = $this->dbObject->prepare(<<<SQL
73 73
                 INSERT INTO `userpreference` (
74 74
                     user, domain, preference, value
75 75
                 ) VALUES (
76 76
                     :user, :domain, :preference, :value
77 77
                 );
78 78
 SQL
79
-            );
80
-            $statement->bindValue(":user", $this->user);
81
-            $statement->bindValue(":domain", $this->domain);
82
-            $statement->bindValue(":preference", $this->preference);
83
-            $statement->bindValue(":value", $this->value);
84
-
85
-            if ($statement->execute()) {
86
-                $this->id = (int)$this->dbObject->lastInsertId();
87
-            }
88
-            else {
89
-                throw new Exception($statement->errorInfo());
90
-            }
91
-        }else{
92
-            // update
93
-            $statement = $this->dbObject->prepare(<<<SQL
79
+			);
80
+			$statement->bindValue(":user", $this->user);
81
+			$statement->bindValue(":domain", $this->domain);
82
+			$statement->bindValue(":preference", $this->preference);
83
+			$statement->bindValue(":value", $this->value);
84
+
85
+			if ($statement->execute()) {
86
+				$this->id = (int)$this->dbObject->lastInsertId();
87
+			}
88
+			else {
89
+				throw new Exception($statement->errorInfo());
90
+			}
91
+		}else{
92
+			// update
93
+			$statement = $this->dbObject->prepare(<<<SQL
94 94
                 UPDATE `userpreference` SET 
95 95
                     value = :value,
96 96
                     updateversion = updateversion + 1
97 97
                 WHERE id = :id AND updateversion = :updateversion;
98 98
 SQL
99
-            );
100
-            $statement->bindValue(":value", $this->value);
101
-
102
-            $statement->bindValue(':id', $this->id);
103
-            $statement->bindValue(':updateversion', $this->updateversion);
104
-
105
-            if (!$statement->execute()) {
106
-                throw new Exception($statement->errorInfo());
107
-            }
108
-
109
-            if ($statement->rowCount() !== 1) {
110
-                throw new OptimisticLockFailedException();
111
-            }
112
-
113
-            $this->updateversion++;
114
-        }
115
-    }
116
-
117
-    /**
118
-     * @return int
119
-     */
120
-    public function getUser(): int
121
-    {
122
-        return $this->user;
123
-    }
124
-
125
-    /**
126
-     * @param int $user
127
-     */
128
-    public function setUser(int $user): void
129
-    {
130
-        $this->user = $user;
131
-    }
132
-
133
-    /**
134
-     * @return ?int
135
-     */
136
-    public function getDomain(): ?int
137
-    {
138
-        return $this->domain;
139
-    }
140
-
141
-    /**
142
-     * @param ?int $domain
143
-     */
144
-    public function setDomain(?int $domain): void
145
-    {
146
-        $this->domain = $domain;
147
-    }
148
-
149
-    /**
150
-     * @return string
151
-     */
152
-    public function getPreference(): string
153
-    {
154
-        return $this->preference;
155
-    }
156
-
157
-    /**
158
-     * @param string $preference
159
-     */
160
-    public function setPreference(string $preference): void
161
-    {
162
-        $this->preference = $preference;
163
-    }
164
-
165
-    /**
166
-     * @return mixed|null
167
-     */
168
-    public function getValue()
169
-    {
170
-        return $this->value;
171
-    }
172
-
173
-    /**
174
-     * @param mixed|null $value
175
-     */
176
-    public function setValue($value): void
177
-    {
178
-        $this->value = $value;
179
-    }
99
+			);
100
+			$statement->bindValue(":value", $this->value);
101
+
102
+			$statement->bindValue(':id', $this->id);
103
+			$statement->bindValue(':updateversion', $this->updateversion);
104
+
105
+			if (!$statement->execute()) {
106
+				throw new Exception($statement->errorInfo());
107
+			}
108
+
109
+			if ($statement->rowCount() !== 1) {
110
+				throw new OptimisticLockFailedException();
111
+			}
112
+
113
+			$this->updateversion++;
114
+		}
115
+	}
116
+
117
+	/**
118
+	 * @return int
119
+	 */
120
+	public function getUser(): int
121
+	{
122
+		return $this->user;
123
+	}
124
+
125
+	/**
126
+	 * @param int $user
127
+	 */
128
+	public function setUser(int $user): void
129
+	{
130
+		$this->user = $user;
131
+	}
132
+
133
+	/**
134
+	 * @return ?int
135
+	 */
136
+	public function getDomain(): ?int
137
+	{
138
+		return $this->domain;
139
+	}
140
+
141
+	/**
142
+	 * @param ?int $domain
143
+	 */
144
+	public function setDomain(?int $domain): void
145
+	{
146
+		$this->domain = $domain;
147
+	}
148
+
149
+	/**
150
+	 * @return string
151
+	 */
152
+	public function getPreference(): string
153
+	{
154
+		return $this->preference;
155
+	}
156
+
157
+	/**
158
+	 * @param string $preference
159
+	 */
160
+	public function setPreference(string $preference): void
161
+	{
162
+		$this->preference = $preference;
163
+	}
164
+
165
+	/**
166
+	 * @return mixed|null
167
+	 */
168
+	public function getValue()
169
+	{
170
+		return $this->value;
171
+	}
172
+
173
+	/**
174
+	 * @param mixed|null $value
175
+	 */
176
+	public function setValue($value): void
177
+	{
178
+		$this->value = $value;
179
+	}
180 180
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      */
68 68
     public function save()
69 69
     {
70
-        if($this->isNew()) {
70
+        if ($this->isNew()) {
71 71
             // insert
72 72
             $statement = $this->dbObject->prepare(<<<SQL
73 73
                 INSERT INTO `userpreference` (
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
             else {
89 89
                 throw new Exception($statement->errorInfo());
90 90
             }
91
-        }else{
91
+        } else {
92 92
             // update
93 93
             $statement = $this->dbObject->prepare(<<<SQL
94 94
                 UPDATE `userpreference` SET 
Please login to merge, or discard this patch.
Braces   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,7 +28,8 @@  discard block
 block discarded – undo
28 28
     /** @var ?mixed */
29 29
     private $value;
30 30
 
31
-    public static function getLocalPreference(PdoDatabase $database, int $user, string $preference, int $domain) {
31
+    public static function getLocalPreference(PdoDatabase $database, int $user, string $preference, int $domain)
32
+    {
32 33
         $statement = $database->prepare('SELECT * FROM userpreference WHERE preference = :preference AND USER = :user AND domain = :domain');
33 34
         $statement->execute([
34 35
             ':user' => $user,
@@ -45,7 +46,8 @@  discard block
 block discarded – undo
45 46
         return $resultObject;
46 47
     }
47 48
 
48
-    public static function getGlobalPreference(PdoDatabase $database, int $user, string $preference) {
49
+    public static function getGlobalPreference(PdoDatabase $database, int $user, string $preference)
50
+    {
49 51
         $statement = $database->prepare('SELECT * FROM userpreference WHERE preference = :preference AND USER = :user AND domain IS NULL');
50 52
         $statement->execute([
51 53
             ':user' => $user,
@@ -84,11 +86,10 @@  discard block
 block discarded – undo
84 86
 
85 87
             if ($statement->execute()) {
86 88
                 $this->id = (int)$this->dbObject->lastInsertId();
87
-            }
88
-            else {
89
+            } else {
89 90
                 throw new Exception($statement->errorInfo());
90 91
             }
91
-        }else{
92
+        } else {
92 93
             // update
93 94
             $statement = $this->dbObject->prepare(<<<SQL
94 95
                 UPDATE `userpreference` SET 
Please login to merge, or discard this patch.