@@ -10,96 +10,96 @@ |
||
10 | 10 | |
11 | 11 | class AuthUtility |
12 | 12 | { |
13 | - /** |
|
14 | - * Test the specified data against the specified credentials |
|
15 | - * |
|
16 | - * @param string $password |
|
17 | - * @param string $credentials |
|
18 | - * |
|
19 | - * @return bool |
|
20 | - */ |
|
21 | - public static function testCredentials($password, $credentials) |
|
22 | - { |
|
23 | - global $minimumPasswordVersion; |
|
13 | + /** |
|
14 | + * Test the specified data against the specified credentials |
|
15 | + * |
|
16 | + * @param string $password |
|
17 | + * @param string $credentials |
|
18 | + * |
|
19 | + * @return bool |
|
20 | + */ |
|
21 | + public static function testCredentials($password, $credentials) |
|
22 | + { |
|
23 | + global $minimumPasswordVersion; |
|
24 | 24 | |
25 | - if (substr($credentials, 0, 1) != ":") { |
|
26 | - return false; |
|
27 | - } |
|
25 | + if (substr($credentials, 0, 1) != ":") { |
|
26 | + return false; |
|
27 | + } |
|
28 | 28 | |
29 | - // determine password version |
|
30 | - $data = explode(':', substr($credentials, 1)); |
|
29 | + // determine password version |
|
30 | + $data = explode(':', substr($credentials, 1)); |
|
31 | 31 | |
32 | - // call the encryptVersion function for the version that this password actually is. |
|
33 | - // syntax: :1:SALT:HASH |
|
34 | - // syntax: :2:x:HASH |
|
32 | + // call the encryptVersion function for the version that this password actually is. |
|
33 | + // syntax: :1:SALT:HASH |
|
34 | + // syntax: :2:x:HASH |
|
35 | 35 | |
36 | - // check the version is one of the allowed ones: |
|
37 | - if ($minimumPasswordVersion > $data[0]) { |
|
38 | - return false; |
|
39 | - } |
|
36 | + // check the version is one of the allowed ones: |
|
37 | + if ($minimumPasswordVersion > $data[0]) { |
|
38 | + return false; |
|
39 | + } |
|
40 | 40 | |
41 | - if ($data[0] == 1) { |
|
42 | - return $credentials == self::encryptVersion1($password, $data[1]); |
|
43 | - } |
|
41 | + if ($data[0] == 1) { |
|
42 | + return $credentials == self::encryptVersion1($password, $data[1]); |
|
43 | + } |
|
44 | 44 | |
45 | - if ($data[0] == 2) { |
|
46 | - return self::verifyVersion2($password, $data[2]); |
|
47 | - } |
|
45 | + if ($data[0] == 2) { |
|
46 | + return self::verifyVersion2($password, $data[2]); |
|
47 | + } |
|
48 | 48 | |
49 | - return false; |
|
50 | - } |
|
49 | + return false; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param string $credentials |
|
54 | - * |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public static function isCredentialVersionLatest($credentials) |
|
58 | - { |
|
59 | - return substr($credentials, 0, 3) === ":2:"; |
|
60 | - } |
|
52 | + /** |
|
53 | + * @param string $credentials |
|
54 | + * |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public static function isCredentialVersionLatest($credentials) |
|
58 | + { |
|
59 | + return substr($credentials, 0, 3) === ":2:"; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Encrypts a user's password with the latest version of the hash algorithm |
|
64 | - * |
|
65 | - * @param string $password |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public static function encryptPassword($password) |
|
70 | - { |
|
71 | - return self::encryptVersion2($password); |
|
72 | - } |
|
62 | + /** |
|
63 | + * Encrypts a user's password with the latest version of the hash algorithm |
|
64 | + * |
|
65 | + * @param string $password |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public static function encryptPassword($password) |
|
70 | + { |
|
71 | + return self::encryptVersion2($password); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $password |
|
76 | - * @param string $salt |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - private static function encryptVersion1($password, $salt) |
|
81 | - { |
|
82 | - return ':1:' . $salt . ':' . md5($salt . '-' . md5($password)); |
|
83 | - } |
|
74 | + /** |
|
75 | + * @param string $password |
|
76 | + * @param string $salt |
|
77 | + * |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + private static function encryptVersion1($password, $salt) |
|
81 | + { |
|
82 | + return ':1:' . $salt . ':' . md5($salt . '-' . md5($password)); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param string $password |
|
87 | - * |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - private static function encryptVersion2($password) |
|
91 | - { |
|
92 | - return ':2:x:' . password_hash($password, PASSWORD_BCRYPT); |
|
93 | - } |
|
85 | + /** |
|
86 | + * @param string $password |
|
87 | + * |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + private static function encryptVersion2($password) |
|
91 | + { |
|
92 | + return ':2:x:' . password_hash($password, PASSWORD_BCRYPT); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @param string $password |
|
97 | - * @param string $hash |
|
98 | - * |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - private static function verifyVersion2($password, $hash) |
|
102 | - { |
|
103 | - return password_verify($password, $hash); |
|
104 | - } |
|
95 | + /** |
|
96 | + * @param string $password |
|
97 | + * @param string $hash |
|
98 | + * |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + private static function verifyVersion2($password, $hash) |
|
102 | + { |
|
103 | + return password_verify($password, $hash); |
|
104 | + } |
|
105 | 105 | } |
@@ -10,8 +10,8 @@ |
||
10 | 10 | |
11 | 11 | class RegexConstants |
12 | 12 | { |
13 | - const IPV6_CIDR = '(?:/(?:12[0-8]|1[01][0-9]|[0-9]{1,2}))?'; |
|
14 | - const IPV4_CIDR = '(?:/(?:32|3[01]|[0-2]?[0-9]))?'; |
|
15 | - const IPV4 = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'; |
|
16 | - const IPV6 = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'; |
|
13 | + const IPV6_CIDR = '(?:/(?:12[0-8]|1[01][0-9]|[0-9]{1,2}))?'; |
|
14 | + const IPV4_CIDR = '(?:/(?:32|3[01]|[0-2]?[0-9]))?'; |
|
15 | + const IPV4 = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'; |
|
16 | + const IPV6 = '(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'; |
|
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -23,124 +23,124 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class DataObject |
25 | 25 | { |
26 | - /** @var int ID of the object */ |
|
27 | - protected $id = null; |
|
28 | - /** @var int update version for optimistic locking */ |
|
29 | - protected $updateversion = 0; |
|
30 | - /** |
|
31 | - * @var PdoDatabase |
|
32 | - */ |
|
33 | - protected $dbObject; |
|
34 | - |
|
35 | - /** |
|
36 | - * Retrieves a data object by it's row ID. |
|
37 | - * |
|
38 | - * @param int $id |
|
39 | - * @param PdoDatabase $database |
|
40 | - * |
|
41 | - * @return DataObject|false |
|
42 | - */ |
|
43 | - public static function getById($id, PdoDatabase $database) |
|
44 | - { |
|
45 | - $array = explode('\\', get_called_class()); |
|
46 | - $realClassName = strtolower(end($array)); |
|
47 | - |
|
48 | - $statement = $database->prepare("SELECT * FROM {$realClassName} WHERE id = :id LIMIT 1;"); |
|
49 | - $statement->bindValue(":id", $id); |
|
50 | - |
|
51 | - $statement->execute(); |
|
52 | - |
|
53 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
54 | - |
|
55 | - if ($resultObject != false) { |
|
56 | - $resultObject->setDatabase($database); |
|
57 | - } |
|
58 | - |
|
59 | - return $resultObject; |
|
60 | - } |
|
61 | - |
|
62 | - public function setDatabase(PdoDatabase $db) |
|
63 | - { |
|
64 | - $this->dbObject = $db; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Gets the database associated with this data object. |
|
69 | - * @return PdoDatabase |
|
70 | - */ |
|
71 | - public function getDatabase() |
|
72 | - { |
|
73 | - return $this->dbObject; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Saves a data object to the database, either updating or inserting a record. |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - abstract public function save(); |
|
82 | - |
|
83 | - /** |
|
84 | - * Retrieves the ID attribute |
|
85 | - */ |
|
86 | - public function getId() |
|
87 | - { |
|
88 | - return (int)$this->id; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Deletes the object from the database |
|
93 | - */ |
|
94 | - public function delete() |
|
95 | - { |
|
96 | - if ($this->id === null) { |
|
97 | - // wtf? |
|
98 | - return; |
|
99 | - } |
|
100 | - |
|
101 | - $array = explode('\\', get_called_class()); |
|
102 | - $realClassName = strtolower(end($array)); |
|
103 | - |
|
104 | - $deleteQuery = "DELETE FROM {$realClassName} WHERE id = :id AND updateversion = :updateversion LIMIT 1;"; |
|
105 | - $statement = $this->dbObject->prepare($deleteQuery); |
|
106 | - |
|
107 | - $statement->bindValue(":id", $this->id); |
|
108 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
109 | - $statement->execute(); |
|
110 | - |
|
111 | - if ($statement->rowCount() !== 1) { |
|
112 | - throw new OptimisticLockFailedException(); |
|
113 | - } |
|
114 | - |
|
115 | - $this->id = null; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function getUpdateVersion() |
|
122 | - { |
|
123 | - return $this->updateversion; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Sets the update version. |
|
128 | - * |
|
129 | - * You should never call this to change the value of the update version. You should only call it when passing user |
|
130 | - * input through. |
|
131 | - * |
|
132 | - * @param int $updateVersion |
|
133 | - */ |
|
134 | - public function setUpdateVersion($updateVersion) |
|
135 | - { |
|
136 | - $this->updateversion = $updateVersion; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return bool |
|
141 | - */ |
|
142 | - public function isNew() |
|
143 | - { |
|
144 | - return $this->id === null; |
|
145 | - } |
|
26 | + /** @var int ID of the object */ |
|
27 | + protected $id = null; |
|
28 | + /** @var int update version for optimistic locking */ |
|
29 | + protected $updateversion = 0; |
|
30 | + /** |
|
31 | + * @var PdoDatabase |
|
32 | + */ |
|
33 | + protected $dbObject; |
|
34 | + |
|
35 | + /** |
|
36 | + * Retrieves a data object by it's row ID. |
|
37 | + * |
|
38 | + * @param int $id |
|
39 | + * @param PdoDatabase $database |
|
40 | + * |
|
41 | + * @return DataObject|false |
|
42 | + */ |
|
43 | + public static function getById($id, PdoDatabase $database) |
|
44 | + { |
|
45 | + $array = explode('\\', get_called_class()); |
|
46 | + $realClassName = strtolower(end($array)); |
|
47 | + |
|
48 | + $statement = $database->prepare("SELECT * FROM {$realClassName} WHERE id = :id LIMIT 1;"); |
|
49 | + $statement->bindValue(":id", $id); |
|
50 | + |
|
51 | + $statement->execute(); |
|
52 | + |
|
53 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
54 | + |
|
55 | + if ($resultObject != false) { |
|
56 | + $resultObject->setDatabase($database); |
|
57 | + } |
|
58 | + |
|
59 | + return $resultObject; |
|
60 | + } |
|
61 | + |
|
62 | + public function setDatabase(PdoDatabase $db) |
|
63 | + { |
|
64 | + $this->dbObject = $db; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Gets the database associated with this data object. |
|
69 | + * @return PdoDatabase |
|
70 | + */ |
|
71 | + public function getDatabase() |
|
72 | + { |
|
73 | + return $this->dbObject; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Saves a data object to the database, either updating or inserting a record. |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + abstract public function save(); |
|
82 | + |
|
83 | + /** |
|
84 | + * Retrieves the ID attribute |
|
85 | + */ |
|
86 | + public function getId() |
|
87 | + { |
|
88 | + return (int)$this->id; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Deletes the object from the database |
|
93 | + */ |
|
94 | + public function delete() |
|
95 | + { |
|
96 | + if ($this->id === null) { |
|
97 | + // wtf? |
|
98 | + return; |
|
99 | + } |
|
100 | + |
|
101 | + $array = explode('\\', get_called_class()); |
|
102 | + $realClassName = strtolower(end($array)); |
|
103 | + |
|
104 | + $deleteQuery = "DELETE FROM {$realClassName} WHERE id = :id AND updateversion = :updateversion LIMIT 1;"; |
|
105 | + $statement = $this->dbObject->prepare($deleteQuery); |
|
106 | + |
|
107 | + $statement->bindValue(":id", $this->id); |
|
108 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
109 | + $statement->execute(); |
|
110 | + |
|
111 | + if ($statement->rowCount() !== 1) { |
|
112 | + throw new OptimisticLockFailedException(); |
|
113 | + } |
|
114 | + |
|
115 | + $this->id = null; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function getUpdateVersion() |
|
122 | + { |
|
123 | + return $this->updateversion; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Sets the update version. |
|
128 | + * |
|
129 | + * You should never call this to change the value of the update version. You should only call it when passing user |
|
130 | + * input through. |
|
131 | + * |
|
132 | + * @param int $updateVersion |
|
133 | + */ |
|
134 | + public function setUpdateVersion($updateVersion) |
|
135 | + { |
|
136 | + $this->updateversion = $updateVersion; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return bool |
|
141 | + */ |
|
142 | + public function isNew() |
|
143 | + { |
|
144 | + return $this->id === null; |
|
145 | + } |
|
146 | 146 | } |
@@ -21,22 +21,22 @@ |
||
21 | 21 | */ |
22 | 22 | abstract class ReadableException extends Exception |
23 | 23 | { |
24 | - use TemplateOutput; |
|
24 | + use TemplateOutput; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Returns a readable HTML error message that's displayable to the user using templates. |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - abstract public function getReadableError(); |
|
26 | + /** |
|
27 | + * Returns a readable HTML error message that's displayable to the user using templates. |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + abstract public function getReadableError(); |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return SiteConfiguration |
|
34 | - */ |
|
35 | - protected function getSiteConfiguration() |
|
36 | - { |
|
37 | - // Uck. However, we have encountered an exception. |
|
38 | - global $siteConfiguration; |
|
32 | + /** |
|
33 | + * @return SiteConfiguration |
|
34 | + */ |
|
35 | + protected function getSiteConfiguration() |
|
36 | + { |
|
37 | + // Uck. However, we have encountered an exception. |
|
38 | + global $siteConfiguration; |
|
39 | 39 | |
40 | - return $siteConfiguration; |
|
41 | - } |
|
40 | + return $siteConfiguration; |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -21,13 +21,13 @@ |
||
21 | 21 | */ |
22 | 22 | class EnvironmentException extends Exception |
23 | 23 | { |
24 | - /** |
|
25 | - * EnvironmentException constructor. |
|
26 | - * |
|
27 | - * @param string $friendlyMessage |
|
28 | - */ |
|
29 | - public function __construct($friendlyMessage) |
|
30 | - { |
|
31 | - parent::__construct($friendlyMessage); |
|
32 | - } |
|
24 | + /** |
|
25 | + * EnvironmentException constructor. |
|
26 | + * |
|
27 | + * @param string $friendlyMessage |
|
28 | + */ |
|
29 | + public function __construct($friendlyMessage) |
|
30 | + { |
|
31 | + parent::__construct($friendlyMessage); |
|
32 | + } |
|
33 | 33 | } |
34 | 34 | \ No newline at end of file |
@@ -26,89 +26,89 @@ |
||
26 | 26 | */ |
27 | 27 | class AccessDeniedException extends ReadableException |
28 | 28 | { |
29 | - use NavigationMenuAccessControl; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var SecurityManager |
|
33 | - */ |
|
34 | - private $securityManager; |
|
35 | - |
|
36 | - /** |
|
37 | - * AccessDeniedException constructor. |
|
38 | - * |
|
39 | - * @param SecurityManager $securityManager |
|
40 | - */ |
|
41 | - public function __construct(SecurityManager $securityManager = null) |
|
42 | - { |
|
43 | - $this->securityManager = $securityManager; |
|
44 | - } |
|
45 | - |
|
46 | - public function getReadableError() |
|
47 | - { |
|
48 | - if (!headers_sent()) { |
|
49 | - header("HTTP/1.1 403 Forbidden"); |
|
50 | - } |
|
51 | - |
|
52 | - $this->setUpSmarty(); |
|
53 | - |
|
54 | - // uck. We should still be able to access the database in this situation though. |
|
55 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
56 | - $currentUser = User::getCurrent($database); |
|
57 | - $this->assign('currentUser', $currentUser); |
|
58 | - $this->assign("loggedIn", (!$currentUser->isCommunityUser())); |
|
59 | - |
|
60 | - if($this->securityManager !== null) { |
|
61 | - $this->setupNavMenuAccess($currentUser); |
|
62 | - } |
|
63 | - |
|
64 | - if ($currentUser->isDeclined()) { |
|
65 | - $this->assign('htmlTitle', 'Account Declined'); |
|
66 | - $this->assign('declineReason', $this->getLogEntry('Declined', $currentUser, $database)); |
|
67 | - |
|
68 | - return $this->fetchTemplate("exception/account-declined.tpl"); |
|
69 | - } |
|
70 | - |
|
71 | - if ($currentUser->isSuspended()) { |
|
72 | - $this->assign('htmlTitle', 'Account Suspended'); |
|
73 | - $this->assign('suspendReason', $this->getLogEntry('Suspended', $currentUser, $database)); |
|
74 | - |
|
75 | - return $this->fetchTemplate("exception/account-suspended.tpl"); |
|
76 | - } |
|
77 | - |
|
78 | - if ($currentUser->isNewUser()) { |
|
79 | - $this->assign('htmlTitle', 'Account Pending'); |
|
80 | - |
|
81 | - return $this->fetchTemplate("exception/account-new.tpl"); |
|
82 | - } |
|
83 | - |
|
84 | - return $this->fetchTemplate("exception/access-denied.tpl"); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param string $action |
|
89 | - * @param User $user |
|
90 | - * @param PdoDatabase $database |
|
91 | - * |
|
92 | - * @return null|string |
|
93 | - */ |
|
94 | - private function getLogEntry($action, User $user, PdoDatabase $database) |
|
95 | - { |
|
96 | - /** @var Log[] $logs */ |
|
97 | - $logs = LogSearchHelper::get($database) |
|
98 | - ->byAction($action) |
|
99 | - ->byObjectType('User') |
|
100 | - ->byObjectId($user->getId()) |
|
101 | - ->limit(1) |
|
102 | - ->fetch(); |
|
103 | - |
|
104 | - return $logs[0]->getComment(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return SecurityManager |
|
109 | - */ |
|
110 | - protected function getSecurityManager() |
|
111 | - { |
|
112 | - return $this->securityManager; |
|
113 | - } |
|
29 | + use NavigationMenuAccessControl; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var SecurityManager |
|
33 | + */ |
|
34 | + private $securityManager; |
|
35 | + |
|
36 | + /** |
|
37 | + * AccessDeniedException constructor. |
|
38 | + * |
|
39 | + * @param SecurityManager $securityManager |
|
40 | + */ |
|
41 | + public function __construct(SecurityManager $securityManager = null) |
|
42 | + { |
|
43 | + $this->securityManager = $securityManager; |
|
44 | + } |
|
45 | + |
|
46 | + public function getReadableError() |
|
47 | + { |
|
48 | + if (!headers_sent()) { |
|
49 | + header("HTTP/1.1 403 Forbidden"); |
|
50 | + } |
|
51 | + |
|
52 | + $this->setUpSmarty(); |
|
53 | + |
|
54 | + // uck. We should still be able to access the database in this situation though. |
|
55 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
56 | + $currentUser = User::getCurrent($database); |
|
57 | + $this->assign('currentUser', $currentUser); |
|
58 | + $this->assign("loggedIn", (!$currentUser->isCommunityUser())); |
|
59 | + |
|
60 | + if($this->securityManager !== null) { |
|
61 | + $this->setupNavMenuAccess($currentUser); |
|
62 | + } |
|
63 | + |
|
64 | + if ($currentUser->isDeclined()) { |
|
65 | + $this->assign('htmlTitle', 'Account Declined'); |
|
66 | + $this->assign('declineReason', $this->getLogEntry('Declined', $currentUser, $database)); |
|
67 | + |
|
68 | + return $this->fetchTemplate("exception/account-declined.tpl"); |
|
69 | + } |
|
70 | + |
|
71 | + if ($currentUser->isSuspended()) { |
|
72 | + $this->assign('htmlTitle', 'Account Suspended'); |
|
73 | + $this->assign('suspendReason', $this->getLogEntry('Suspended', $currentUser, $database)); |
|
74 | + |
|
75 | + return $this->fetchTemplate("exception/account-suspended.tpl"); |
|
76 | + } |
|
77 | + |
|
78 | + if ($currentUser->isNewUser()) { |
|
79 | + $this->assign('htmlTitle', 'Account Pending'); |
|
80 | + |
|
81 | + return $this->fetchTemplate("exception/account-new.tpl"); |
|
82 | + } |
|
83 | + |
|
84 | + return $this->fetchTemplate("exception/access-denied.tpl"); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param string $action |
|
89 | + * @param User $user |
|
90 | + * @param PdoDatabase $database |
|
91 | + * |
|
92 | + * @return null|string |
|
93 | + */ |
|
94 | + private function getLogEntry($action, User $user, PdoDatabase $database) |
|
95 | + { |
|
96 | + /** @var Log[] $logs */ |
|
97 | + $logs = LogSearchHelper::get($database) |
|
98 | + ->byAction($action) |
|
99 | + ->byObjectType('User') |
|
100 | + ->byObjectId($user->getId()) |
|
101 | + ->limit(1) |
|
102 | + ->fetch(); |
|
103 | + |
|
104 | + return $logs[0]->getComment(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return SecurityManager |
|
109 | + */ |
|
110 | + protected function getSecurityManager() |
|
111 | + { |
|
112 | + return $this->securityManager; |
|
113 | + } |
|
114 | 114 | } |
115 | 115 | \ No newline at end of file |
@@ -57,7 +57,7 @@ |
||
57 | 57 | $this->assign('currentUser', $currentUser); |
58 | 58 | $this->assign("loggedIn", (!$currentUser->isCommunityUser())); |
59 | 59 | |
60 | - if($this->securityManager !== null) { |
|
60 | + if ($this->securityManager !== null) { |
|
61 | 61 | $this->setupNavMenuAccess($currentUser); |
62 | 62 | } |
63 | 63 |
@@ -15,52 +15,52 @@ |
||
15 | 15 | |
16 | 16 | class NotIdentifiedException extends ReadableException |
17 | 17 | { |
18 | - use NavigationMenuAccessControl; |
|
19 | - /** |
|
20 | - * @var SecurityManager |
|
21 | - */ |
|
22 | - private $securityManager; |
|
18 | + use NavigationMenuAccessControl; |
|
19 | + /** |
|
20 | + * @var SecurityManager |
|
21 | + */ |
|
22 | + private $securityManager; |
|
23 | 23 | |
24 | - /** |
|
25 | - * NotIdentifiedException constructor. |
|
26 | - * |
|
27 | - * @param SecurityManager $securityManager |
|
28 | - */ |
|
29 | - public function __construct(SecurityManager $securityManager = null) |
|
30 | - { |
|
31 | - $this->securityManager = $securityManager; |
|
32 | - } |
|
24 | + /** |
|
25 | + * NotIdentifiedException constructor. |
|
26 | + * |
|
27 | + * @param SecurityManager $securityManager |
|
28 | + */ |
|
29 | + public function __construct(SecurityManager $securityManager = null) |
|
30 | + { |
|
31 | + $this->securityManager = $securityManager; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Returns a readable HTML error message that's displayable to the user using templates. |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getReadableError() |
|
39 | - { |
|
40 | - if (!headers_sent()) { |
|
41 | - header("HTTP/1.1 403 Forbidden"); |
|
42 | - } |
|
34 | + /** |
|
35 | + * Returns a readable HTML error message that's displayable to the user using templates. |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getReadableError() |
|
39 | + { |
|
40 | + if (!headers_sent()) { |
|
41 | + header("HTTP/1.1 403 Forbidden"); |
|
42 | + } |
|
43 | 43 | |
44 | - $this->setUpSmarty(); |
|
44 | + $this->setUpSmarty(); |
|
45 | 45 | |
46 | - // uck. We should still be able to access the database in this situation though. |
|
47 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
48 | - $currentUser = User::getCurrent($database); |
|
49 | - $this->assign('currentUser', $currentUser); |
|
50 | - $this->assign("loggedIn", (!$currentUser->isCommunityUser())); |
|
46 | + // uck. We should still be able to access the database in this situation though. |
|
47 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
48 | + $currentUser = User::getCurrent($database); |
|
49 | + $this->assign('currentUser', $currentUser); |
|
50 | + $this->assign("loggedIn", (!$currentUser->isCommunityUser())); |
|
51 | 51 | |
52 | - if($this->securityManager !== null) { |
|
53 | - $this->setupNavMenuAccess($currentUser); |
|
54 | - } |
|
52 | + if($this->securityManager !== null) { |
|
53 | + $this->setupNavMenuAccess($currentUser); |
|
54 | + } |
|
55 | 55 | |
56 | - return $this->fetchTemplate("exception/not-identified.tpl"); |
|
57 | - } |
|
56 | + return $this->fetchTemplate("exception/not-identified.tpl"); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return SecurityManager |
|
61 | - */ |
|
62 | - protected function getSecurityManager() |
|
63 | - { |
|
64 | - return $this->securityManager; |
|
65 | - } |
|
59 | + /** |
|
60 | + * @return SecurityManager |
|
61 | + */ |
|
62 | + protected function getSecurityManager() |
|
63 | + { |
|
64 | + return $this->securityManager; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | \ No newline at end of file |
@@ -57,7 +57,7 @@ |
||
57 | 57 | $this->assign('currentUser', $currentUser); |
58 | 58 | $this->assign("loggedIn", (!$currentUser->isCommunityUser())); |
59 | 59 | |
60 | - if($this->securityManager !== null) { |
|
60 | + if ($this->securityManager !== null) { |
|
61 | 61 | $this->setupNavMenuAccess($currentUser); |
62 | 62 | } |
63 | 63 |
@@ -15,112 +15,112 @@ |
||
15 | 15 | |
16 | 16 | class PdoDatabase extends PDO |
17 | 17 | { |
18 | - /** |
|
19 | - * @var PdoDatabase[] |
|
20 | - */ |
|
21 | - private static $connections = array(); |
|
22 | - /** |
|
23 | - * @var bool True if a transaction is active |
|
24 | - */ |
|
25 | - protected $hasActiveTransaction = false; |
|
26 | - |
|
27 | - /** |
|
28 | - * Unless you're doing low-level work, this is not the function you want. |
|
29 | - * |
|
30 | - * @param string $connectionName |
|
31 | - * |
|
32 | - * @return PdoDatabase |
|
33 | - * @throws Exception |
|
34 | - */ |
|
35 | - public static function getDatabaseConnection($connectionName) |
|
36 | - { |
|
37 | - if (!isset(self::$connections[$connectionName])) { |
|
38 | - global $cDatabaseConfig; |
|
39 | - |
|
40 | - if (!array_key_exists($connectionName, $cDatabaseConfig)) { |
|
41 | - throw new Exception("Database configuration not found for alias $connectionName"); |
|
42 | - } |
|
43 | - |
|
44 | - try { |
|
45 | - $databaseObject = new PdoDatabase( |
|
46 | - $cDatabaseConfig[$connectionName]["dsrcname"], |
|
47 | - $cDatabaseConfig[$connectionName]["username"], |
|
48 | - $cDatabaseConfig[$connectionName]["password"] |
|
49 | - ); |
|
50 | - } |
|
51 | - catch (PDOException $ex) { |
|
52 | - // wrap around any potential stack traces which may include passwords |
|
53 | - throw new EnvironmentException("Error connecting to database '$connectionName': " . $ex->getMessage()); |
|
54 | - } |
|
55 | - |
|
56 | - $databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
57 | - |
|
58 | - // emulating prepared statements gives a performance boost on MySQL. |
|
59 | - // |
|
60 | - // however, our version of PDO doesn't seem to understand parameter types when emulating |
|
61 | - // the prepared statements, so we're forced to turn this off for now. |
|
62 | - // -- stw 2014-02-11 |
|
63 | - $databaseObject->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); |
|
64 | - |
|
65 | - self::$connections[$connectionName] = $databaseObject; |
|
66 | - } |
|
67 | - |
|
68 | - return self::$connections[$connectionName]; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Determines if this connection has a transaction in progress or not |
|
73 | - * @return boolean true if there is a transaction in progress. |
|
74 | - */ |
|
75 | - public function hasActiveTransaction() |
|
76 | - { |
|
77 | - return $this->hasActiveTransaction; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Summary of beginTransaction |
|
82 | - * @return bool |
|
83 | - */ |
|
84 | - public function beginTransaction() |
|
85 | - { |
|
86 | - // Override the pre-existing method, which doesn't stop you from |
|
87 | - // starting transactions within transactions - which doesn't work and |
|
88 | - // will throw an exception. This eliminates the need to catch exceptions |
|
89 | - // all over the rest of the code |
|
90 | - if ($this->hasActiveTransaction) { |
|
91 | - return false; |
|
92 | - } |
|
93 | - else { |
|
94 | - // set the transaction isolation level for every transaction. |
|
95 | - $this->exec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;"); |
|
96 | - |
|
97 | - // start a new transaction, and return whether or not the start was |
|
98 | - // successful |
|
99 | - $this->hasActiveTransaction = parent::beginTransaction(); |
|
100 | - |
|
101 | - return $this->hasActiveTransaction; |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Commits the active transaction |
|
107 | - */ |
|
108 | - public function commit() |
|
109 | - { |
|
110 | - if ($this->hasActiveTransaction) { |
|
111 | - parent::commit(); |
|
112 | - $this->hasActiveTransaction = false; |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Rolls back a transaction |
|
118 | - */ |
|
119 | - public function rollBack() |
|
120 | - { |
|
121 | - if ($this->hasActiveTransaction) { |
|
122 | - parent::rollback(); |
|
123 | - $this->hasActiveTransaction = false; |
|
124 | - } |
|
125 | - } |
|
18 | + /** |
|
19 | + * @var PdoDatabase[] |
|
20 | + */ |
|
21 | + private static $connections = array(); |
|
22 | + /** |
|
23 | + * @var bool True if a transaction is active |
|
24 | + */ |
|
25 | + protected $hasActiveTransaction = false; |
|
26 | + |
|
27 | + /** |
|
28 | + * Unless you're doing low-level work, this is not the function you want. |
|
29 | + * |
|
30 | + * @param string $connectionName |
|
31 | + * |
|
32 | + * @return PdoDatabase |
|
33 | + * @throws Exception |
|
34 | + */ |
|
35 | + public static function getDatabaseConnection($connectionName) |
|
36 | + { |
|
37 | + if (!isset(self::$connections[$connectionName])) { |
|
38 | + global $cDatabaseConfig; |
|
39 | + |
|
40 | + if (!array_key_exists($connectionName, $cDatabaseConfig)) { |
|
41 | + throw new Exception("Database configuration not found for alias $connectionName"); |
|
42 | + } |
|
43 | + |
|
44 | + try { |
|
45 | + $databaseObject = new PdoDatabase( |
|
46 | + $cDatabaseConfig[$connectionName]["dsrcname"], |
|
47 | + $cDatabaseConfig[$connectionName]["username"], |
|
48 | + $cDatabaseConfig[$connectionName]["password"] |
|
49 | + ); |
|
50 | + } |
|
51 | + catch (PDOException $ex) { |
|
52 | + // wrap around any potential stack traces which may include passwords |
|
53 | + throw new EnvironmentException("Error connecting to database '$connectionName': " . $ex->getMessage()); |
|
54 | + } |
|
55 | + |
|
56 | + $databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
57 | + |
|
58 | + // emulating prepared statements gives a performance boost on MySQL. |
|
59 | + // |
|
60 | + // however, our version of PDO doesn't seem to understand parameter types when emulating |
|
61 | + // the prepared statements, so we're forced to turn this off for now. |
|
62 | + // -- stw 2014-02-11 |
|
63 | + $databaseObject->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); |
|
64 | + |
|
65 | + self::$connections[$connectionName] = $databaseObject; |
|
66 | + } |
|
67 | + |
|
68 | + return self::$connections[$connectionName]; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Determines if this connection has a transaction in progress or not |
|
73 | + * @return boolean true if there is a transaction in progress. |
|
74 | + */ |
|
75 | + public function hasActiveTransaction() |
|
76 | + { |
|
77 | + return $this->hasActiveTransaction; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Summary of beginTransaction |
|
82 | + * @return bool |
|
83 | + */ |
|
84 | + public function beginTransaction() |
|
85 | + { |
|
86 | + // Override the pre-existing method, which doesn't stop you from |
|
87 | + // starting transactions within transactions - which doesn't work and |
|
88 | + // will throw an exception. This eliminates the need to catch exceptions |
|
89 | + // all over the rest of the code |
|
90 | + if ($this->hasActiveTransaction) { |
|
91 | + return false; |
|
92 | + } |
|
93 | + else { |
|
94 | + // set the transaction isolation level for every transaction. |
|
95 | + $this->exec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;"); |
|
96 | + |
|
97 | + // start a new transaction, and return whether or not the start was |
|
98 | + // successful |
|
99 | + $this->hasActiveTransaction = parent::beginTransaction(); |
|
100 | + |
|
101 | + return $this->hasActiveTransaction; |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Commits the active transaction |
|
107 | + */ |
|
108 | + public function commit() |
|
109 | + { |
|
110 | + if ($this->hasActiveTransaction) { |
|
111 | + parent::commit(); |
|
112 | + $this->hasActiveTransaction = false; |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Rolls back a transaction |
|
118 | + */ |
|
119 | + public function rollBack() |
|
120 | + { |
|
121 | + if ($this->hasActiveTransaction) { |
|
122 | + parent::rollback(); |
|
123 | + $this->hasActiveTransaction = false; |
|
124 | + } |
|
125 | + } |
|
126 | 126 | } |
@@ -89,8 +89,7 @@ |
||
89 | 89 | // all over the rest of the code |
90 | 90 | if ($this->hasActiveTransaction) { |
91 | 91 | return false; |
92 | - } |
|
93 | - else { |
|
92 | + } else { |
|
94 | 93 | // set the transaction isolation level for every transaction. |
95 | 94 | $this->exec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;"); |
96 | 95 |
@@ -21,110 +21,110 @@ |
||
21 | 21 | */ |
22 | 22 | class GeoLocation extends DataObject |
23 | 23 | { |
24 | - private $address; |
|
25 | - private $data; |
|
26 | - private $creation; |
|
27 | - |
|
28 | - /** |
|
29 | - * @param string $address |
|
30 | - * @param PdoDatabase $database |
|
31 | - * |
|
32 | - * @return GeoLocation |
|
33 | - */ |
|
34 | - public static function getByAddress($address, PdoDatabase $database) |
|
35 | - { |
|
36 | - $statement = $database->prepare("SELECT * FROM geolocation WHERE address = :id LIMIT 1;"); |
|
37 | - $statement->bindValue(":id", $address); |
|
38 | - |
|
39 | - $statement->execute(); |
|
40 | - |
|
41 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
42 | - |
|
43 | - if ($resultObject != false) { |
|
44 | - $resultObject->setDatabase($database); |
|
45 | - } |
|
46 | - |
|
47 | - return $resultObject; |
|
48 | - } |
|
49 | - |
|
50 | - public function save() |
|
51 | - { |
|
52 | - if ($this->isNew()) { |
|
53 | - // insert |
|
54 | - $statement = $this->dbObject->prepare(<<<SQL |
|
24 | + private $address; |
|
25 | + private $data; |
|
26 | + private $creation; |
|
27 | + |
|
28 | + /** |
|
29 | + * @param string $address |
|
30 | + * @param PdoDatabase $database |
|
31 | + * |
|
32 | + * @return GeoLocation |
|
33 | + */ |
|
34 | + public static function getByAddress($address, PdoDatabase $database) |
|
35 | + { |
|
36 | + $statement = $database->prepare("SELECT * FROM geolocation WHERE address = :id LIMIT 1;"); |
|
37 | + $statement->bindValue(":id", $address); |
|
38 | + |
|
39 | + $statement->execute(); |
|
40 | + |
|
41 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
42 | + |
|
43 | + if ($resultObject != false) { |
|
44 | + $resultObject->setDatabase($database); |
|
45 | + } |
|
46 | + |
|
47 | + return $resultObject; |
|
48 | + } |
|
49 | + |
|
50 | + public function save() |
|
51 | + { |
|
52 | + if ($this->isNew()) { |
|
53 | + // insert |
|
54 | + $statement = $this->dbObject->prepare(<<<SQL |
|
55 | 55 | INSERT INTO `geolocation` (address, data) VALUES (:address, :data); |
56 | 56 | SQL |
57 | - ); |
|
58 | - $statement->bindValue(":address", $this->address); |
|
59 | - $statement->bindValue(":data", $this->data); |
|
60 | - |
|
61 | - if ($statement->execute()) { |
|
62 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
63 | - } |
|
64 | - else { |
|
65 | - throw new Exception($statement->errorInfo()); |
|
66 | - } |
|
67 | - } |
|
68 | - else { |
|
69 | - // update |
|
70 | - $statement = $this->dbObject->prepare(<<<SQL |
|
57 | + ); |
|
58 | + $statement->bindValue(":address", $this->address); |
|
59 | + $statement->bindValue(":data", $this->data); |
|
60 | + |
|
61 | + if ($statement->execute()) { |
|
62 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
63 | + } |
|
64 | + else { |
|
65 | + throw new Exception($statement->errorInfo()); |
|
66 | + } |
|
67 | + } |
|
68 | + else { |
|
69 | + // update |
|
70 | + $statement = $this->dbObject->prepare(<<<SQL |
|
71 | 71 | UPDATE `geolocation` |
72 | 72 | SET address = :address, data = :data, updateversion = updateversion + 1 |
73 | 73 | WHERE id = :id AND updateversion = :updateversion |
74 | 74 | LIMIT 1; |
75 | 75 | SQL |
76 | - ); |
|
77 | - |
|
78 | - $statement->bindValue(":id", $this->id); |
|
79 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
80 | - |
|
81 | - $statement->bindValue(":address", $this->address); |
|
82 | - $statement->bindValue(":data", $this->data); |
|
83 | - |
|
84 | - if (!$statement->execute()) { |
|
85 | - throw new Exception($statement->errorInfo()); |
|
86 | - } |
|
87 | - |
|
88 | - if ($statement->rowCount() !== 1) { |
|
89 | - throw new OptimisticLockFailedException(); |
|
90 | - } |
|
91 | - |
|
92 | - $this->updateversion++; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - public function getAddress() |
|
97 | - { |
|
98 | - return $this->address; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param string $address |
|
103 | - */ |
|
104 | - public function setAddress($address) |
|
105 | - { |
|
106 | - $this->address = $address; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function getData() |
|
113 | - { |
|
114 | - return unserialize($this->data); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param array $data |
|
119 | - */ |
|
120 | - public function setData($data) |
|
121 | - { |
|
122 | - $this->data = serialize($data); |
|
123 | - } |
|
124 | - |
|
125 | - /** @return DateTimeImmutable */ |
|
126 | - public function getCreation() |
|
127 | - { |
|
128 | - return new DateTimeImmutable($this->creation); |
|
129 | - } |
|
76 | + ); |
|
77 | + |
|
78 | + $statement->bindValue(":id", $this->id); |
|
79 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
80 | + |
|
81 | + $statement->bindValue(":address", $this->address); |
|
82 | + $statement->bindValue(":data", $this->data); |
|
83 | + |
|
84 | + if (!$statement->execute()) { |
|
85 | + throw new Exception($statement->errorInfo()); |
|
86 | + } |
|
87 | + |
|
88 | + if ($statement->rowCount() !== 1) { |
|
89 | + throw new OptimisticLockFailedException(); |
|
90 | + } |
|
91 | + |
|
92 | + $this->updateversion++; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + public function getAddress() |
|
97 | + { |
|
98 | + return $this->address; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param string $address |
|
103 | + */ |
|
104 | + public function setAddress($address) |
|
105 | + { |
|
106 | + $this->address = $address; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function getData() |
|
113 | + { |
|
114 | + return unserialize($this->data); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param array $data |
|
119 | + */ |
|
120 | + public function setData($data) |
|
121 | + { |
|
122 | + $this->data = serialize($data); |
|
123 | + } |
|
124 | + |
|
125 | + /** @return DateTimeImmutable */ |
|
126 | + public function getCreation() |
|
127 | + { |
|
128 | + return new DateTimeImmutable($this->creation); |
|
129 | + } |
|
130 | 130 | } |
@@ -60,12 +60,10 @@ |
||
60 | 60 | |
61 | 61 | if ($statement->execute()) { |
62 | 62 | $this->id = (int)$this->dbObject->lastInsertId(); |
63 | - } |
|
64 | - else { |
|
63 | + } else { |
|
65 | 64 | throw new Exception($statement->errorInfo()); |
66 | 65 | } |
67 | - } |
|
68 | - else { |
|
66 | + } else { |
|
69 | 67 | // update |
70 | 68 | $statement = $this->dbObject->prepare(<<<SQL |
71 | 69 | UPDATE `geolocation` |