@@ -78,7 +78,7 @@ |
||
| 78 | 78 | $this->logger->debug('Default user calendar reset'); |
| 79 | 79 | } catch (Throwable $e) { |
| 80 | 80 | // Any error with activities shouldn't abort the calendar deletion, so we just log it |
| 81 | - $this->logger->error('Error generating activities for a deleted calendar: ' . $e->getMessage(), [ |
|
| 81 | + $this->logger->error('Error generating activities for a deleted calendar: '.$e->getMessage(), [ |
|
| 82 | 82 | 'exception' => $e, |
| 83 | 83 | ]); |
| 84 | 84 | } |
@@ -20,43 +20,43 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class CalendarDeletionDefaultUpdaterListener implements IEventListener { |
| 22 | 22 | |
| 23 | - public function __construct( |
|
| 24 | - private IConfig $config, |
|
| 25 | - private LoggerInterface $logger, |
|
| 26 | - ) { |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * In case the user has set their default calendar to the deleted one |
|
| 31 | - */ |
|
| 32 | - public function handle(Event $event): void { |
|
| 33 | - if (!($event instanceof CalendarDeletedEvent)) { |
|
| 34 | - // Not what we subscribed to |
|
| 35 | - return; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - try { |
|
| 39 | - $principalUri = $event->getCalendarData()['principaluri']; |
|
| 40 | - if (!str_starts_with($principalUri, 'principals/users')) { |
|
| 41 | - $this->logger->debug('Default calendar needs no update because the deleted calendar does not belong to a user principal'); |
|
| 42 | - return; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - [, $uid] = \Sabre\Uri\split($principalUri); |
|
| 46 | - $uri = $event->getCalendarData()['uri']; |
|
| 47 | - if ($this->config->getUserValue($uid, 'dav', 'defaultCalendar') !== $uri) { |
|
| 48 | - $this->logger->debug('Default calendar needs no update because the deleted calendar is no the user\'s default one'); |
|
| 49 | - return; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - $this->config->deleteUserValue($uid, 'dav', 'defaultCalendar'); |
|
| 53 | - |
|
| 54 | - $this->logger->debug('Default user calendar reset'); |
|
| 55 | - } catch (Throwable $e) { |
|
| 56 | - // Any error with activities shouldn't abort the calendar deletion, so we just log it |
|
| 57 | - $this->logger->error('Error generating activities for a deleted calendar: ' . $e->getMessage(), [ |
|
| 58 | - 'exception' => $e, |
|
| 59 | - ]); |
|
| 60 | - } |
|
| 61 | - } |
|
| 23 | + public function __construct( |
|
| 24 | + private IConfig $config, |
|
| 25 | + private LoggerInterface $logger, |
|
| 26 | + ) { |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * In case the user has set their default calendar to the deleted one |
|
| 31 | + */ |
|
| 32 | + public function handle(Event $event): void { |
|
| 33 | + if (!($event instanceof CalendarDeletedEvent)) { |
|
| 34 | + // Not what we subscribed to |
|
| 35 | + return; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + try { |
|
| 39 | + $principalUri = $event->getCalendarData()['principaluri']; |
|
| 40 | + if (!str_starts_with($principalUri, 'principals/users')) { |
|
| 41 | + $this->logger->debug('Default calendar needs no update because the deleted calendar does not belong to a user principal'); |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + [, $uid] = \Sabre\Uri\split($principalUri); |
|
| 46 | + $uri = $event->getCalendarData()['uri']; |
|
| 47 | + if ($this->config->getUserValue($uid, 'dav', 'defaultCalendar') !== $uri) { |
|
| 48 | + $this->logger->debug('Default calendar needs no update because the deleted calendar is no the user\'s default one'); |
|
| 49 | + return; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + $this->config->deleteUserValue($uid, 'dav', 'defaultCalendar'); |
|
| 53 | + |
|
| 54 | + $this->logger->debug('Default user calendar reset'); |
|
| 55 | + } catch (Throwable $e) { |
|
| 56 | + // Any error with activities shouldn't abort the calendar deletion, so we just log it |
|
| 57 | + $this->logger->error('Error generating activities for a deleted calendar: ' . $e->getMessage(), [ |
|
| 58 | + 'exception' => $e, |
|
| 59 | + ]); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | protected function run($argument) { |
| 110 | - $try = (int)$argument['try'] + 1; |
|
| 110 | + $try = (int) $argument['try'] + 1; |
|
| 111 | 111 | |
| 112 | 112 | switch ($argument['type']) { |
| 113 | 113 | case IAccountManager::PROPERTY_WEBSITE: |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | break; |
| 120 | 120 | default: |
| 121 | 121 | // no valid type given, no need to retry |
| 122 | - $this->logger->error($argument['type'] . ' is no valid type for user account data.'); |
|
| 122 | + $this->logger->error($argument['type'].' is no valid type for user account data.'); |
|
| 123 | 123 | $result = true; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | protected function verifyWebsite(array $argument) { |
| 138 | 138 | $result = false; |
| 139 | 139 | |
| 140 | - $url = rtrim($argument['data'], '/') . '/.well-known/' . 'CloudIdVerificationCode.txt'; |
|
| 140 | + $url = rtrim($argument['data'], '/').'/.well-known/'.'CloudIdVerificationCode.txt'; |
|
| 141 | 141 | |
| 142 | 142 | $client = $this->httpClientService->newClient(); |
| 143 | 143 | try { |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | $user = $this->userManager->get($argument['uid']); |
| 155 | 155 | // we don't check a valid user -> give up |
| 156 | 156 | if ($user === null) { |
| 157 | - $this->logger->error($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 157 | + $this->logger->error($argument['uid'].' doesn\'t exist, can\'t verify user data.'); |
|
| 158 | 158 | return $result; |
| 159 | 159 | } |
| 160 | 160 | $userAccount = $this->accountManager->getAccount($user); |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | // we don't check a valid user -> give up |
| 182 | 182 | if ($user === null) { |
| 183 | - $this->logger->info($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 183 | + $this->logger->info($argument['uid'].' doesn\'t exist, can\'t verify user data.'); |
|
| 184 | 184 | return true; |
| 185 | 185 | } |
| 186 | 186 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | try { |
| 223 | 223 | $client = $this->httpClientService->newClient(); |
| 224 | 224 | $response = $client->get( |
| 225 | - $this->lookupServerUrl . '/users?search=' . urlencode($cloudId) . '&exactCloudId=1', |
|
| 225 | + $this->lookupServerUrl.'/users?search='.urlencode($cloudId).'&exactCloudId=1', |
|
| 226 | 226 | [ |
| 227 | 227 | 'timeout' => 10, |
| 228 | 228 | 'connect_timeout' => 3, |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | 'data' => $argument['data'], |
| 255 | 255 | 'type' => $argument['type'], |
| 256 | 256 | 'uid' => $argument['uid'], |
| 257 | - 'try' => (int)$argument['try'] + 1, |
|
| 257 | + 'try' => (int) $argument['try'] + 1, |
|
| 258 | 258 | 'lastRun' => time() |
| 259 | 259 | ] |
| 260 | 260 | ); |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @return bool |
| 268 | 268 | */ |
| 269 | 269 | protected function shouldRun(array $argument) { |
| 270 | - $lastRun = (int)$argument['lastRun']; |
|
| 270 | + $lastRun = (int) $argument['lastRun']; |
|
| 271 | 271 | return ((time() - $lastRun) > $this->interval); |
| 272 | 272 | } |
| 273 | 273 | |
@@ -20,224 +20,224 @@ |
||
| 20 | 20 | use Psr\Log\LoggerInterface; |
| 21 | 21 | |
| 22 | 22 | class VerifyUserData extends Job { |
| 23 | - /** @var bool */ |
|
| 24 | - private bool $retainJob = true; |
|
| 25 | - |
|
| 26 | - /** @var int max number of attempts to send the request */ |
|
| 27 | - private int $maxTry = 24; |
|
| 28 | - |
|
| 29 | - /** @var int how much time should be between two tries (1 hour) */ |
|
| 30 | - private int $interval = 3600; |
|
| 31 | - private string $lookupServerUrl; |
|
| 32 | - |
|
| 33 | - public function __construct( |
|
| 34 | - private IAccountManager $accountManager, |
|
| 35 | - private IUserManager $userManager, |
|
| 36 | - private IClientService $httpClientService, |
|
| 37 | - private LoggerInterface $logger, |
|
| 38 | - ITimeFactory $timeFactory, |
|
| 39 | - private IConfig $config, |
|
| 40 | - ) { |
|
| 41 | - parent::__construct($timeFactory); |
|
| 42 | - |
|
| 43 | - $lookupServerUrl = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 44 | - $this->lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function start(IJobList $jobList): void { |
|
| 48 | - if ($this->shouldRun($this->argument)) { |
|
| 49 | - parent::start($jobList); |
|
| 50 | - $jobList->remove($this, $this->argument); |
|
| 51 | - if ($this->retainJob) { |
|
| 52 | - $this->reAddJob($jobList, $this->argument); |
|
| 53 | - } else { |
|
| 54 | - $this->resetVerificationState(); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - protected function run($argument) { |
|
| 60 | - $try = (int)$argument['try'] + 1; |
|
| 61 | - |
|
| 62 | - switch ($argument['type']) { |
|
| 63 | - case IAccountManager::PROPERTY_WEBSITE: |
|
| 64 | - $result = $this->verifyWebsite($argument); |
|
| 65 | - break; |
|
| 66 | - case IAccountManager::PROPERTY_TWITTER: |
|
| 67 | - case IAccountManager::PROPERTY_EMAIL: |
|
| 68 | - $result = $this->verifyViaLookupServer($argument, $argument['type']); |
|
| 69 | - break; |
|
| 70 | - default: |
|
| 71 | - // no valid type given, no need to retry |
|
| 72 | - $this->logger->error($argument['type'] . ' is no valid type for user account data.'); |
|
| 73 | - $result = true; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ($result === true || $try > $this->maxTry) { |
|
| 77 | - $this->retainJob = false; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * verify web page |
|
| 83 | - * |
|
| 84 | - * @param array $argument |
|
| 85 | - * @return bool true if we could check the verification code, otherwise false |
|
| 86 | - */ |
|
| 87 | - protected function verifyWebsite(array $argument) { |
|
| 88 | - $result = false; |
|
| 89 | - |
|
| 90 | - $url = rtrim($argument['data'], '/') . '/.well-known/' . 'CloudIdVerificationCode.txt'; |
|
| 91 | - |
|
| 92 | - $client = $this->httpClientService->newClient(); |
|
| 93 | - try { |
|
| 94 | - $response = $client->get($url); |
|
| 95 | - } catch (\Exception $e) { |
|
| 96 | - return false; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if ($response->getStatusCode() === Http::STATUS_OK) { |
|
| 100 | - $result = true; |
|
| 101 | - $publishedCode = $response->getBody(); |
|
| 102 | - // remove new lines and spaces |
|
| 103 | - $publishedCodeSanitized = trim(preg_replace('/\s\s+/', ' ', $publishedCode)); |
|
| 104 | - $user = $this->userManager->get($argument['uid']); |
|
| 105 | - // we don't check a valid user -> give up |
|
| 106 | - if ($user === null) { |
|
| 107 | - $this->logger->error($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 108 | - return $result; |
|
| 109 | - } |
|
| 110 | - $userAccount = $this->accountManager->getAccount($user); |
|
| 111 | - $websiteProp = $userAccount->getProperty(IAccountManager::PROPERTY_WEBSITE); |
|
| 112 | - $websiteProp->setVerified($publishedCodeSanitized === $argument['verificationCode'] |
|
| 113 | - ? IAccountManager::VERIFIED |
|
| 114 | - : IAccountManager::NOT_VERIFIED |
|
| 115 | - ); |
|
| 116 | - $this->accountManager->updateAccount($userAccount); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - return $result; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - protected function verifyViaLookupServer(array $argument, string $dataType): bool { |
|
| 123 | - // TODO: Consider to enable for non-global-scale setups by checking 'files_sharing', 'lookupServerUploadEnabled' |
|
| 124 | - if (!$this->config->getSystemValueBool('gs.enabled', false) |
|
| 125 | - || empty($this->lookupServerUrl) |
|
| 126 | - || $this->config->getSystemValue('has_internet_connection', true) === false |
|
| 127 | - ) { |
|
| 128 | - return true; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $user = $this->userManager->get($argument['uid']); |
|
| 132 | - |
|
| 133 | - // we don't check a valid user -> give up |
|
| 134 | - if ($user === null) { |
|
| 135 | - $this->logger->info($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 136 | - return true; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $cloudId = $user->getCloudId(); |
|
| 140 | - $lookupServerData = $this->queryLookupServer($cloudId); |
|
| 141 | - |
|
| 142 | - // for some reasons we couldn't read any data from the lookup server, try again later |
|
| 143 | - if (empty($lookupServerData) || empty($lookupServerData[$dataType])) { |
|
| 144 | - return false; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // lookup server has verification data for wrong user data (e.g. email address), try again later |
|
| 148 | - if ($lookupServerData[$dataType]['value'] !== $argument['data']) { |
|
| 149 | - return false; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // lookup server hasn't verified the email address so far, try again later |
|
| 153 | - if ($lookupServerData[$dataType]['verified'] === IAccountManager::NOT_VERIFIED) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - try { |
|
| 158 | - $userAccount = $this->accountManager->getAccount($user); |
|
| 159 | - $property = $userAccount->getProperty($dataType); |
|
| 160 | - $property->setVerified(IAccountManager::VERIFIED); |
|
| 161 | - $this->accountManager->updateAccount($userAccount); |
|
| 162 | - } catch (PropertyDoesNotExistException $e) { |
|
| 163 | - return false; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - return true; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param string $cloudId |
|
| 171 | - * @return array |
|
| 172 | - */ |
|
| 173 | - protected function queryLookupServer($cloudId) { |
|
| 174 | - try { |
|
| 175 | - $client = $this->httpClientService->newClient(); |
|
| 176 | - $response = $client->get( |
|
| 177 | - $this->lookupServerUrl . '/users?search=' . urlencode($cloudId) . '&exactCloudId=1', |
|
| 178 | - [ |
|
| 179 | - 'timeout' => 10, |
|
| 180 | - 'connect_timeout' => 3, |
|
| 181 | - ] |
|
| 182 | - ); |
|
| 183 | - |
|
| 184 | - $body = json_decode($response->getBody(), true); |
|
| 185 | - |
|
| 186 | - if (is_array($body) && isset($body['federationId']) && $body['federationId'] === $cloudId) { |
|
| 187 | - return $body; |
|
| 188 | - } |
|
| 189 | - } catch (\Exception $e) { |
|
| 190 | - // do nothing, we will just re-try later |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - return []; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * re-add background job with new arguments |
|
| 198 | - * |
|
| 199 | - * @param IJobList $jobList |
|
| 200 | - * @param array $argument |
|
| 201 | - */ |
|
| 202 | - protected function reAddJob(IJobList $jobList, array $argument) { |
|
| 203 | - $jobList->add(VerifyUserData::class, |
|
| 204 | - [ |
|
| 205 | - 'verificationCode' => $argument['verificationCode'], |
|
| 206 | - 'data' => $argument['data'], |
|
| 207 | - 'type' => $argument['type'], |
|
| 208 | - 'uid' => $argument['uid'], |
|
| 209 | - 'try' => (int)$argument['try'] + 1, |
|
| 210 | - 'lastRun' => time() |
|
| 211 | - ] |
|
| 212 | - ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * test if it is time for the next run |
|
| 217 | - * |
|
| 218 | - * @param array $argument |
|
| 219 | - * @return bool |
|
| 220 | - */ |
|
| 221 | - protected function shouldRun(array $argument) { |
|
| 222 | - $lastRun = (int)$argument['lastRun']; |
|
| 223 | - return ((time() - $lastRun) > $this->interval); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * reset verification state after max tries are reached |
|
| 229 | - */ |
|
| 230 | - protected function resetVerificationState(): void { |
|
| 231 | - $user = $this->userManager->get($this->argument['uid']); |
|
| 232 | - if ($user !== null) { |
|
| 233 | - $userAccount = $this->accountManager->getAccount($user); |
|
| 234 | - try { |
|
| 235 | - $property = $userAccount->getProperty($this->argument['type']); |
|
| 236 | - $property->setVerified(IAccountManager::NOT_VERIFIED); |
|
| 237 | - $this->accountManager->updateAccount($userAccount); |
|
| 238 | - } catch (PropertyDoesNotExistException $e) { |
|
| 239 | - return; |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - } |
|
| 23 | + /** @var bool */ |
|
| 24 | + private bool $retainJob = true; |
|
| 25 | + |
|
| 26 | + /** @var int max number of attempts to send the request */ |
|
| 27 | + private int $maxTry = 24; |
|
| 28 | + |
|
| 29 | + /** @var int how much time should be between two tries (1 hour) */ |
|
| 30 | + private int $interval = 3600; |
|
| 31 | + private string $lookupServerUrl; |
|
| 32 | + |
|
| 33 | + public function __construct( |
|
| 34 | + private IAccountManager $accountManager, |
|
| 35 | + private IUserManager $userManager, |
|
| 36 | + private IClientService $httpClientService, |
|
| 37 | + private LoggerInterface $logger, |
|
| 38 | + ITimeFactory $timeFactory, |
|
| 39 | + private IConfig $config, |
|
| 40 | + ) { |
|
| 41 | + parent::__construct($timeFactory); |
|
| 42 | + |
|
| 43 | + $lookupServerUrl = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 44 | + $this->lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function start(IJobList $jobList): void { |
|
| 48 | + if ($this->shouldRun($this->argument)) { |
|
| 49 | + parent::start($jobList); |
|
| 50 | + $jobList->remove($this, $this->argument); |
|
| 51 | + if ($this->retainJob) { |
|
| 52 | + $this->reAddJob($jobList, $this->argument); |
|
| 53 | + } else { |
|
| 54 | + $this->resetVerificationState(); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + protected function run($argument) { |
|
| 60 | + $try = (int)$argument['try'] + 1; |
|
| 61 | + |
|
| 62 | + switch ($argument['type']) { |
|
| 63 | + case IAccountManager::PROPERTY_WEBSITE: |
|
| 64 | + $result = $this->verifyWebsite($argument); |
|
| 65 | + break; |
|
| 66 | + case IAccountManager::PROPERTY_TWITTER: |
|
| 67 | + case IAccountManager::PROPERTY_EMAIL: |
|
| 68 | + $result = $this->verifyViaLookupServer($argument, $argument['type']); |
|
| 69 | + break; |
|
| 70 | + default: |
|
| 71 | + // no valid type given, no need to retry |
|
| 72 | + $this->logger->error($argument['type'] . ' is no valid type for user account data.'); |
|
| 73 | + $result = true; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ($result === true || $try > $this->maxTry) { |
|
| 77 | + $this->retainJob = false; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * verify web page |
|
| 83 | + * |
|
| 84 | + * @param array $argument |
|
| 85 | + * @return bool true if we could check the verification code, otherwise false |
|
| 86 | + */ |
|
| 87 | + protected function verifyWebsite(array $argument) { |
|
| 88 | + $result = false; |
|
| 89 | + |
|
| 90 | + $url = rtrim($argument['data'], '/') . '/.well-known/' . 'CloudIdVerificationCode.txt'; |
|
| 91 | + |
|
| 92 | + $client = $this->httpClientService->newClient(); |
|
| 93 | + try { |
|
| 94 | + $response = $client->get($url); |
|
| 95 | + } catch (\Exception $e) { |
|
| 96 | + return false; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if ($response->getStatusCode() === Http::STATUS_OK) { |
|
| 100 | + $result = true; |
|
| 101 | + $publishedCode = $response->getBody(); |
|
| 102 | + // remove new lines and spaces |
|
| 103 | + $publishedCodeSanitized = trim(preg_replace('/\s\s+/', ' ', $publishedCode)); |
|
| 104 | + $user = $this->userManager->get($argument['uid']); |
|
| 105 | + // we don't check a valid user -> give up |
|
| 106 | + if ($user === null) { |
|
| 107 | + $this->logger->error($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 108 | + return $result; |
|
| 109 | + } |
|
| 110 | + $userAccount = $this->accountManager->getAccount($user); |
|
| 111 | + $websiteProp = $userAccount->getProperty(IAccountManager::PROPERTY_WEBSITE); |
|
| 112 | + $websiteProp->setVerified($publishedCodeSanitized === $argument['verificationCode'] |
|
| 113 | + ? IAccountManager::VERIFIED |
|
| 114 | + : IAccountManager::NOT_VERIFIED |
|
| 115 | + ); |
|
| 116 | + $this->accountManager->updateAccount($userAccount); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + return $result; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + protected function verifyViaLookupServer(array $argument, string $dataType): bool { |
|
| 123 | + // TODO: Consider to enable for non-global-scale setups by checking 'files_sharing', 'lookupServerUploadEnabled' |
|
| 124 | + if (!$this->config->getSystemValueBool('gs.enabled', false) |
|
| 125 | + || empty($this->lookupServerUrl) |
|
| 126 | + || $this->config->getSystemValue('has_internet_connection', true) === false |
|
| 127 | + ) { |
|
| 128 | + return true; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $user = $this->userManager->get($argument['uid']); |
|
| 132 | + |
|
| 133 | + // we don't check a valid user -> give up |
|
| 134 | + if ($user === null) { |
|
| 135 | + $this->logger->info($argument['uid'] . ' doesn\'t exist, can\'t verify user data.'); |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $cloudId = $user->getCloudId(); |
|
| 140 | + $lookupServerData = $this->queryLookupServer($cloudId); |
|
| 141 | + |
|
| 142 | + // for some reasons we couldn't read any data from the lookup server, try again later |
|
| 143 | + if (empty($lookupServerData) || empty($lookupServerData[$dataType])) { |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // lookup server has verification data for wrong user data (e.g. email address), try again later |
|
| 148 | + if ($lookupServerData[$dataType]['value'] !== $argument['data']) { |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // lookup server hasn't verified the email address so far, try again later |
|
| 153 | + if ($lookupServerData[$dataType]['verified'] === IAccountManager::NOT_VERIFIED) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + try { |
|
| 158 | + $userAccount = $this->accountManager->getAccount($user); |
|
| 159 | + $property = $userAccount->getProperty($dataType); |
|
| 160 | + $property->setVerified(IAccountManager::VERIFIED); |
|
| 161 | + $this->accountManager->updateAccount($userAccount); |
|
| 162 | + } catch (PropertyDoesNotExistException $e) { |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + return true; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param string $cloudId |
|
| 171 | + * @return array |
|
| 172 | + */ |
|
| 173 | + protected function queryLookupServer($cloudId) { |
|
| 174 | + try { |
|
| 175 | + $client = $this->httpClientService->newClient(); |
|
| 176 | + $response = $client->get( |
|
| 177 | + $this->lookupServerUrl . '/users?search=' . urlencode($cloudId) . '&exactCloudId=1', |
|
| 178 | + [ |
|
| 179 | + 'timeout' => 10, |
|
| 180 | + 'connect_timeout' => 3, |
|
| 181 | + ] |
|
| 182 | + ); |
|
| 183 | + |
|
| 184 | + $body = json_decode($response->getBody(), true); |
|
| 185 | + |
|
| 186 | + if (is_array($body) && isset($body['federationId']) && $body['federationId'] === $cloudId) { |
|
| 187 | + return $body; |
|
| 188 | + } |
|
| 189 | + } catch (\Exception $e) { |
|
| 190 | + // do nothing, we will just re-try later |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + return []; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * re-add background job with new arguments |
|
| 198 | + * |
|
| 199 | + * @param IJobList $jobList |
|
| 200 | + * @param array $argument |
|
| 201 | + */ |
|
| 202 | + protected function reAddJob(IJobList $jobList, array $argument) { |
|
| 203 | + $jobList->add(VerifyUserData::class, |
|
| 204 | + [ |
|
| 205 | + 'verificationCode' => $argument['verificationCode'], |
|
| 206 | + 'data' => $argument['data'], |
|
| 207 | + 'type' => $argument['type'], |
|
| 208 | + 'uid' => $argument['uid'], |
|
| 209 | + 'try' => (int)$argument['try'] + 1, |
|
| 210 | + 'lastRun' => time() |
|
| 211 | + ] |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * test if it is time for the next run |
|
| 217 | + * |
|
| 218 | + * @param array $argument |
|
| 219 | + * @return bool |
|
| 220 | + */ |
|
| 221 | + protected function shouldRun(array $argument) { |
|
| 222 | + $lastRun = (int)$argument['lastRun']; |
|
| 223 | + return ((time() - $lastRun) > $this->interval); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * reset verification state after max tries are reached |
|
| 229 | + */ |
|
| 230 | + protected function resetVerificationState(): void { |
|
| 231 | + $user = $this->userManager->get($this->argument['uid']); |
|
| 232 | + if ($user !== null) { |
|
| 233 | + $userAccount = $this->accountManager->getAccount($user); |
|
| 234 | + try { |
|
| 235 | + $property = $userAccount->getProperty($this->argument['type']); |
|
| 236 | + $property->setVerified(IAccountManager::NOT_VERIFIED); |
|
| 237 | + $this->accountManager->updateAccount($userAccount); |
|
| 238 | + } catch (PropertyDoesNotExistException $e) { |
|
| 239 | + return; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | 243 | } |
@@ -32,51 +32,51 @@ |
||
| 32 | 32 | * @since 8.0.0 |
| 33 | 33 | */ |
| 34 | 34 | interface ICertificate { |
| 35 | - /** |
|
| 36 | - * @return string |
|
| 37 | - * @since 8.0.0 |
|
| 38 | - */ |
|
| 39 | - public function getName(): string; |
|
| 35 | + /** |
|
| 36 | + * @return string |
|
| 37 | + * @since 8.0.0 |
|
| 38 | + */ |
|
| 39 | + public function getName(): string; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return string|null |
|
| 43 | - * @since 8.0.0 |
|
| 44 | - */ |
|
| 45 | - public function getCommonName(): ?string; |
|
| 41 | + /** |
|
| 42 | + * @return string|null |
|
| 43 | + * @since 8.0.0 |
|
| 44 | + */ |
|
| 45 | + public function getCommonName(): ?string; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @return string|null |
|
| 49 | - * @since 8.0.0 |
|
| 50 | - */ |
|
| 51 | - public function getOrganization(): ?string; |
|
| 47 | + /** |
|
| 48 | + * @return string|null |
|
| 49 | + * @since 8.0.0 |
|
| 50 | + */ |
|
| 51 | + public function getOrganization(): ?string; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return \DateTime |
|
| 55 | - * @since 8.0.0 |
|
| 56 | - */ |
|
| 57 | - public function getIssueDate(): \DateTime; |
|
| 53 | + /** |
|
| 54 | + * @return \DateTime |
|
| 55 | + * @since 8.0.0 |
|
| 56 | + */ |
|
| 57 | + public function getIssueDate(): \DateTime; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @return \DateTime |
|
| 61 | - * @since 8.0.0 |
|
| 62 | - */ |
|
| 63 | - public function getExpireDate(): \DateTime; |
|
| 59 | + /** |
|
| 60 | + * @return \DateTime |
|
| 61 | + * @since 8.0.0 |
|
| 62 | + */ |
|
| 63 | + public function getExpireDate(): \DateTime; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @return bool |
|
| 67 | - * @since 8.0.0 |
|
| 68 | - */ |
|
| 69 | - public function isExpired(): bool; |
|
| 65 | + /** |
|
| 66 | + * @return bool |
|
| 67 | + * @since 8.0.0 |
|
| 68 | + */ |
|
| 69 | + public function isExpired(): bool; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return string|null |
|
| 73 | - * @since 8.0.0 |
|
| 74 | - */ |
|
| 75 | - public function getIssuerName(): ?string; |
|
| 71 | + /** |
|
| 72 | + * @return string|null |
|
| 73 | + * @since 8.0.0 |
|
| 74 | + */ |
|
| 75 | + public function getIssuerName(): ?string; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @return string|null |
|
| 79 | - * @since 8.0.0 |
|
| 80 | - */ |
|
| 81 | - public function getIssuerOrganization(): ?string; |
|
| 77 | + /** |
|
| 78 | + * @return string|null |
|
| 79 | + * @since 8.0.0 |
|
| 80 | + */ |
|
| 81 | + public function getIssuerOrganization(): ?string; |
|
| 82 | 82 | } |
@@ -32,43 +32,43 @@ |
||
| 32 | 32 | * @since 8.0.0 |
| 33 | 33 | */ |
| 34 | 34 | interface ICertificateManager { |
| 35 | - /** |
|
| 36 | - * Returns all certificates trusted by the system |
|
| 37 | - * |
|
| 38 | - * @return \OCP\ICertificate[] |
|
| 39 | - * @since 8.0.0 |
|
| 40 | - */ |
|
| 41 | - public function listCertificates(): array; |
|
| 35 | + /** |
|
| 36 | + * Returns all certificates trusted by the system |
|
| 37 | + * |
|
| 38 | + * @return \OCP\ICertificate[] |
|
| 39 | + * @since 8.0.0 |
|
| 40 | + */ |
|
| 41 | + public function listCertificates(): array; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param string $certificate the certificate data |
|
| 45 | - * @param string $name the filename for the certificate |
|
| 46 | - * @return \OCP\ICertificate |
|
| 47 | - * @throws \Exception If the certificate could not get added |
|
| 48 | - * @since 8.0.0 - since 8.1.0 throws exception instead of returning false |
|
| 49 | - */ |
|
| 50 | - public function addCertificate(string $certificate, string $name): \OCP\ICertificate; |
|
| 43 | + /** |
|
| 44 | + * @param string $certificate the certificate data |
|
| 45 | + * @param string $name the filename for the certificate |
|
| 46 | + * @return \OCP\ICertificate |
|
| 47 | + * @throws \Exception If the certificate could not get added |
|
| 48 | + * @since 8.0.0 - since 8.1.0 throws exception instead of returning false |
|
| 49 | + */ |
|
| 50 | + public function addCertificate(string $certificate, string $name): \OCP\ICertificate; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param string $name |
|
| 54 | - * @return bool |
|
| 55 | - * @since 8.0.0 |
|
| 56 | - */ |
|
| 57 | - public function removeCertificate(string $name): bool; |
|
| 52 | + /** |
|
| 53 | + * @param string $name |
|
| 54 | + * @return bool |
|
| 55 | + * @since 8.0.0 |
|
| 56 | + */ |
|
| 57 | + public function removeCertificate(string $name): bool; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Get the path to the certificate bundle |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - * @since 8.0.0 |
|
| 64 | - */ |
|
| 65 | - public function getCertificateBundle(): string; |
|
| 59 | + /** |
|
| 60 | + * Get the path to the certificate bundle |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + * @since 8.0.0 |
|
| 64 | + */ |
|
| 65 | + public function getCertificateBundle(): string; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Get the full local path to the certificate bundle |
|
| 69 | - * |
|
| 70 | - * @return string |
|
| 71 | - * @since 9.0.0 |
|
| 72 | - */ |
|
| 73 | - public function getAbsoluteBundlePath(): string; |
|
| 67 | + /** |
|
| 68 | + * Get the full local path to the certificate bundle |
|
| 69 | + * |
|
| 70 | + * @return string |
|
| 71 | + * @since 9.0.0 |
|
| 72 | + */ |
|
| 73 | + public function getAbsoluteBundlePath(): string; |
|
| 74 | 74 | } |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | 'count-dirs', |
| 62 | 62 | null, |
| 63 | 63 | InputOption::VALUE_NONE, |
| 64 | - 'Also count the number of user directories in the database (could time out on huge installations, therefore defaults to no with ' . self::DEFAULT_COUNT_DIRS_MAX_USERS . '+ users)' |
|
| 64 | + 'Also count the number of user directories in the database (could time out on huge installations, therefore defaults to no with '.self::DEFAULT_COUNT_DIRS_MAX_USERS.'+ users)' |
|
| 65 | 65 | ) |
| 66 | 66 | ; |
| 67 | 67 | } |
@@ -19,71 +19,71 @@ |
||
| 19 | 19 | use Symfony\Component\Console\Output\OutputInterface; |
| 20 | 20 | |
| 21 | 21 | class Report extends Command { |
| 22 | - public const DEFAULT_COUNT_DIRS_MAX_USERS = 500; |
|
| 22 | + public const DEFAULT_COUNT_DIRS_MAX_USERS = 500; |
|
| 23 | 23 | |
| 24 | - public function __construct( |
|
| 25 | - protected IUserManager $userManager, |
|
| 26 | - private IConfig $config, |
|
| 27 | - ) { |
|
| 28 | - parent::__construct(); |
|
| 29 | - } |
|
| 24 | + public function __construct( |
|
| 25 | + protected IUserManager $userManager, |
|
| 26 | + private IConfig $config, |
|
| 27 | + ) { |
|
| 28 | + parent::__construct(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - protected function configure(): void { |
|
| 32 | - $this |
|
| 33 | - ->setName('user:report') |
|
| 34 | - ->setDescription('shows how many users have access') |
|
| 35 | - ->addOption( |
|
| 36 | - 'count-dirs', |
|
| 37 | - null, |
|
| 38 | - InputOption::VALUE_NONE, |
|
| 39 | - 'Also count the number of user directories in the database (could time out on huge installations, therefore defaults to no with ' . self::DEFAULT_COUNT_DIRS_MAX_USERS . '+ users)' |
|
| 40 | - ) |
|
| 41 | - ; |
|
| 42 | - } |
|
| 31 | + protected function configure(): void { |
|
| 32 | + $this |
|
| 33 | + ->setName('user:report') |
|
| 34 | + ->setDescription('shows how many users have access') |
|
| 35 | + ->addOption( |
|
| 36 | + 'count-dirs', |
|
| 37 | + null, |
|
| 38 | + InputOption::VALUE_NONE, |
|
| 39 | + 'Also count the number of user directories in the database (could time out on huge installations, therefore defaults to no with ' . self::DEFAULT_COUNT_DIRS_MAX_USERS . '+ users)' |
|
| 40 | + ) |
|
| 41 | + ; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 45 | - $table = new Table($output); |
|
| 46 | - $table->setHeaders(['Account Report', '']); |
|
| 47 | - $userCountArray = $this->countUsers(); |
|
| 48 | - $total = 0; |
|
| 49 | - if (!empty($userCountArray)) { |
|
| 50 | - $rows = []; |
|
| 51 | - foreach ($userCountArray as $classname => $users) { |
|
| 52 | - $total += $users; |
|
| 53 | - $rows[] = [$classname, $users]; |
|
| 54 | - } |
|
| 44 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 45 | + $table = new Table($output); |
|
| 46 | + $table->setHeaders(['Account Report', '']); |
|
| 47 | + $userCountArray = $this->countUsers(); |
|
| 48 | + $total = 0; |
|
| 49 | + if (!empty($userCountArray)) { |
|
| 50 | + $rows = []; |
|
| 51 | + foreach ($userCountArray as $classname => $users) { |
|
| 52 | + $total += $users; |
|
| 53 | + $rows[] = [$classname, $users]; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $rows[] = [' ']; |
|
| 57 | - $rows[] = ['total users', $total]; |
|
| 58 | - } else { |
|
| 59 | - $rows[] = ['No backend enabled that supports user counting', '']; |
|
| 60 | - } |
|
| 61 | - $rows[] = [' ']; |
|
| 56 | + $rows[] = [' ']; |
|
| 57 | + $rows[] = ['total users', $total]; |
|
| 58 | + } else { |
|
| 59 | + $rows[] = ['No backend enabled that supports user counting', '']; |
|
| 60 | + } |
|
| 61 | + $rows[] = [' ']; |
|
| 62 | 62 | |
| 63 | - if ($total <= self::DEFAULT_COUNT_DIRS_MAX_USERS || $input->getOption('count-dirs')) { |
|
| 64 | - $userDirectoryCount = $this->countUserDirectories(); |
|
| 65 | - $rows[] = ['user directories', $userDirectoryCount]; |
|
| 66 | - } |
|
| 63 | + if ($total <= self::DEFAULT_COUNT_DIRS_MAX_USERS || $input->getOption('count-dirs')) { |
|
| 64 | + $userDirectoryCount = $this->countUserDirectories(); |
|
| 65 | + $rows[] = ['user directories', $userDirectoryCount]; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $activeUsers = $this->userManager->countSeenUsers(); |
|
| 69 | - $rows[] = ['active users', $activeUsers]; |
|
| 68 | + $activeUsers = $this->userManager->countSeenUsers(); |
|
| 69 | + $rows[] = ['active users', $activeUsers]; |
|
| 70 | 70 | |
| 71 | - $disabledUsers = $this->config->getUsersForUserValue('core', 'enabled', 'false'); |
|
| 72 | - $disabledUsersCount = count($disabledUsers); |
|
| 73 | - $rows[] = ['disabled users', $disabledUsersCount]; |
|
| 71 | + $disabledUsers = $this->config->getUsersForUserValue('core', 'enabled', 'false'); |
|
| 72 | + $disabledUsersCount = count($disabledUsers); |
|
| 73 | + $rows[] = ['disabled users', $disabledUsersCount]; |
|
| 74 | 74 | |
| 75 | - $table->setRows($rows); |
|
| 76 | - $table->render(); |
|
| 77 | - return 0; |
|
| 78 | - } |
|
| 75 | + $table->setRows($rows); |
|
| 76 | + $table->render(); |
|
| 77 | + return 0; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - private function countUsers(): array { |
|
| 81 | - return $this->userManager->countUsers(); |
|
| 82 | - } |
|
| 80 | + private function countUsers(): array { |
|
| 81 | + return $this->userManager->countUsers(); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - private function countUserDirectories(): int { |
|
| 85 | - $dataview = new View('/'); |
|
| 86 | - $userDirectories = $dataview->getDirectoryContent('/', 'httpd/unix-directory'); |
|
| 87 | - return count($userDirectories); |
|
| 88 | - } |
|
| 84 | + private function countUserDirectories(): int { |
|
| 85 | + $dataview = new View('/'); |
|
| 86 | + $userDirectories = $dataview->getDirectoryContent('/', 'httpd/unix-directory'); |
|
| 87 | + return count($userDirectories); |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | ); |
| 64 | 64 | } catch (Throwable $e) { |
| 65 | 65 | // Any error with activities shouldn't abort the addressbook creation, so we just log it |
| 66 | - $this->logger->error('Error generating activities for a new card in addressbook: ' . $e->getMessage(), [ |
|
| 66 | + $this->logger->error('Error generating activities for a new card in addressbook: '.$e->getMessage(), [ |
|
| 67 | 67 | 'exception' => $e, |
| 68 | 68 | ]); |
| 69 | 69 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | ); |
| 82 | 82 | } catch (Throwable $e) { |
| 83 | 83 | // Any error with activities shouldn't abort the addressbook update, so we just log it |
| 84 | - $this->logger->error('Error generating activities for a changed card in addressbook: ' . $e->getMessage(), [ |
|
| 84 | + $this->logger->error('Error generating activities for a changed card in addressbook: '.$e->getMessage(), [ |
|
| 85 | 85 | 'exception' => $e, |
| 86 | 86 | ]); |
| 87 | 87 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | ); |
| 100 | 100 | } catch (Throwable $e) { |
| 101 | 101 | // Any error with activities shouldn't abort the addressbook deletion, so we just log it |
| 102 | - $this->logger->error('Error generating activities for a deleted card in addressbook: ' . $e->getMessage(), [ |
|
| 102 | + $this->logger->error('Error generating activities for a deleted card in addressbook: '.$e->getMessage(), [ |
|
| 103 | 103 | 'exception' => $e, |
| 104 | 104 | ]); |
| 105 | 105 | } |
@@ -21,67 +21,67 @@ |
||
| 21 | 21 | |
| 22 | 22 | /** @template-implements IEventListener<CardCreatedEvent|CardUpdatedEvent|CardDeletedEvent> */ |
| 23 | 23 | class CardListener implements IEventListener { |
| 24 | - public function __construct( |
|
| 25 | - private ActivityBackend $activityBackend, |
|
| 26 | - private LoggerInterface $logger, |
|
| 27 | - ) { |
|
| 28 | - } |
|
| 24 | + public function __construct( |
|
| 25 | + private ActivityBackend $activityBackend, |
|
| 26 | + private LoggerInterface $logger, |
|
| 27 | + ) { |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function handle(Event $event): void { |
|
| 31 | - if ($event instanceof CardCreatedEvent) { |
|
| 32 | - try { |
|
| 33 | - $this->activityBackend->triggerCardActivity( |
|
| 34 | - Card::SUBJECT_ADD, |
|
| 35 | - $event->getAddressBookData(), |
|
| 36 | - $event->getShares(), |
|
| 37 | - $event->getCardData() |
|
| 38 | - ); |
|
| 30 | + public function handle(Event $event): void { |
|
| 31 | + if ($event instanceof CardCreatedEvent) { |
|
| 32 | + try { |
|
| 33 | + $this->activityBackend->triggerCardActivity( |
|
| 34 | + Card::SUBJECT_ADD, |
|
| 35 | + $event->getAddressBookData(), |
|
| 36 | + $event->getShares(), |
|
| 37 | + $event->getCardData() |
|
| 38 | + ); |
|
| 39 | 39 | |
| 40 | - $this->logger->debug( |
|
| 41 | - sprintf('Activity generated for a new card in addressbook %d', $event->getAddressBookId()) |
|
| 42 | - ); |
|
| 43 | - } catch (Throwable $e) { |
|
| 44 | - // Any error with activities shouldn't abort the addressbook creation, so we just log it |
|
| 45 | - $this->logger->error('Error generating activities for a new card in addressbook: ' . $e->getMessage(), [ |
|
| 46 | - 'exception' => $e, |
|
| 47 | - ]); |
|
| 48 | - } |
|
| 49 | - } elseif ($event instanceof CardUpdatedEvent) { |
|
| 50 | - try { |
|
| 51 | - $this->activityBackend->triggerCardActivity( |
|
| 52 | - Card::SUBJECT_UPDATE, |
|
| 53 | - $event->getAddressBookData(), |
|
| 54 | - $event->getShares(), |
|
| 55 | - $event->getCardData() |
|
| 56 | - ); |
|
| 40 | + $this->logger->debug( |
|
| 41 | + sprintf('Activity generated for a new card in addressbook %d', $event->getAddressBookId()) |
|
| 42 | + ); |
|
| 43 | + } catch (Throwable $e) { |
|
| 44 | + // Any error with activities shouldn't abort the addressbook creation, so we just log it |
|
| 45 | + $this->logger->error('Error generating activities for a new card in addressbook: ' . $e->getMessage(), [ |
|
| 46 | + 'exception' => $e, |
|
| 47 | + ]); |
|
| 48 | + } |
|
| 49 | + } elseif ($event instanceof CardUpdatedEvent) { |
|
| 50 | + try { |
|
| 51 | + $this->activityBackend->triggerCardActivity( |
|
| 52 | + Card::SUBJECT_UPDATE, |
|
| 53 | + $event->getAddressBookData(), |
|
| 54 | + $event->getShares(), |
|
| 55 | + $event->getCardData() |
|
| 56 | + ); |
|
| 57 | 57 | |
| 58 | - $this->logger->debug( |
|
| 59 | - sprintf('Activity generated for a changed card in addressbook %d', $event->getAddressBookId()) |
|
| 60 | - ); |
|
| 61 | - } catch (Throwable $e) { |
|
| 62 | - // Any error with activities shouldn't abort the addressbook update, so we just log it |
|
| 63 | - $this->logger->error('Error generating activities for a changed card in addressbook: ' . $e->getMessage(), [ |
|
| 64 | - 'exception' => $e, |
|
| 65 | - ]); |
|
| 66 | - } |
|
| 67 | - } elseif ($event instanceof CardDeletedEvent) { |
|
| 68 | - try { |
|
| 69 | - $this->activityBackend->triggerCardActivity( |
|
| 70 | - Card::SUBJECT_DELETE, |
|
| 71 | - $event->getAddressBookData(), |
|
| 72 | - $event->getShares(), |
|
| 73 | - $event->getCardData() |
|
| 74 | - ); |
|
| 58 | + $this->logger->debug( |
|
| 59 | + sprintf('Activity generated for a changed card in addressbook %d', $event->getAddressBookId()) |
|
| 60 | + ); |
|
| 61 | + } catch (Throwable $e) { |
|
| 62 | + // Any error with activities shouldn't abort the addressbook update, so we just log it |
|
| 63 | + $this->logger->error('Error generating activities for a changed card in addressbook: ' . $e->getMessage(), [ |
|
| 64 | + 'exception' => $e, |
|
| 65 | + ]); |
|
| 66 | + } |
|
| 67 | + } elseif ($event instanceof CardDeletedEvent) { |
|
| 68 | + try { |
|
| 69 | + $this->activityBackend->triggerCardActivity( |
|
| 70 | + Card::SUBJECT_DELETE, |
|
| 71 | + $event->getAddressBookData(), |
|
| 72 | + $event->getShares(), |
|
| 73 | + $event->getCardData() |
|
| 74 | + ); |
|
| 75 | 75 | |
| 76 | - $this->logger->debug( |
|
| 77 | - sprintf('Activity generated for a deleted card in addressbook %d', $event->getAddressBookId()) |
|
| 78 | - ); |
|
| 79 | - } catch (Throwable $e) { |
|
| 80 | - // Any error with activities shouldn't abort the addressbook deletion, so we just log it |
|
| 81 | - $this->logger->error('Error generating activities for a deleted card in addressbook: ' . $e->getMessage(), [ |
|
| 82 | - 'exception' => $e, |
|
| 83 | - ]); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - } |
|
| 76 | + $this->logger->debug( |
|
| 77 | + sprintf('Activity generated for a deleted card in addressbook %d', $event->getAddressBookId()) |
|
| 78 | + ); |
|
| 79 | + } catch (Throwable $e) { |
|
| 80 | + // Any error with activities shouldn't abort the addressbook deletion, so we just log it |
|
| 81 | + $this->logger->error('Error generating activities for a deleted card in addressbook: ' . $e->getMessage(), [ |
|
| 82 | + 'exception' => $e, |
|
| 83 | + ]); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | ); |
| 61 | 61 | } catch (Throwable $e) { |
| 62 | 62 | // Any error with activities shouldn't abort the addressbook creation, so we just log it |
| 63 | - $this->logger->error('Error generating activities for a new addressbook: ' . $e->getMessage(), [ |
|
| 63 | + $this->logger->error('Error generating activities for a new addressbook: '.$e->getMessage(), [ |
|
| 64 | 64 | 'exception' => $e, |
| 65 | 65 | ]); |
| 66 | 66 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | ); |
| 78 | 78 | } catch (Throwable $e) { |
| 79 | 79 | // Any error with activities shouldn't abort the addressbook update, so we just log it |
| 80 | - $this->logger->error('Error generating activities for a changed addressbook: ' . $e->getMessage(), [ |
|
| 80 | + $this->logger->error('Error generating activities for a changed addressbook: '.$e->getMessage(), [ |
|
| 81 | 81 | 'exception' => $e, |
| 82 | 82 | ]); |
| 83 | 83 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | ); |
| 94 | 94 | } catch (Throwable $e) { |
| 95 | 95 | // Any error with activities shouldn't abort the addressbook deletion, so we just log it |
| 96 | - $this->logger->error('Error generating activities for a deleted addressbook: ' . $e->getMessage(), [ |
|
| 96 | + $this->logger->error('Error generating activities for a deleted addressbook: '.$e->getMessage(), [ |
|
| 97 | 97 | 'exception' => $e, |
| 98 | 98 | ]); |
| 99 | 99 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | ); |
| 112 | 112 | } catch (Throwable $e) { |
| 113 | 113 | // Any error with activities shouldn't abort the addressbook creation, so we just log it |
| 114 | - $this->logger->error('Error generating activities for (un)sharing addressbook: ' . $e->getMessage(), [ |
|
| 114 | + $this->logger->error('Error generating activities for (un)sharing addressbook: '.$e->getMessage(), [ |
|
| 115 | 115 | 'exception' => $e, |
| 116 | 116 | ]); |
| 117 | 117 | } |
@@ -21,79 +21,79 @@ |
||
| 21 | 21 | |
| 22 | 22 | /** @template-implements IEventListener<AddressBookCreatedEvent|AddressBookUpdatedEvent|AddressBookDeletedEvent|AddressBookShareUpdatedEvent> */ |
| 23 | 23 | class AddressbookListener implements IEventListener { |
| 24 | - public function __construct( |
|
| 25 | - private ActivityBackend $activityBackend, |
|
| 26 | - private LoggerInterface $logger, |
|
| 27 | - ) { |
|
| 28 | - } |
|
| 24 | + public function __construct( |
|
| 25 | + private ActivityBackend $activityBackend, |
|
| 26 | + private LoggerInterface $logger, |
|
| 27 | + ) { |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function handle(Event $event): void { |
|
| 31 | - if ($event instanceof AddressBookCreatedEvent) { |
|
| 32 | - try { |
|
| 33 | - $this->activityBackend->onAddressbookCreate( |
|
| 34 | - $event->getAddressBookData() |
|
| 35 | - ); |
|
| 30 | + public function handle(Event $event): void { |
|
| 31 | + if ($event instanceof AddressBookCreatedEvent) { |
|
| 32 | + try { |
|
| 33 | + $this->activityBackend->onAddressbookCreate( |
|
| 34 | + $event->getAddressBookData() |
|
| 35 | + ); |
|
| 36 | 36 | |
| 37 | - $this->logger->debug( |
|
| 38 | - sprintf('Activity generated for new addressbook %d', $event->getAddressBookId()) |
|
| 39 | - ); |
|
| 40 | - } catch (Throwable $e) { |
|
| 41 | - // Any error with activities shouldn't abort the addressbook creation, so we just log it |
|
| 42 | - $this->logger->error('Error generating activities for a new addressbook: ' . $e->getMessage(), [ |
|
| 43 | - 'exception' => $e, |
|
| 44 | - ]); |
|
| 45 | - } |
|
| 46 | - } elseif ($event instanceof AddressBookUpdatedEvent) { |
|
| 47 | - try { |
|
| 48 | - $this->activityBackend->onAddressbookUpdate( |
|
| 49 | - $event->getAddressBookData(), |
|
| 50 | - $event->getShares(), |
|
| 51 | - $event->getMutations() |
|
| 52 | - ); |
|
| 37 | + $this->logger->debug( |
|
| 38 | + sprintf('Activity generated for new addressbook %d', $event->getAddressBookId()) |
|
| 39 | + ); |
|
| 40 | + } catch (Throwable $e) { |
|
| 41 | + // Any error with activities shouldn't abort the addressbook creation, so we just log it |
|
| 42 | + $this->logger->error('Error generating activities for a new addressbook: ' . $e->getMessage(), [ |
|
| 43 | + 'exception' => $e, |
|
| 44 | + ]); |
|
| 45 | + } |
|
| 46 | + } elseif ($event instanceof AddressBookUpdatedEvent) { |
|
| 47 | + try { |
|
| 48 | + $this->activityBackend->onAddressbookUpdate( |
|
| 49 | + $event->getAddressBookData(), |
|
| 50 | + $event->getShares(), |
|
| 51 | + $event->getMutations() |
|
| 52 | + ); |
|
| 53 | 53 | |
| 54 | - $this->logger->debug( |
|
| 55 | - sprintf('Activity generated for changed addressbook %d', $event->getAddressBookId()) |
|
| 56 | - ); |
|
| 57 | - } catch (Throwable $e) { |
|
| 58 | - // Any error with activities shouldn't abort the addressbook update, so we just log it |
|
| 59 | - $this->logger->error('Error generating activities for a changed addressbook: ' . $e->getMessage(), [ |
|
| 60 | - 'exception' => $e, |
|
| 61 | - ]); |
|
| 62 | - } |
|
| 63 | - } elseif ($event instanceof AddressBookDeletedEvent) { |
|
| 64 | - try { |
|
| 65 | - $this->activityBackend->onAddressbookDelete( |
|
| 66 | - $event->getAddressBookData(), |
|
| 67 | - $event->getShares() |
|
| 68 | - ); |
|
| 54 | + $this->logger->debug( |
|
| 55 | + sprintf('Activity generated for changed addressbook %d', $event->getAddressBookId()) |
|
| 56 | + ); |
|
| 57 | + } catch (Throwable $e) { |
|
| 58 | + // Any error with activities shouldn't abort the addressbook update, so we just log it |
|
| 59 | + $this->logger->error('Error generating activities for a changed addressbook: ' . $e->getMessage(), [ |
|
| 60 | + 'exception' => $e, |
|
| 61 | + ]); |
|
| 62 | + } |
|
| 63 | + } elseif ($event instanceof AddressBookDeletedEvent) { |
|
| 64 | + try { |
|
| 65 | + $this->activityBackend->onAddressbookDelete( |
|
| 66 | + $event->getAddressBookData(), |
|
| 67 | + $event->getShares() |
|
| 68 | + ); |
|
| 69 | 69 | |
| 70 | - $this->logger->debug( |
|
| 71 | - sprintf('Activity generated for deleted addressbook %d', $event->getAddressBookId()) |
|
| 72 | - ); |
|
| 73 | - } catch (Throwable $e) { |
|
| 74 | - // Any error with activities shouldn't abort the addressbook deletion, so we just log it |
|
| 75 | - $this->logger->error('Error generating activities for a deleted addressbook: ' . $e->getMessage(), [ |
|
| 76 | - 'exception' => $e, |
|
| 77 | - ]); |
|
| 78 | - } |
|
| 79 | - } elseif ($event instanceof AddressBookShareUpdatedEvent) { |
|
| 80 | - try { |
|
| 81 | - $this->activityBackend->onAddressbookUpdateShares( |
|
| 82 | - $event->getAddressBookData(), |
|
| 83 | - $event->getOldShares(), |
|
| 84 | - $event->getAdded(), |
|
| 85 | - $event->getRemoved() |
|
| 86 | - ); |
|
| 70 | + $this->logger->debug( |
|
| 71 | + sprintf('Activity generated for deleted addressbook %d', $event->getAddressBookId()) |
|
| 72 | + ); |
|
| 73 | + } catch (Throwable $e) { |
|
| 74 | + // Any error with activities shouldn't abort the addressbook deletion, so we just log it |
|
| 75 | + $this->logger->error('Error generating activities for a deleted addressbook: ' . $e->getMessage(), [ |
|
| 76 | + 'exception' => $e, |
|
| 77 | + ]); |
|
| 78 | + } |
|
| 79 | + } elseif ($event instanceof AddressBookShareUpdatedEvent) { |
|
| 80 | + try { |
|
| 81 | + $this->activityBackend->onAddressbookUpdateShares( |
|
| 82 | + $event->getAddressBookData(), |
|
| 83 | + $event->getOldShares(), |
|
| 84 | + $event->getAdded(), |
|
| 85 | + $event->getRemoved() |
|
| 86 | + ); |
|
| 87 | 87 | |
| 88 | - $this->logger->debug( |
|
| 89 | - sprintf('Activity generated for (un)sharing addressbook %d', $event->getAddressBookId()) |
|
| 90 | - ); |
|
| 91 | - } catch (Throwable $e) { |
|
| 92 | - // Any error with activities shouldn't abort the addressbook creation, so we just log it |
|
| 93 | - $this->logger->error('Error generating activities for (un)sharing addressbook: ' . $e->getMessage(), [ |
|
| 94 | - 'exception' => $e, |
|
| 95 | - ]); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 88 | + $this->logger->debug( |
|
| 89 | + sprintf('Activity generated for (un)sharing addressbook %d', $event->getAddressBookId()) |
|
| 90 | + ); |
|
| 91 | + } catch (Throwable $e) { |
|
| 92 | + // Any error with activities shouldn't abort the addressbook creation, so we just log it |
|
| 93 | + $this->logger->error('Error generating activities for (un)sharing addressbook: ' . $e->getMessage(), [ |
|
| 94 | + 'exception' => $e, |
|
| 95 | + ]); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | ); |
| 79 | 79 | } catch (Throwable $e) { |
| 80 | 80 | // Any error with reminders shouldn't abort the calendar move, so we just log it |
| 81 | - $this->logger->error('Error cleaning up reminders of a calendar moved into trashbin: ' . $e->getMessage(), [ |
|
| 81 | + $this->logger->error('Error cleaning up reminders of a calendar moved into trashbin: '.$e->getMessage(), [ |
|
| 82 | 82 | 'exception' => $e, |
| 83 | 83 | ]); |
| 84 | 84 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | ); |
| 94 | 94 | } catch (Throwable $e) { |
| 95 | 95 | // Any error with activities shouldn't abort the calendar deletion, so we just log it |
| 96 | - $this->logger->error('Error cleaning up reminders of a deleted calendar: ' . $e->getMessage(), [ |
|
| 96 | + $this->logger->error('Error cleaning up reminders of a deleted calendar: '.$e->getMessage(), [ |
|
| 97 | 97 | 'exception' => $e, |
| 98 | 98 | ]); |
| 99 | 99 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | ); |
| 115 | 115 | } catch (Throwable $e) { |
| 116 | 116 | // Any error with reminders shouldn't abort the calendar deletion, so we just log it |
| 117 | - $this->logger->error('Error restoring reminders of a calendar: ' . $e->getMessage(), [ |
|
| 117 | + $this->logger->error('Error restoring reminders of a calendar: '.$e->getMessage(), [ |
|
| 118 | 118 | 'exception' => $e, |
| 119 | 119 | ]); |
| 120 | 120 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | ); |
| 130 | 130 | } catch (Throwable $e) { |
| 131 | 131 | // Any error with reminders shouldn't abort the calendar object creation, so we just log it |
| 132 | - $this->logger->error('Error creating reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 132 | + $this->logger->error('Error creating reminders of a calendar object: '.$e->getMessage(), [ |
|
| 133 | 133 | 'exception' => $e, |
| 134 | 134 | ]); |
| 135 | 135 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | ); |
| 145 | 145 | } catch (Throwable $e) { |
| 146 | 146 | // Any error with activities shouldn't abort the calendar object deletion, so we just log it |
| 147 | - $this->logger->error('Error cleaning up reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 147 | + $this->logger->error('Error cleaning up reminders of a calendar object: '.$e->getMessage(), [ |
|
| 148 | 148 | 'exception' => $e, |
| 149 | 149 | ]); |
| 150 | 150 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | ); |
| 160 | 160 | } catch (Throwable $e) { |
| 161 | 161 | // Any error with reminders shouldn't abort the calendar object deletion, so we just log it |
| 162 | - $this->logger->error('Error deleting reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 162 | + $this->logger->error('Error deleting reminders of a calendar object: '.$e->getMessage(), [ |
|
| 163 | 163 | 'exception' => $e, |
| 164 | 164 | ]); |
| 165 | 165 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | ); |
| 175 | 175 | } catch (Throwable $e) { |
| 176 | 176 | // Any error with reminders shouldn't abort the calendar object deletion, so we just log it |
| 177 | - $this->logger->error('Error restoring reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 177 | + $this->logger->error('Error restoring reminders of a calendar object: '.$e->getMessage(), [ |
|
| 178 | 178 | 'exception' => $e, |
| 179 | 179 | ]); |
| 180 | 180 | } |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | ); |
| 190 | 190 | } catch (Throwable $e) { |
| 191 | 191 | // Any error with activities shouldn't abort the calendar object deletion, so we just log it |
| 192 | - $this->logger->error('Error cleaning up reminders of a deleted calendar object: ' . $e->getMessage(), [ |
|
| 192 | + $this->logger->error('Error cleaning up reminders of a deleted calendar object: '.$e->getMessage(), [ |
|
| 193 | 193 | 'exception' => $e, |
| 194 | 194 | ]); |
| 195 | 195 | } |
@@ -28,141 +28,141 @@ |
||
| 28 | 28 | /** @template-implements IEventListener<CalendarMovedToTrashEvent|CalendarDeletedEvent|CalendarRestoredEvent|CalendarObjectCreatedEvent|CalendarObjectUpdatedEvent|CalendarObjectMovedToTrashEvent|CalendarObjectRestoredEvent|CalendarObjectDeletedEvent> */ |
| 29 | 29 | class CalendarObjectReminderUpdaterListener implements IEventListener { |
| 30 | 30 | |
| 31 | - public function __construct( |
|
| 32 | - private ReminderBackend $reminderBackend, |
|
| 33 | - private ReminderService $reminderService, |
|
| 34 | - private CalDavBackend $calDavBackend, |
|
| 35 | - private LoggerInterface $logger, |
|
| 36 | - ) { |
|
| 37 | - } |
|
| 31 | + public function __construct( |
|
| 32 | + private ReminderBackend $reminderBackend, |
|
| 33 | + private ReminderService $reminderService, |
|
| 34 | + private CalDavBackend $calDavBackend, |
|
| 35 | + private LoggerInterface $logger, |
|
| 36 | + ) { |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function handle(Event $event): void { |
|
| 40 | - if ($event instanceof CalendarMovedToTrashEvent) { |
|
| 41 | - try { |
|
| 42 | - $this->reminderBackend->cleanRemindersForCalendar( |
|
| 43 | - $event->getCalendarId() |
|
| 44 | - ); |
|
| 39 | + public function handle(Event $event): void { |
|
| 40 | + if ($event instanceof CalendarMovedToTrashEvent) { |
|
| 41 | + try { |
|
| 42 | + $this->reminderBackend->cleanRemindersForCalendar( |
|
| 43 | + $event->getCalendarId() |
|
| 44 | + ); |
|
| 45 | 45 | |
| 46 | - $this->logger->debug( |
|
| 47 | - sprintf('Reminders of calendar %d cleaned up after move into trashbin', $event->getCalendarId()) |
|
| 48 | - ); |
|
| 49 | - } catch (Throwable $e) { |
|
| 50 | - // Any error with reminders shouldn't abort the calendar move, so we just log it |
|
| 51 | - $this->logger->error('Error cleaning up reminders of a calendar moved into trashbin: ' . $e->getMessage(), [ |
|
| 52 | - 'exception' => $e, |
|
| 53 | - ]); |
|
| 54 | - } |
|
| 55 | - } elseif ($event instanceof CalendarDeletedEvent) { |
|
| 56 | - try { |
|
| 57 | - $this->reminderBackend->cleanRemindersForCalendar( |
|
| 58 | - $event->getCalendarId() |
|
| 59 | - ); |
|
| 46 | + $this->logger->debug( |
|
| 47 | + sprintf('Reminders of calendar %d cleaned up after move into trashbin', $event->getCalendarId()) |
|
| 48 | + ); |
|
| 49 | + } catch (Throwable $e) { |
|
| 50 | + // Any error with reminders shouldn't abort the calendar move, so we just log it |
|
| 51 | + $this->logger->error('Error cleaning up reminders of a calendar moved into trashbin: ' . $e->getMessage(), [ |
|
| 52 | + 'exception' => $e, |
|
| 53 | + ]); |
|
| 54 | + } |
|
| 55 | + } elseif ($event instanceof CalendarDeletedEvent) { |
|
| 56 | + try { |
|
| 57 | + $this->reminderBackend->cleanRemindersForCalendar( |
|
| 58 | + $event->getCalendarId() |
|
| 59 | + ); |
|
| 60 | 60 | |
| 61 | - $this->logger->debug( |
|
| 62 | - sprintf('Reminders of calendar %d cleaned up', $event->getCalendarId()) |
|
| 63 | - ); |
|
| 64 | - } catch (Throwable $e) { |
|
| 65 | - // Any error with activities shouldn't abort the calendar deletion, so we just log it |
|
| 66 | - $this->logger->error('Error cleaning up reminders of a deleted calendar: ' . $e->getMessage(), [ |
|
| 67 | - 'exception' => $e, |
|
| 68 | - ]); |
|
| 69 | - } |
|
| 70 | - } elseif ($event instanceof CalendarRestoredEvent) { |
|
| 71 | - try { |
|
| 72 | - $objects = $this->calDavBackend->getCalendarObjects($event->getCalendarId()); |
|
| 73 | - $this->logger->debug(sprintf('Restoring calendar reminder objects for %d items', count($objects))); |
|
| 74 | - foreach ($objects as $object) { |
|
| 75 | - $fullObject = $this->calDavBackend->getCalendarObject( |
|
| 76 | - $event->getCalendarId(), |
|
| 77 | - $object['uri'] |
|
| 78 | - ); |
|
| 79 | - $this->reminderService->onCalendarObjectCreate($fullObject); |
|
| 80 | - } |
|
| 61 | + $this->logger->debug( |
|
| 62 | + sprintf('Reminders of calendar %d cleaned up', $event->getCalendarId()) |
|
| 63 | + ); |
|
| 64 | + } catch (Throwable $e) { |
|
| 65 | + // Any error with activities shouldn't abort the calendar deletion, so we just log it |
|
| 66 | + $this->logger->error('Error cleaning up reminders of a deleted calendar: ' . $e->getMessage(), [ |
|
| 67 | + 'exception' => $e, |
|
| 68 | + ]); |
|
| 69 | + } |
|
| 70 | + } elseif ($event instanceof CalendarRestoredEvent) { |
|
| 71 | + try { |
|
| 72 | + $objects = $this->calDavBackend->getCalendarObjects($event->getCalendarId()); |
|
| 73 | + $this->logger->debug(sprintf('Restoring calendar reminder objects for %d items', count($objects))); |
|
| 74 | + foreach ($objects as $object) { |
|
| 75 | + $fullObject = $this->calDavBackend->getCalendarObject( |
|
| 76 | + $event->getCalendarId(), |
|
| 77 | + $object['uri'] |
|
| 78 | + ); |
|
| 79 | + $this->reminderService->onCalendarObjectCreate($fullObject); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - $this->logger->debug( |
|
| 83 | - sprintf('Reminders of calendar %d restored', $event->getCalendarId()) |
|
| 84 | - ); |
|
| 85 | - } catch (Throwable $e) { |
|
| 86 | - // Any error with reminders shouldn't abort the calendar deletion, so we just log it |
|
| 87 | - $this->logger->error('Error restoring reminders of a calendar: ' . $e->getMessage(), [ |
|
| 88 | - 'exception' => $e, |
|
| 89 | - ]); |
|
| 90 | - } |
|
| 91 | - } elseif ($event instanceof CalendarObjectCreatedEvent) { |
|
| 92 | - try { |
|
| 93 | - $this->reminderService->onCalendarObjectCreate( |
|
| 94 | - $event->getObjectData() |
|
| 95 | - ); |
|
| 82 | + $this->logger->debug( |
|
| 83 | + sprintf('Reminders of calendar %d restored', $event->getCalendarId()) |
|
| 84 | + ); |
|
| 85 | + } catch (Throwable $e) { |
|
| 86 | + // Any error with reminders shouldn't abort the calendar deletion, so we just log it |
|
| 87 | + $this->logger->error('Error restoring reminders of a calendar: ' . $e->getMessage(), [ |
|
| 88 | + 'exception' => $e, |
|
| 89 | + ]); |
|
| 90 | + } |
|
| 91 | + } elseif ($event instanceof CalendarObjectCreatedEvent) { |
|
| 92 | + try { |
|
| 93 | + $this->reminderService->onCalendarObjectCreate( |
|
| 94 | + $event->getObjectData() |
|
| 95 | + ); |
|
| 96 | 96 | |
| 97 | - $this->logger->debug( |
|
| 98 | - sprintf('Reminders of calendar object of calendar %d created', $event->getCalendarId()) |
|
| 99 | - ); |
|
| 100 | - } catch (Throwable $e) { |
|
| 101 | - // Any error with reminders shouldn't abort the calendar object creation, so we just log it |
|
| 102 | - $this->logger->error('Error creating reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 103 | - 'exception' => $e, |
|
| 104 | - ]); |
|
| 105 | - } |
|
| 106 | - } elseif ($event instanceof CalendarObjectUpdatedEvent) { |
|
| 107 | - try { |
|
| 108 | - $this->reminderService->onCalendarObjectEdit( |
|
| 109 | - $event->getObjectData() |
|
| 110 | - ); |
|
| 97 | + $this->logger->debug( |
|
| 98 | + sprintf('Reminders of calendar object of calendar %d created', $event->getCalendarId()) |
|
| 99 | + ); |
|
| 100 | + } catch (Throwable $e) { |
|
| 101 | + // Any error with reminders shouldn't abort the calendar object creation, so we just log it |
|
| 102 | + $this->logger->error('Error creating reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 103 | + 'exception' => $e, |
|
| 104 | + ]); |
|
| 105 | + } |
|
| 106 | + } elseif ($event instanceof CalendarObjectUpdatedEvent) { |
|
| 107 | + try { |
|
| 108 | + $this->reminderService->onCalendarObjectEdit( |
|
| 109 | + $event->getObjectData() |
|
| 110 | + ); |
|
| 111 | 111 | |
| 112 | - $this->logger->debug( |
|
| 113 | - sprintf('Reminders of calendar object of calendar %d cleaned up', $event->getCalendarId()) |
|
| 114 | - ); |
|
| 115 | - } catch (Throwable $e) { |
|
| 116 | - // Any error with activities shouldn't abort the calendar object deletion, so we just log it |
|
| 117 | - $this->logger->error('Error cleaning up reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 118 | - 'exception' => $e, |
|
| 119 | - ]); |
|
| 120 | - } |
|
| 121 | - } elseif ($event instanceof CalendarObjectMovedToTrashEvent) { |
|
| 122 | - try { |
|
| 123 | - $this->reminderService->onCalendarObjectDelete( |
|
| 124 | - $event->getObjectData() |
|
| 125 | - ); |
|
| 112 | + $this->logger->debug( |
|
| 113 | + sprintf('Reminders of calendar object of calendar %d cleaned up', $event->getCalendarId()) |
|
| 114 | + ); |
|
| 115 | + } catch (Throwable $e) { |
|
| 116 | + // Any error with activities shouldn't abort the calendar object deletion, so we just log it |
|
| 117 | + $this->logger->error('Error cleaning up reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 118 | + 'exception' => $e, |
|
| 119 | + ]); |
|
| 120 | + } |
|
| 121 | + } elseif ($event instanceof CalendarObjectMovedToTrashEvent) { |
|
| 122 | + try { |
|
| 123 | + $this->reminderService->onCalendarObjectDelete( |
|
| 124 | + $event->getObjectData() |
|
| 125 | + ); |
|
| 126 | 126 | |
| 127 | - $this->logger->debug( |
|
| 128 | - sprintf('Reminders of restored calendar object of calendar %d deleted', $event->getCalendarId()) |
|
| 129 | - ); |
|
| 130 | - } catch (Throwable $e) { |
|
| 131 | - // Any error with reminders shouldn't abort the calendar object deletion, so we just log it |
|
| 132 | - $this->logger->error('Error deleting reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 133 | - 'exception' => $e, |
|
| 134 | - ]); |
|
| 135 | - } |
|
| 136 | - } elseif ($event instanceof CalendarObjectRestoredEvent) { |
|
| 137 | - try { |
|
| 138 | - $this->reminderService->onCalendarObjectCreate( |
|
| 139 | - $event->getObjectData() |
|
| 140 | - ); |
|
| 127 | + $this->logger->debug( |
|
| 128 | + sprintf('Reminders of restored calendar object of calendar %d deleted', $event->getCalendarId()) |
|
| 129 | + ); |
|
| 130 | + } catch (Throwable $e) { |
|
| 131 | + // Any error with reminders shouldn't abort the calendar object deletion, so we just log it |
|
| 132 | + $this->logger->error('Error deleting reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 133 | + 'exception' => $e, |
|
| 134 | + ]); |
|
| 135 | + } |
|
| 136 | + } elseif ($event instanceof CalendarObjectRestoredEvent) { |
|
| 137 | + try { |
|
| 138 | + $this->reminderService->onCalendarObjectCreate( |
|
| 139 | + $event->getObjectData() |
|
| 140 | + ); |
|
| 141 | 141 | |
| 142 | - $this->logger->debug( |
|
| 143 | - sprintf('Reminders of restored calendar object of calendar %d restored', $event->getCalendarId()) |
|
| 144 | - ); |
|
| 145 | - } catch (Throwable $e) { |
|
| 146 | - // Any error with reminders shouldn't abort the calendar object deletion, so we just log it |
|
| 147 | - $this->logger->error('Error restoring reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 148 | - 'exception' => $e, |
|
| 149 | - ]); |
|
| 150 | - } |
|
| 151 | - } elseif ($event instanceof CalendarObjectDeletedEvent) { |
|
| 152 | - try { |
|
| 153 | - $this->reminderService->onCalendarObjectDelete( |
|
| 154 | - $event->getObjectData() |
|
| 155 | - ); |
|
| 142 | + $this->logger->debug( |
|
| 143 | + sprintf('Reminders of restored calendar object of calendar %d restored', $event->getCalendarId()) |
|
| 144 | + ); |
|
| 145 | + } catch (Throwable $e) { |
|
| 146 | + // Any error with reminders shouldn't abort the calendar object deletion, so we just log it |
|
| 147 | + $this->logger->error('Error restoring reminders of a calendar object: ' . $e->getMessage(), [ |
|
| 148 | + 'exception' => $e, |
|
| 149 | + ]); |
|
| 150 | + } |
|
| 151 | + } elseif ($event instanceof CalendarObjectDeletedEvent) { |
|
| 152 | + try { |
|
| 153 | + $this->reminderService->onCalendarObjectDelete( |
|
| 154 | + $event->getObjectData() |
|
| 155 | + ); |
|
| 156 | 156 | |
| 157 | - $this->logger->debug( |
|
| 158 | - sprintf('Reminders of calendar object of calendar %d cleaned up', $event->getCalendarId()) |
|
| 159 | - ); |
|
| 160 | - } catch (Throwable $e) { |
|
| 161 | - // Any error with activities shouldn't abort the calendar object deletion, so we just log it |
|
| 162 | - $this->logger->error('Error cleaning up reminders of a deleted calendar object: ' . $e->getMessage(), [ |
|
| 163 | - 'exception' => $e, |
|
| 164 | - ]); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } |
|
| 157 | + $this->logger->debug( |
|
| 158 | + sprintf('Reminders of calendar object of calendar %d cleaned up', $event->getCalendarId()) |
|
| 159 | + ); |
|
| 160 | + } catch (Throwable $e) { |
|
| 161 | + // Any error with activities shouldn't abort the calendar object deletion, so we just log it |
|
| 162 | + $this->logger->error('Error cleaning up reminders of a deleted calendar object: ' . $e->getMessage(), [ |
|
| 163 | + 'exception' => $e, |
|
| 164 | + ]); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | } |
@@ -12,34 +12,34 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Version1018Date20210312100735 extends SimpleMigrationStep { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param IOutput $output |
|
| 17 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 18 | - * @param array $options |
|
| 19 | - * @return ISchemaWrapper |
|
| 20 | - */ |
|
| 21 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 22 | - /** @var ISchemaWrapper $schema */ |
|
| 23 | - $schema = $schemaClosure(); |
|
| 24 | - |
|
| 25 | - $calendarsTable = $schema->getTable('calendars'); |
|
| 26 | - $calendarsTable->addColumn('deleted_at', Types::INTEGER, [ |
|
| 27 | - 'notnull' => false, |
|
| 28 | - 'length' => 4, |
|
| 29 | - 'unsigned' => true, |
|
| 30 | - ]); |
|
| 31 | - $calendarsTable->addIndex([ |
|
| 32 | - 'principaluri', |
|
| 33 | - 'deleted_at', |
|
| 34 | - ], 'cals_princ_del_idx'); |
|
| 35 | - |
|
| 36 | - $calendarObjectsTable = $schema->getTable('calendarobjects'); |
|
| 37 | - $calendarObjectsTable->addColumn('deleted_at', Types::INTEGER, [ |
|
| 38 | - 'notnull' => false, |
|
| 39 | - 'length' => 4, |
|
| 40 | - 'unsigned' => true, |
|
| 41 | - ]); |
|
| 42 | - |
|
| 43 | - return $schema; |
|
| 44 | - } |
|
| 15 | + /** |
|
| 16 | + * @param IOutput $output |
|
| 17 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 18 | + * @param array $options |
|
| 19 | + * @return ISchemaWrapper |
|
| 20 | + */ |
|
| 21 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 22 | + /** @var ISchemaWrapper $schema */ |
|
| 23 | + $schema = $schemaClosure(); |
|
| 24 | + |
|
| 25 | + $calendarsTable = $schema->getTable('calendars'); |
|
| 26 | + $calendarsTable->addColumn('deleted_at', Types::INTEGER, [ |
|
| 27 | + 'notnull' => false, |
|
| 28 | + 'length' => 4, |
|
| 29 | + 'unsigned' => true, |
|
| 30 | + ]); |
|
| 31 | + $calendarsTable->addIndex([ |
|
| 32 | + 'principaluri', |
|
| 33 | + 'deleted_at', |
|
| 34 | + ], 'cals_princ_del_idx'); |
|
| 35 | + |
|
| 36 | + $calendarObjectsTable = $schema->getTable('calendarobjects'); |
|
| 37 | + $calendarObjectsTable->addColumn('deleted_at', Types::INTEGER, [ |
|
| 38 | + 'notnull' => false, |
|
| 39 | + 'length' => 4, |
|
| 40 | + 'unsigned' => true, |
|
| 41 | + ]); |
|
| 42 | + |
|
| 43 | + return $schema; |
|
| 44 | + } |
|
| 45 | 45 | } |