@@ -100,7 +100,7 @@ |
||
| 100 | 100 | |
| 101 | 101 | // casted to string because cast to float cause equality for non equal numbers |
| 102 | 102 | // and integer has the problem of limited size on 32 bit systems |
| 103 | - if ((string)$expectedSize !== (string)$actualSize) { |
|
| 103 | + if ((string) $expectedSize !== (string) $actualSize) { |
|
| 104 | 104 | throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -18,97 +18,97 @@ |
||
| 18 | 18 | |
| 19 | 19 | class ChunkingPlugin extends ServerPlugin { |
| 20 | 20 | |
| 21 | - /** @var Server */ |
|
| 22 | - private $server; |
|
| 23 | - /** @var FutureFile */ |
|
| 24 | - private $sourceNode; |
|
| 21 | + /** @var Server */ |
|
| 22 | + private $server; |
|
| 23 | + /** @var FutureFile */ |
|
| 24 | + private $sourceNode; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @inheritdoc |
|
| 28 | - */ |
|
| 29 | - public function initialize(Server $server) { |
|
| 30 | - $server->on('beforeMove', [$this, 'beforeMove']); |
|
| 31 | - $this->server = $server; |
|
| 32 | - } |
|
| 26 | + /** |
|
| 27 | + * @inheritdoc |
|
| 28 | + */ |
|
| 29 | + public function initialize(Server $server) { |
|
| 30 | + $server->on('beforeMove', [$this, 'beforeMove']); |
|
| 31 | + $this->server = $server; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param string $sourcePath source path |
|
| 36 | - * @param string $destination destination path |
|
| 37 | - * @return bool|void |
|
| 38 | - * @throws BadRequest |
|
| 39 | - * @throws NotFound |
|
| 40 | - */ |
|
| 41 | - public function beforeMove($sourcePath, $destination) { |
|
| 42 | - $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
| 43 | - if (!$this->sourceNode instanceof FutureFile) { |
|
| 44 | - // skip handling as the source is not a chunked FutureFile |
|
| 45 | - return; |
|
| 46 | - } |
|
| 34 | + /** |
|
| 35 | + * @param string $sourcePath source path |
|
| 36 | + * @param string $destination destination path |
|
| 37 | + * @return bool|void |
|
| 38 | + * @throws BadRequest |
|
| 39 | + * @throws NotFound |
|
| 40 | + */ |
|
| 41 | + public function beforeMove($sourcePath, $destination) { |
|
| 42 | + $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
| 43 | + if (!$this->sourceNode instanceof FutureFile) { |
|
| 44 | + // skip handling as the source is not a chunked FutureFile |
|
| 45 | + return; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - try { |
|
| 49 | - /** @var INode $destinationNode */ |
|
| 50 | - $destinationNode = $this->server->tree->getNodeForPath($destination); |
|
| 51 | - if ($destinationNode instanceof Directory) { |
|
| 52 | - throw new BadRequest("The given destination $destination is a directory."); |
|
| 53 | - } |
|
| 54 | - } catch (NotFound $e) { |
|
| 55 | - // If the destination does not exist yet it's not a directory either ;) |
|
| 56 | - } |
|
| 48 | + try { |
|
| 49 | + /** @var INode $destinationNode */ |
|
| 50 | + $destinationNode = $this->server->tree->getNodeForPath($destination); |
|
| 51 | + if ($destinationNode instanceof Directory) { |
|
| 52 | + throw new BadRequest("The given destination $destination is a directory."); |
|
| 53 | + } |
|
| 54 | + } catch (NotFound $e) { |
|
| 55 | + // If the destination does not exist yet it's not a directory either ;) |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $this->verifySize(); |
|
| 59 | - return $this->performMove($sourcePath, $destination); |
|
| 60 | - } |
|
| 58 | + $this->verifySize(); |
|
| 59 | + return $this->performMove($sourcePath, $destination); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Move handler for future file. |
|
| 64 | - * |
|
| 65 | - * This overrides the default move behavior to prevent Sabre |
|
| 66 | - * to delete the target file before moving. Because deleting would |
|
| 67 | - * lose the file id and metadata. |
|
| 68 | - * |
|
| 69 | - * @param string $path source path |
|
| 70 | - * @param string $destination destination path |
|
| 71 | - * @return bool|void false to stop handling, void to skip this handler |
|
| 72 | - */ |
|
| 73 | - public function performMove($path, $destination) { |
|
| 74 | - $fileExists = $this->server->tree->nodeExists($destination); |
|
| 75 | - // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
| 76 | - try { |
|
| 77 | - $this->server->tree->move($path, $destination); |
|
| 78 | - } catch (Forbidden $e) { |
|
| 79 | - $sourceNode = $this->server->tree->getNodeForPath($path); |
|
| 80 | - if ($sourceNode instanceof FutureFile) { |
|
| 81 | - $sourceNode->delete(); |
|
| 82 | - } |
|
| 83 | - throw $e; |
|
| 84 | - } |
|
| 62 | + /** |
|
| 63 | + * Move handler for future file. |
|
| 64 | + * |
|
| 65 | + * This overrides the default move behavior to prevent Sabre |
|
| 66 | + * to delete the target file before moving. Because deleting would |
|
| 67 | + * lose the file id and metadata. |
|
| 68 | + * |
|
| 69 | + * @param string $path source path |
|
| 70 | + * @param string $destination destination path |
|
| 71 | + * @return bool|void false to stop handling, void to skip this handler |
|
| 72 | + */ |
|
| 73 | + public function performMove($path, $destination) { |
|
| 74 | + $fileExists = $this->server->tree->nodeExists($destination); |
|
| 75 | + // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
| 76 | + try { |
|
| 77 | + $this->server->tree->move($path, $destination); |
|
| 78 | + } catch (Forbidden $e) { |
|
| 79 | + $sourceNode = $this->server->tree->getNodeForPath($path); |
|
| 80 | + if ($sourceNode instanceof FutureFile) { |
|
| 81 | + $sourceNode->delete(); |
|
| 82 | + } |
|
| 83 | + throw $e; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - // trigger all default events (copied from CorePlugin::move) |
|
| 87 | - $this->server->emit('afterMove', [$path, $destination]); |
|
| 88 | - $this->server->emit('afterUnbind', [$path]); |
|
| 89 | - $this->server->emit('afterBind', [$destination]); |
|
| 86 | + // trigger all default events (copied from CorePlugin::move) |
|
| 87 | + $this->server->emit('afterMove', [$path, $destination]); |
|
| 88 | + $this->server->emit('afterUnbind', [$path]); |
|
| 89 | + $this->server->emit('afterBind', [$destination]); |
|
| 90 | 90 | |
| 91 | - $response = $this->server->httpResponse; |
|
| 92 | - $response->setHeader('Content-Length', '0'); |
|
| 93 | - $response->setStatus($fileExists ? Http::STATUS_NO_CONTENT : Http::STATUS_CREATED); |
|
| 91 | + $response = $this->server->httpResponse; |
|
| 92 | + $response->setHeader('Content-Length', '0'); |
|
| 93 | + $response->setStatus($fileExists ? Http::STATUS_NO_CONTENT : Http::STATUS_CREATED); |
|
| 94 | 94 | |
| 95 | - return false; |
|
| 96 | - } |
|
| 95 | + return false; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @throws BadRequest |
|
| 100 | - */ |
|
| 101 | - private function verifySize() { |
|
| 102 | - $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length'); |
|
| 103 | - if ($expectedSize === null) { |
|
| 104 | - return; |
|
| 105 | - } |
|
| 106 | - $actualSize = $this->sourceNode->getSize(); |
|
| 98 | + /** |
|
| 99 | + * @throws BadRequest |
|
| 100 | + */ |
|
| 101 | + private function verifySize() { |
|
| 102 | + $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length'); |
|
| 103 | + if ($expectedSize === null) { |
|
| 104 | + return; |
|
| 105 | + } |
|
| 106 | + $actualSize = $this->sourceNode->getSize(); |
|
| 107 | 107 | |
| 108 | - // casted to string because cast to float cause equality for non equal numbers |
|
| 109 | - // and integer has the problem of limited size on 32 bit systems |
|
| 110 | - if ((string)$expectedSize !== (string)$actualSize) { |
|
| 111 | - throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
|
| 112 | - } |
|
| 113 | - } |
|
| 108 | + // casted to string because cast to float cause equality for non equal numbers |
|
| 109 | + // and integer has the problem of limited size on 32 bit systems |
|
| 110 | + if ((string)$expectedSize !== (string)$actualSize) { |
|
| 111 | + throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -30,30 +30,30 @@ |
||
| 30 | 30 | * Delete the admin|personal sections and settings tables |
| 31 | 31 | */ |
| 32 | 32 | class Version14000Date20180129121024 extends SimpleMigrationStep { |
| 33 | - public function name(): string { |
|
| 34 | - return 'Drop obsolete settings tables'; |
|
| 35 | - } |
|
| 33 | + public function name(): string { |
|
| 34 | + return 'Drop obsolete settings tables'; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public function description(): string { |
|
| 38 | - return 'Drops the following obsolete tables: "admin_sections", "admin_settings", "personal_sections" and "personal_settings"'; |
|
| 39 | - } |
|
| 37 | + public function description(): string { |
|
| 38 | + return 'Drops the following obsolete tables: "admin_sections", "admin_settings", "personal_sections" and "personal_settings"'; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param IOutput $output |
|
| 43 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 44 | - * @param array $options |
|
| 45 | - * @return null|ISchemaWrapper |
|
| 46 | - * @since 13.0.0 |
|
| 47 | - */ |
|
| 48 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 49 | - /** @var ISchemaWrapper $schema */ |
|
| 50 | - $schema = $schemaClosure(); |
|
| 41 | + /** |
|
| 42 | + * @param IOutput $output |
|
| 43 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 44 | + * @param array $options |
|
| 45 | + * @return null|ISchemaWrapper |
|
| 46 | + * @since 13.0.0 |
|
| 47 | + */ |
|
| 48 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
| 49 | + /** @var ISchemaWrapper $schema */ |
|
| 50 | + $schema = $schemaClosure(); |
|
| 51 | 51 | |
| 52 | - $schema->dropTable('admin_sections'); |
|
| 53 | - $schema->dropTable('admin_settings'); |
|
| 54 | - $schema->dropTable('personal_sections'); |
|
| 55 | - $schema->dropTable('personal_settings'); |
|
| 52 | + $schema->dropTable('admin_sections'); |
|
| 53 | + $schema->dropTable('admin_settings'); |
|
| 54 | + $schema->dropTable('personal_sections'); |
|
| 55 | + $schema->dropTable('personal_settings'); |
|
| 56 | 56 | |
| 57 | - return $schema; |
|
| 58 | - } |
|
| 57 | + return $schema; |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -25,9 +25,9 @@ |
||
| 25 | 25 | namespace OCA\DAV\Direct; |
| 26 | 26 | |
| 27 | 27 | class Server extends \Sabre\DAV\Server { |
| 28 | - public function __construct($treeOrNode = null) { |
|
| 29 | - parent::__construct($treeOrNode); |
|
| 30 | - self::$exposeVersion = false; |
|
| 31 | - $this->enablePropfindDepthInfinityf = false; |
|
| 32 | - } |
|
| 28 | + public function __construct($treeOrNode = null) { |
|
| 29 | + parent::__construct($treeOrNode); |
|
| 30 | + self::$exposeVersion = false; |
|
| 31 | + $this->enablePropfindDepthInfinityf = false; |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | */ |
| 63 | 63 | public function addEntityCollection(string $name, \Closure $entityExistsFunction) { |
| 64 | 64 | if (isset($this->collections[$name])) { |
| 65 | - throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"'); |
|
| 65 | + throw new \OutOfBoundsException('Duplicate entity name "'.$name.'"'); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $this->collections[$name] = $entityExistsFunction; |
@@ -17,45 +17,45 @@ |
||
| 17 | 17 | * @since 28.0.0 Dispatched as a typed event |
| 18 | 18 | */ |
| 19 | 19 | class SystemTagsEntityEvent extends Event { |
| 20 | - /** |
|
| 21 | - * @since 9.1.0 |
|
| 22 | - * @deprecated 22.0.0 Listen to the typed event instead |
|
| 23 | - */ |
|
| 24 | - public const EVENT_ENTITY = 'OCP\SystemTag\ISystemTagManager::registerEntity'; |
|
| 25 | - |
|
| 26 | - /** @var \Closure[] */ |
|
| 27 | - protected $collections; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @since 9.1.0 |
|
| 31 | - */ |
|
| 32 | - public function __construct() { |
|
| 33 | - parent::__construct(); |
|
| 34 | - $this->collections = []; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param string $name |
|
| 39 | - * @param \Closure $entityExistsFunction The closure should take one |
|
| 40 | - * argument, which is the id of the entity, that tags |
|
| 41 | - * should be handled for. The return should then be bool, |
|
| 42 | - * depending on whether tags are allowed (true) or not. |
|
| 43 | - * @throws \OutOfBoundsException when the entity name is already taken |
|
| 44 | - * @since 9.1.0 |
|
| 45 | - */ |
|
| 46 | - public function addEntityCollection(string $name, \Closure $entityExistsFunction) { |
|
| 47 | - if (isset($this->collections[$name])) { |
|
| 48 | - throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"'); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $this->collections[$name] = $entityExistsFunction; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @return \Closure[] |
|
| 56 | - * @since 9.1.0 |
|
| 57 | - */ |
|
| 58 | - public function getEntityCollections(): array { |
|
| 59 | - return $this->collections; |
|
| 60 | - } |
|
| 20 | + /** |
|
| 21 | + * @since 9.1.0 |
|
| 22 | + * @deprecated 22.0.0 Listen to the typed event instead |
|
| 23 | + */ |
|
| 24 | + public const EVENT_ENTITY = 'OCP\SystemTag\ISystemTagManager::registerEntity'; |
|
| 25 | + |
|
| 26 | + /** @var \Closure[] */ |
|
| 27 | + protected $collections; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @since 9.1.0 |
|
| 31 | + */ |
|
| 32 | + public function __construct() { |
|
| 33 | + parent::__construct(); |
|
| 34 | + $this->collections = []; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param string $name |
|
| 39 | + * @param \Closure $entityExistsFunction The closure should take one |
|
| 40 | + * argument, which is the id of the entity, that tags |
|
| 41 | + * should be handled for. The return should then be bool, |
|
| 42 | + * depending on whether tags are allowed (true) or not. |
|
| 43 | + * @throws \OutOfBoundsException when the entity name is already taken |
|
| 44 | + * @since 9.1.0 |
|
| 45 | + */ |
|
| 46 | + public function addEntityCollection(string $name, \Closure $entityExistsFunction) { |
|
| 47 | + if (isset($this->collections[$name])) { |
|
| 48 | + throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"'); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $this->collections[$name] = $entityExistsFunction; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @return \Closure[] |
|
| 56 | + * @since 9.1.0 |
|
| 57 | + */ |
|
| 58 | + public function getEntityCollections(): array { |
|
| 59 | + return $this->collections; |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -67,6 +67,6 @@ |
||
| 67 | 67 | $implements |= Backend::COUNT_USERS; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - return (bool)($actions & $implements); |
|
| 70 | + return (bool) ($actions & $implements); |
|
| 71 | 71 | } |
| 72 | 72 | } |
@@ -34,41 +34,41 @@ |
||
| 34 | 34 | * @since 14.0.0 |
| 35 | 35 | */ |
| 36 | 36 | abstract class ABackend implements IUserBackend, UserInterface { |
| 37 | - /** |
|
| 38 | - * @deprecated 14.0.0 |
|
| 39 | - * @since 14.0.0 |
|
| 40 | - * |
|
| 41 | - * @param int $actions The action to check for |
|
| 42 | - * @return bool |
|
| 43 | - */ |
|
| 44 | - public function implementsActions($actions): bool { |
|
| 45 | - $implements = 0; |
|
| 37 | + /** |
|
| 38 | + * @deprecated 14.0.0 |
|
| 39 | + * @since 14.0.0 |
|
| 40 | + * |
|
| 41 | + * @param int $actions The action to check for |
|
| 42 | + * @return bool |
|
| 43 | + */ |
|
| 44 | + public function implementsActions($actions): bool { |
|
| 45 | + $implements = 0; |
|
| 46 | 46 | |
| 47 | - if ($this instanceof ICreateUserBackend) { |
|
| 48 | - $implements |= Backend::CREATE_USER; |
|
| 49 | - } |
|
| 50 | - if ($this instanceof ISetPasswordBackend) { |
|
| 51 | - $implements |= Backend::SET_PASSWORD; |
|
| 52 | - } |
|
| 53 | - if ($this instanceof ICheckPasswordBackend) { |
|
| 54 | - $implements |= Backend::CHECK_PASSWORD; |
|
| 55 | - } |
|
| 56 | - if ($this instanceof IGetHomeBackend) { |
|
| 57 | - $implements |= Backend::GET_HOME; |
|
| 58 | - } |
|
| 59 | - if ($this instanceof IGetDisplayNameBackend) { |
|
| 60 | - $implements |= Backend::GET_DISPLAYNAME; |
|
| 61 | - } |
|
| 62 | - if ($this instanceof ISetDisplayNameBackend) { |
|
| 63 | - $implements |= Backend::SET_DISPLAYNAME; |
|
| 64 | - } |
|
| 65 | - if ($this instanceof IProvideAvatarBackend) { |
|
| 66 | - $implements |= Backend::PROVIDE_AVATAR; |
|
| 67 | - } |
|
| 68 | - if ($this instanceof ICountUsersBackend) { |
|
| 69 | - $implements |= Backend::COUNT_USERS; |
|
| 70 | - } |
|
| 47 | + if ($this instanceof ICreateUserBackend) { |
|
| 48 | + $implements |= Backend::CREATE_USER; |
|
| 49 | + } |
|
| 50 | + if ($this instanceof ISetPasswordBackend) { |
|
| 51 | + $implements |= Backend::SET_PASSWORD; |
|
| 52 | + } |
|
| 53 | + if ($this instanceof ICheckPasswordBackend) { |
|
| 54 | + $implements |= Backend::CHECK_PASSWORD; |
|
| 55 | + } |
|
| 56 | + if ($this instanceof IGetHomeBackend) { |
|
| 57 | + $implements |= Backend::GET_HOME; |
|
| 58 | + } |
|
| 59 | + if ($this instanceof IGetDisplayNameBackend) { |
|
| 60 | + $implements |= Backend::GET_DISPLAYNAME; |
|
| 61 | + } |
|
| 62 | + if ($this instanceof ISetDisplayNameBackend) { |
|
| 63 | + $implements |= Backend::SET_DISPLAYNAME; |
|
| 64 | + } |
|
| 65 | + if ($this instanceof IProvideAvatarBackend) { |
|
| 66 | + $implements |= Backend::PROVIDE_AVATAR; |
|
| 67 | + } |
|
| 68 | + if ($this instanceof ICountUsersBackend) { |
|
| 69 | + $implements |= Backend::COUNT_USERS; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return (bool)($actions & $implements); |
|
| 73 | - } |
|
| 72 | + return (bool)($actions & $implements); |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | public function connectWatcher() { |
| 58 | 58 | // Do not connect if we are not setup yet! |
| 59 | 59 | if ($this->config->getValue('instanceid', null) !== null) { |
| 60 | - $this->root->listen('\OC\Files', 'postWrite', function (Node $node) { |
|
| 60 | + $this->root->listen('\OC\Files', 'postWrite', function(Node $node) { |
|
| 61 | 61 | $this->getWatcher()->postWrite($node); |
| 62 | 62 | }); |
| 63 | 63 | |
@@ -13,39 +13,39 @@ |
||
| 13 | 13 | use OCP\Files\Node; |
| 14 | 14 | |
| 15 | 15 | class WatcherConnector { |
| 16 | - /** @var IRootFolder */ |
|
| 17 | - private $root; |
|
| 18 | - |
|
| 19 | - /** @var SystemConfig */ |
|
| 20 | - private $config; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * WatcherConnector constructor. |
|
| 24 | - * |
|
| 25 | - * @param IRootFolder $root |
|
| 26 | - * @param SystemConfig $config |
|
| 27 | - */ |
|
| 28 | - public function __construct(IRootFolder $root, |
|
| 29 | - SystemConfig $config) { |
|
| 30 | - $this->root = $root; |
|
| 31 | - $this->config = $config; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @return Watcher |
|
| 36 | - */ |
|
| 37 | - private function getWatcher(): Watcher { |
|
| 38 | - return \OCP\Server::get(Watcher::class); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function connectWatcher() { |
|
| 42 | - // Do not connect if we are not setup yet! |
|
| 43 | - if ($this->config->getValue('instanceid', null) !== null) { |
|
| 44 | - $this->root->listen('\OC\Files', 'postWrite', function (Node $node) { |
|
| 45 | - $this->getWatcher()->postWrite($node); |
|
| 46 | - }); |
|
| 47 | - |
|
| 48 | - \OC_Hook::connect('\OCP\Versions', 'rollback', $this->getWatcher(), 'versionRollback'); |
|
| 49 | - } |
|
| 50 | - } |
|
| 16 | + /** @var IRootFolder */ |
|
| 17 | + private $root; |
|
| 18 | + |
|
| 19 | + /** @var SystemConfig */ |
|
| 20 | + private $config; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * WatcherConnector constructor. |
|
| 24 | + * |
|
| 25 | + * @param IRootFolder $root |
|
| 26 | + * @param SystemConfig $config |
|
| 27 | + */ |
|
| 28 | + public function __construct(IRootFolder $root, |
|
| 29 | + SystemConfig $config) { |
|
| 30 | + $this->root = $root; |
|
| 31 | + $this->config = $config; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @return Watcher |
|
| 36 | + */ |
|
| 37 | + private function getWatcher(): Watcher { |
|
| 38 | + return \OCP\Server::get(Watcher::class); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function connectWatcher() { |
|
| 42 | + // Do not connect if we are not setup yet! |
|
| 43 | + if ($this->config->getValue('instanceid', null) !== null) { |
|
| 44 | + $this->root->listen('\OC\Files', 'postWrite', function (Node $node) { |
|
| 45 | + $this->getWatcher()->postWrite($node); |
|
| 46 | + }); |
|
| 47 | + |
|
| 48 | + \OC_Hook::connect('\OCP\Versions', 'rollback', $this->getWatcher(), 'versionRollback'); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -25,10 +25,10 @@ |
||
| 25 | 25 | use OCP\IL10N; |
| 26 | 26 | |
| 27 | 27 | class KerberosAuth extends AuthMechanism { |
| 28 | - public function __construct(IL10N $l) { |
|
| 29 | - $this |
|
| 30 | - ->setIdentifier('smb::kerberos') |
|
| 31 | - ->setScheme(self::SCHEME_SMB) |
|
| 32 | - ->setText($l->t('Kerberos ticket')); |
|
| 33 | - } |
|
| 28 | + public function __construct(IL10N $l) { |
|
| 29 | + $this |
|
| 30 | + ->setIdentifier('smb::kerberos') |
|
| 31 | + ->setScheme(self::SCHEME_SMB) |
|
| 32 | + ->setText($l->t('Kerberos ticket')); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -129,7 +129,7 @@ |
||
| 129 | 129 | $data = $result->fetchAll(); |
| 130 | 130 | $result->closeCursor(); |
| 131 | 131 | |
| 132 | - $entities = array_map(function ($row) { |
|
| 132 | + $entities = array_map(function($row) { |
|
| 133 | 133 | return PublicKeyToken::fromRow($row); |
| 134 | 134 | }, $data); |
| 135 | 135 | |
@@ -18,235 +18,235 @@ |
||
| 18 | 18 | * @template-extends QBMapper<PublicKeyToken> |
| 19 | 19 | */ |
| 20 | 20 | class PublicKeyTokenMapper extends QBMapper { |
| 21 | - public function __construct(IDBConnection $db) { |
|
| 22 | - parent::__construct($db, 'authtoken'); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Invalidate (delete) a given token |
|
| 27 | - */ |
|
| 28 | - public function invalidate(string $token) { |
|
| 29 | - /* @var $qb IQueryBuilder */ |
|
| 30 | - $qb = $this->db->getQueryBuilder(); |
|
| 31 | - $qb->delete($this->tableName) |
|
| 32 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 33 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 34 | - ->executeStatement(); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param int $olderThan |
|
| 39 | - * @param int $type |
|
| 40 | - * @param int|null $remember |
|
| 41 | - */ |
|
| 42 | - public function invalidateOld(int $olderThan, int $type = IToken::TEMPORARY_TOKEN, ?int $remember = null) { |
|
| 43 | - /* @var $qb IQueryBuilder */ |
|
| 44 | - $qb = $this->db->getQueryBuilder(); |
|
| 45 | - $delete = $qb->delete($this->tableName) |
|
| 46 | - ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
| 47 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_INT))) |
|
| 48 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 49 | - if ($remember !== null) { |
|
| 50 | - $delete->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))); |
|
| 51 | - } |
|
| 52 | - $delete->executeStatement(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function invalidateLastUsedBefore(string $uid, int $before): int { |
|
| 56 | - $qb = $this->db->getQueryBuilder(); |
|
| 57 | - $qb->delete($this->tableName) |
|
| 58 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 59 | - ->andWhere($qb->expr()->lt('last_activity', $qb->createNamedParameter($before, IQueryBuilder::PARAM_INT))) |
|
| 60 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 61 | - return $qb->executeStatement(); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Get the user UID for the given token |
|
| 66 | - * |
|
| 67 | - * @throws DoesNotExistException |
|
| 68 | - */ |
|
| 69 | - public function getToken(string $token): PublicKeyToken { |
|
| 70 | - /* @var $qb IQueryBuilder */ |
|
| 71 | - $qb = $this->db->getQueryBuilder(); |
|
| 72 | - $result = $qb->select('*') |
|
| 73 | - ->from($this->tableName) |
|
| 74 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 75 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 76 | - ->executeQuery(); |
|
| 77 | - |
|
| 78 | - $data = $result->fetch(); |
|
| 79 | - $result->closeCursor(); |
|
| 80 | - if ($data === false) { |
|
| 81 | - throw new DoesNotExistException('token does not exist'); |
|
| 82 | - } |
|
| 83 | - return PublicKeyToken::fromRow($data); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Get the token for $id |
|
| 88 | - * |
|
| 89 | - * @throws DoesNotExistException |
|
| 90 | - */ |
|
| 91 | - public function getTokenById(int $id): PublicKeyToken { |
|
| 92 | - /* @var $qb IQueryBuilder */ |
|
| 93 | - $qb = $this->db->getQueryBuilder(); |
|
| 94 | - $result = $qb->select('*') |
|
| 95 | - ->from($this->tableName) |
|
| 96 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 97 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 98 | - ->executeQuery(); |
|
| 99 | - |
|
| 100 | - $data = $result->fetch(); |
|
| 101 | - $result->closeCursor(); |
|
| 102 | - if ($data === false) { |
|
| 103 | - throw new DoesNotExistException('token does not exist'); |
|
| 104 | - } |
|
| 105 | - return PublicKeyToken::fromRow($data); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Get all tokens of a user |
|
| 110 | - * |
|
| 111 | - * The provider may limit the number of result rows in case of an abuse |
|
| 112 | - * where a high number of (session) tokens is generated |
|
| 113 | - * |
|
| 114 | - * @param string $uid |
|
| 115 | - * @return PublicKeyToken[] |
|
| 116 | - */ |
|
| 117 | - public function getTokenByUser(string $uid): array { |
|
| 118 | - /* @var $qb IQueryBuilder */ |
|
| 119 | - $qb = $this->db->getQueryBuilder(); |
|
| 120 | - $qb->select('*') |
|
| 121 | - ->from($this->tableName) |
|
| 122 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 123 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 124 | - ->setMaxResults(1000); |
|
| 125 | - $result = $qb->executeQuery(); |
|
| 126 | - $data = $result->fetchAll(); |
|
| 127 | - $result->closeCursor(); |
|
| 128 | - |
|
| 129 | - $entities = array_map(function ($row) { |
|
| 130 | - return PublicKeyToken::fromRow($row); |
|
| 131 | - }, $data); |
|
| 132 | - |
|
| 133 | - return $entities; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function getTokenByUserAndId(string $uid, int $id): ?string { |
|
| 137 | - /* @var $qb IQueryBuilder */ |
|
| 138 | - $qb = $this->db->getQueryBuilder(); |
|
| 139 | - $qb->select('token') |
|
| 140 | - ->from($this->tableName) |
|
| 141 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 142 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 143 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 144 | - return $qb->executeQuery()->fetchOne() ?: null; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * delete all auth token which belong to a specific client if the client was deleted |
|
| 149 | - * |
|
| 150 | - * @param string $name |
|
| 151 | - */ |
|
| 152 | - public function deleteByName(string $name) { |
|
| 153 | - $qb = $this->db->getQueryBuilder(); |
|
| 154 | - $qb->delete($this->tableName) |
|
| 155 | - ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
| 156 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 157 | - $qb->executeStatement(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - public function deleteTempToken(PublicKeyToken $except) { |
|
| 161 | - $qb = $this->db->getQueryBuilder(); |
|
| 162 | - |
|
| 163 | - $qb->delete($this->tableName) |
|
| 164 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($except->getUID()))) |
|
| 165 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN))) |
|
| 166 | - ->andWhere($qb->expr()->neq('id', $qb->createNamedParameter($except->getId()))) |
|
| 167 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 168 | - |
|
| 169 | - $qb->executeStatement(); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function hasExpiredTokens(string $uid): bool { |
|
| 173 | - $qb = $this->db->getQueryBuilder(); |
|
| 174 | - $qb->select('*') |
|
| 175 | - ->from($this->tableName) |
|
| 176 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 177 | - ->andWhere($qb->expr()->eq('password_invalid', $qb->createNamedParameter(true), IQueryBuilder::PARAM_BOOL)) |
|
| 178 | - ->setMaxResults(1); |
|
| 179 | - |
|
| 180 | - $cursor = $qb->executeQuery(); |
|
| 181 | - $data = $cursor->fetchAll(); |
|
| 182 | - $cursor->closeCursor(); |
|
| 183 | - |
|
| 184 | - return count($data) === 1; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Update the last activity timestamp |
|
| 189 | - * |
|
| 190 | - * In highly concurrent setups it can happen that two parallel processes |
|
| 191 | - * trigger the update at (nearly) the same time. In that special case it's |
|
| 192 | - * not necessary to hit the database with two actual updates. Therefore the |
|
| 193 | - * target last activity is included in the WHERE clause with a few seconds |
|
| 194 | - * of tolerance. |
|
| 195 | - * |
|
| 196 | - * Example: |
|
| 197 | - * - process 1 (P1) reads the token at timestamp 1500 |
|
| 198 | - * - process 1 (P2) reads the token at timestamp 1501 |
|
| 199 | - * - activity update interval is 100 |
|
| 200 | - * |
|
| 201 | - * This means |
|
| 202 | - * |
|
| 203 | - * - P1 will see a last_activity smaller than the current time and update |
|
| 204 | - * the token row |
|
| 205 | - * - If P2 reads after P1 had written, it will see 1600 as last activity |
|
| 206 | - * and the comparison on last_activity won't be truthy. This means no rows |
|
| 207 | - * need to be updated a second time |
|
| 208 | - * - If P2 reads before P1 had written, it will see 1501 as last activity, |
|
| 209 | - * but the comparison on last_activity will still not be truthy and the |
|
| 210 | - * token row is not updated a second time |
|
| 211 | - * |
|
| 212 | - * @param IToken $token |
|
| 213 | - * @param int $now |
|
| 214 | - */ |
|
| 215 | - public function updateActivity(IToken $token, int $now): void { |
|
| 216 | - $qb = $this->db->getQueryBuilder(); |
|
| 217 | - $update = $qb->update($this->getTableName()) |
|
| 218 | - ->set('last_activity', $qb->createNamedParameter($now, IQueryBuilder::PARAM_INT)) |
|
| 219 | - ->where( |
|
| 220 | - $qb->expr()->eq('id', $qb->createNamedParameter($token->getId(), IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT), |
|
| 221 | - $qb->expr()->lt('last_activity', $qb->createNamedParameter($now - 15, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT) |
|
| 222 | - ); |
|
| 223 | - $update->executeStatement(); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - public function updateHashesForUser(string $userId, string $passwordHash): void { |
|
| 227 | - $qb = $this->db->getQueryBuilder(); |
|
| 228 | - $update = $qb->update($this->getTableName()) |
|
| 229 | - ->set('password_hash', $qb->createNamedParameter($passwordHash)) |
|
| 230 | - ->where( |
|
| 231 | - $qb->expr()->eq('uid', $qb->createNamedParameter($userId)) |
|
| 232 | - ); |
|
| 233 | - $update->executeStatement(); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - public function getFirstTokenForUser(string $userId): ?PublicKeyToken { |
|
| 237 | - $qb = $this->db->getQueryBuilder(); |
|
| 238 | - $qb->select('*') |
|
| 239 | - ->from($this->getTableName()) |
|
| 240 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($userId))) |
|
| 241 | - ->setMaxResults(1) |
|
| 242 | - ->orderBy('id'); |
|
| 243 | - $result = $qb->executeQuery(); |
|
| 244 | - |
|
| 245 | - $data = $result->fetch(); |
|
| 246 | - $result->closeCursor(); |
|
| 247 | - if ($data === false) { |
|
| 248 | - return null; |
|
| 249 | - } |
|
| 250 | - return PublicKeyToken::fromRow($data); |
|
| 251 | - } |
|
| 21 | + public function __construct(IDBConnection $db) { |
|
| 22 | + parent::__construct($db, 'authtoken'); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Invalidate (delete) a given token |
|
| 27 | + */ |
|
| 28 | + public function invalidate(string $token) { |
|
| 29 | + /* @var $qb IQueryBuilder */ |
|
| 30 | + $qb = $this->db->getQueryBuilder(); |
|
| 31 | + $qb->delete($this->tableName) |
|
| 32 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 33 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 34 | + ->executeStatement(); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param int $olderThan |
|
| 39 | + * @param int $type |
|
| 40 | + * @param int|null $remember |
|
| 41 | + */ |
|
| 42 | + public function invalidateOld(int $olderThan, int $type = IToken::TEMPORARY_TOKEN, ?int $remember = null) { |
|
| 43 | + /* @var $qb IQueryBuilder */ |
|
| 44 | + $qb = $this->db->getQueryBuilder(); |
|
| 45 | + $delete = $qb->delete($this->tableName) |
|
| 46 | + ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
| 47 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_INT))) |
|
| 48 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 49 | + if ($remember !== null) { |
|
| 50 | + $delete->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))); |
|
| 51 | + } |
|
| 52 | + $delete->executeStatement(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function invalidateLastUsedBefore(string $uid, int $before): int { |
|
| 56 | + $qb = $this->db->getQueryBuilder(); |
|
| 57 | + $qb->delete($this->tableName) |
|
| 58 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 59 | + ->andWhere($qb->expr()->lt('last_activity', $qb->createNamedParameter($before, IQueryBuilder::PARAM_INT))) |
|
| 60 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 61 | + return $qb->executeStatement(); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Get the user UID for the given token |
|
| 66 | + * |
|
| 67 | + * @throws DoesNotExistException |
|
| 68 | + */ |
|
| 69 | + public function getToken(string $token): PublicKeyToken { |
|
| 70 | + /* @var $qb IQueryBuilder */ |
|
| 71 | + $qb = $this->db->getQueryBuilder(); |
|
| 72 | + $result = $qb->select('*') |
|
| 73 | + ->from($this->tableName) |
|
| 74 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
| 75 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 76 | + ->executeQuery(); |
|
| 77 | + |
|
| 78 | + $data = $result->fetch(); |
|
| 79 | + $result->closeCursor(); |
|
| 80 | + if ($data === false) { |
|
| 81 | + throw new DoesNotExistException('token does not exist'); |
|
| 82 | + } |
|
| 83 | + return PublicKeyToken::fromRow($data); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Get the token for $id |
|
| 88 | + * |
|
| 89 | + * @throws DoesNotExistException |
|
| 90 | + */ |
|
| 91 | + public function getTokenById(int $id): PublicKeyToken { |
|
| 92 | + /* @var $qb IQueryBuilder */ |
|
| 93 | + $qb = $this->db->getQueryBuilder(); |
|
| 94 | + $result = $qb->select('*') |
|
| 95 | + ->from($this->tableName) |
|
| 96 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 97 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 98 | + ->executeQuery(); |
|
| 99 | + |
|
| 100 | + $data = $result->fetch(); |
|
| 101 | + $result->closeCursor(); |
|
| 102 | + if ($data === false) { |
|
| 103 | + throw new DoesNotExistException('token does not exist'); |
|
| 104 | + } |
|
| 105 | + return PublicKeyToken::fromRow($data); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Get all tokens of a user |
|
| 110 | + * |
|
| 111 | + * The provider may limit the number of result rows in case of an abuse |
|
| 112 | + * where a high number of (session) tokens is generated |
|
| 113 | + * |
|
| 114 | + * @param string $uid |
|
| 115 | + * @return PublicKeyToken[] |
|
| 116 | + */ |
|
| 117 | + public function getTokenByUser(string $uid): array { |
|
| 118 | + /* @var $qb IQueryBuilder */ |
|
| 119 | + $qb = $this->db->getQueryBuilder(); |
|
| 120 | + $qb->select('*') |
|
| 121 | + ->from($this->tableName) |
|
| 122 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 123 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
| 124 | + ->setMaxResults(1000); |
|
| 125 | + $result = $qb->executeQuery(); |
|
| 126 | + $data = $result->fetchAll(); |
|
| 127 | + $result->closeCursor(); |
|
| 128 | + |
|
| 129 | + $entities = array_map(function ($row) { |
|
| 130 | + return PublicKeyToken::fromRow($row); |
|
| 131 | + }, $data); |
|
| 132 | + |
|
| 133 | + return $entities; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function getTokenByUserAndId(string $uid, int $id): ?string { |
|
| 137 | + /* @var $qb IQueryBuilder */ |
|
| 138 | + $qb = $this->db->getQueryBuilder(); |
|
| 139 | + $qb->select('token') |
|
| 140 | + ->from($this->tableName) |
|
| 141 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
| 142 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 143 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 144 | + return $qb->executeQuery()->fetchOne() ?: null; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * delete all auth token which belong to a specific client if the client was deleted |
|
| 149 | + * |
|
| 150 | + * @param string $name |
|
| 151 | + */ |
|
| 152 | + public function deleteByName(string $name) { |
|
| 153 | + $qb = $this->db->getQueryBuilder(); |
|
| 154 | + $qb->delete($this->tableName) |
|
| 155 | + ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
| 156 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 157 | + $qb->executeStatement(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + public function deleteTempToken(PublicKeyToken $except) { |
|
| 161 | + $qb = $this->db->getQueryBuilder(); |
|
| 162 | + |
|
| 163 | + $qb->delete($this->tableName) |
|
| 164 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($except->getUID()))) |
|
| 165 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN))) |
|
| 166 | + ->andWhere($qb->expr()->neq('id', $qb->createNamedParameter($except->getId()))) |
|
| 167 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
| 168 | + |
|
| 169 | + $qb->executeStatement(); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function hasExpiredTokens(string $uid): bool { |
|
| 173 | + $qb = $this->db->getQueryBuilder(); |
|
| 174 | + $qb->select('*') |
|
| 175 | + ->from($this->tableName) |
|
| 176 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
| 177 | + ->andWhere($qb->expr()->eq('password_invalid', $qb->createNamedParameter(true), IQueryBuilder::PARAM_BOOL)) |
|
| 178 | + ->setMaxResults(1); |
|
| 179 | + |
|
| 180 | + $cursor = $qb->executeQuery(); |
|
| 181 | + $data = $cursor->fetchAll(); |
|
| 182 | + $cursor->closeCursor(); |
|
| 183 | + |
|
| 184 | + return count($data) === 1; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Update the last activity timestamp |
|
| 189 | + * |
|
| 190 | + * In highly concurrent setups it can happen that two parallel processes |
|
| 191 | + * trigger the update at (nearly) the same time. In that special case it's |
|
| 192 | + * not necessary to hit the database with two actual updates. Therefore the |
|
| 193 | + * target last activity is included in the WHERE clause with a few seconds |
|
| 194 | + * of tolerance. |
|
| 195 | + * |
|
| 196 | + * Example: |
|
| 197 | + * - process 1 (P1) reads the token at timestamp 1500 |
|
| 198 | + * - process 1 (P2) reads the token at timestamp 1501 |
|
| 199 | + * - activity update interval is 100 |
|
| 200 | + * |
|
| 201 | + * This means |
|
| 202 | + * |
|
| 203 | + * - P1 will see a last_activity smaller than the current time and update |
|
| 204 | + * the token row |
|
| 205 | + * - If P2 reads after P1 had written, it will see 1600 as last activity |
|
| 206 | + * and the comparison on last_activity won't be truthy. This means no rows |
|
| 207 | + * need to be updated a second time |
|
| 208 | + * - If P2 reads before P1 had written, it will see 1501 as last activity, |
|
| 209 | + * but the comparison on last_activity will still not be truthy and the |
|
| 210 | + * token row is not updated a second time |
|
| 211 | + * |
|
| 212 | + * @param IToken $token |
|
| 213 | + * @param int $now |
|
| 214 | + */ |
|
| 215 | + public function updateActivity(IToken $token, int $now): void { |
|
| 216 | + $qb = $this->db->getQueryBuilder(); |
|
| 217 | + $update = $qb->update($this->getTableName()) |
|
| 218 | + ->set('last_activity', $qb->createNamedParameter($now, IQueryBuilder::PARAM_INT)) |
|
| 219 | + ->where( |
|
| 220 | + $qb->expr()->eq('id', $qb->createNamedParameter($token->getId(), IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT), |
|
| 221 | + $qb->expr()->lt('last_activity', $qb->createNamedParameter($now - 15, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT) |
|
| 222 | + ); |
|
| 223 | + $update->executeStatement(); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + public function updateHashesForUser(string $userId, string $passwordHash): void { |
|
| 227 | + $qb = $this->db->getQueryBuilder(); |
|
| 228 | + $update = $qb->update($this->getTableName()) |
|
| 229 | + ->set('password_hash', $qb->createNamedParameter($passwordHash)) |
|
| 230 | + ->where( |
|
| 231 | + $qb->expr()->eq('uid', $qb->createNamedParameter($userId)) |
|
| 232 | + ); |
|
| 233 | + $update->executeStatement(); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + public function getFirstTokenForUser(string $userId): ?PublicKeyToken { |
|
| 237 | + $qb = $this->db->getQueryBuilder(); |
|
| 238 | + $qb->select('*') |
|
| 239 | + ->from($this->getTableName()) |
|
| 240 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($userId))) |
|
| 241 | + ->setMaxResults(1) |
|
| 242 | + ->orderBy('id'); |
|
| 243 | + $result = $qb->executeQuery(); |
|
| 244 | + |
|
| 245 | + $data = $result->fetch(); |
|
| 246 | + $result->closeCursor(); |
|
| 247 | + if ($data === false) { |
|
| 248 | + return null; |
|
| 249 | + } |
|
| 250 | + return PublicKeyToken::fromRow($data); |
|
| 251 | + } |
|
| 252 | 252 | } |
@@ -107,7 +107,7 @@ |
||
| 107 | 107 | * @return string language |
| 108 | 108 | * @since 7.0.0 |
| 109 | 109 | */ |
| 110 | - public function getLanguageCode(): string ; |
|
| 110 | + public function getLanguageCode(): string; |
|
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * * The code (en_US, fr_CA, ...) of the locale that is used for this IL10N object |
@@ -17,77 +17,77 @@ |
||
| 17 | 17 | * @since 6.0.0 |
| 18 | 18 | */ |
| 19 | 19 | interface IL10N { |
| 20 | - /** |
|
| 21 | - * Translating |
|
| 22 | - * @param string $text The text we need a translation for |
|
| 23 | - * @param array|string $parameters default:array() Parameters for sprintf |
|
| 24 | - * @return string Translation or the same text |
|
| 25 | - * |
|
| 26 | - * Returns the translation. If no translation is found, $text will be |
|
| 27 | - * returned. |
|
| 28 | - * @since 6.0.0 |
|
| 29 | - */ |
|
| 30 | - public function t(string $text, $parameters = []): string; |
|
| 20 | + /** |
|
| 21 | + * Translating |
|
| 22 | + * @param string $text The text we need a translation for |
|
| 23 | + * @param array|string $parameters default:array() Parameters for sprintf |
|
| 24 | + * @return string Translation or the same text |
|
| 25 | + * |
|
| 26 | + * Returns the translation. If no translation is found, $text will be |
|
| 27 | + * returned. |
|
| 28 | + * @since 6.0.0 |
|
| 29 | + */ |
|
| 30 | + public function t(string $text, $parameters = []): string; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Translating |
|
| 34 | - * @param string $text_singular the string to translate for exactly one object |
|
| 35 | - * @param string $text_plural the string to translate for n objects |
|
| 36 | - * @param integer $count Number of objects |
|
| 37 | - * @param array $parameters default:array() Parameters for sprintf |
|
| 38 | - * @return string Translation or the same text |
|
| 39 | - * |
|
| 40 | - * Returns the translation. If no translation is found, $text will be |
|
| 41 | - * returned. %n will be replaced with the number of objects. |
|
| 42 | - * |
|
| 43 | - * The correct plural is determined by the plural_forms-function |
|
| 44 | - * provided by the po file. |
|
| 45 | - * @since 6.0.0 |
|
| 46 | - * |
|
| 47 | - */ |
|
| 48 | - public function n(string $text_singular, string $text_plural, int $count, array $parameters = []): string; |
|
| 32 | + /** |
|
| 33 | + * Translating |
|
| 34 | + * @param string $text_singular the string to translate for exactly one object |
|
| 35 | + * @param string $text_plural the string to translate for n objects |
|
| 36 | + * @param integer $count Number of objects |
|
| 37 | + * @param array $parameters default:array() Parameters for sprintf |
|
| 38 | + * @return string Translation or the same text |
|
| 39 | + * |
|
| 40 | + * Returns the translation. If no translation is found, $text will be |
|
| 41 | + * returned. %n will be replaced with the number of objects. |
|
| 42 | + * |
|
| 43 | + * The correct plural is determined by the plural_forms-function |
|
| 44 | + * provided by the po file. |
|
| 45 | + * @since 6.0.0 |
|
| 46 | + * |
|
| 47 | + */ |
|
| 48 | + public function n(string $text_singular, string $text_plural, int $count, array $parameters = []): string; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Localization |
|
| 52 | - * @param string $type Type of localization |
|
| 53 | - * @param \DateTime|int|string $data parameters for this localization |
|
| 54 | - * @param array $options currently supports following options: |
|
| 55 | - * - 'width': handed into \Punic\Calendar::formatDate as second parameter |
|
| 56 | - * @return string|int|false |
|
| 57 | - * |
|
| 58 | - * Returns the localized data. |
|
| 59 | - * |
|
| 60 | - * Implemented types: |
|
| 61 | - * - date |
|
| 62 | - * - Creates a date |
|
| 63 | - * - l10n-field: date |
|
| 64 | - * - params: timestamp (int/string) |
|
| 65 | - * - datetime |
|
| 66 | - * - Creates date and time |
|
| 67 | - * - l10n-field: datetime |
|
| 68 | - * - params: timestamp (int/string) |
|
| 69 | - * - time |
|
| 70 | - * - Creates a time |
|
| 71 | - * - l10n-field: time |
|
| 72 | - * - params: timestamp (int/string) |
|
| 73 | - * @since 6.0.0 - parameter $options was added in 8.0.0 |
|
| 74 | - */ |
|
| 75 | - public function l(string $type, $data, array $options = []); |
|
| 50 | + /** |
|
| 51 | + * Localization |
|
| 52 | + * @param string $type Type of localization |
|
| 53 | + * @param \DateTime|int|string $data parameters for this localization |
|
| 54 | + * @param array $options currently supports following options: |
|
| 55 | + * - 'width': handed into \Punic\Calendar::formatDate as second parameter |
|
| 56 | + * @return string|int|false |
|
| 57 | + * |
|
| 58 | + * Returns the localized data. |
|
| 59 | + * |
|
| 60 | + * Implemented types: |
|
| 61 | + * - date |
|
| 62 | + * - Creates a date |
|
| 63 | + * - l10n-field: date |
|
| 64 | + * - params: timestamp (int/string) |
|
| 65 | + * - datetime |
|
| 66 | + * - Creates date and time |
|
| 67 | + * - l10n-field: datetime |
|
| 68 | + * - params: timestamp (int/string) |
|
| 69 | + * - time |
|
| 70 | + * - Creates a time |
|
| 71 | + * - l10n-field: time |
|
| 72 | + * - params: timestamp (int/string) |
|
| 73 | + * @since 6.0.0 - parameter $options was added in 8.0.0 |
|
| 74 | + */ |
|
| 75 | + public function l(string $type, $data, array $options = []); |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * The code (en, de, ...) of the language that is used for this IL10N object |
|
| 80 | - * |
|
| 81 | - * @return string language |
|
| 82 | - * @since 7.0.0 |
|
| 83 | - */ |
|
| 84 | - public function getLanguageCode(): string ; |
|
| 78 | + /** |
|
| 79 | + * The code (en, de, ...) of the language that is used for this IL10N object |
|
| 80 | + * |
|
| 81 | + * @return string language |
|
| 82 | + * @since 7.0.0 |
|
| 83 | + */ |
|
| 84 | + public function getLanguageCode(): string ; |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * * The code (en_US, fr_CA, ...) of the locale that is used for this IL10N object |
|
| 88 | - * |
|
| 89 | - * @return string locale |
|
| 90 | - * @since 14.0.0 |
|
| 91 | - */ |
|
| 92 | - public function getLocaleCode(): string; |
|
| 86 | + /** |
|
| 87 | + * * The code (en_US, fr_CA, ...) of the locale that is used for this IL10N object |
|
| 88 | + * |
|
| 89 | + * @return string locale |
|
| 90 | + * @since 14.0.0 |
|
| 91 | + */ |
|
| 92 | + public function getLocaleCode(): string; |
|
| 93 | 93 | } |