@@ -25,150 +25,150 @@ |
||
| 25 | 25 | |
| 26 | 26 | abstract class ApplicationBase |
| 27 | 27 | { |
| 28 | - private $configuration; |
|
| 29 | - |
|
| 30 | - public function __construct(SiteConfiguration $configuration) |
|
| 31 | - { |
|
| 32 | - $this->configuration = $configuration; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Application entry point. |
|
| 37 | - * |
|
| 38 | - * Sets up the environment and runs the application, performing any global cleanup operations when done. |
|
| 39 | - */ |
|
| 40 | - public function run() |
|
| 41 | - { |
|
| 42 | - try { |
|
| 43 | - if ($this->setupEnvironment()) { |
|
| 44 | - $this->main(); |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - catch (Exception $ex) { |
|
| 48 | - print $ex->getMessage(); |
|
| 49 | - } |
|
| 50 | - finally { |
|
| 51 | - $this->cleanupEnvironment(); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Environment setup |
|
| 57 | - * |
|
| 58 | - * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
| 59 | - * and shut down prematurely. |
|
| 60 | - * |
|
| 61 | - * @return bool |
|
| 62 | - * @throws EnvironmentException |
|
| 63 | - */ |
|
| 64 | - protected function setupEnvironment() |
|
| 65 | - { |
|
| 66 | - $this->setupDatabase(); |
|
| 67 | - |
|
| 68 | - return true; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return PdoDatabase |
|
| 73 | - * @throws EnvironmentException |
|
| 74 | - * @throws Exception |
|
| 75 | - */ |
|
| 76 | - protected function setupDatabase() |
|
| 77 | - { |
|
| 78 | - // check the schema version |
|
| 79 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
| 80 | - |
|
| 81 | - $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn(); |
|
| 82 | - if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) { |
|
| 83 | - throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.'); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return $database; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @return SiteConfiguration |
|
| 91 | - */ |
|
| 92 | - public function getConfiguration() |
|
| 93 | - { |
|
| 94 | - return $this->configuration; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Main application logic |
|
| 99 | - * @return void |
|
| 100 | - */ |
|
| 101 | - abstract protected function main(); |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Any cleanup tasks should go here |
|
| 105 | - * |
|
| 106 | - * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
| 107 | - * This should *only* be for cleaning up, no logic should go here. |
|
| 108 | - * |
|
| 109 | - * @return void |
|
| 110 | - */ |
|
| 111 | - abstract protected function cleanupEnvironment(); |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @param ITask $page |
|
| 115 | - * @param SiteConfiguration $siteConfiguration |
|
| 116 | - * @param PdoDatabase $database |
|
| 117 | - * @param PdoDatabase $notificationsDatabase |
|
| 118 | - * |
|
| 119 | - * @return void |
|
| 120 | - */ |
|
| 121 | - protected function setupHelpers( |
|
| 122 | - ITask $page, |
|
| 123 | - SiteConfiguration $siteConfiguration, |
|
| 124 | - PdoDatabase $database, |
|
| 125 | - PdoDatabase $notificationsDatabase = null |
|
| 126 | - ) { |
|
| 127 | - $page->setSiteConfiguration($siteConfiguration); |
|
| 128 | - |
|
| 129 | - // setup the global database object |
|
| 130 | - $page->setDatabase($database); |
|
| 131 | - |
|
| 132 | - // set up helpers and inject them into the page. |
|
| 133 | - $httpHelper = new HttpHelper($siteConfiguration); |
|
| 134 | - |
|
| 135 | - $page->setEmailHelper(new EmailHelper()); |
|
| 136 | - $page->setHttpHelper($httpHelper); |
|
| 137 | - $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper())); |
|
| 138 | - |
|
| 139 | - if ($siteConfiguration->getLocationProviderApiKey() === null) { |
|
| 140 | - $page->setLocationProvider(new FakeLocationProvider()); |
|
| 141 | - } |
|
| 142 | - else { |
|
| 143 | - $page->setLocationProvider( |
|
| 144 | - new IpLocationProvider( |
|
| 145 | - $database, |
|
| 146 | - $siteConfiguration->getLocationProviderApiKey(), |
|
| 147 | - $httpHelper |
|
| 148 | - )); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database)); |
|
| 152 | - |
|
| 153 | - $page->setRdnsProvider(new CachedRDnsLookupProvider($database)); |
|
| 154 | - |
|
| 155 | - $page->setAntiSpoofProvider(new CachedApiAntispoofProvider( |
|
| 156 | - $database, |
|
| 157 | - $this->getConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 158 | - $httpHelper)); |
|
| 159 | - |
|
| 160 | - $page->setOAuthProtocolHelper(new OAuthProtocolHelper( |
|
| 161 | - $siteConfiguration->getOAuthBaseUrl(), |
|
| 162 | - $siteConfiguration->getOAuthConsumerToken(), |
|
| 163 | - $siteConfiguration->getOAuthConsumerSecret(), |
|
| 164 | - $siteConfiguration->getMediawikiWebServiceEndpoint() |
|
| 165 | - )); |
|
| 166 | - |
|
| 167 | - $page->setNotificationHelper(new IrcNotificationHelper( |
|
| 168 | - $siteConfiguration, |
|
| 169 | - $database, |
|
| 170 | - $notificationsDatabase)); |
|
| 171 | - |
|
| 172 | - $page->setTorExitProvider(new TorExitProvider($database)); |
|
| 173 | - } |
|
| 28 | + private $configuration; |
|
| 29 | + |
|
| 30 | + public function __construct(SiteConfiguration $configuration) |
|
| 31 | + { |
|
| 32 | + $this->configuration = $configuration; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Application entry point. |
|
| 37 | + * |
|
| 38 | + * Sets up the environment and runs the application, performing any global cleanup operations when done. |
|
| 39 | + */ |
|
| 40 | + public function run() |
|
| 41 | + { |
|
| 42 | + try { |
|
| 43 | + if ($this->setupEnvironment()) { |
|
| 44 | + $this->main(); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + catch (Exception $ex) { |
|
| 48 | + print $ex->getMessage(); |
|
| 49 | + } |
|
| 50 | + finally { |
|
| 51 | + $this->cleanupEnvironment(); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Environment setup |
|
| 57 | + * |
|
| 58 | + * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
| 59 | + * and shut down prematurely. |
|
| 60 | + * |
|
| 61 | + * @return bool |
|
| 62 | + * @throws EnvironmentException |
|
| 63 | + */ |
|
| 64 | + protected function setupEnvironment() |
|
| 65 | + { |
|
| 66 | + $this->setupDatabase(); |
|
| 67 | + |
|
| 68 | + return true; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return PdoDatabase |
|
| 73 | + * @throws EnvironmentException |
|
| 74 | + * @throws Exception |
|
| 75 | + */ |
|
| 76 | + protected function setupDatabase() |
|
| 77 | + { |
|
| 78 | + // check the schema version |
|
| 79 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
| 80 | + |
|
| 81 | + $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn(); |
|
| 82 | + if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) { |
|
| 83 | + throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.'); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return $database; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @return SiteConfiguration |
|
| 91 | + */ |
|
| 92 | + public function getConfiguration() |
|
| 93 | + { |
|
| 94 | + return $this->configuration; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Main application logic |
|
| 99 | + * @return void |
|
| 100 | + */ |
|
| 101 | + abstract protected function main(); |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Any cleanup tasks should go here |
|
| 105 | + * |
|
| 106 | + * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
| 107 | + * This should *only* be for cleaning up, no logic should go here. |
|
| 108 | + * |
|
| 109 | + * @return void |
|
| 110 | + */ |
|
| 111 | + abstract protected function cleanupEnvironment(); |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @param ITask $page |
|
| 115 | + * @param SiteConfiguration $siteConfiguration |
|
| 116 | + * @param PdoDatabase $database |
|
| 117 | + * @param PdoDatabase $notificationsDatabase |
|
| 118 | + * |
|
| 119 | + * @return void |
|
| 120 | + */ |
|
| 121 | + protected function setupHelpers( |
|
| 122 | + ITask $page, |
|
| 123 | + SiteConfiguration $siteConfiguration, |
|
| 124 | + PdoDatabase $database, |
|
| 125 | + PdoDatabase $notificationsDatabase = null |
|
| 126 | + ) { |
|
| 127 | + $page->setSiteConfiguration($siteConfiguration); |
|
| 128 | + |
|
| 129 | + // setup the global database object |
|
| 130 | + $page->setDatabase($database); |
|
| 131 | + |
|
| 132 | + // set up helpers and inject them into the page. |
|
| 133 | + $httpHelper = new HttpHelper($siteConfiguration); |
|
| 134 | + |
|
| 135 | + $page->setEmailHelper(new EmailHelper()); |
|
| 136 | + $page->setHttpHelper($httpHelper); |
|
| 137 | + $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper())); |
|
| 138 | + |
|
| 139 | + if ($siteConfiguration->getLocationProviderApiKey() === null) { |
|
| 140 | + $page->setLocationProvider(new FakeLocationProvider()); |
|
| 141 | + } |
|
| 142 | + else { |
|
| 143 | + $page->setLocationProvider( |
|
| 144 | + new IpLocationProvider( |
|
| 145 | + $database, |
|
| 146 | + $siteConfiguration->getLocationProviderApiKey(), |
|
| 147 | + $httpHelper |
|
| 148 | + )); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database)); |
|
| 152 | + |
|
| 153 | + $page->setRdnsProvider(new CachedRDnsLookupProvider($database)); |
|
| 154 | + |
|
| 155 | + $page->setAntiSpoofProvider(new CachedApiAntispoofProvider( |
|
| 156 | + $database, |
|
| 157 | + $this->getConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 158 | + $httpHelper)); |
|
| 159 | + |
|
| 160 | + $page->setOAuthProtocolHelper(new OAuthProtocolHelper( |
|
| 161 | + $siteConfiguration->getOAuthBaseUrl(), |
|
| 162 | + $siteConfiguration->getOAuthConsumerToken(), |
|
| 163 | + $siteConfiguration->getOAuthConsumerSecret(), |
|
| 164 | + $siteConfiguration->getMediawikiWebServiceEndpoint() |
|
| 165 | + )); |
|
| 166 | + |
|
| 167 | + $page->setNotificationHelper(new IrcNotificationHelper( |
|
| 168 | + $siteConfiguration, |
|
| 169 | + $database, |
|
| 170 | + $notificationsDatabase)); |
|
| 171 | + |
|
| 172 | + $page->setTorExitProvider(new TorExitProvider($database)); |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -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 | } |
@@ -21,31 +21,31 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class Request extends DataObject |
| 23 | 23 | { |
| 24 | - private $email; |
|
| 25 | - private $ip; |
|
| 26 | - private $name; |
|
| 27 | - /** @var string|null */ |
|
| 28 | - private $comment; |
|
| 29 | - private $status = "Open"; |
|
| 30 | - private $date; |
|
| 31 | - private $emailsent = 0; |
|
| 32 | - private $emailconfirm; |
|
| 33 | - /** @var int|null */ |
|
| 34 | - private $reserved = null; |
|
| 35 | - private $useragent; |
|
| 36 | - private $forwardedip; |
|
| 37 | - private $hasComments = false; |
|
| 38 | - private $hasCommentsResolved = false; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @throws Exception |
|
| 42 | - * @throws OptimisticLockFailedException |
|
| 43 | - */ |
|
| 44 | - public function save() |
|
| 45 | - { |
|
| 46 | - if ($this->isNew()) { |
|
| 47 | - // insert |
|
| 48 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 24 | + private $email; |
|
| 25 | + private $ip; |
|
| 26 | + private $name; |
|
| 27 | + /** @var string|null */ |
|
| 28 | + private $comment; |
|
| 29 | + private $status = "Open"; |
|
| 30 | + private $date; |
|
| 31 | + private $emailsent = 0; |
|
| 32 | + private $emailconfirm; |
|
| 33 | + /** @var int|null */ |
|
| 34 | + private $reserved = null; |
|
| 35 | + private $useragent; |
|
| 36 | + private $forwardedip; |
|
| 37 | + private $hasComments = false; |
|
| 38 | + private $hasCommentsResolved = false; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @throws Exception |
|
| 42 | + * @throws OptimisticLockFailedException |
|
| 43 | + */ |
|
| 44 | + public function save() |
|
| 45 | + { |
|
| 46 | + if ($this->isNew()) { |
|
| 47 | + // insert |
|
| 48 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 49 | 49 | INSERT INTO `request` ( |
| 50 | 50 | email, ip, name, comment, status, date, emailsent, |
| 51 | 51 | emailconfirm, reserved, useragent, forwardedip |
@@ -54,28 +54,28 @@ discard block |
||
| 54 | 54 | :emailconfirm, :reserved, :useragent, :forwardedip |
| 55 | 55 | ); |
| 56 | 56 | SQL |
| 57 | - ); |
|
| 58 | - $statement->bindValue(':email', $this->email); |
|
| 59 | - $statement->bindValue(':ip', $this->ip); |
|
| 60 | - $statement->bindValue(':name', $this->name); |
|
| 61 | - $statement->bindValue(':comment', $this->comment); |
|
| 62 | - $statement->bindValue(':status', $this->status); |
|
| 63 | - $statement->bindValue(':emailsent', $this->emailsent); |
|
| 64 | - $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
| 65 | - $statement->bindValue(':reserved', $this->reserved); |
|
| 66 | - $statement->bindValue(':useragent', $this->useragent); |
|
| 67 | - $statement->bindValue(':forwardedip', $this->forwardedip); |
|
| 68 | - |
|
| 69 | - if ($statement->execute()) { |
|
| 70 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 71 | - } |
|
| 72 | - else { |
|
| 73 | - throw new Exception($statement->errorInfo()); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - else { |
|
| 77 | - // update |
|
| 78 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 57 | + ); |
|
| 58 | + $statement->bindValue(':email', $this->email); |
|
| 59 | + $statement->bindValue(':ip', $this->ip); |
|
| 60 | + $statement->bindValue(':name', $this->name); |
|
| 61 | + $statement->bindValue(':comment', $this->comment); |
|
| 62 | + $statement->bindValue(':status', $this->status); |
|
| 63 | + $statement->bindValue(':emailsent', $this->emailsent); |
|
| 64 | + $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
| 65 | + $statement->bindValue(':reserved', $this->reserved); |
|
| 66 | + $statement->bindValue(':useragent', $this->useragent); |
|
| 67 | + $statement->bindValue(':forwardedip', $this->forwardedip); |
|
| 68 | + |
|
| 69 | + if ($statement->execute()) { |
|
| 70 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 71 | + } |
|
| 72 | + else { |
|
| 73 | + throw new Exception($statement->errorInfo()); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + else { |
|
| 77 | + // update |
|
| 78 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 79 | 79 | UPDATE `request` SET |
| 80 | 80 | status = :status, |
| 81 | 81 | emailsent = :emailsent, |
@@ -84,163 +84,163 @@ discard block |
||
| 84 | 84 | updateversion = updateversion + 1 |
| 85 | 85 | WHERE id = :id AND updateversion = :updateversion; |
| 86 | 86 | SQL |
| 87 | - ); |
|
| 88 | - |
|
| 89 | - $statement->bindValue(':id', $this->id); |
|
| 90 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 91 | - |
|
| 92 | - $statement->bindValue(':status', $this->status); |
|
| 93 | - $statement->bindValue(':emailsent', $this->emailsent); |
|
| 94 | - $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
| 95 | - $statement->bindValue(':reserved', $this->reserved); |
|
| 96 | - |
|
| 97 | - if (!$statement->execute()) { |
|
| 98 | - throw new Exception($statement->errorInfo()); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ($statement->rowCount() !== 1) { |
|
| 102 | - throw new OptimisticLockFailedException(); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $this->updateversion++; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function getIp() |
|
| 113 | - { |
|
| 114 | - return $this->ip; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @param string $ip |
|
| 119 | - */ |
|
| 120 | - public function setIp($ip) |
|
| 121 | - { |
|
| 122 | - $this->ip = $ip; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - public function getName() |
|
| 129 | - { |
|
| 130 | - return $this->name; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param string $name |
|
| 135 | - */ |
|
| 136 | - public function setName($name) |
|
| 137 | - { |
|
| 138 | - $this->name = $name; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return string|null |
|
| 143 | - */ |
|
| 144 | - public function getComment() |
|
| 145 | - { |
|
| 146 | - return $this->comment; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $comment |
|
| 151 | - */ |
|
| 152 | - public function setComment($comment) |
|
| 153 | - { |
|
| 154 | - $this->comment = $comment; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - public function getStatus() |
|
| 161 | - { |
|
| 162 | - return $this->status; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param string $status |
|
| 167 | - */ |
|
| 168 | - public function setStatus($status) |
|
| 169 | - { |
|
| 170 | - $this->status = $status; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Returns the time the request was first submitted |
|
| 175 | - * |
|
| 176 | - * @return DateTimeImmutable |
|
| 177 | - */ |
|
| 178 | - public function getDate() |
|
| 179 | - { |
|
| 180 | - return new DateTimeImmutable($this->date); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * @return bool |
|
| 185 | - */ |
|
| 186 | - public function getEmailSent() |
|
| 187 | - { |
|
| 188 | - return $this->emailsent == "1"; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @param bool $emailSent |
|
| 193 | - */ |
|
| 194 | - public function setEmailSent($emailSent) |
|
| 195 | - { |
|
| 196 | - $this->emailsent = $emailSent ? 1 : 0; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @return int|null |
|
| 201 | - */ |
|
| 202 | - public function getReserved() |
|
| 203 | - { |
|
| 204 | - return $this->reserved; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * @param int|null $reserved |
|
| 209 | - */ |
|
| 210 | - public function setReserved($reserved) |
|
| 211 | - { |
|
| 212 | - $this->reserved = $reserved; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function getUserAgent() |
|
| 219 | - { |
|
| 220 | - return $this->useragent; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @param string $useragent |
|
| 225 | - */ |
|
| 226 | - public function setUserAgent($useragent) |
|
| 227 | - { |
|
| 228 | - $this->useragent = $useragent; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @return string|null |
|
| 233 | - */ |
|
| 234 | - public function getForwardedIp() |
|
| 235 | - { |
|
| 236 | - return $this->forwardedip; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * @param string|null $forwardedip |
|
| 241 | - */ |
|
| 242 | - public function setForwardedIp($forwardedip) |
|
| 243 | - { |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + $statement->bindValue(':id', $this->id); |
|
| 90 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 91 | + |
|
| 92 | + $statement->bindValue(':status', $this->status); |
|
| 93 | + $statement->bindValue(':emailsent', $this->emailsent); |
|
| 94 | + $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
| 95 | + $statement->bindValue(':reserved', $this->reserved); |
|
| 96 | + |
|
| 97 | + if (!$statement->execute()) { |
|
| 98 | + throw new Exception($statement->errorInfo()); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ($statement->rowCount() !== 1) { |
|
| 102 | + throw new OptimisticLockFailedException(); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $this->updateversion++; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function getIp() |
|
| 113 | + { |
|
| 114 | + return $this->ip; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @param string $ip |
|
| 119 | + */ |
|
| 120 | + public function setIp($ip) |
|
| 121 | + { |
|
| 122 | + $this->ip = $ip; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + public function getName() |
|
| 129 | + { |
|
| 130 | + return $this->name; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param string $name |
|
| 135 | + */ |
|
| 136 | + public function setName($name) |
|
| 137 | + { |
|
| 138 | + $this->name = $name; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @return string|null |
|
| 143 | + */ |
|
| 144 | + public function getComment() |
|
| 145 | + { |
|
| 146 | + return $this->comment; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param string $comment |
|
| 151 | + */ |
|
| 152 | + public function setComment($comment) |
|
| 153 | + { |
|
| 154 | + $this->comment = $comment; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + public function getStatus() |
|
| 161 | + { |
|
| 162 | + return $this->status; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param string $status |
|
| 167 | + */ |
|
| 168 | + public function setStatus($status) |
|
| 169 | + { |
|
| 170 | + $this->status = $status; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Returns the time the request was first submitted |
|
| 175 | + * |
|
| 176 | + * @return DateTimeImmutable |
|
| 177 | + */ |
|
| 178 | + public function getDate() |
|
| 179 | + { |
|
| 180 | + return new DateTimeImmutable($this->date); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * @return bool |
|
| 185 | + */ |
|
| 186 | + public function getEmailSent() |
|
| 187 | + { |
|
| 188 | + return $this->emailsent == "1"; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @param bool $emailSent |
|
| 193 | + */ |
|
| 194 | + public function setEmailSent($emailSent) |
|
| 195 | + { |
|
| 196 | + $this->emailsent = $emailSent ? 1 : 0; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @return int|null |
|
| 201 | + */ |
|
| 202 | + public function getReserved() |
|
| 203 | + { |
|
| 204 | + return $this->reserved; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * @param int|null $reserved |
|
| 209 | + */ |
|
| 210 | + public function setReserved($reserved) |
|
| 211 | + { |
|
| 212 | + $this->reserved = $reserved; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function getUserAgent() |
|
| 219 | + { |
|
| 220 | + return $this->useragent; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @param string $useragent |
|
| 225 | + */ |
|
| 226 | + public function setUserAgent($useragent) |
|
| 227 | + { |
|
| 228 | + $this->useragent = $useragent; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @return string|null |
|
| 233 | + */ |
|
| 234 | + public function getForwardedIp() |
|
| 235 | + { |
|
| 236 | + return $this->forwardedip; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * @param string|null $forwardedip |
|
| 241 | + */ |
|
| 242 | + public function setForwardedIp($forwardedip) |
|
| 243 | + { |
|
| 244 | 244 | // Verify that the XFF chain only contains valid IP addresses, and silently discard anything that isn't. |
| 245 | 245 | |
| 246 | 246 | $xff = explode(',', $forwardedip); |
@@ -254,83 +254,83 @@ discard block |
||
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | $this->forwardedip = implode(", ", $valid); |
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return bool |
|
| 261 | - */ |
|
| 262 | - public function hasComments() |
|
| 263 | - { |
|
| 264 | - if ($this->hasCommentsResolved) { |
|
| 265 | - return $this->hasComments; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - if ($this->comment != "") { |
|
| 269 | - $this->hasComments = true; |
|
| 270 | - $this->hasCommentsResolved = true; |
|
| 271 | - |
|
| 272 | - return true; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;"); |
|
| 276 | - $commentsQuery->bindValue(":id", $this->id); |
|
| 277 | - |
|
| 278 | - $commentsQuery->execute(); |
|
| 279 | - |
|
| 280 | - $this->hasComments = ($commentsQuery->fetchColumn() != 0); |
|
| 281 | - $this->hasCommentsResolved = true; |
|
| 282 | - |
|
| 283 | - return $this->hasComments; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @return string |
|
| 288 | - */ |
|
| 289 | - public function getEmailConfirm() |
|
| 290 | - { |
|
| 291 | - return $this->emailconfirm; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @param string $emailconfirm |
|
| 296 | - */ |
|
| 297 | - public function setEmailConfirm($emailconfirm) |
|
| 298 | - { |
|
| 299 | - $this->emailconfirm = $emailconfirm; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - public function generateEmailConfirmationHash() |
|
| 303 | - { |
|
| 304 | - $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16)); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * @return string|null |
|
| 309 | - */ |
|
| 310 | - public function getEmail() |
|
| 311 | - { |
|
| 312 | - return $this->email; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * @param string|null $email |
|
| 317 | - */ |
|
| 318 | - public function setEmail($email) |
|
| 319 | - { |
|
| 320 | - $this->email = $email; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @return string |
|
| 325 | - * @throws Exception |
|
| 326 | - */ |
|
| 327 | - public function getClosureReason() |
|
| 328 | - { |
|
| 329 | - if ($this->status != 'Closed') { |
|
| 330 | - throw new Exception("Can't get closure reason for open request."); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return bool |
|
| 261 | + */ |
|
| 262 | + public function hasComments() |
|
| 263 | + { |
|
| 264 | + if ($this->hasCommentsResolved) { |
|
| 265 | + return $this->hasComments; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + if ($this->comment != "") { |
|
| 269 | + $this->hasComments = true; |
|
| 270 | + $this->hasCommentsResolved = true; |
|
| 271 | + |
|
| 272 | + return true; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;"); |
|
| 276 | + $commentsQuery->bindValue(":id", $this->id); |
|
| 277 | + |
|
| 278 | + $commentsQuery->execute(); |
|
| 279 | + |
|
| 280 | + $this->hasComments = ($commentsQuery->fetchColumn() != 0); |
|
| 281 | + $this->hasCommentsResolved = true; |
|
| 282 | + |
|
| 283 | + return $this->hasComments; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @return string |
|
| 288 | + */ |
|
| 289 | + public function getEmailConfirm() |
|
| 290 | + { |
|
| 291 | + return $this->emailconfirm; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @param string $emailconfirm |
|
| 296 | + */ |
|
| 297 | + public function setEmailConfirm($emailconfirm) |
|
| 298 | + { |
|
| 299 | + $this->emailconfirm = $emailconfirm; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + public function generateEmailConfirmationHash() |
|
| 303 | + { |
|
| 304 | + $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16)); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * @return string|null |
|
| 309 | + */ |
|
| 310 | + public function getEmail() |
|
| 311 | + { |
|
| 312 | + return $this->email; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * @param string|null $email |
|
| 317 | + */ |
|
| 318 | + public function setEmail($email) |
|
| 319 | + { |
|
| 320 | + $this->email = $email; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @return string |
|
| 325 | + * @throws Exception |
|
| 326 | + */ |
|
| 327 | + public function getClosureReason() |
|
| 328 | + { |
|
| 329 | + if ($this->status != 'Closed') { |
|
| 330 | + throw new Exception("Can't get closure reason for open request."); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 334 | 334 | SELECT closes.mail_desc |
| 335 | 335 | FROM log |
| 336 | 336 | INNER JOIN closes ON log.action = closes.closes |
@@ -340,25 +340,25 @@ discard block |
||
| 340 | 340 | ORDER BY log.timestamp DESC |
| 341 | 341 | LIMIT 1; |
| 342 | 342 | SQL |
| 343 | - ); |
|
| 344 | - |
|
| 345 | - $statement->bindValue(":requestId", $this->id); |
|
| 346 | - $statement->execute(); |
|
| 347 | - $reason = $statement->fetchColumn(); |
|
| 348 | - |
|
| 349 | - return $reason; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Gets a value indicating whether the request was closed as created or not. |
|
| 354 | - */ |
|
| 355 | - public function getWasCreated() |
|
| 356 | - { |
|
| 357 | - if ($this->status != 'Closed') { |
|
| 358 | - throw new Exception("Can't get closure reason for open request."); |
|
| 359 | - } |
|
| 343 | + ); |
|
| 344 | + |
|
| 345 | + $statement->bindValue(":requestId", $this->id); |
|
| 346 | + $statement->execute(); |
|
| 347 | + $reason = $statement->fetchColumn(); |
|
| 348 | + |
|
| 349 | + return $reason; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Gets a value indicating whether the request was closed as created or not. |
|
| 354 | + */ |
|
| 355 | + public function getWasCreated() |
|
| 356 | + { |
|
| 357 | + if ($this->status != 'Closed') { |
|
| 358 | + throw new Exception("Can't get closure reason for open request."); |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 361 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 362 | 362 | SELECT emailtemplate.oncreated, log.action |
| 363 | 363 | FROM log |
| 364 | 364 | LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action |
@@ -368,60 +368,60 @@ discard block |
||
| 368 | 368 | ORDER BY log.timestamp DESC |
| 369 | 369 | LIMIT 1; |
| 370 | 370 | SQL |
| 371 | - ); |
|
| 372 | - |
|
| 373 | - $statement->bindValue(":requestId", $this->id); |
|
| 374 | - $statement->execute(); |
|
| 375 | - $onCreated = $statement->fetchColumn(0); |
|
| 376 | - $logAction = $statement->fetchColumn(1); |
|
| 377 | - $statement->closeCursor(); |
|
| 378 | - |
|
| 379 | - if ($onCreated === null) { |
|
| 380 | - return $logAction === "Closed custom-y"; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - return (bool)$onCreated; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * @return DateTime |
|
| 388 | - */ |
|
| 389 | - public function getClosureDate() |
|
| 390 | - { |
|
| 391 | - $logQuery = $this->dbObject->prepare(<<<SQL |
|
| 371 | + ); |
|
| 372 | + |
|
| 373 | + $statement->bindValue(":requestId", $this->id); |
|
| 374 | + $statement->execute(); |
|
| 375 | + $onCreated = $statement->fetchColumn(0); |
|
| 376 | + $logAction = $statement->fetchColumn(1); |
|
| 377 | + $statement->closeCursor(); |
|
| 378 | + |
|
| 379 | + if ($onCreated === null) { |
|
| 380 | + return $logAction === "Closed custom-y"; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + return (bool)$onCreated; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * @return DateTime |
|
| 388 | + */ |
|
| 389 | + public function getClosureDate() |
|
| 390 | + { |
|
| 391 | + $logQuery = $this->dbObject->prepare(<<<SQL |
|
| 392 | 392 | SELECT timestamp FROM log |
| 393 | 393 | WHERE objectid = :request AND objecttype = 'Request' AND action LIKE 'Closed%' |
| 394 | 394 | ORDER BY timestamp DESC LIMIT 1; |
| 395 | 395 | SQL |
| 396 | - ); |
|
| 397 | - $logQuery->bindValue(":request", $this->getId()); |
|
| 398 | - $logQuery->execute(); |
|
| 399 | - $logTime = $logQuery->fetchColumn(); |
|
| 400 | - $logQuery->closeCursor(); |
|
| 401 | - |
|
| 402 | - return new DateTime($logTime); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal |
|
| 407 | - * data to unauthorised* users. |
|
| 408 | - * |
|
| 409 | - * *:Not tool admins, check users, or the reserving user. |
|
| 410 | - * |
|
| 411 | - * @return string |
|
| 412 | - * |
|
| 413 | - * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events? |
|
| 414 | - * Maybe depend on the last logged action timestamp? |
|
| 415 | - */ |
|
| 416 | - public function getRevealHash() |
|
| 417 | - { |
|
| 418 | - $data = $this->id // unique per request |
|
| 419 | - . '|' . $this->ip // } |
|
| 420 | - . '|' . $this->forwardedip // } private data not known to those without access |
|
| 421 | - . '|' . $this->useragent // } |
|
| 422 | - . '|' . $this->email // } |
|
| 423 | - . '|' . $this->status; // to rudimentarily invalidate the token on status change |
|
| 424 | - |
|
| 425 | - return hash('sha256', $data); |
|
| 426 | - } |
|
| 396 | + ); |
|
| 397 | + $logQuery->bindValue(":request", $this->getId()); |
|
| 398 | + $logQuery->execute(); |
|
| 399 | + $logTime = $logQuery->fetchColumn(); |
|
| 400 | + $logQuery->closeCursor(); |
|
| 401 | + |
|
| 402 | + return new DateTime($logTime); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal |
|
| 407 | + * data to unauthorised* users. |
|
| 408 | + * |
|
| 409 | + * *:Not tool admins, check users, or the reserving user. |
|
| 410 | + * |
|
| 411 | + * @return string |
|
| 412 | + * |
|
| 413 | + * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events? |
|
| 414 | + * Maybe depend on the last logged action timestamp? |
|
| 415 | + */ |
|
| 416 | + public function getRevealHash() |
|
| 417 | + { |
|
| 418 | + $data = $this->id // unique per request |
|
| 419 | + . '|' . $this->ip // } |
|
| 420 | + . '|' . $this->forwardedip // } private data not known to those without access |
|
| 421 | + . '|' . $this->useragent // } |
|
| 422 | + . '|' . $this->email // } |
|
| 423 | + . '|' . $this->status; // to rudimentarily invalidate the token on status change |
|
| 424 | + |
|
| 425 | + return hash('sha256', $data); |
|
| 426 | + } |
|
| 427 | 427 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | class JobQueue extends DataObject |
| 19 | 19 | { |
| 20 | - /* |
|
| 20 | + /* |
|
| 21 | 21 | * Status workflow is this: |
| 22 | 22 | * |
| 23 | 23 | * 1) Ready. The job has been added to the queue |
@@ -26,78 +26,78 @@ discard block |
||
| 26 | 26 | * 3) Complete / Failed. The job has been processed |
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | - const STATUS_READY = 'ready'; |
|
| 30 | - const STATUS_WAITING = 'waiting'; |
|
| 31 | - const STATUS_RUNNING = 'running'; |
|
| 32 | - const STATUS_COMPLETE = 'complete'; |
|
| 33 | - const STATUS_CANCELLED = 'cancelled'; |
|
| 34 | - const STATUS_FAILED = 'failed'; |
|
| 35 | - const STATUS_HELD = 'held'; |
|
| 36 | - |
|
| 37 | - /** @var string */ |
|
| 38 | - private $task; |
|
| 39 | - /** @var int */ |
|
| 40 | - private $user; |
|
| 41 | - /** @var int */ |
|
| 42 | - private $request; |
|
| 43 | - /** @var int */ |
|
| 44 | - private $emailtemplate; |
|
| 45 | - /** @var string */ |
|
| 46 | - private $status; |
|
| 47 | - /** @var string */ |
|
| 48 | - private $enqueue; |
|
| 49 | - /** @var string */ |
|
| 50 | - private $parameters; |
|
| 51 | - /** @var string */ |
|
| 52 | - private $error; |
|
| 53 | - /** @var int */ |
|
| 54 | - private $acknowledged; |
|
| 55 | - /** @var int */ |
|
| 56 | - private $parent; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * This feels like the least bad place to put this method. |
|
| 60 | - */ |
|
| 61 | - public static function getTaskDescriptions() { |
|
| 62 | - return array( |
|
| 63 | - BotCreationTask::class => 'Create account (via bot)', |
|
| 64 | - UserCreationTask::class => 'Create account (via OAuth)', |
|
| 65 | - WelcomeUserTask::class => 'Welcome user', |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Saves a data object to the database, either updating or inserting a record. |
|
| 71 | - * @return void |
|
| 72 | - * @throws Exception |
|
| 73 | - * @throws OptimisticLockFailedException |
|
| 74 | - */ |
|
| 75 | - public function save() |
|
| 76 | - { |
|
| 77 | - if ($this->isNew()) { |
|
| 78 | - // insert |
|
| 79 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 29 | + const STATUS_READY = 'ready'; |
|
| 30 | + const STATUS_WAITING = 'waiting'; |
|
| 31 | + const STATUS_RUNNING = 'running'; |
|
| 32 | + const STATUS_COMPLETE = 'complete'; |
|
| 33 | + const STATUS_CANCELLED = 'cancelled'; |
|
| 34 | + const STATUS_FAILED = 'failed'; |
|
| 35 | + const STATUS_HELD = 'held'; |
|
| 36 | + |
|
| 37 | + /** @var string */ |
|
| 38 | + private $task; |
|
| 39 | + /** @var int */ |
|
| 40 | + private $user; |
|
| 41 | + /** @var int */ |
|
| 42 | + private $request; |
|
| 43 | + /** @var int */ |
|
| 44 | + private $emailtemplate; |
|
| 45 | + /** @var string */ |
|
| 46 | + private $status; |
|
| 47 | + /** @var string */ |
|
| 48 | + private $enqueue; |
|
| 49 | + /** @var string */ |
|
| 50 | + private $parameters; |
|
| 51 | + /** @var string */ |
|
| 52 | + private $error; |
|
| 53 | + /** @var int */ |
|
| 54 | + private $acknowledged; |
|
| 55 | + /** @var int */ |
|
| 56 | + private $parent; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * This feels like the least bad place to put this method. |
|
| 60 | + */ |
|
| 61 | + public static function getTaskDescriptions() { |
|
| 62 | + return array( |
|
| 63 | + BotCreationTask::class => 'Create account (via bot)', |
|
| 64 | + UserCreationTask::class => 'Create account (via OAuth)', |
|
| 65 | + WelcomeUserTask::class => 'Welcome user', |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Saves a data object to the database, either updating or inserting a record. |
|
| 71 | + * @return void |
|
| 72 | + * @throws Exception |
|
| 73 | + * @throws OptimisticLockFailedException |
|
| 74 | + */ |
|
| 75 | + public function save() |
|
| 76 | + { |
|
| 77 | + if ($this->isNew()) { |
|
| 78 | + // insert |
|
| 79 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 80 | 80 | INSERT INTO jobqueue (task, user, request, emailtemplate, parameters, parent) |
| 81 | 81 | VALUES (:task, :user, :request, :emailtemplate, :parameters, :parent) |
| 82 | 82 | SQL |
| 83 | - ); |
|
| 84 | - $statement->bindValue(":task", $this->task); |
|
| 85 | - $statement->bindValue(":user", $this->user); |
|
| 86 | - $statement->bindValue(":request", $this->request); |
|
| 87 | - $statement->bindValue(":emailtemplate", $this->emailtemplate); |
|
| 88 | - $statement->bindValue(":parameters", $this->parameters); |
|
| 89 | - $statement->bindValue(":parent", $this->parent); |
|
| 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 | - // update |
|
| 100 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 83 | + ); |
|
| 84 | + $statement->bindValue(":task", $this->task); |
|
| 85 | + $statement->bindValue(":user", $this->user); |
|
| 86 | + $statement->bindValue(":request", $this->request); |
|
| 87 | + $statement->bindValue(":emailtemplate", $this->emailtemplate); |
|
| 88 | + $statement->bindValue(":parameters", $this->parameters); |
|
| 89 | + $statement->bindValue(":parent", $this->parent); |
|
| 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 | + // update |
|
| 100 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 101 | 101 | UPDATE jobqueue SET |
| 102 | 102 | status = :status |
| 103 | 103 | , error = :error |
@@ -105,187 +105,187 @@ discard block |
||
| 105 | 105 | , updateversion = updateversion + 1 |
| 106 | 106 | WHERE id = :id AND updateversion = :updateversion; |
| 107 | 107 | SQL |
| 108 | - ); |
|
| 109 | - |
|
| 110 | - $statement->bindValue(":id", $this->id); |
|
| 111 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
| 112 | - |
|
| 113 | - $statement->bindValue(":status", $this->status); |
|
| 114 | - $statement->bindValue(":error", $this->error); |
|
| 115 | - $statement->bindValue(":ack", $this->acknowledged); |
|
| 116 | - |
|
| 117 | - if (!$statement->execute()) { |
|
| 118 | - throw new Exception($statement->errorInfo()); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if ($statement->rowCount() !== 1) { |
|
| 122 | - throw new OptimisticLockFailedException(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $this->updateversion++; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - #region Properties |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - public function getTask() |
|
| 135 | - { |
|
| 136 | - return $this->task; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @param string $task |
|
| 141 | - */ |
|
| 142 | - public function setTask($task) |
|
| 143 | - { |
|
| 144 | - $this->task = $task; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @return int |
|
| 149 | - */ |
|
| 150 | - public function getTriggerUserId() |
|
| 151 | - { |
|
| 152 | - return $this->user; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param int $user |
|
| 157 | - */ |
|
| 158 | - public function setTriggerUserId($user) |
|
| 159 | - { |
|
| 160 | - $this->user = $user; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @return int |
|
| 165 | - */ |
|
| 166 | - public function getRequest() |
|
| 167 | - { |
|
| 168 | - return $this->request; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param int $request |
|
| 173 | - */ |
|
| 174 | - public function setRequest($request) |
|
| 175 | - { |
|
| 176 | - $this->request = $request; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - public function getStatus() |
|
| 183 | - { |
|
| 184 | - return $this->status; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @param string $status |
|
| 189 | - */ |
|
| 190 | - public function setStatus($status) |
|
| 191 | - { |
|
| 192 | - $this->status = $status; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @return string |
|
| 197 | - */ |
|
| 198 | - public function getEnqueue() |
|
| 199 | - { |
|
| 200 | - return $this->enqueue; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @param string $enqueue |
|
| 205 | - */ |
|
| 206 | - public function setEnqueue($enqueue) |
|
| 207 | - { |
|
| 208 | - $this->enqueue = $enqueue; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @return string |
|
| 213 | - */ |
|
| 214 | - public function getParameters() |
|
| 215 | - { |
|
| 216 | - return $this->parameters; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param string $parameters |
|
| 221 | - */ |
|
| 222 | - public function setParameters($parameters) |
|
| 223 | - { |
|
| 224 | - $this->parameters = $parameters; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @return mixed |
|
| 229 | - */ |
|
| 230 | - public function getError() |
|
| 231 | - { |
|
| 232 | - return $this->error; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @param mixed $error |
|
| 237 | - */ |
|
| 238 | - public function setError($error) |
|
| 239 | - { |
|
| 240 | - $this->error = $error; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @return int |
|
| 245 | - */ |
|
| 246 | - public function getAcknowledged() |
|
| 247 | - { |
|
| 248 | - return $this->acknowledged; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @param int $acknowledged |
|
| 253 | - */ |
|
| 254 | - public function setAcknowledged($acknowledged) |
|
| 255 | - { |
|
| 256 | - $this->acknowledged = $acknowledged; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return int |
|
| 261 | - */ |
|
| 262 | - public function getParent() |
|
| 263 | - { |
|
| 264 | - return $this->parent; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @param int $parent |
|
| 269 | - */ |
|
| 270 | - public function setParent($parent) |
|
| 271 | - { |
|
| 272 | - $this->parent = $parent; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @return int |
|
| 277 | - */ |
|
| 278 | - public function getEmailTemplate() |
|
| 279 | - { |
|
| 280 | - return $this->emailtemplate; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * @param int $emailTemplate |
|
| 285 | - */ |
|
| 286 | - public function setEmailTemplate($emailTemplate) |
|
| 287 | - { |
|
| 288 | - $this->emailtemplate = $emailTemplate; |
|
| 289 | - } |
|
| 290 | - #endregion |
|
| 108 | + ); |
|
| 109 | + |
|
| 110 | + $statement->bindValue(":id", $this->id); |
|
| 111 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
| 112 | + |
|
| 113 | + $statement->bindValue(":status", $this->status); |
|
| 114 | + $statement->bindValue(":error", $this->error); |
|
| 115 | + $statement->bindValue(":ack", $this->acknowledged); |
|
| 116 | + |
|
| 117 | + if (!$statement->execute()) { |
|
| 118 | + throw new Exception($statement->errorInfo()); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if ($statement->rowCount() !== 1) { |
|
| 122 | + throw new OptimisticLockFailedException(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $this->updateversion++; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + #region Properties |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + public function getTask() |
|
| 135 | + { |
|
| 136 | + return $this->task; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @param string $task |
|
| 141 | + */ |
|
| 142 | + public function setTask($task) |
|
| 143 | + { |
|
| 144 | + $this->task = $task; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @return int |
|
| 149 | + */ |
|
| 150 | + public function getTriggerUserId() |
|
| 151 | + { |
|
| 152 | + return $this->user; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param int $user |
|
| 157 | + */ |
|
| 158 | + public function setTriggerUserId($user) |
|
| 159 | + { |
|
| 160 | + $this->user = $user; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @return int |
|
| 165 | + */ |
|
| 166 | + public function getRequest() |
|
| 167 | + { |
|
| 168 | + return $this->request; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param int $request |
|
| 173 | + */ |
|
| 174 | + public function setRequest($request) |
|
| 175 | + { |
|
| 176 | + $this->request = $request; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + public function getStatus() |
|
| 183 | + { |
|
| 184 | + return $this->status; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @param string $status |
|
| 189 | + */ |
|
| 190 | + public function setStatus($status) |
|
| 191 | + { |
|
| 192 | + $this->status = $status; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @return string |
|
| 197 | + */ |
|
| 198 | + public function getEnqueue() |
|
| 199 | + { |
|
| 200 | + return $this->enqueue; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @param string $enqueue |
|
| 205 | + */ |
|
| 206 | + public function setEnqueue($enqueue) |
|
| 207 | + { |
|
| 208 | + $this->enqueue = $enqueue; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return string |
|
| 213 | + */ |
|
| 214 | + public function getParameters() |
|
| 215 | + { |
|
| 216 | + return $this->parameters; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param string $parameters |
|
| 221 | + */ |
|
| 222 | + public function setParameters($parameters) |
|
| 223 | + { |
|
| 224 | + $this->parameters = $parameters; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @return mixed |
|
| 229 | + */ |
|
| 230 | + public function getError() |
|
| 231 | + { |
|
| 232 | + return $this->error; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @param mixed $error |
|
| 237 | + */ |
|
| 238 | + public function setError($error) |
|
| 239 | + { |
|
| 240 | + $this->error = $error; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @return int |
|
| 245 | + */ |
|
| 246 | + public function getAcknowledged() |
|
| 247 | + { |
|
| 248 | + return $this->acknowledged; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @param int $acknowledged |
|
| 253 | + */ |
|
| 254 | + public function setAcknowledged($acknowledged) |
|
| 255 | + { |
|
| 256 | + $this->acknowledged = $acknowledged; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return int |
|
| 261 | + */ |
|
| 262 | + public function getParent() |
|
| 263 | + { |
|
| 264 | + return $this->parent; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @param int $parent |
|
| 269 | + */ |
|
| 270 | + public function setParent($parent) |
|
| 271 | + { |
|
| 272 | + $this->parent = $parent; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @return int |
|
| 277 | + */ |
|
| 278 | + public function getEmailTemplate() |
|
| 279 | + { |
|
| 280 | + return $this->emailtemplate; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * @param int $emailTemplate |
|
| 285 | + */ |
|
| 286 | + public function setEmailTemplate($emailTemplate) |
|
| 287 | + { |
|
| 288 | + $this->emailtemplate = $emailTemplate; |
|
| 289 | + } |
|
| 290 | + #endregion |
|
| 291 | 291 | } |
| 292 | 292 | \ No newline at end of file |
@@ -19,166 +19,166 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class WelcomeTemplate extends DataObject |
| 21 | 21 | { |
| 22 | - /** @var string */ |
|
| 23 | - private $usercode; |
|
| 24 | - /** @var string */ |
|
| 25 | - private $botcode; |
|
| 26 | - private $usageCache; |
|
| 27 | - private $deleted = 0; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Summary of getAll |
|
| 31 | - * |
|
| 32 | - * @param PdoDatabase $database |
|
| 33 | - * |
|
| 34 | - * @return WelcomeTemplate[] |
|
| 35 | - */ |
|
| 36 | - public static function getAll(PdoDatabase $database) |
|
| 37 | - { |
|
| 38 | - $statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0;"); |
|
| 39 | - |
|
| 40 | - $statement->execute(); |
|
| 41 | - |
|
| 42 | - $result = array(); |
|
| 43 | - /** @var WelcomeTemplate $v */ |
|
| 44 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) { |
|
| 45 | - $v->setDatabase($database); |
|
| 46 | - $result[] = $v; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - return $result; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @throws Exception |
|
| 54 | - */ |
|
| 55 | - public function save() |
|
| 56 | - { |
|
| 57 | - if ($this->isNew()) { |
|
| 58 | - // insert |
|
| 59 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 22 | + /** @var string */ |
|
| 23 | + private $usercode; |
|
| 24 | + /** @var string */ |
|
| 25 | + private $botcode; |
|
| 26 | + private $usageCache; |
|
| 27 | + private $deleted = 0; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Summary of getAll |
|
| 31 | + * |
|
| 32 | + * @param PdoDatabase $database |
|
| 33 | + * |
|
| 34 | + * @return WelcomeTemplate[] |
|
| 35 | + */ |
|
| 36 | + public static function getAll(PdoDatabase $database) |
|
| 37 | + { |
|
| 38 | + $statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0;"); |
|
| 39 | + |
|
| 40 | + $statement->execute(); |
|
| 41 | + |
|
| 42 | + $result = array(); |
|
| 43 | + /** @var WelcomeTemplate $v */ |
|
| 44 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) { |
|
| 45 | + $v->setDatabase($database); |
|
| 46 | + $result[] = $v; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + return $result; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @throws Exception |
|
| 54 | + */ |
|
| 55 | + public function save() |
|
| 56 | + { |
|
| 57 | + if ($this->isNew()) { |
|
| 58 | + // insert |
|
| 59 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 60 | 60 | INSERT INTO welcometemplate (usercode, botcode) VALUES (:usercode, :botcode); |
| 61 | 61 | SQL |
| 62 | - ); |
|
| 63 | - $statement->bindValue(":usercode", $this->usercode); |
|
| 64 | - $statement->bindValue(":botcode", $this->botcode); |
|
| 65 | - |
|
| 66 | - if ($statement->execute()) { |
|
| 67 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 68 | - } |
|
| 69 | - else { |
|
| 70 | - throw new Exception($statement->errorInfo()); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - else { |
|
| 74 | - // update |
|
| 75 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 62 | + ); |
|
| 63 | + $statement->bindValue(":usercode", $this->usercode); |
|
| 64 | + $statement->bindValue(":botcode", $this->botcode); |
|
| 65 | + |
|
| 66 | + if ($statement->execute()) { |
|
| 67 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 68 | + } |
|
| 69 | + else { |
|
| 70 | + throw new Exception($statement->errorInfo()); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + else { |
|
| 74 | + // update |
|
| 75 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 76 | 76 | UPDATE `welcometemplate` |
| 77 | 77 | SET usercode = :usercode, botcode = :botcode, updateversion = updateversion + 1 |
| 78 | 78 | WHERE id = :id AND updateversion = :updateversion; |
| 79 | 79 | SQL |
| 80 | - ); |
|
| 81 | - |
|
| 82 | - $statement->bindValue(':id', $this->id); |
|
| 83 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 84 | - |
|
| 85 | - $statement->bindValue(':usercode', $this->usercode); |
|
| 86 | - $statement->bindValue(':botcode', $this->botcode); |
|
| 87 | - |
|
| 88 | - if (!$statement->execute()) { |
|
| 89 | - throw new Exception($statement->errorInfo()); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if ($statement->rowCount() !== 1) { |
|
| 93 | - throw new OptimisticLockFailedException(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $this->updateversion++; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function getUserCode() |
|
| 104 | - { |
|
| 105 | - return $this->usercode; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param string $usercode |
|
| 110 | - */ |
|
| 111 | - public function setUserCode($usercode) |
|
| 112 | - { |
|
| 113 | - $this->usercode = $usercode; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @return string |
|
| 118 | - */ |
|
| 119 | - public function getBotCode() |
|
| 120 | - { |
|
| 121 | - return $this->botcode; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param string $botcode |
|
| 126 | - */ |
|
| 127 | - public function setBotCode($botcode) |
|
| 128 | - { |
|
| 129 | - $this->botcode = $botcode; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return User[] |
|
| 134 | - */ |
|
| 135 | - public function getUsersUsingTemplate() |
|
| 136 | - { |
|
| 137 | - if ($this->usageCache === null) { |
|
| 138 | - $statement = $this->dbObject->prepare("SELECT * FROM user WHERE welcome_template = :id;"); |
|
| 139 | - |
|
| 140 | - $statement->execute(array(":id" => $this->id)); |
|
| 141 | - |
|
| 142 | - $result = array(); |
|
| 143 | - /** @var WelcomeTemplate $v */ |
|
| 144 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) { |
|
| 145 | - $v->setDatabase($this->dbObject); |
|
| 146 | - $result[] = $v; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $this->usageCache = $result; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $this->usageCache; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Deletes the object from the database |
|
| 157 | - */ |
|
| 158 | - public function delete() |
|
| 159 | - { |
|
| 160 | - if ($this->id === null) { |
|
| 161 | - // wtf? |
|
| 162 | - return; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $deleteQuery = "UPDATE welcometemplate SET deleted = 1 WHERE id = :id AND updateversion = :updateversion;"; |
|
| 166 | - $statement = $this->dbObject->prepare($deleteQuery); |
|
| 167 | - |
|
| 168 | - $statement->bindValue(":id", $this->id); |
|
| 169 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
| 170 | - $statement->execute(); |
|
| 171 | - |
|
| 172 | - if ($statement->rowCount() !== 1) { |
|
| 173 | - throw new OptimisticLockFailedException(); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @return bool |
|
| 179 | - */ |
|
| 180 | - public function isDeleted() |
|
| 181 | - { |
|
| 182 | - return ((int)$this->deleted) === 1; |
|
| 183 | - } |
|
| 80 | + ); |
|
| 81 | + |
|
| 82 | + $statement->bindValue(':id', $this->id); |
|
| 83 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 84 | + |
|
| 85 | + $statement->bindValue(':usercode', $this->usercode); |
|
| 86 | + $statement->bindValue(':botcode', $this->botcode); |
|
| 87 | + |
|
| 88 | + if (!$statement->execute()) { |
|
| 89 | + throw new Exception($statement->errorInfo()); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if ($statement->rowCount() !== 1) { |
|
| 93 | + throw new OptimisticLockFailedException(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $this->updateversion++; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function getUserCode() |
|
| 104 | + { |
|
| 105 | + return $this->usercode; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param string $usercode |
|
| 110 | + */ |
|
| 111 | + public function setUserCode($usercode) |
|
| 112 | + { |
|
| 113 | + $this->usercode = $usercode; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @return string |
|
| 118 | + */ |
|
| 119 | + public function getBotCode() |
|
| 120 | + { |
|
| 121 | + return $this->botcode; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param string $botcode |
|
| 126 | + */ |
|
| 127 | + public function setBotCode($botcode) |
|
| 128 | + { |
|
| 129 | + $this->botcode = $botcode; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return User[] |
|
| 134 | + */ |
|
| 135 | + public function getUsersUsingTemplate() |
|
| 136 | + { |
|
| 137 | + if ($this->usageCache === null) { |
|
| 138 | + $statement = $this->dbObject->prepare("SELECT * FROM user WHERE welcome_template = :id;"); |
|
| 139 | + |
|
| 140 | + $statement->execute(array(":id" => $this->id)); |
|
| 141 | + |
|
| 142 | + $result = array(); |
|
| 143 | + /** @var WelcomeTemplate $v */ |
|
| 144 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) { |
|
| 145 | + $v->setDatabase($this->dbObject); |
|
| 146 | + $result[] = $v; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $this->usageCache = $result; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $this->usageCache; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Deletes the object from the database |
|
| 157 | + */ |
|
| 158 | + public function delete() |
|
| 159 | + { |
|
| 160 | + if ($this->id === null) { |
|
| 161 | + // wtf? |
|
| 162 | + return; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $deleteQuery = "UPDATE welcometemplate SET deleted = 1 WHERE id = :id AND updateversion = :updateversion;"; |
|
| 166 | + $statement = $this->dbObject->prepare($deleteQuery); |
|
| 167 | + |
|
| 168 | + $statement->bindValue(":id", $this->id); |
|
| 169 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
| 170 | + $statement->execute(); |
|
| 171 | + |
|
| 172 | + if ($statement->rowCount() !== 1) { |
|
| 173 | + throw new OptimisticLockFailedException(); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @return bool |
|
| 179 | + */ |
|
| 180 | + public function isDeleted() |
|
| 181 | + { |
|
| 182 | + return ((int)$this->deleted) === 1; |
|
| 183 | + } |
|
| 184 | 184 | } |