@@ -36,16 +36,16 @@ |
||
36 | 36 | */ |
37 | 37 | class Proxy extends Entity { |
38 | 38 | |
39 | - /** @var string */ |
|
40 | - protected $ownerId; |
|
41 | - /** @var string */ |
|
42 | - protected $proxyId; |
|
43 | - /** @var int */ |
|
44 | - protected $permissions; |
|
39 | + /** @var string */ |
|
40 | + protected $ownerId; |
|
41 | + /** @var string */ |
|
42 | + protected $proxyId; |
|
43 | + /** @var int */ |
|
44 | + protected $permissions; |
|
45 | 45 | |
46 | - public function __construct() { |
|
47 | - $this->addType('ownerId', 'string'); |
|
48 | - $this->addType('proxyId', 'string'); |
|
49 | - $this->addType('permissions', 'int'); |
|
50 | - } |
|
46 | + public function __construct() { |
|
47 | + $this->addType('ownerId', 'string'); |
|
48 | + $this->addType('proxyId', 'string'); |
|
49 | + $this->addType('permissions', 'int'); |
|
50 | + } |
|
51 | 51 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | */ |
43 | 43 | public function changeSchema(IOutput $output, |
44 | 44 | \Closure $schemaClosure, |
45 | - array $options):?ISchemaWrapper { |
|
45 | + array $options): ?ISchemaWrapper { |
|
46 | 46 | /** @var ISchemaWrapper $schema */ |
47 | 47 | $schema = $schemaClosure(); |
48 | 48 |
@@ -38,86 +38,86 @@ |
||
38 | 38 | */ |
39 | 39 | class Version1012Date20190808122342 extends SimpleMigrationStep { |
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 17.0.0 |
|
47 | - */ |
|
48 | - public function changeSchema(IOutput $output, |
|
49 | - \Closure $schemaClosure, |
|
50 | - array $options):?ISchemaWrapper { |
|
51 | - /** @var ISchemaWrapper $schema */ |
|
52 | - $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 17.0.0 |
|
47 | + */ |
|
48 | + public function changeSchema(IOutput $output, |
|
49 | + \Closure $schemaClosure, |
|
50 | + array $options):?ISchemaWrapper { |
|
51 | + /** @var ISchemaWrapper $schema */ |
|
52 | + $schema = $schemaClosure(); |
|
53 | 53 | |
54 | - if (!$schema->hasTable('calendar_reminders')) { |
|
55 | - $table = $schema->createTable('calendar_reminders'); |
|
54 | + if (!$schema->hasTable('calendar_reminders')) { |
|
55 | + $table = $schema->createTable('calendar_reminders'); |
|
56 | 56 | |
57 | - $table->addColumn('id', Types::BIGINT, [ |
|
58 | - 'autoincrement' => true, |
|
59 | - 'notnull' => true, |
|
60 | - 'length' => 11, |
|
61 | - 'unsigned' => true, |
|
62 | - ]); |
|
63 | - $table->addColumn('calendar_id', Types::BIGINT, [ |
|
64 | - 'notnull' => true, |
|
65 | - 'length' => 11, |
|
66 | - ]); |
|
67 | - $table->addColumn('object_id', Types::BIGINT, [ |
|
68 | - 'notnull' => true, |
|
69 | - 'length' => 11, |
|
70 | - ]); |
|
71 | - $table->addColumn('is_recurring', Types::SMALLINT, [ |
|
72 | - 'notnull' => false, |
|
73 | - 'length' => 1, |
|
74 | - ]); |
|
75 | - $table->addColumn('uid', Types::STRING, [ |
|
76 | - 'notnull' => true, |
|
77 | - 'length' => 255, |
|
78 | - ]); |
|
79 | - $table->addColumn('recurrence_id', Types::BIGINT, [ |
|
80 | - 'notnull' => false, |
|
81 | - 'length' => 11, |
|
82 | - 'unsigned' => true, |
|
83 | - ]); |
|
84 | - $table->addColumn('is_recurrence_exception', Types::SMALLINT, [ |
|
85 | - 'notnull' => true, |
|
86 | - 'length' => 1, |
|
87 | - ]); |
|
88 | - $table->addColumn('event_hash', Types::STRING, [ |
|
89 | - 'notnull' => true, |
|
90 | - 'length' => 255, |
|
91 | - ]); |
|
92 | - $table->addColumn('alarm_hash', Types::STRING, [ |
|
93 | - 'notnull' => true, |
|
94 | - 'length' => 255, |
|
95 | - ]); |
|
96 | - $table->addColumn('type', Types::STRING, [ |
|
97 | - 'notnull' => true, |
|
98 | - 'length' => 255, |
|
99 | - ]); |
|
100 | - $table->addColumn('is_relative', Types::SMALLINT, [ |
|
101 | - 'notnull' => true, |
|
102 | - 'length' => 1, |
|
103 | - ]); |
|
104 | - $table->addColumn('notification_date', Types::BIGINT, [ |
|
105 | - 'notnull' => true, |
|
106 | - 'length' => 11, |
|
107 | - 'unsigned' => true, |
|
108 | - ]); |
|
109 | - $table->addColumn('is_repeat_based', Types::SMALLINT, [ |
|
110 | - 'notnull' => true, |
|
111 | - 'length' => 1, |
|
112 | - ]); |
|
57 | + $table->addColumn('id', Types::BIGINT, [ |
|
58 | + 'autoincrement' => true, |
|
59 | + 'notnull' => true, |
|
60 | + 'length' => 11, |
|
61 | + 'unsigned' => true, |
|
62 | + ]); |
|
63 | + $table->addColumn('calendar_id', Types::BIGINT, [ |
|
64 | + 'notnull' => true, |
|
65 | + 'length' => 11, |
|
66 | + ]); |
|
67 | + $table->addColumn('object_id', Types::BIGINT, [ |
|
68 | + 'notnull' => true, |
|
69 | + 'length' => 11, |
|
70 | + ]); |
|
71 | + $table->addColumn('is_recurring', Types::SMALLINT, [ |
|
72 | + 'notnull' => false, |
|
73 | + 'length' => 1, |
|
74 | + ]); |
|
75 | + $table->addColumn('uid', Types::STRING, [ |
|
76 | + 'notnull' => true, |
|
77 | + 'length' => 255, |
|
78 | + ]); |
|
79 | + $table->addColumn('recurrence_id', Types::BIGINT, [ |
|
80 | + 'notnull' => false, |
|
81 | + 'length' => 11, |
|
82 | + 'unsigned' => true, |
|
83 | + ]); |
|
84 | + $table->addColumn('is_recurrence_exception', Types::SMALLINT, [ |
|
85 | + 'notnull' => true, |
|
86 | + 'length' => 1, |
|
87 | + ]); |
|
88 | + $table->addColumn('event_hash', Types::STRING, [ |
|
89 | + 'notnull' => true, |
|
90 | + 'length' => 255, |
|
91 | + ]); |
|
92 | + $table->addColumn('alarm_hash', Types::STRING, [ |
|
93 | + 'notnull' => true, |
|
94 | + 'length' => 255, |
|
95 | + ]); |
|
96 | + $table->addColumn('type', Types::STRING, [ |
|
97 | + 'notnull' => true, |
|
98 | + 'length' => 255, |
|
99 | + ]); |
|
100 | + $table->addColumn('is_relative', Types::SMALLINT, [ |
|
101 | + 'notnull' => true, |
|
102 | + 'length' => 1, |
|
103 | + ]); |
|
104 | + $table->addColumn('notification_date', Types::BIGINT, [ |
|
105 | + 'notnull' => true, |
|
106 | + 'length' => 11, |
|
107 | + 'unsigned' => true, |
|
108 | + ]); |
|
109 | + $table->addColumn('is_repeat_based', Types::SMALLINT, [ |
|
110 | + 'notnull' => true, |
|
111 | + 'length' => 1, |
|
112 | + ]); |
|
113 | 113 | |
114 | - $table->setPrimaryKey(['id']); |
|
115 | - $table->addIndex(['object_id'], 'calendar_reminder_objid'); |
|
116 | - $table->addIndex(['uid', 'recurrence_id'], 'calendar_reminder_uidrec'); |
|
114 | + $table->setPrimaryKey(['id']); |
|
115 | + $table->addIndex(['object_id'], 'calendar_reminder_objid'); |
|
116 | + $table->addIndex(['uid', 'recurrence_id'], 'calendar_reminder_uidrec'); |
|
117 | 117 | |
118 | - return $schema; |
|
119 | - } |
|
118 | + return $schema; |
|
119 | + } |
|
120 | 120 | |
121 | - return null; |
|
122 | - } |
|
121 | + return null; |
|
122 | + } |
|
123 | 123 | } |
@@ -31,51 +31,51 @@ |
||
31 | 31 | */ |
32 | 32 | class NotificationProviderManager { |
33 | 33 | |
34 | - /** @var INotificationProvider[] */ |
|
35 | - private $providers = []; |
|
34 | + /** @var INotificationProvider[] */ |
|
35 | + private $providers = []; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Checks whether a provider for a given ACTION exists |
|
39 | - * |
|
40 | - * @param string $type |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public function hasProvider(string $type):bool { |
|
44 | - return (\in_array($type, ReminderService::REMINDER_TYPES, true) |
|
45 | - && isset($this->providers[$type])); |
|
46 | - } |
|
37 | + /** |
|
38 | + * Checks whether a provider for a given ACTION exists |
|
39 | + * |
|
40 | + * @param string $type |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public function hasProvider(string $type):bool { |
|
44 | + return (\in_array($type, ReminderService::REMINDER_TYPES, true) |
|
45 | + && isset($this->providers[$type])); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Get provider for a given ACTION |
|
50 | - * |
|
51 | - * @param string $type |
|
52 | - * @return INotificationProvider |
|
53 | - * @throws NotificationProvider\ProviderNotAvailableException |
|
54 | - * @throws NotificationTypeDoesNotExistException |
|
55 | - */ |
|
56 | - public function getProvider(string $type):INotificationProvider { |
|
57 | - if (in_array($type, ReminderService::REMINDER_TYPES, true)) { |
|
58 | - if (isset($this->providers[$type])) { |
|
59 | - return $this->providers[$type]; |
|
60 | - } |
|
61 | - throw new NotificationProvider\ProviderNotAvailableException($type); |
|
62 | - } |
|
63 | - throw new NotificationTypeDoesNotExistException($type); |
|
64 | - } |
|
48 | + /** |
|
49 | + * Get provider for a given ACTION |
|
50 | + * |
|
51 | + * @param string $type |
|
52 | + * @return INotificationProvider |
|
53 | + * @throws NotificationProvider\ProviderNotAvailableException |
|
54 | + * @throws NotificationTypeDoesNotExistException |
|
55 | + */ |
|
56 | + public function getProvider(string $type):INotificationProvider { |
|
57 | + if (in_array($type, ReminderService::REMINDER_TYPES, true)) { |
|
58 | + if (isset($this->providers[$type])) { |
|
59 | + return $this->providers[$type]; |
|
60 | + } |
|
61 | + throw new NotificationProvider\ProviderNotAvailableException($type); |
|
62 | + } |
|
63 | + throw new NotificationTypeDoesNotExistException($type); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Registers a new provider |
|
68 | - * |
|
69 | - * @param string $providerClassName |
|
70 | - * @throws \OCP\AppFramework\QueryException |
|
71 | - */ |
|
72 | - public function registerProvider(string $providerClassName):void { |
|
73 | - $provider = \OC::$server->query($providerClassName); |
|
66 | + /** |
|
67 | + * Registers a new provider |
|
68 | + * |
|
69 | + * @param string $providerClassName |
|
70 | + * @throws \OCP\AppFramework\QueryException |
|
71 | + */ |
|
72 | + public function registerProvider(string $providerClassName):void { |
|
73 | + $provider = \OC::$server->query($providerClassName); |
|
74 | 74 | |
75 | - if (!$provider instanceof INotificationProvider) { |
|
76 | - throw new \InvalidArgumentException('Invalid notification provider registered'); |
|
77 | - } |
|
75 | + if (!$provider instanceof INotificationProvider) { |
|
76 | + throw new \InvalidArgumentException('Invalid notification provider registered'); |
|
77 | + } |
|
78 | 78 | |
79 | - $this->providers[$provider::NOTIFICATION_TYPE] = $provider; |
|
80 | - } |
|
79 | + $this->providers[$provider::NOTIFICATION_TYPE] = $provider; |
|
80 | + } |
|
81 | 81 | } |
@@ -26,15 +26,15 @@ |
||
26 | 26 | |
27 | 27 | class NotificationTypeDoesNotExistException extends \Exception { |
28 | 28 | |
29 | - /** |
|
30 | - * NotificationTypeDoesNotExistException constructor. |
|
31 | - * |
|
32 | - * @since 16.0.0 |
|
33 | - * |
|
34 | - * @param string $type ReminderType |
|
35 | - */ |
|
36 | - public function __construct(string $type) { |
|
37 | - parent::__construct("Type $type is not an accepted type of notification"); |
|
38 | - } |
|
29 | + /** |
|
30 | + * NotificationTypeDoesNotExistException constructor. |
|
31 | + * |
|
32 | + * @since 16.0.0 |
|
33 | + * |
|
34 | + * @param string $type ReminderType |
|
35 | + */ |
|
36 | + public function __construct(string $type) { |
|
37 | + parent::__construct("Type $type is not an accepted type of notification"); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | } |
@@ -25,15 +25,15 @@ |
||
25 | 25 | |
26 | 26 | class ProviderNotAvailableException extends \Exception { |
27 | 27 | |
28 | - /** |
|
29 | - * ProviderNotAvailableException constructor. |
|
30 | - * |
|
31 | - * @since 16.0.0 |
|
32 | - * |
|
33 | - * @param string $type ReminderType |
|
34 | - */ |
|
35 | - public function __construct(string $type) { |
|
36 | - parent::__construct("No notification provider for type $type available"); |
|
37 | - } |
|
28 | + /** |
|
29 | + * ProviderNotAvailableException constructor. |
|
30 | + * |
|
31 | + * @since 16.0.0 |
|
32 | + * |
|
33 | + * @param string $type ReminderType |
|
34 | + */ |
|
35 | + public function __construct(string $type) { |
|
36 | + parent::__construct("No notification provider for type $type available"); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
@@ -32,6 +32,6 @@ |
||
32 | 32 | */ |
33 | 33 | class AudioProvider extends PushProvider { |
34 | 34 | |
35 | - /** @var string */ |
|
36 | - public const NOTIFICATION_TYPE = 'AUDIO'; |
|
35 | + /** @var string */ |
|
36 | + public const NOTIFICATION_TYPE = 'AUDIO'; |
|
37 | 37 | } |
@@ -36,11 +36,11 @@ |
||
36 | 36 | } |
37 | 37 | |
38 | 38 | public function getMimeType(): string { |
39 | - return (string)$this->providerV1->getMimeType(); |
|
39 | + return (string) $this->providerV1->getMimeType(); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function isAvailable(FileInfo $file): bool { |
43 | - return (bool)$this->providerV1->isAvailable($file); |
|
43 | + return (bool) $this->providerV1->isAvailable($file); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { |
@@ -34,30 +34,30 @@ |
||
34 | 34 | use OCP\Preview\IProviderV2; |
35 | 35 | |
36 | 36 | class ProviderV1Adapter implements IProviderV2 { |
37 | - private $providerV1; |
|
37 | + private $providerV1; |
|
38 | 38 | |
39 | - public function __construct(IProvider $providerV1) { |
|
40 | - $this->providerV1 = $providerV1; |
|
41 | - } |
|
39 | + public function __construct(IProvider $providerV1) { |
|
40 | + $this->providerV1 = $providerV1; |
|
41 | + } |
|
42 | 42 | |
43 | - public function getMimeType(): string { |
|
44 | - return (string)$this->providerV1->getMimeType(); |
|
45 | - } |
|
43 | + public function getMimeType(): string { |
|
44 | + return (string)$this->providerV1->getMimeType(); |
|
45 | + } |
|
46 | 46 | |
47 | - public function isAvailable(FileInfo $file): bool { |
|
48 | - return (bool)$this->providerV1->isAvailable($file); |
|
49 | - } |
|
47 | + public function isAvailable(FileInfo $file): bool { |
|
48 | + return (bool)$this->providerV1->isAvailable($file); |
|
49 | + } |
|
50 | 50 | |
51 | - public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { |
|
52 | - [$view, $path] = $this->getViewAndPath($file); |
|
53 | - $thumbnail = $this->providerV1->getThumbnail($path, $maxX, $maxY, false, $view); |
|
54 | - return $thumbnail === false ? null: $thumbnail; |
|
55 | - } |
|
51 | + public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { |
|
52 | + [$view, $path] = $this->getViewAndPath($file); |
|
53 | + $thumbnail = $this->providerV1->getThumbnail($path, $maxX, $maxY, false, $view); |
|
54 | + return $thumbnail === false ? null: $thumbnail; |
|
55 | + } |
|
56 | 56 | |
57 | - private function getViewAndPath(File $file) { |
|
58 | - $view = new View(dirname($file->getPath())); |
|
59 | - $path = $file->getName(); |
|
57 | + private function getViewAndPath(File $file) { |
|
58 | + $view = new View(dirname($file->getPath())); |
|
59 | + $path = $file->getName(); |
|
60 | 60 | |
61 | - return [$view, $path]; |
|
62 | - } |
|
61 | + return [$view, $path]; |
|
62 | + } |
|
63 | 63 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | string $ip): void { |
81 | 81 | $ipSubnet = (new IpAddress($ip))->getSubnet(); |
82 | 82 | |
83 | - $anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet); |
|
83 | + $anonHashIdentifier = hash('sha512', 'anon::'.$identifier.$ipSubnet); |
|
84 | 84 | $this->register($identifier, $anonHashIdentifier, $anonPeriod, $anonLimit); |
85 | 85 | } |
86 | 86 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | int $userLimit, |
98 | 98 | int $userPeriod, |
99 | 99 | IUser $user): void { |
100 | - $userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID()); |
|
100 | + $userHashIdentifier = hash('sha512', 'user::'.$identifier.$user->getUID()); |
|
101 | 101 | $this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit); |
102 | 102 | } |
103 | 103 | } |
@@ -32,68 +32,68 @@ |
||
32 | 32 | use OCP\IUser; |
33 | 33 | |
34 | 34 | class Limiter { |
35 | - /** @var IBackend */ |
|
36 | - private $backend; |
|
35 | + /** @var IBackend */ |
|
36 | + private $backend; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param IBackend $backend |
|
40 | - */ |
|
41 | - public function __construct(IBackend $backend) { |
|
42 | - $this->backend = $backend; |
|
43 | - } |
|
38 | + /** |
|
39 | + * @param IBackend $backend |
|
40 | + */ |
|
41 | + public function __construct(IBackend $backend) { |
|
42 | + $this->backend = $backend; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $methodIdentifier |
|
47 | - * @param string $userIdentifier |
|
48 | - * @param int $period in seconds |
|
49 | - * @param int $limit |
|
50 | - * @throws RateLimitExceededException |
|
51 | - */ |
|
52 | - private function register(string $methodIdentifier, |
|
53 | - string $userIdentifier, |
|
54 | - int $period, |
|
55 | - int $limit): void { |
|
56 | - $existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier); |
|
57 | - if ($existingAttempts >= $limit) { |
|
58 | - throw new RateLimitExceededException(); |
|
59 | - } |
|
45 | + /** |
|
46 | + * @param string $methodIdentifier |
|
47 | + * @param string $userIdentifier |
|
48 | + * @param int $period in seconds |
|
49 | + * @param int $limit |
|
50 | + * @throws RateLimitExceededException |
|
51 | + */ |
|
52 | + private function register(string $methodIdentifier, |
|
53 | + string $userIdentifier, |
|
54 | + int $period, |
|
55 | + int $limit): void { |
|
56 | + $existingAttempts = $this->backend->getAttempts($methodIdentifier, $userIdentifier); |
|
57 | + if ($existingAttempts >= $limit) { |
|
58 | + throw new RateLimitExceededException(); |
|
59 | + } |
|
60 | 60 | |
61 | - $this->backend->registerAttempt($methodIdentifier, $userIdentifier, $period); |
|
62 | - } |
|
61 | + $this->backend->registerAttempt($methodIdentifier, $userIdentifier, $period); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Registers attempt for an anonymous request |
|
66 | - * |
|
67 | - * @param string $identifier |
|
68 | - * @param int $anonLimit |
|
69 | - * @param int $anonPeriod in seconds |
|
70 | - * @param string $ip |
|
71 | - * @throws RateLimitExceededException |
|
72 | - */ |
|
73 | - public function registerAnonRequest(string $identifier, |
|
74 | - int $anonLimit, |
|
75 | - int $anonPeriod, |
|
76 | - string $ip): void { |
|
77 | - $ipSubnet = (new IpAddress($ip))->getSubnet(); |
|
64 | + /** |
|
65 | + * Registers attempt for an anonymous request |
|
66 | + * |
|
67 | + * @param string $identifier |
|
68 | + * @param int $anonLimit |
|
69 | + * @param int $anonPeriod in seconds |
|
70 | + * @param string $ip |
|
71 | + * @throws RateLimitExceededException |
|
72 | + */ |
|
73 | + public function registerAnonRequest(string $identifier, |
|
74 | + int $anonLimit, |
|
75 | + int $anonPeriod, |
|
76 | + string $ip): void { |
|
77 | + $ipSubnet = (new IpAddress($ip))->getSubnet(); |
|
78 | 78 | |
79 | - $anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet); |
|
80 | - $this->register($identifier, $anonHashIdentifier, $anonPeriod, $anonLimit); |
|
81 | - } |
|
79 | + $anonHashIdentifier = hash('sha512', 'anon::' . $identifier . $ipSubnet); |
|
80 | + $this->register($identifier, $anonHashIdentifier, $anonPeriod, $anonLimit); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Registers attempt for an authenticated request |
|
85 | - * |
|
86 | - * @param string $identifier |
|
87 | - * @param int $userLimit |
|
88 | - * @param int $userPeriod in seconds |
|
89 | - * @param IUser $user |
|
90 | - * @throws RateLimitExceededException |
|
91 | - */ |
|
92 | - public function registerUserRequest(string $identifier, |
|
93 | - int $userLimit, |
|
94 | - int $userPeriod, |
|
95 | - IUser $user): void { |
|
96 | - $userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID()); |
|
97 | - $this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit); |
|
98 | - } |
|
83 | + /** |
|
84 | + * Registers attempt for an authenticated request |
|
85 | + * |
|
86 | + * @param string $identifier |
|
87 | + * @param int $userLimit |
|
88 | + * @param int $userPeriod in seconds |
|
89 | + * @param IUser $user |
|
90 | + * @throws RateLimitExceededException |
|
91 | + */ |
|
92 | + public function registerUserRequest(string $identifier, |
|
93 | + int $userLimit, |
|
94 | + int $userPeriod, |
|
95 | + IUser $user): void { |
|
96 | + $userHashIdentifier = hash('sha512', 'user::' . $identifier . $user->getUID()); |
|
97 | + $this->register($identifier, $userHashIdentifier, $userPeriod, $userLimit); |
|
98 | + } |
|
99 | 99 | } |
@@ -48,23 +48,23 @@ discard block |
||
48 | 48 | * @inheritdoc |
49 | 49 | */ |
50 | 50 | public function run(IOutput $output) { |
51 | - $orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendars', 'calendarid'); |
|
51 | + $orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendars', 'calendarid'); |
|
52 | 52 | $output->info(sprintf('%d events without a calendar have been cleaned up', $orphanItems)); |
53 | - $orphanItems = $this->removeOrphanChildren('calendarobjects_props', 'calendarobjects', 'objectid'); |
|
53 | + $orphanItems = $this->removeOrphanChildren('calendarobjects_props', 'calendarobjects', 'objectid'); |
|
54 | 54 | $output->info(sprintf('%d properties without an events have been cleaned up', $orphanItems)); |
55 | - $orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendars', 'calendarid'); |
|
55 | + $orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendars', 'calendarid'); |
|
56 | 56 | $output->info(sprintf('%d changes without a calendar have been cleaned up', $orphanItems)); |
57 | 57 | |
58 | - $orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendarsubscriptions', 'calendarid'); |
|
58 | + $orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendarsubscriptions', 'calendarid'); |
|
59 | 59 | $output->info(sprintf('%d cached events without a calendar subscription have been cleaned up', $orphanItems)); |
60 | - $orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendarsubscriptions', 'calendarid'); |
|
60 | + $orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendarsubscriptions', 'calendarid'); |
|
61 | 61 | $output->info(sprintf('%d changes without a calendar subscription have been cleaned up', $orphanItems)); |
62 | 62 | |
63 | - $orphanItems = $this->removeOrphanChildren('cards', 'addressbooks', 'addressbookid'); |
|
63 | + $orphanItems = $this->removeOrphanChildren('cards', 'addressbooks', 'addressbookid'); |
|
64 | 64 | $output->info(sprintf('%d contacts without an addressbook have been cleaned up', $orphanItems)); |
65 | - $orphanItems = $this->removeOrphanChildren('cards_properties', 'cards', 'cardid'); |
|
65 | + $orphanItems = $this->removeOrphanChildren('cards_properties', 'cards', 'cardid'); |
|
66 | 66 | $output->info(sprintf('%d properties without a contact have been cleaned up', $orphanItems)); |
67 | - $orphanItems = $this->removeOrphanChildren('addressbookchanges', 'addressbooks', 'addressbookid'); |
|
67 | + $orphanItems = $this->removeOrphanChildren('addressbookchanges', 'addressbooks', 'addressbookid'); |
|
68 | 68 | $output->info(sprintf('%d changes without an addressbook have been cleaned up', $orphanItems)); |
69 | 69 | } |
70 | 70 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | $qb->select('c.id') |
75 | 75 | ->from($childTable, 'c') |
76 | - ->leftJoin('c', $parentTable, 'p', $qb->expr()->eq('c.' . $parentId, 'p.id')) |
|
76 | + ->leftJoin('c', $parentTable, 'p', $qb->expr()->eq('c.'.$parentId, 'p.id')) |
|
77 | 77 | ->where($qb->expr()->isNull('p.id')); |
78 | 78 | |
79 | 79 | if (\in_array($parentTable, ['calendars', 'calendarsubscriptions'], true)) { |
@@ -35,76 +35,76 @@ |
||
35 | 35 | |
36 | 36 | class RemoveOrphanEventsAndContacts implements IRepairStep { |
37 | 37 | |
38 | - /** @var IDBConnection */ |
|
39 | - private $connection; |
|
40 | - |
|
41 | - public function __construct(IDBConnection $connection) { |
|
42 | - $this->connection = $connection; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @inheritdoc |
|
47 | - */ |
|
48 | - public function getName(): string { |
|
49 | - return 'Clean up orphan event and contact data'; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @inheritdoc |
|
54 | - */ |
|
55 | - public function run(IOutput $output) { |
|
56 | - $orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendars', 'calendarid'); |
|
57 | - $output->info(sprintf('%d events without a calendar have been cleaned up', $orphanItems)); |
|
58 | - $orphanItems = $this->removeOrphanChildren('calendarobjects_props', 'calendarobjects', 'objectid'); |
|
59 | - $output->info(sprintf('%d properties without an events have been cleaned up', $orphanItems)); |
|
60 | - $orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendars', 'calendarid'); |
|
61 | - $output->info(sprintf('%d changes without a calendar have been cleaned up', $orphanItems)); |
|
62 | - |
|
63 | - $orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendarsubscriptions', 'calendarid'); |
|
64 | - $output->info(sprintf('%d cached events without a calendar subscription have been cleaned up', $orphanItems)); |
|
65 | - $orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendarsubscriptions', 'calendarid'); |
|
66 | - $output->info(sprintf('%d changes without a calendar subscription have been cleaned up', $orphanItems)); |
|
67 | - |
|
68 | - $orphanItems = $this->removeOrphanChildren('cards', 'addressbooks', 'addressbookid'); |
|
69 | - $output->info(sprintf('%d contacts without an addressbook have been cleaned up', $orphanItems)); |
|
70 | - $orphanItems = $this->removeOrphanChildren('cards_properties', 'cards', 'cardid'); |
|
71 | - $output->info(sprintf('%d properties without a contact have been cleaned up', $orphanItems)); |
|
72 | - $orphanItems = $this->removeOrphanChildren('addressbookchanges', 'addressbooks', 'addressbookid'); |
|
73 | - $output->info(sprintf('%d changes without an addressbook have been cleaned up', $orphanItems)); |
|
74 | - } |
|
75 | - |
|
76 | - protected function removeOrphanChildren($childTable, $parentTable, $parentId): int { |
|
77 | - $qb = $this->connection->getQueryBuilder(); |
|
78 | - |
|
79 | - $qb->select('c.id') |
|
80 | - ->from($childTable, 'c') |
|
81 | - ->leftJoin('c', $parentTable, 'p', $qb->expr()->eq('c.' . $parentId, 'p.id')) |
|
82 | - ->where($qb->expr()->isNull('p.id')); |
|
83 | - |
|
84 | - if (\in_array($parentTable, ['calendars', 'calendarsubscriptions'], true)) { |
|
85 | - $calendarType = $parentTable === 'calendarsubscriptions' ? CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION : CalDavBackend::CALENDAR_TYPE_CALENDAR; |
|
86 | - $qb->andWhere($qb->expr()->eq('c.calendartype', $qb->createNamedParameter($calendarType, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT)); |
|
87 | - } |
|
88 | - |
|
89 | - $result = $qb->execute(); |
|
90 | - |
|
91 | - $orphanItems = []; |
|
92 | - while ($row = $result->fetch()) { |
|
93 | - $orphanItems[] = (int) $row['id']; |
|
94 | - } |
|
95 | - $result->closeCursor(); |
|
96 | - |
|
97 | - if (!empty($orphanItems)) { |
|
98 | - $qb->delete($childTable) |
|
99 | - ->where($qb->expr()->in('id', $qb->createParameter('ids'))); |
|
100 | - |
|
101 | - $orphanItemsBatch = array_chunk($orphanItems, 200); |
|
102 | - foreach ($orphanItemsBatch as $items) { |
|
103 | - $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY); |
|
104 | - $qb->execute(); |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - return count($orphanItems); |
|
109 | - } |
|
38 | + /** @var IDBConnection */ |
|
39 | + private $connection; |
|
40 | + |
|
41 | + public function __construct(IDBConnection $connection) { |
|
42 | + $this->connection = $connection; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @inheritdoc |
|
47 | + */ |
|
48 | + public function getName(): string { |
|
49 | + return 'Clean up orphan event and contact data'; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @inheritdoc |
|
54 | + */ |
|
55 | + public function run(IOutput $output) { |
|
56 | + $orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendars', 'calendarid'); |
|
57 | + $output->info(sprintf('%d events without a calendar have been cleaned up', $orphanItems)); |
|
58 | + $orphanItems = $this->removeOrphanChildren('calendarobjects_props', 'calendarobjects', 'objectid'); |
|
59 | + $output->info(sprintf('%d properties without an events have been cleaned up', $orphanItems)); |
|
60 | + $orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendars', 'calendarid'); |
|
61 | + $output->info(sprintf('%d changes without a calendar have been cleaned up', $orphanItems)); |
|
62 | + |
|
63 | + $orphanItems = $this->removeOrphanChildren('calendarobjects', 'calendarsubscriptions', 'calendarid'); |
|
64 | + $output->info(sprintf('%d cached events without a calendar subscription have been cleaned up', $orphanItems)); |
|
65 | + $orphanItems = $this->removeOrphanChildren('calendarchanges', 'calendarsubscriptions', 'calendarid'); |
|
66 | + $output->info(sprintf('%d changes without a calendar subscription have been cleaned up', $orphanItems)); |
|
67 | + |
|
68 | + $orphanItems = $this->removeOrphanChildren('cards', 'addressbooks', 'addressbookid'); |
|
69 | + $output->info(sprintf('%d contacts without an addressbook have been cleaned up', $orphanItems)); |
|
70 | + $orphanItems = $this->removeOrphanChildren('cards_properties', 'cards', 'cardid'); |
|
71 | + $output->info(sprintf('%d properties without a contact have been cleaned up', $orphanItems)); |
|
72 | + $orphanItems = $this->removeOrphanChildren('addressbookchanges', 'addressbooks', 'addressbookid'); |
|
73 | + $output->info(sprintf('%d changes without an addressbook have been cleaned up', $orphanItems)); |
|
74 | + } |
|
75 | + |
|
76 | + protected function removeOrphanChildren($childTable, $parentTable, $parentId): int { |
|
77 | + $qb = $this->connection->getQueryBuilder(); |
|
78 | + |
|
79 | + $qb->select('c.id') |
|
80 | + ->from($childTable, 'c') |
|
81 | + ->leftJoin('c', $parentTable, 'p', $qb->expr()->eq('c.' . $parentId, 'p.id')) |
|
82 | + ->where($qb->expr()->isNull('p.id')); |
|
83 | + |
|
84 | + if (\in_array($parentTable, ['calendars', 'calendarsubscriptions'], true)) { |
|
85 | + $calendarType = $parentTable === 'calendarsubscriptions' ? CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION : CalDavBackend::CALENDAR_TYPE_CALENDAR; |
|
86 | + $qb->andWhere($qb->expr()->eq('c.calendartype', $qb->createNamedParameter($calendarType, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT)); |
|
87 | + } |
|
88 | + |
|
89 | + $result = $qb->execute(); |
|
90 | + |
|
91 | + $orphanItems = []; |
|
92 | + while ($row = $result->fetch()) { |
|
93 | + $orphanItems[] = (int) $row['id']; |
|
94 | + } |
|
95 | + $result->closeCursor(); |
|
96 | + |
|
97 | + if (!empty($orphanItems)) { |
|
98 | + $qb->delete($childTable) |
|
99 | + ->where($qb->expr()->in('id', $qb->createParameter('ids'))); |
|
100 | + |
|
101 | + $orphanItemsBatch = array_chunk($orphanItems, 200); |
|
102 | + foreach ($orphanItemsBatch as $items) { |
|
103 | + $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY); |
|
104 | + $qb->execute(); |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + return count($orphanItems); |
|
109 | + } |
|
110 | 110 | } |