@@ -21,141 +21,141 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class SessionAlert |
| 23 | 23 | { |
| 24 | - private $message; |
|
| 25 | - private $title; |
|
| 26 | - private $type; |
|
| 27 | - private $closable; |
|
| 28 | - private $block; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param string $message |
|
| 32 | - * @param string $title |
|
| 33 | - * @param string $type |
|
| 34 | - * @param bool $closable |
|
| 35 | - * @param bool $block |
|
| 36 | - */ |
|
| 37 | - public function __construct($message, $title, $type = "alert-info", $closable = true, $block = true) |
|
| 38 | - { |
|
| 39 | - $this->message = $message; |
|
| 40 | - $this->title = $title; |
|
| 41 | - $this->type = $type; |
|
| 42 | - $this->closable = $closable; |
|
| 43 | - $this->block = $block; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Shows a quick one-liner message |
|
| 48 | - * |
|
| 49 | - * @param string $message |
|
| 50 | - * @param string $type |
|
| 51 | - */ |
|
| 52 | - public static function quick($message, $type = "alert-info") |
|
| 53 | - { |
|
| 54 | - self::append(new SessionAlert($message, "", $type, true, false)); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param SessionAlert $alert |
|
| 59 | - */ |
|
| 60 | - public static function append(SessionAlert $alert) |
|
| 61 | - { |
|
| 62 | - $data = WebRequest::getSessionAlertData(); |
|
| 63 | - $data[] = serialize($alert); |
|
| 64 | - WebRequest::setSessionAlertData($data); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Shows a quick one-liner success message |
|
| 69 | - * |
|
| 70 | - * @param string $message |
|
| 71 | - */ |
|
| 72 | - public static function success($message) |
|
| 73 | - { |
|
| 74 | - self::append(new SessionAlert($message, "", "alert-success", true, true)); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Shows a quick one-liner warning message |
|
| 79 | - * |
|
| 80 | - * @param string $message |
|
| 81 | - * @param string $title |
|
| 82 | - */ |
|
| 83 | - public static function warning($message, $title = "Warning!") |
|
| 84 | - { |
|
| 85 | - self::append(new SessionAlert($message, $title, "alert-warning", true, true)); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Shows a quick one-liner error message |
|
| 90 | - * |
|
| 91 | - * @param string $message |
|
| 92 | - * @param string $title |
|
| 93 | - */ |
|
| 94 | - public static function error($message, $title = "Error!") |
|
| 95 | - { |
|
| 96 | - self::append(new SessionAlert($message, $title, "alert-danger", true, true)); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Retrieves the alerts which have been saved to the session |
|
| 101 | - * @return array |
|
| 102 | - */ |
|
| 103 | - public static function getAlerts() |
|
| 104 | - { |
|
| 105 | - $alertData = array(); |
|
| 106 | - |
|
| 107 | - foreach (WebRequest::getSessionAlertData() as $a) { |
|
| 108 | - $alertData[] = unserialize($a); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $alertData; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Clears the alerts from the session |
|
| 116 | - */ |
|
| 117 | - public static function clearAlerts() |
|
| 118 | - { |
|
| 119 | - WebRequest::clearSessionAlertData(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return boolean |
|
| 124 | - */ |
|
| 125 | - public function isBlock() |
|
| 126 | - { |
|
| 127 | - return $this->block; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return boolean |
|
| 132 | - */ |
|
| 133 | - public function isClosable() |
|
| 134 | - { |
|
| 135 | - return $this->closable; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function getType() |
|
| 142 | - { |
|
| 143 | - return $this->type; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - public function getTitle() |
|
| 150 | - { |
|
| 151 | - return $this->title; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function getMessage() |
|
| 158 | - { |
|
| 159 | - return $this->message; |
|
| 160 | - } |
|
| 24 | + private $message; |
|
| 25 | + private $title; |
|
| 26 | + private $type; |
|
| 27 | + private $closable; |
|
| 28 | + private $block; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param string $message |
|
| 32 | + * @param string $title |
|
| 33 | + * @param string $type |
|
| 34 | + * @param bool $closable |
|
| 35 | + * @param bool $block |
|
| 36 | + */ |
|
| 37 | + public function __construct($message, $title, $type = "alert-info", $closable = true, $block = true) |
|
| 38 | + { |
|
| 39 | + $this->message = $message; |
|
| 40 | + $this->title = $title; |
|
| 41 | + $this->type = $type; |
|
| 42 | + $this->closable = $closable; |
|
| 43 | + $this->block = $block; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Shows a quick one-liner message |
|
| 48 | + * |
|
| 49 | + * @param string $message |
|
| 50 | + * @param string $type |
|
| 51 | + */ |
|
| 52 | + public static function quick($message, $type = "alert-info") |
|
| 53 | + { |
|
| 54 | + self::append(new SessionAlert($message, "", $type, true, false)); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param SessionAlert $alert |
|
| 59 | + */ |
|
| 60 | + public static function append(SessionAlert $alert) |
|
| 61 | + { |
|
| 62 | + $data = WebRequest::getSessionAlertData(); |
|
| 63 | + $data[] = serialize($alert); |
|
| 64 | + WebRequest::setSessionAlertData($data); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Shows a quick one-liner success message |
|
| 69 | + * |
|
| 70 | + * @param string $message |
|
| 71 | + */ |
|
| 72 | + public static function success($message) |
|
| 73 | + { |
|
| 74 | + self::append(new SessionAlert($message, "", "alert-success", true, true)); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Shows a quick one-liner warning message |
|
| 79 | + * |
|
| 80 | + * @param string $message |
|
| 81 | + * @param string $title |
|
| 82 | + */ |
|
| 83 | + public static function warning($message, $title = "Warning!") |
|
| 84 | + { |
|
| 85 | + self::append(new SessionAlert($message, $title, "alert-warning", true, true)); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Shows a quick one-liner error message |
|
| 90 | + * |
|
| 91 | + * @param string $message |
|
| 92 | + * @param string $title |
|
| 93 | + */ |
|
| 94 | + public static function error($message, $title = "Error!") |
|
| 95 | + { |
|
| 96 | + self::append(new SessionAlert($message, $title, "alert-danger", true, true)); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Retrieves the alerts which have been saved to the session |
|
| 101 | + * @return array |
|
| 102 | + */ |
|
| 103 | + public static function getAlerts() |
|
| 104 | + { |
|
| 105 | + $alertData = array(); |
|
| 106 | + |
|
| 107 | + foreach (WebRequest::getSessionAlertData() as $a) { |
|
| 108 | + $alertData[] = unserialize($a); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $alertData; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Clears the alerts from the session |
|
| 116 | + */ |
|
| 117 | + public static function clearAlerts() |
|
| 118 | + { |
|
| 119 | + WebRequest::clearSessionAlertData(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return boolean |
|
| 124 | + */ |
|
| 125 | + public function isBlock() |
|
| 126 | + { |
|
| 127 | + return $this->block; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return boolean |
|
| 132 | + */ |
|
| 133 | + public function isClosable() |
|
| 134 | + { |
|
| 135 | + return $this->closable; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function getType() |
|
| 142 | + { |
|
| 143 | + return $this->type; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + public function getTitle() |
|
| 150 | + { |
|
| 151 | + return $this->title; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function getMessage() |
|
| 158 | + { |
|
| 159 | + return $this->message; |
|
| 160 | + } |
|
| 161 | 161 | } |
@@ -10,20 +10,20 @@ |
||
| 10 | 10 | |
| 11 | 11 | class StringFunctions |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Make a string's first character uppercase |
|
| 15 | - * |
|
| 16 | - * @param string $string |
|
| 17 | - * |
|
| 18 | - * @return string |
|
| 19 | - */ |
|
| 20 | - public function upperCaseFirst($string) |
|
| 21 | - { |
|
| 22 | - if (ord($string) < 128) { |
|
| 23 | - return ucfirst($string); |
|
| 24 | - } |
|
| 25 | - else { |
|
| 26 | - return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
|
| 27 | - } |
|
| 28 | - } |
|
| 13 | + /** |
|
| 14 | + * Make a string's first character uppercase |
|
| 15 | + * |
|
| 16 | + * @param string $string |
|
| 17 | + * |
|
| 18 | + * @return string |
|
| 19 | + */ |
|
| 20 | + public function upperCaseFirst($string) |
|
| 21 | + { |
|
| 22 | + if (ord($string) < 128) { |
|
| 23 | + return ucfirst($string); |
|
| 24 | + } |
|
| 25 | + else { |
|
| 26 | + return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -22,49 +22,49 @@ |
||
| 22 | 22 | |
| 23 | 23 | class ApiRequestRouter implements IRequestRouter |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @return string[] |
|
| 27 | - */ |
|
| 28 | - public static function getActionList() |
|
| 29 | - { |
|
| 30 | - return array("count", "status", "stats", "help", "monitor"); |
|
| 31 | - } |
|
| 25 | + /** |
|
| 26 | + * @return string[] |
|
| 27 | + */ |
|
| 28 | + public static function getActionList() |
|
| 29 | + { |
|
| 30 | + return array("count", "status", "stats", "help", "monitor"); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @return IRoutedTask |
|
| 35 | - * @throws Exception |
|
| 36 | - */ |
|
| 37 | - public function route() |
|
| 38 | - { |
|
| 39 | - $requestAction = WebRequest::getString('action'); |
|
| 33 | + /** |
|
| 34 | + * @return IRoutedTask |
|
| 35 | + * @throws Exception |
|
| 36 | + */ |
|
| 37 | + public function route() |
|
| 38 | + { |
|
| 39 | + $requestAction = WebRequest::getString('action'); |
|
| 40 | 40 | |
| 41 | - switch ($requestAction) { |
|
| 42 | - case "count": |
|
| 43 | - $result = new CountAction(); |
|
| 44 | - break; |
|
| 45 | - case "status": |
|
| 46 | - $result = new StatusAction(); |
|
| 47 | - break; |
|
| 48 | - case "stats": |
|
| 49 | - $result = new StatsAction(); |
|
| 50 | - break; |
|
| 51 | - case "help": |
|
| 52 | - $result = new HelpAction(); |
|
| 53 | - break; |
|
| 54 | - case "monitor": |
|
| 55 | - $result = new MonitorAction(); |
|
| 56 | - break; |
|
| 57 | - case "users": |
|
| 58 | - $result = new JsUsersAction(); |
|
| 59 | - break; |
|
| 60 | - case "templates": |
|
| 61 | - $result = new JsTemplateConfirmsAction(); |
|
| 62 | - break; |
|
| 63 | - default: |
|
| 64 | - $result = new UnknownAction(); |
|
| 65 | - break; |
|
| 66 | - } |
|
| 41 | + switch ($requestAction) { |
|
| 42 | + case "count": |
|
| 43 | + $result = new CountAction(); |
|
| 44 | + break; |
|
| 45 | + case "status": |
|
| 46 | + $result = new StatusAction(); |
|
| 47 | + break; |
|
| 48 | + case "stats": |
|
| 49 | + $result = new StatsAction(); |
|
| 50 | + break; |
|
| 51 | + case "help": |
|
| 52 | + $result = new HelpAction(); |
|
| 53 | + break; |
|
| 54 | + case "monitor": |
|
| 55 | + $result = new MonitorAction(); |
|
| 56 | + break; |
|
| 57 | + case "users": |
|
| 58 | + $result = new JsUsersAction(); |
|
| 59 | + break; |
|
| 60 | + case "templates": |
|
| 61 | + $result = new JsTemplateConfirmsAction(); |
|
| 62 | + break; |
|
| 63 | + default: |
|
| 64 | + $result = new UnknownAction(); |
|
| 65 | + break; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - return $result; |
|
| 69 | - } |
|
| 68 | + return $result; |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -17,9 +17,9 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class OAuthRequestRouter extends RequestRouter |
| 19 | 19 | { |
| 20 | - protected function getRouteFromPath($pathInfo) |
|
| 21 | - { |
|
| 22 | - // Hardcode the route for this entry point |
|
| 23 | - return array(PageOAuthCallback::class, 'authorise'); |
|
| 24 | - } |
|
| 20 | + protected function getRouteFromPath($pathInfo) |
|
| 21 | + { |
|
| 22 | + // Hardcode the route for this entry point |
|
| 23 | + return array(PageOAuthCallback::class, 'authorise'); |
|
| 24 | + } |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -16,51 +16,51 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | class OAuthIdentity extends DataObject |
| 18 | 18 | { |
| 19 | - #region Fields |
|
| 20 | - /** @var int */ |
|
| 21 | - private $user; |
|
| 22 | - /** @var string */ |
|
| 23 | - private $iss; |
|
| 24 | - /** @var int */ |
|
| 25 | - private $sub; |
|
| 26 | - /** @var string */ |
|
| 27 | - private $aud; |
|
| 28 | - /** @var int */ |
|
| 29 | - private $exp; |
|
| 30 | - /** @var int */ |
|
| 31 | - private $iat; |
|
| 32 | - /** @var string */ |
|
| 33 | - private $username; |
|
| 34 | - /** @var int */ |
|
| 35 | - private $editcount; |
|
| 36 | - /** @var int */ |
|
| 37 | - private $confirmed_email; |
|
| 38 | - /** @var int */ |
|
| 39 | - private $blocked; |
|
| 40 | - /** @var string */ |
|
| 41 | - private $registered; |
|
| 42 | - /** @var int */ |
|
| 43 | - private $checkuser; |
|
| 44 | - /** @var int */ |
|
| 45 | - private $grantbasic; |
|
| 46 | - /** @var int */ |
|
| 47 | - private $grantcreateaccount; |
|
| 48 | - /** @var int */ |
|
| 49 | - private $granthighvolume; |
|
| 50 | - /** @var int */ |
|
| 51 | - private $grantcreateeditmovepage; |
|
| 52 | - #endregion |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Saves a data object to the database, either updating or inserting a record. |
|
| 56 | - * @return void |
|
| 57 | - * @throws Exception |
|
| 58 | - * @throws OptimisticLockFailedException |
|
| 59 | - */ |
|
| 60 | - public function save() |
|
| 61 | - { |
|
| 62 | - if ($this->isNew()) { |
|
| 63 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 19 | + #region Fields |
|
| 20 | + /** @var int */ |
|
| 21 | + private $user; |
|
| 22 | + /** @var string */ |
|
| 23 | + private $iss; |
|
| 24 | + /** @var int */ |
|
| 25 | + private $sub; |
|
| 26 | + /** @var string */ |
|
| 27 | + private $aud; |
|
| 28 | + /** @var int */ |
|
| 29 | + private $exp; |
|
| 30 | + /** @var int */ |
|
| 31 | + private $iat; |
|
| 32 | + /** @var string */ |
|
| 33 | + private $username; |
|
| 34 | + /** @var int */ |
|
| 35 | + private $editcount; |
|
| 36 | + /** @var int */ |
|
| 37 | + private $confirmed_email; |
|
| 38 | + /** @var int */ |
|
| 39 | + private $blocked; |
|
| 40 | + /** @var string */ |
|
| 41 | + private $registered; |
|
| 42 | + /** @var int */ |
|
| 43 | + private $checkuser; |
|
| 44 | + /** @var int */ |
|
| 45 | + private $grantbasic; |
|
| 46 | + /** @var int */ |
|
| 47 | + private $grantcreateaccount; |
|
| 48 | + /** @var int */ |
|
| 49 | + private $granthighvolume; |
|
| 50 | + /** @var int */ |
|
| 51 | + private $grantcreateeditmovepage; |
|
| 52 | + #endregion |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Saves a data object to the database, either updating or inserting a record. |
|
| 56 | + * @return void |
|
| 57 | + * @throws Exception |
|
| 58 | + * @throws OptimisticLockFailedException |
|
| 59 | + */ |
|
| 60 | + public function save() |
|
| 61 | + { |
|
| 62 | + if ($this->isNew()) { |
|
| 63 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 64 | 64 | INSERT INTO oauthidentity ( |
| 65 | 65 | user, iss, sub, aud, exp, iat, username, editcount, confirmed_email, blocked, registered, checkuser, |
| 66 | 66 | grantbasic, grantcreateaccount, granthighvolume, grantcreateeditmovepage |
@@ -69,34 +69,34 @@ discard block |
||
| 69 | 69 | :checkuser, :grantbasic, :grantcreateaccount, :granthighvolume, :grantcreateeditmovepage |
| 70 | 70 | ) |
| 71 | 71 | SQL |
| 72 | - ); |
|
| 73 | - |
|
| 74 | - $statement->bindValue(':user', $this->user); |
|
| 75 | - $statement->bindValue(':iss', $this->iss); |
|
| 76 | - $statement->bindValue(':sub', $this->sub); |
|
| 77 | - $statement->bindValue(':aud', $this->aud); |
|
| 78 | - $statement->bindValue(':exp', $this->exp); |
|
| 79 | - $statement->bindValue(':iat', $this->iat); |
|
| 80 | - $statement->bindValue(':username', $this->username); |
|
| 81 | - $statement->bindValue(':editcount', $this->editcount); |
|
| 82 | - $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
| 83 | - $statement->bindValue(':blocked', $this->blocked); |
|
| 84 | - $statement->bindValue(':registered', $this->registered); |
|
| 85 | - $statement->bindValue(':checkuser', $this->checkuser); |
|
| 86 | - $statement->bindValue(':grantbasic', $this->grantbasic); |
|
| 87 | - $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
| 88 | - $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
| 89 | - $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
| 90 | - |
|
| 91 | - if ($statement->execute()) { |
|
| 92 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 93 | - } |
|
| 94 | - else { |
|
| 95 | - throw new Exception($statement->errorInfo()); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - else { |
|
| 99 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 72 | + ); |
|
| 73 | + |
|
| 74 | + $statement->bindValue(':user', $this->user); |
|
| 75 | + $statement->bindValue(':iss', $this->iss); |
|
| 76 | + $statement->bindValue(':sub', $this->sub); |
|
| 77 | + $statement->bindValue(':aud', $this->aud); |
|
| 78 | + $statement->bindValue(':exp', $this->exp); |
|
| 79 | + $statement->bindValue(':iat', $this->iat); |
|
| 80 | + $statement->bindValue(':username', $this->username); |
|
| 81 | + $statement->bindValue(':editcount', $this->editcount); |
|
| 82 | + $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
| 83 | + $statement->bindValue(':blocked', $this->blocked); |
|
| 84 | + $statement->bindValue(':registered', $this->registered); |
|
| 85 | + $statement->bindValue(':checkuser', $this->checkuser); |
|
| 86 | + $statement->bindValue(':grantbasic', $this->grantbasic); |
|
| 87 | + $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
| 88 | + $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
| 89 | + $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
| 90 | + |
|
| 91 | + if ($statement->execute()) { |
|
| 92 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 93 | + } |
|
| 94 | + else { |
|
| 95 | + throw new Exception($statement->errorInfo()); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + else { |
|
| 99 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 100 | 100 | UPDATE oauthidentity SET |
| 101 | 101 | iss = :iss |
| 102 | 102 | , sub = :sub |
@@ -116,211 +116,211 @@ discard block |
||
| 116 | 116 | , updateversion = updateversion + 1 |
| 117 | 117 | WHERE id = :id AND updateversion = :updateversion |
| 118 | 118 | SQL |
| 119 | - ); |
|
| 120 | - |
|
| 121 | - $statement->bindValue(':iss', $this->iss); |
|
| 122 | - $statement->bindValue(':sub', $this->sub); |
|
| 123 | - $statement->bindValue(':aud', $this->aud); |
|
| 124 | - $statement->bindValue(':exp', $this->exp); |
|
| 125 | - $statement->bindValue(':iat', $this->iat); |
|
| 126 | - $statement->bindValue(':username', $this->username); |
|
| 127 | - $statement->bindValue(':editcount', $this->editcount); |
|
| 128 | - $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
| 129 | - $statement->bindValue(':blocked', $this->blocked); |
|
| 130 | - $statement->bindValue(':registered', $this->registered); |
|
| 131 | - $statement->bindValue(':checkuser', $this->checkuser); |
|
| 132 | - $statement->bindValue(':grantbasic', $this->grantbasic); |
|
| 133 | - $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
| 134 | - $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
| 135 | - $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
| 136 | - |
|
| 137 | - $statement->bindValue(':id', $this->id); |
|
| 138 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 139 | - |
|
| 140 | - if (!$statement->execute()) { |
|
| 141 | - throw new Exception($statement->errorInfo()); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if ($statement->rowCount() !== 1) { |
|
| 145 | - throw new OptimisticLockFailedException(); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $this->updateversion++; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - #region Properties |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return int |
|
| 156 | - */ |
|
| 157 | - public function getUserId() |
|
| 158 | - { |
|
| 159 | - return $this->user; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param int $user |
|
| 164 | - */ |
|
| 165 | - public function setUserId($user) |
|
| 166 | - { |
|
| 167 | - $this->user = $user; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @return string |
|
| 172 | - */ |
|
| 173 | - public function getIssuer() |
|
| 174 | - { |
|
| 175 | - return $this->iss; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @return int |
|
| 180 | - */ |
|
| 181 | - public function getSubject() |
|
| 182 | - { |
|
| 183 | - return $this->sub; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function getAudience() |
|
| 190 | - { |
|
| 191 | - return $this->aud; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @return int |
|
| 196 | - */ |
|
| 197 | - public function getExpirationTime() |
|
| 198 | - { |
|
| 199 | - return $this->exp; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @return int |
|
| 204 | - */ |
|
| 205 | - public function getIssuedAtTime() |
|
| 206 | - { |
|
| 207 | - return $this->iat; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @return string |
|
| 212 | - */ |
|
| 213 | - public function getUsername() |
|
| 214 | - { |
|
| 215 | - return $this->username; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * @return int |
|
| 220 | - */ |
|
| 221 | - public function getEditCount() |
|
| 222 | - { |
|
| 223 | - return $this->editcount; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @return bool |
|
| 228 | - */ |
|
| 229 | - public function getConfirmedEmail() |
|
| 230 | - { |
|
| 231 | - return $this->confirmed_email == 1; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * @return bool |
|
| 236 | - */ |
|
| 237 | - public function getBlocked() |
|
| 238 | - { |
|
| 239 | - return $this->blocked == 1; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public function getRegistered() |
|
| 246 | - { |
|
| 247 | - return $this->registered; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - public function getRegistrationDate() |
|
| 251 | - { |
|
| 252 | - return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r'); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - public function getAccountAge() |
|
| 256 | - { |
|
| 257 | - $regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered); |
|
| 258 | - $interval = $regDate->diff(new DateTimeImmutable(), true); |
|
| 259 | - |
|
| 260 | - return $interval->days; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * @return bool |
|
| 265 | - */ |
|
| 266 | - public function getCheckuser() |
|
| 267 | - { |
|
| 268 | - return $this->checkuser == 1; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @return bool |
|
| 273 | - */ |
|
| 274 | - public function getGrantBasic() |
|
| 275 | - { |
|
| 276 | - return $this->grantbasic == 1; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @return bool |
|
| 281 | - */ |
|
| 282 | - public function getGrantCreateAccount() |
|
| 283 | - { |
|
| 284 | - return $this->grantcreateaccount == 1; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * @return bool |
|
| 289 | - */ |
|
| 290 | - public function getGrantHighVolume() |
|
| 291 | - { |
|
| 292 | - return $this->granthighvolume == 1; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * @return bool |
|
| 297 | - */ |
|
| 298 | - public function getGrantCreateEditMovePage() |
|
| 299 | - { |
|
| 300 | - return $this->grantcreateeditmovepage == 1; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - #endregion Properties |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Populates the fields of this instance from a provided JSON Web Token |
|
| 307 | - * |
|
| 308 | - * @param stdClass $jwt |
|
| 309 | - */ |
|
| 310 | - public function populate($jwt) |
|
| 311 | - { |
|
| 312 | - $this->iss = $jwt->iss; |
|
| 313 | - $this->sub = $jwt->sub; |
|
| 314 | - $this->aud = $jwt->aud; |
|
| 315 | - $this->exp = $jwt->exp; |
|
| 316 | - $this->iat = $jwt->iat; |
|
| 317 | - $this->username = $jwt->username; |
|
| 318 | - $this->editcount = $jwt->editcount; |
|
| 319 | - $this->confirmed_email = $jwt->confirmed_email ? 1 : 0; |
|
| 320 | - $this->blocked = $jwt->blocked ? 1 : 0; |
|
| 321 | - $this->registered = $jwt->registered; |
|
| 322 | - |
|
| 323 | - /* |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + $statement->bindValue(':iss', $this->iss); |
|
| 122 | + $statement->bindValue(':sub', $this->sub); |
|
| 123 | + $statement->bindValue(':aud', $this->aud); |
|
| 124 | + $statement->bindValue(':exp', $this->exp); |
|
| 125 | + $statement->bindValue(':iat', $this->iat); |
|
| 126 | + $statement->bindValue(':username', $this->username); |
|
| 127 | + $statement->bindValue(':editcount', $this->editcount); |
|
| 128 | + $statement->bindValue(':confirmed_email', $this->confirmed_email); |
|
| 129 | + $statement->bindValue(':blocked', $this->blocked); |
|
| 130 | + $statement->bindValue(':registered', $this->registered); |
|
| 131 | + $statement->bindValue(':checkuser', $this->checkuser); |
|
| 132 | + $statement->bindValue(':grantbasic', $this->grantbasic); |
|
| 133 | + $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount); |
|
| 134 | + $statement->bindValue(':granthighvolume', $this->granthighvolume); |
|
| 135 | + $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage); |
|
| 136 | + |
|
| 137 | + $statement->bindValue(':id', $this->id); |
|
| 138 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 139 | + |
|
| 140 | + if (!$statement->execute()) { |
|
| 141 | + throw new Exception($statement->errorInfo()); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if ($statement->rowCount() !== 1) { |
|
| 145 | + throw new OptimisticLockFailedException(); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $this->updateversion++; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + #region Properties |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return int |
|
| 156 | + */ |
|
| 157 | + public function getUserId() |
|
| 158 | + { |
|
| 159 | + return $this->user; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param int $user |
|
| 164 | + */ |
|
| 165 | + public function setUserId($user) |
|
| 166 | + { |
|
| 167 | + $this->user = $user; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 173 | + public function getIssuer() |
|
| 174 | + { |
|
| 175 | + return $this->iss; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @return int |
|
| 180 | + */ |
|
| 181 | + public function getSubject() |
|
| 182 | + { |
|
| 183 | + return $this->sub; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function getAudience() |
|
| 190 | + { |
|
| 191 | + return $this->aud; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @return int |
|
| 196 | + */ |
|
| 197 | + public function getExpirationTime() |
|
| 198 | + { |
|
| 199 | + return $this->exp; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @return int |
|
| 204 | + */ |
|
| 205 | + public function getIssuedAtTime() |
|
| 206 | + { |
|
| 207 | + return $this->iat; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @return string |
|
| 212 | + */ |
|
| 213 | + public function getUsername() |
|
| 214 | + { |
|
| 215 | + return $this->username; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * @return int |
|
| 220 | + */ |
|
| 221 | + public function getEditCount() |
|
| 222 | + { |
|
| 223 | + return $this->editcount; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return bool |
|
| 228 | + */ |
|
| 229 | + public function getConfirmedEmail() |
|
| 230 | + { |
|
| 231 | + return $this->confirmed_email == 1; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @return bool |
|
| 236 | + */ |
|
| 237 | + public function getBlocked() |
|
| 238 | + { |
|
| 239 | + return $this->blocked == 1; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public function getRegistered() |
|
| 246 | + { |
|
| 247 | + return $this->registered; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + public function getRegistrationDate() |
|
| 251 | + { |
|
| 252 | + return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r'); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + public function getAccountAge() |
|
| 256 | + { |
|
| 257 | + $regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered); |
|
| 258 | + $interval = $regDate->diff(new DateTimeImmutable(), true); |
|
| 259 | + |
|
| 260 | + return $interval->days; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * @return bool |
|
| 265 | + */ |
|
| 266 | + public function getCheckuser() |
|
| 267 | + { |
|
| 268 | + return $this->checkuser == 1; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @return bool |
|
| 273 | + */ |
|
| 274 | + public function getGrantBasic() |
|
| 275 | + { |
|
| 276 | + return $this->grantbasic == 1; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @return bool |
|
| 281 | + */ |
|
| 282 | + public function getGrantCreateAccount() |
|
| 283 | + { |
|
| 284 | + return $this->grantcreateaccount == 1; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * @return bool |
|
| 289 | + */ |
|
| 290 | + public function getGrantHighVolume() |
|
| 291 | + { |
|
| 292 | + return $this->granthighvolume == 1; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * @return bool |
|
| 297 | + */ |
|
| 298 | + public function getGrantCreateEditMovePage() |
|
| 299 | + { |
|
| 300 | + return $this->grantcreateeditmovepage == 1; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + #endregion Properties |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Populates the fields of this instance from a provided JSON Web Token |
|
| 307 | + * |
|
| 308 | + * @param stdClass $jwt |
|
| 309 | + */ |
|
| 310 | + public function populate($jwt) |
|
| 311 | + { |
|
| 312 | + $this->iss = $jwt->iss; |
|
| 313 | + $this->sub = $jwt->sub; |
|
| 314 | + $this->aud = $jwt->aud; |
|
| 315 | + $this->exp = $jwt->exp; |
|
| 316 | + $this->iat = $jwt->iat; |
|
| 317 | + $this->username = $jwt->username; |
|
| 318 | + $this->editcount = $jwt->editcount; |
|
| 319 | + $this->confirmed_email = $jwt->confirmed_email ? 1 : 0; |
|
| 320 | + $this->blocked = $jwt->blocked ? 1 : 0; |
|
| 321 | + $this->registered = $jwt->registered; |
|
| 322 | + |
|
| 323 | + /* |
|
| 324 | 324 | * Rights we need: |
| 325 | 325 | * Account creation |
| 326 | 326 | * createaccount => createaccount |
@@ -342,11 +342,11 @@ discard block |
||
| 342 | 342 | * Any antispoof conflicts will still have to be resolved manually using the normal creation form. |
| 343 | 343 | */ |
| 344 | 344 | |
| 345 | - $this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0; |
|
| 346 | - $this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0; |
|
| 347 | - $this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0; |
|
| 348 | - $this->granthighvolume = in_array('highvolume', $jwt->grants) ? 1 : 0; |
|
| 345 | + $this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0; |
|
| 346 | + $this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0; |
|
| 347 | + $this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0; |
|
| 348 | + $this->granthighvolume = in_array('highvolume', $jwt->grants) ? 1 : 0; |
|
| 349 | 349 | |
| 350 | - $this->checkuser = in_array('checkuser-log', $jwt->rights) ? 1 : 0; |
|
| 351 | - } |
|
| 350 | + $this->checkuser = in_array('checkuser-log', $jwt->rights) ? 1 : 0; |
|
| 351 | + } |
|
| 352 | 352 | } |
@@ -20,74 +20,74 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class SiteNotice extends DataObject |
| 22 | 22 | { |
| 23 | - /** @var string */ |
|
| 24 | - private $content; |
|
| 23 | + /** @var string */ |
|
| 24 | + private $content; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Get a message. |
|
| 28 | - * |
|
| 29 | - * @param PdoDatabase $database |
|
| 30 | - * |
|
| 31 | - * @return string The content for display |
|
| 32 | - */ |
|
| 33 | - public static function get(PdoDatabase $database) |
|
| 34 | - { |
|
| 35 | - /** @var SiteNotice $message */ |
|
| 36 | - $message = self::getById(1, $database); |
|
| 26 | + /** |
|
| 27 | + * Get a message. |
|
| 28 | + * |
|
| 29 | + * @param PdoDatabase $database |
|
| 30 | + * |
|
| 31 | + * @return string The content for display |
|
| 32 | + */ |
|
| 33 | + public static function get(PdoDatabase $database) |
|
| 34 | + { |
|
| 35 | + /** @var SiteNotice $message */ |
|
| 36 | + $message = self::getById(1, $database); |
|
| 37 | 37 | |
| 38 | - return $message->getContent(); |
|
| 39 | - } |
|
| 38 | + return $message->getContent(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Saves the object |
|
| 43 | - * @throws Exception |
|
| 44 | - */ |
|
| 45 | - public function save() |
|
| 46 | - { |
|
| 47 | - if ($this->isNew()) { |
|
| 48 | - // insert |
|
| 49 | - throw new Exception('Not allowed to create new site notice object'); |
|
| 50 | - } |
|
| 51 | - else { |
|
| 52 | - // update |
|
| 53 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 41 | + /** |
|
| 42 | + * Saves the object |
|
| 43 | + * @throws Exception |
|
| 44 | + */ |
|
| 45 | + public function save() |
|
| 46 | + { |
|
| 47 | + if ($this->isNew()) { |
|
| 48 | + // insert |
|
| 49 | + throw new Exception('Not allowed to create new site notice object'); |
|
| 50 | + } |
|
| 51 | + else { |
|
| 52 | + // update |
|
| 53 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 54 | 54 | UPDATE sitenotice |
| 55 | 55 | SET content = :content, updateversion = updateversion + 1 |
| 56 | 56 | WHERE updateversion = :updateversion; |
| 57 | 57 | SQL |
| 58 | - ); |
|
| 59 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 58 | + ); |
|
| 59 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 60 | 60 | |
| 61 | - $statement->bindValue(':content', $this->content); |
|
| 61 | + $statement->bindValue(':content', $this->content); |
|
| 62 | 62 | |
| 63 | - if (!$statement->execute()) { |
|
| 64 | - throw new Exception($statement->errorInfo()); |
|
| 65 | - } |
|
| 63 | + if (!$statement->execute()) { |
|
| 64 | + throw new Exception($statement->errorInfo()); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - if ($statement->rowCount() !== 1) { |
|
| 68 | - throw new OptimisticLockFailedException(); |
|
| 69 | - } |
|
| 67 | + if ($statement->rowCount() !== 1) { |
|
| 68 | + throw new OptimisticLockFailedException(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - $this->updateversion++; |
|
| 72 | - } |
|
| 73 | - } |
|
| 71 | + $this->updateversion++; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Gets the content of the message |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - public function getContent() |
|
| 80 | - { |
|
| 81 | - return $this->content; |
|
| 82 | - } |
|
| 75 | + /** |
|
| 76 | + * Gets the content of the message |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + public function getContent() |
|
| 80 | + { |
|
| 81 | + return $this->content; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Sets the content of the message |
|
| 86 | - * |
|
| 87 | - * @param string $content |
|
| 88 | - */ |
|
| 89 | - public function setContent($content) |
|
| 90 | - { |
|
| 91 | - $this->content = $content; |
|
| 92 | - } |
|
| 84 | + /** |
|
| 85 | + * Sets the content of the message |
|
| 86 | + * |
|
| 87 | + * @param string $content |
|
| 88 | + */ |
|
| 89 | + public function setContent($content) |
|
| 90 | + { |
|
| 91 | + $this->content = $content; |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -15,187 +15,187 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | class Credential extends DataObject |
| 17 | 17 | { |
| 18 | - /** @var int */ |
|
| 19 | - private $user; |
|
| 20 | - /** @var int */ |
|
| 21 | - private $factor; |
|
| 22 | - /** @var string */ |
|
| 23 | - private $type; |
|
| 24 | - /** @var string */ |
|
| 25 | - private $data; |
|
| 26 | - /** @var int */ |
|
| 27 | - private $version; |
|
| 28 | - private $timeout; |
|
| 29 | - /** @var int */ |
|
| 30 | - private $disabled = 0; |
|
| 31 | - /** @var int */ |
|
| 32 | - private $priority; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @return int |
|
| 36 | - */ |
|
| 37 | - public function getUserId() |
|
| 38 | - { |
|
| 39 | - return $this->user; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param int $user |
|
| 44 | - */ |
|
| 45 | - public function setUserId($user) |
|
| 46 | - { |
|
| 47 | - $this->user = $user; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return int |
|
| 52 | - */ |
|
| 53 | - public function getFactor() |
|
| 54 | - { |
|
| 55 | - return $this->factor; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param int $factor |
|
| 60 | - */ |
|
| 61 | - public function setFactor($factor) |
|
| 62 | - { |
|
| 63 | - $this->factor = $factor; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function getType() |
|
| 70 | - { |
|
| 71 | - return $this->type; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param string $type |
|
| 76 | - */ |
|
| 77 | - public function setType($type) |
|
| 78 | - { |
|
| 79 | - $this->type = $type; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function getData() |
|
| 86 | - { |
|
| 87 | - return $this->data; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param string $data |
|
| 92 | - */ |
|
| 93 | - public function setData($data) |
|
| 94 | - { |
|
| 95 | - $this->data = $data; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return int |
|
| 100 | - */ |
|
| 101 | - public function getVersion() |
|
| 102 | - { |
|
| 103 | - return $this->version; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @param int $version |
|
| 108 | - */ |
|
| 109 | - public function setVersion($version) |
|
| 110 | - { |
|
| 111 | - $this->version = $version; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @return mixed |
|
| 116 | - */ |
|
| 117 | - public function getTimeout() |
|
| 118 | - { |
|
| 119 | - if ($this->timeout === null) { |
|
| 120 | - return null; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return new DateTimeImmutable($this->timeout); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @param mixed $timeout |
|
| 128 | - */ |
|
| 129 | - public function setTimeout(DateTimeImmutable $timeout = null) |
|
| 130 | - { |
|
| 131 | - if ($timeout === null) { |
|
| 132 | - $this->timeout = null; |
|
| 133 | - } |
|
| 134 | - else { |
|
| 135 | - $this->timeout = $timeout->format('Y-m-d H:i:s'); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return int |
|
| 141 | - */ |
|
| 142 | - public function getDisabled() |
|
| 143 | - { |
|
| 144 | - return $this->disabled; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param int $disabled |
|
| 149 | - */ |
|
| 150 | - public function setDisabled($disabled) |
|
| 151 | - { |
|
| 152 | - $this->disabled = $disabled; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @return int |
|
| 157 | - */ |
|
| 158 | - public function getPriority() |
|
| 159 | - { |
|
| 160 | - return $this->priority; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param int $priority |
|
| 165 | - */ |
|
| 166 | - public function setPriority($priority) |
|
| 167 | - { |
|
| 168 | - $this->priority = $priority; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - public function save() |
|
| 172 | - { |
|
| 173 | - if ($this->isNew()) { |
|
| 174 | - // insert |
|
| 175 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 18 | + /** @var int */ |
|
| 19 | + private $user; |
|
| 20 | + /** @var int */ |
|
| 21 | + private $factor; |
|
| 22 | + /** @var string */ |
|
| 23 | + private $type; |
|
| 24 | + /** @var string */ |
|
| 25 | + private $data; |
|
| 26 | + /** @var int */ |
|
| 27 | + private $version; |
|
| 28 | + private $timeout; |
|
| 29 | + /** @var int */ |
|
| 30 | + private $disabled = 0; |
|
| 31 | + /** @var int */ |
|
| 32 | + private $priority; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @return int |
|
| 36 | + */ |
|
| 37 | + public function getUserId() |
|
| 38 | + { |
|
| 39 | + return $this->user; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param int $user |
|
| 44 | + */ |
|
| 45 | + public function setUserId($user) |
|
| 46 | + { |
|
| 47 | + $this->user = $user; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return int |
|
| 52 | + */ |
|
| 53 | + public function getFactor() |
|
| 54 | + { |
|
| 55 | + return $this->factor; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param int $factor |
|
| 60 | + */ |
|
| 61 | + public function setFactor($factor) |
|
| 62 | + { |
|
| 63 | + $this->factor = $factor; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function getType() |
|
| 70 | + { |
|
| 71 | + return $this->type; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param string $type |
|
| 76 | + */ |
|
| 77 | + public function setType($type) |
|
| 78 | + { |
|
| 79 | + $this->type = $type; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function getData() |
|
| 86 | + { |
|
| 87 | + return $this->data; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param string $data |
|
| 92 | + */ |
|
| 93 | + public function setData($data) |
|
| 94 | + { |
|
| 95 | + $this->data = $data; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return int |
|
| 100 | + */ |
|
| 101 | + public function getVersion() |
|
| 102 | + { |
|
| 103 | + return $this->version; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @param int $version |
|
| 108 | + */ |
|
| 109 | + public function setVersion($version) |
|
| 110 | + { |
|
| 111 | + $this->version = $version; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @return mixed |
|
| 116 | + */ |
|
| 117 | + public function getTimeout() |
|
| 118 | + { |
|
| 119 | + if ($this->timeout === null) { |
|
| 120 | + return null; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return new DateTimeImmutable($this->timeout); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @param mixed $timeout |
|
| 128 | + */ |
|
| 129 | + public function setTimeout(DateTimeImmutable $timeout = null) |
|
| 130 | + { |
|
| 131 | + if ($timeout === null) { |
|
| 132 | + $this->timeout = null; |
|
| 133 | + } |
|
| 134 | + else { |
|
| 135 | + $this->timeout = $timeout->format('Y-m-d H:i:s'); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return int |
|
| 141 | + */ |
|
| 142 | + public function getDisabled() |
|
| 143 | + { |
|
| 144 | + return $this->disabled; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param int $disabled |
|
| 149 | + */ |
|
| 150 | + public function setDisabled($disabled) |
|
| 151 | + { |
|
| 152 | + $this->disabled = $disabled; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @return int |
|
| 157 | + */ |
|
| 158 | + public function getPriority() |
|
| 159 | + { |
|
| 160 | + return $this->priority; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param int $priority |
|
| 165 | + */ |
|
| 166 | + public function setPriority($priority) |
|
| 167 | + { |
|
| 168 | + $this->priority = $priority; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + public function save() |
|
| 172 | + { |
|
| 173 | + if ($this->isNew()) { |
|
| 174 | + // insert |
|
| 175 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 176 | 176 | INSERT INTO credential ( updateversion, user, factor, type, data, version, timeout, disabled, priority ) |
| 177 | 177 | VALUES ( 0, :user, :factor, :type, :data, :version, :timeout, :disabled, :priority ); |
| 178 | 178 | SQL |
| 179 | - ); |
|
| 180 | - $statement->bindValue(":user", $this->user); |
|
| 181 | - $statement->bindValue(":factor", $this->factor); |
|
| 182 | - $statement->bindValue(":type", $this->type); |
|
| 183 | - $statement->bindValue(":data", $this->data); |
|
| 184 | - $statement->bindValue(":version", $this->version); |
|
| 185 | - $statement->bindValue(":timeout", $this->timeout); |
|
| 186 | - $statement->bindValue(":disabled", $this->disabled); |
|
| 187 | - $statement->bindValue(":priority", $this->priority); |
|
| 188 | - |
|
| 189 | - if ($statement->execute()) { |
|
| 190 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 191 | - } |
|
| 192 | - else { |
|
| 193 | - throw new Exception($statement->errorInfo()); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - else { |
|
| 197 | - // update |
|
| 198 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 179 | + ); |
|
| 180 | + $statement->bindValue(":user", $this->user); |
|
| 181 | + $statement->bindValue(":factor", $this->factor); |
|
| 182 | + $statement->bindValue(":type", $this->type); |
|
| 183 | + $statement->bindValue(":data", $this->data); |
|
| 184 | + $statement->bindValue(":version", $this->version); |
|
| 185 | + $statement->bindValue(":timeout", $this->timeout); |
|
| 186 | + $statement->bindValue(":disabled", $this->disabled); |
|
| 187 | + $statement->bindValue(":priority", $this->priority); |
|
| 188 | + |
|
| 189 | + if ($statement->execute()) { |
|
| 190 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 191 | + } |
|
| 192 | + else { |
|
| 193 | + throw new Exception($statement->errorInfo()); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + else { |
|
| 197 | + // update |
|
| 198 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 199 | 199 | UPDATE credential |
| 200 | 200 | SET factor = :factor |
| 201 | 201 | , data = :data |
@@ -206,27 +206,27 @@ discard block |
||
| 206 | 206 | , updateversion = updateversion + 1 |
| 207 | 207 | WHERE id = :id AND updateversion = :updateversion; |
| 208 | 208 | SQL |
| 209 | - ); |
|
| 209 | + ); |
|
| 210 | 210 | |
| 211 | - $statement->bindValue(':id', $this->id); |
|
| 212 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 211 | + $statement->bindValue(':id', $this->id); |
|
| 212 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 213 | 213 | |
| 214 | - $statement->bindValue(":factor", $this->factor); |
|
| 215 | - $statement->bindValue(":data", $this->data); |
|
| 216 | - $statement->bindValue(":version", $this->version); |
|
| 217 | - $statement->bindValue(":timeout", $this->timeout); |
|
| 218 | - $statement->bindValue(":disabled", $this->disabled); |
|
| 219 | - $statement->bindValue(":priority", $this->priority); |
|
| 214 | + $statement->bindValue(":factor", $this->factor); |
|
| 215 | + $statement->bindValue(":data", $this->data); |
|
| 216 | + $statement->bindValue(":version", $this->version); |
|
| 217 | + $statement->bindValue(":timeout", $this->timeout); |
|
| 218 | + $statement->bindValue(":disabled", $this->disabled); |
|
| 219 | + $statement->bindValue(":priority", $this->priority); |
|
| 220 | 220 | |
| 221 | - if (!$statement->execute()) { |
|
| 222 | - throw new Exception($statement->errorInfo()); |
|
| 223 | - } |
|
| 221 | + if (!$statement->execute()) { |
|
| 222 | + throw new Exception($statement->errorInfo()); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - if ($statement->rowCount() !== 1) { |
|
| 226 | - throw new OptimisticLockFailedException(); |
|
| 227 | - } |
|
| 225 | + if ($statement->rowCount() !== 1) { |
|
| 226 | + throw new OptimisticLockFailedException(); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - $this->updateversion++; |
|
| 230 | - } |
|
| 231 | - } |
|
| 229 | + $this->updateversion++; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | 232 | } |
| 233 | 233 | \ No newline at end of file |
@@ -19,109 +19,109 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class RDnsCache extends DataObject |
| 21 | 21 | { |
| 22 | - private $address; |
|
| 23 | - private $data; |
|
| 24 | - private $creation; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @param string $address |
|
| 28 | - * @param PdoDatabase $database |
|
| 29 | - * |
|
| 30 | - * @return RDnsCache|false |
|
| 31 | - */ |
|
| 32 | - public static function getByAddress($address, PdoDatabase $database) |
|
| 33 | - { |
|
| 34 | - // @todo add cache invalidation (timestamp?) |
|
| 35 | - $statement = $database->prepare("SELECT * FROM rdnscache WHERE address = :id LIMIT 1;"); |
|
| 36 | - $statement->bindValue(":id", $address); |
|
| 37 | - |
|
| 38 | - $statement->execute(); |
|
| 39 | - |
|
| 40 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 41 | - |
|
| 42 | - if ($resultObject != false) { |
|
| 43 | - $resultObject->setDatabase($database); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - return $resultObject; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function save() |
|
| 50 | - { |
|
| 51 | - if ($this->isNew()) { |
|
| 52 | - // insert |
|
| 53 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 22 | + private $address; |
|
| 23 | + private $data; |
|
| 24 | + private $creation; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @param string $address |
|
| 28 | + * @param PdoDatabase $database |
|
| 29 | + * |
|
| 30 | + * @return RDnsCache|false |
|
| 31 | + */ |
|
| 32 | + public static function getByAddress($address, PdoDatabase $database) |
|
| 33 | + { |
|
| 34 | + // @todo add cache invalidation (timestamp?) |
|
| 35 | + $statement = $database->prepare("SELECT * FROM rdnscache WHERE address = :id LIMIT 1;"); |
|
| 36 | + $statement->bindValue(":id", $address); |
|
| 37 | + |
|
| 38 | + $statement->execute(); |
|
| 39 | + |
|
| 40 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 41 | + |
|
| 42 | + if ($resultObject != false) { |
|
| 43 | + $resultObject->setDatabase($database); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + return $resultObject; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function save() |
|
| 50 | + { |
|
| 51 | + if ($this->isNew()) { |
|
| 52 | + // insert |
|
| 53 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 54 | 54 | INSERT INTO `rdnscache` (address, data) VALUES (:address, :data); |
| 55 | 55 | SQL |
| 56 | - ); |
|
| 57 | - $statement->bindValue(":address", $this->address); |
|
| 58 | - $statement->bindValue(":data", $this->data); |
|
| 59 | - |
|
| 60 | - if ($statement->execute()) { |
|
| 61 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 62 | - } |
|
| 63 | - else { |
|
| 64 | - throw new Exception($statement->errorInfo()); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - else { |
|
| 68 | - // update |
|
| 69 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 56 | + ); |
|
| 57 | + $statement->bindValue(":address", $this->address); |
|
| 58 | + $statement->bindValue(":data", $this->data); |
|
| 59 | + |
|
| 60 | + if ($statement->execute()) { |
|
| 61 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 62 | + } |
|
| 63 | + else { |
|
| 64 | + throw new Exception($statement->errorInfo()); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + else { |
|
| 68 | + // update |
|
| 69 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 70 | 70 | UPDATE `rdnscache` |
| 71 | 71 | SET address = :address, data = :data, updateversion = updateversion + 1 |
| 72 | 72 | WHERE id = :id AND updateversion = :updateversion; |
| 73 | 73 | SQL |
| 74 | - ); |
|
| 75 | - |
|
| 76 | - $statement->bindValue(':id', $this->id); |
|
| 77 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 78 | - |
|
| 79 | - $statement->bindValue(':address', $this->address); |
|
| 80 | - $statement->bindValue(':data', $this->data); |
|
| 81 | - |
|
| 82 | - if (!$statement->execute()) { |
|
| 83 | - throw new Exception($statement->errorInfo()); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ($statement->rowCount() !== 1) { |
|
| 87 | - throw new OptimisticLockFailedException(); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $this->updateversion++; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - public function getAddress() |
|
| 95 | - { |
|
| 96 | - return $this->address; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param string $address |
|
| 101 | - */ |
|
| 102 | - public function setAddress($address) |
|
| 103 | - { |
|
| 104 | - $this->address = $address; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public function getData() |
|
| 111 | - { |
|
| 112 | - return unserialize($this->data); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function setData($data) |
|
| 116 | - { |
|
| 117 | - $this->data = serialize($data); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return DateTimeImmutable |
|
| 122 | - */ |
|
| 123 | - public function getCreation() |
|
| 124 | - { |
|
| 125 | - return new DateTimeImmutable($this->creation); |
|
| 126 | - } |
|
| 74 | + ); |
|
| 75 | + |
|
| 76 | + $statement->bindValue(':id', $this->id); |
|
| 77 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 78 | + |
|
| 79 | + $statement->bindValue(':address', $this->address); |
|
| 80 | + $statement->bindValue(':data', $this->data); |
|
| 81 | + |
|
| 82 | + if (!$statement->execute()) { |
|
| 83 | + throw new Exception($statement->errorInfo()); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ($statement->rowCount() !== 1) { |
|
| 87 | + throw new OptimisticLockFailedException(); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $this->updateversion++; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + public function getAddress() |
|
| 95 | + { |
|
| 96 | + return $this->address; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param string $address |
|
| 101 | + */ |
|
| 102 | + public function setAddress($address) |
|
| 103 | + { |
|
| 104 | + $this->address = $address; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public function getData() |
|
| 111 | + { |
|
| 112 | + return unserialize($this->data); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function setData($data) |
|
| 116 | + { |
|
| 117 | + $this->data = serialize($data); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return DateTimeImmutable |
|
| 122 | + */ |
|
| 123 | + public function getCreation() |
|
| 124 | + { |
|
| 125 | + return new DateTimeImmutable($this->creation); |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -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 | - * @param bool $forUpdate |
|
| 32 | - * @return GeoLocation |
|
| 33 | - */ |
|
| 34 | - public static function getByAddress($address, PdoDatabase $database, $forUpdate = false) |
|
| 35 | - { |
|
| 36 | - $lockMode = $forUpdate ? ' FOR UPDATE' : ''; |
|
| 37 | - $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1" . $lockMode; |
|
| 38 | - |
|
| 39 | - $statement = $database->prepare($sql); |
|
| 40 | - $statement->bindValue(":id", $address); |
|
| 41 | - |
|
| 42 | - $statement->execute(); |
|
| 43 | - |
|
| 44 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
| 45 | - |
|
| 46 | - if ($resultObject != false) { |
|
| 47 | - $resultObject->setDatabase($database); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - return $resultObject; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function save() |
|
| 54 | - { |
|
| 55 | - if ($this->isNew()) { |
|
| 56 | - // insert |
|
| 57 | - $statement = $this->dbObject->prepare("INSERT INTO `geolocation` (address, data) VALUES (:address, :data) ON DUPLICATE KEY UPDATE address = address;"); |
|
| 58 | - |
|
| 59 | - $statement->bindValue(":address", $this->address); |
|
| 60 | - $statement->bindValue(":data", $this->data); |
|
| 61 | - |
|
| 62 | - if ($statement->execute()) { |
|
| 63 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 64 | - } |
|
| 65 | - else { |
|
| 66 | - throw new Exception($statement->errorInfo()); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - else { |
|
| 70 | - // update |
|
| 71 | - $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 | + * @param bool $forUpdate |
|
| 32 | + * @return GeoLocation |
|
| 33 | + */ |
|
| 34 | + public static function getByAddress($address, PdoDatabase $database, $forUpdate = false) |
|
| 35 | + { |
|
| 36 | + $lockMode = $forUpdate ? ' FOR UPDATE' : ''; |
|
| 37 | + $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1" . $lockMode; |
|
| 38 | + |
|
| 39 | + $statement = $database->prepare($sql); |
|
| 40 | + $statement->bindValue(":id", $address); |
|
| 41 | + |
|
| 42 | + $statement->execute(); |
|
| 43 | + |
|
| 44 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
| 45 | + |
|
| 46 | + if ($resultObject != false) { |
|
| 47 | + $resultObject->setDatabase($database); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + return $resultObject; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function save() |
|
| 54 | + { |
|
| 55 | + if ($this->isNew()) { |
|
| 56 | + // insert |
|
| 57 | + $statement = $this->dbObject->prepare("INSERT INTO `geolocation` (address, data) VALUES (:address, :data) ON DUPLICATE KEY UPDATE address = address;"); |
|
| 58 | + |
|
| 59 | + $statement->bindValue(":address", $this->address); |
|
| 60 | + $statement->bindValue(":data", $this->data); |
|
| 61 | + |
|
| 62 | + if ($statement->execute()) { |
|
| 63 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 64 | + } |
|
| 65 | + else { |
|
| 66 | + throw new Exception($statement->errorInfo()); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + else { |
|
| 70 | + // update |
|
| 71 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 72 | 72 | UPDATE `geolocation` |
| 73 | 73 | SET address = :address, data = :data, updateversion = updateversion + 1 |
| 74 | 74 | WHERE id = :id AND updateversion = :updateversion; |
| 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 | } |