@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $qb = $this->dbc->getQueryBuilder(); |
| 75 | 75 | $qb->select(['id', 'principaluri']) |
| 76 | 76 | ->from('dav_shares') |
| 77 | - ->where($qb->expr()->like('principaluri', $qb->createNamedParameter(self::GROUP_PRINCIPAL_PREFIX . '%'))); |
|
| 77 | + ->where($qb->expr()->like('principaluri', $qb->createNamedParameter(self::GROUP_PRINCIPAL_PREFIX.'%'))); |
|
| 78 | 78 | |
| 79 | 79 | $updateQuery = $this->dbc->getQueryBuilder(); |
| 80 | 80 | $updateQuery->update('dav_shares') |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | // + AND there are no ambivalent groups |
| 101 | 101 | |
| 102 | 102 | try { |
| 103 | - $fixedPrincipal = self::GROUP_PRINCIPAL_PREFIX . $encodedGid; |
|
| 103 | + $fixedPrincipal = self::GROUP_PRINCIPAL_PREFIX.$encodedGid; |
|
| 104 | 104 | $logParameters = [ |
| 105 | 105 | 'app' => 'core', |
| 106 | 106 | 'id' => $share['id'], |
@@ -21,89 +21,89 @@ |
||
| 21 | 21 | use function urlencode; |
| 22 | 22 | |
| 23 | 23 | class RepairDavShares implements IRepairStep { |
| 24 | - protected const GROUP_PRINCIPAL_PREFIX = 'principals/groups/'; |
|
| 24 | + protected const GROUP_PRINCIPAL_PREFIX = 'principals/groups/'; |
|
| 25 | 25 | |
| 26 | - /** @var bool */ |
|
| 27 | - private $hintInvalidShares = false; |
|
| 26 | + /** @var bool */ |
|
| 27 | + private $hintInvalidShares = false; |
|
| 28 | 28 | |
| 29 | - public function __construct( |
|
| 30 | - private IConfig $config, |
|
| 31 | - private IDBConnection $dbc, |
|
| 32 | - private IGroupManager $groupManager, |
|
| 33 | - private LoggerInterface $logger, |
|
| 34 | - ) { |
|
| 35 | - } |
|
| 29 | + public function __construct( |
|
| 30 | + private IConfig $config, |
|
| 31 | + private IDBConnection $dbc, |
|
| 32 | + private IGroupManager $groupManager, |
|
| 33 | + private LoggerInterface $logger, |
|
| 34 | + ) { |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @inheritDoc |
|
| 39 | - */ |
|
| 40 | - public function getName() { |
|
| 41 | - return 'Repair DAV shares'; |
|
| 42 | - } |
|
| 37 | + /** |
|
| 38 | + * @inheritDoc |
|
| 39 | + */ |
|
| 40 | + public function getName() { |
|
| 41 | + return 'Repair DAV shares'; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - protected function repairUnencodedGroupShares() { |
|
| 45 | - $qb = $this->dbc->getQueryBuilder(); |
|
| 46 | - $qb->select(['id', 'principaluri']) |
|
| 47 | - ->from('dav_shares') |
|
| 48 | - ->where($qb->expr()->like('principaluri', $qb->createNamedParameter(self::GROUP_PRINCIPAL_PREFIX . '%'))); |
|
| 44 | + protected function repairUnencodedGroupShares() { |
|
| 45 | + $qb = $this->dbc->getQueryBuilder(); |
|
| 46 | + $qb->select(['id', 'principaluri']) |
|
| 47 | + ->from('dav_shares') |
|
| 48 | + ->where($qb->expr()->like('principaluri', $qb->createNamedParameter(self::GROUP_PRINCIPAL_PREFIX . '%'))); |
|
| 49 | 49 | |
| 50 | - $updateQuery = $this->dbc->getQueryBuilder(); |
|
| 51 | - $updateQuery->update('dav_shares') |
|
| 52 | - ->set('principaluri', $updateQuery->createParameter('updatedPrincipalUri')) |
|
| 53 | - ->where($updateQuery->expr()->eq('id', $updateQuery->createParameter('shareId'))); |
|
| 50 | + $updateQuery = $this->dbc->getQueryBuilder(); |
|
| 51 | + $updateQuery->update('dav_shares') |
|
| 52 | + ->set('principaluri', $updateQuery->createParameter('updatedPrincipalUri')) |
|
| 53 | + ->where($updateQuery->expr()->eq('id', $updateQuery->createParameter('shareId'))); |
|
| 54 | 54 | |
| 55 | - $statement = $qb->executeQuery(); |
|
| 56 | - while ($share = $statement->fetch()) { |
|
| 57 | - $gid = substr($share['principaluri'], strlen(self::GROUP_PRINCIPAL_PREFIX)); |
|
| 58 | - $decodedGid = urldecode($gid); |
|
| 59 | - $encodedGid = urlencode($gid); |
|
| 60 | - if ($gid === $encodedGid |
|
| 61 | - || !$this->groupManager->groupExists($gid) |
|
| 62 | - || ($gid !== $decodedGid && $this->groupManager->groupExists($decodedGid)) |
|
| 63 | - ) { |
|
| 64 | - $this->hintInvalidShares = $this->hintInvalidShares || $gid !== $encodedGid; |
|
| 65 | - continue; |
|
| 66 | - } |
|
| 55 | + $statement = $qb->executeQuery(); |
|
| 56 | + while ($share = $statement->fetch()) { |
|
| 57 | + $gid = substr($share['principaluri'], strlen(self::GROUP_PRINCIPAL_PREFIX)); |
|
| 58 | + $decodedGid = urldecode($gid); |
|
| 59 | + $encodedGid = urlencode($gid); |
|
| 60 | + if ($gid === $encodedGid |
|
| 61 | + || !$this->groupManager->groupExists($gid) |
|
| 62 | + || ($gid !== $decodedGid && $this->groupManager->groupExists($decodedGid)) |
|
| 63 | + ) { |
|
| 64 | + $this->hintInvalidShares = $this->hintInvalidShares || $gid !== $encodedGid; |
|
| 65 | + continue; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - // Repair when |
|
| 69 | - // + the group name needs encoding |
|
| 70 | - // + AND it is not encoded yet |
|
| 71 | - // + AND there are no ambivalent groups |
|
| 68 | + // Repair when |
|
| 69 | + // + the group name needs encoding |
|
| 70 | + // + AND it is not encoded yet |
|
| 71 | + // + AND there are no ambivalent groups |
|
| 72 | 72 | |
| 73 | - try { |
|
| 74 | - $fixedPrincipal = self::GROUP_PRINCIPAL_PREFIX . $encodedGid; |
|
| 75 | - $logParameters = [ |
|
| 76 | - 'app' => 'core', |
|
| 77 | - 'id' => $share['id'], |
|
| 78 | - 'old' => $share['principaluri'], |
|
| 79 | - 'new' => $fixedPrincipal, |
|
| 80 | - ]; |
|
| 81 | - $updateQuery |
|
| 82 | - ->setParameter('updatedPrincipalUri', $fixedPrincipal) |
|
| 83 | - ->setParameter('shareId', $share['id']) |
|
| 84 | - ->executeStatement(); |
|
| 85 | - $this->logger->info('Repaired principal for dav share {id} from {old} to {new}', $logParameters); |
|
| 86 | - } catch (Exception $e) { |
|
| 87 | - $logParameters['message'] = $e->getMessage(); |
|
| 88 | - $logParameters['exception'] = $e; |
|
| 89 | - $this->logger->info('Could not repair principal for dav share {id} from {old} to {new}: {message}', $logParameters); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - return true; |
|
| 93 | - } |
|
| 73 | + try { |
|
| 74 | + $fixedPrincipal = self::GROUP_PRINCIPAL_PREFIX . $encodedGid; |
|
| 75 | + $logParameters = [ |
|
| 76 | + 'app' => 'core', |
|
| 77 | + 'id' => $share['id'], |
|
| 78 | + 'old' => $share['principaluri'], |
|
| 79 | + 'new' => $fixedPrincipal, |
|
| 80 | + ]; |
|
| 81 | + $updateQuery |
|
| 82 | + ->setParameter('updatedPrincipalUri', $fixedPrincipal) |
|
| 83 | + ->setParameter('shareId', $share['id']) |
|
| 84 | + ->executeStatement(); |
|
| 85 | + $this->logger->info('Repaired principal for dav share {id} from {old} to {new}', $logParameters); |
|
| 86 | + } catch (Exception $e) { |
|
| 87 | + $logParameters['message'] = $e->getMessage(); |
|
| 88 | + $logParameters['exception'] = $e; |
|
| 89 | + $this->logger->info('Could not repair principal for dav share {id} from {old} to {new}: {message}', $logParameters); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + return true; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @inheritDoc |
|
| 97 | - */ |
|
| 98 | - public function run(IOutput $output) { |
|
| 99 | - $versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0'); |
|
| 100 | - if (version_compare($versionFromBeforeUpdate, '20.0.8', '<') |
|
| 101 | - && $this->repairUnencodedGroupShares() |
|
| 102 | - ) { |
|
| 103 | - $output->info('Repaired DAV group shares'); |
|
| 104 | - if ($this->hintInvalidShares) { |
|
| 105 | - $output->info('Invalid shares might be left in the database, running "occ dav:remove-invalid-shares" can remove them.'); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 95 | + /** |
|
| 96 | + * @inheritDoc |
|
| 97 | + */ |
|
| 98 | + public function run(IOutput $output) { |
|
| 99 | + $versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0'); |
|
| 100 | + if (version_compare($versionFromBeforeUpdate, '20.0.8', '<') |
|
| 101 | + && $this->repairUnencodedGroupShares() |
|
| 102 | + ) { |
|
| 103 | + $output->info('Repaired DAV group shares'); |
|
| 104 | + if ($this->hintInvalidShares) { |
|
| 105 | + $output->info('Invalid shares might be left in the database, running "occ dav:remove-invalid-shares" can remove them.'); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -101,7 +101,7 @@ |
||
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | } catch (Throwable $e) { |
| 104 | - $this->logger->warning('Could not read calendar data for interaction events: ' . $e->getMessage(), [ |
|
| 104 | + $this->logger->warning('Could not read calendar data for interaction events: '.$e->getMessage(), [ |
|
| 105 | 105 | 'exception' => $e, |
| 106 | 106 | ]); |
| 107 | 107 | } |
@@ -30,113 +30,113 @@ |
||
| 30 | 30 | |
| 31 | 31 | /** @template-implements IEventListener<CalendarObjectCreatedEvent|CalendarObjectUpdatedEvent|CalendarShareUpdatedEvent> */ |
| 32 | 32 | class CalendarContactInteractionListener implements IEventListener { |
| 33 | - private const URI_USERS = 'principals/users/'; |
|
| 34 | - |
|
| 35 | - public function __construct( |
|
| 36 | - private IEventDispatcher $dispatcher, |
|
| 37 | - private IUserSession $userSession, |
|
| 38 | - private Principal $principalConnector, |
|
| 39 | - private IMailer $mailer, |
|
| 40 | - private LoggerInterface $logger, |
|
| 41 | - ) { |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function handle(Event $event): void { |
|
| 45 | - if (($user = $this->userSession->getUser()) === null) { |
|
| 46 | - // Without user context we can't do anything |
|
| 47 | - return; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if ($event instanceof CalendarObjectCreatedEvent || $event instanceof CalendarObjectUpdatedEvent) { |
|
| 51 | - // users: href => principal:principals/users/admin |
|
| 52 | - foreach ($event->getShares() as $share) { |
|
| 53 | - if (!isset($share['href'])) { |
|
| 54 | - continue; |
|
| 55 | - } |
|
| 56 | - $this->emitFromUri($share['href'], $user); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // emit interaction for email attendees as well |
|
| 60 | - if (isset($event->getObjectData()['calendardata'])) { |
|
| 61 | - try { |
|
| 62 | - $calendar = Reader::read($event->getObjectData()['calendardata']); |
|
| 63 | - if ($calendar->VEVENT) { |
|
| 64 | - foreach ($calendar->VEVENT as $calendarEvent) { |
|
| 65 | - $this->emitFromObject($calendarEvent, $user); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - } catch (Throwable $e) { |
|
| 69 | - $this->logger->warning('Could not read calendar data for interaction events: ' . $e->getMessage(), [ |
|
| 70 | - 'exception' => $e, |
|
| 71 | - ]); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ($event instanceof CalendarShareUpdatedEvent && !empty($event->getAdded())) { |
|
| 77 | - // group: href => principal:principals/groups/admin |
|
| 78 | - // users: href => principal:principals/users/admin |
|
| 79 | - foreach ($event->getAdded() as $added) { |
|
| 80 | - if (!isset($added['href'])) { |
|
| 81 | - // Nothing to work with |
|
| 82 | - continue; |
|
| 83 | - } |
|
| 84 | - $this->emitFromUri($added['href'], $user); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - private function emitFromUri(string $uri, IUser $user): void { |
|
| 90 | - $principal = $this->principalConnector->findByUri( |
|
| 91 | - $uri, |
|
| 92 | - $this->principalConnector->getPrincipalPrefix() |
|
| 93 | - ); |
|
| 94 | - if ($principal === null) { |
|
| 95 | - // Invalid principal |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - if (!str_starts_with($principal, self::URI_USERS)) { |
|
| 99 | - // Not a user principal |
|
| 100 | - return; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $uid = substr($principal, strlen(self::URI_USERS)); |
|
| 104 | - $this->dispatcher->dispatchTyped( |
|
| 105 | - (new ContactInteractedWithEvent($user))->setUid($uid) |
|
| 106 | - ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - private function emitFromObject(VEvent $vevent, IUser $user): void { |
|
| 110 | - if (!$vevent->ATTENDEE) { |
|
| 111 | - // Nothing left to do |
|
| 112 | - return; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - foreach ($vevent->ATTENDEE as $attendee) { |
|
| 116 | - if (!($attendee instanceof Property)) { |
|
| 117 | - continue; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $cuType = $attendee->offsetGet('CUTYPE'); |
|
| 121 | - if ($cuType instanceof Parameter && $cuType->getValue() !== 'INDIVIDUAL') { |
|
| 122 | - // Don't care about those |
|
| 123 | - continue; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $mailTo = $attendee->getValue(); |
|
| 127 | - if (!str_starts_with($mailTo, 'mailto:')) { |
|
| 128 | - // Doesn't look like an email |
|
| 129 | - continue; |
|
| 130 | - } |
|
| 131 | - $email = substr($mailTo, strlen('mailto:')); |
|
| 132 | - if (!$this->mailer->validateMailAddress($email)) { |
|
| 133 | - // This really isn't a valid email |
|
| 134 | - continue; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $this->dispatcher->dispatchTyped( |
|
| 138 | - (new ContactInteractedWithEvent($user))->setEmail($email) |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - } |
|
| 33 | + private const URI_USERS = 'principals/users/'; |
|
| 34 | + |
|
| 35 | + public function __construct( |
|
| 36 | + private IEventDispatcher $dispatcher, |
|
| 37 | + private IUserSession $userSession, |
|
| 38 | + private Principal $principalConnector, |
|
| 39 | + private IMailer $mailer, |
|
| 40 | + private LoggerInterface $logger, |
|
| 41 | + ) { |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function handle(Event $event): void { |
|
| 45 | + if (($user = $this->userSession->getUser()) === null) { |
|
| 46 | + // Without user context we can't do anything |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if ($event instanceof CalendarObjectCreatedEvent || $event instanceof CalendarObjectUpdatedEvent) { |
|
| 51 | + // users: href => principal:principals/users/admin |
|
| 52 | + foreach ($event->getShares() as $share) { |
|
| 53 | + if (!isset($share['href'])) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 56 | + $this->emitFromUri($share['href'], $user); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // emit interaction for email attendees as well |
|
| 60 | + if (isset($event->getObjectData()['calendardata'])) { |
|
| 61 | + try { |
|
| 62 | + $calendar = Reader::read($event->getObjectData()['calendardata']); |
|
| 63 | + if ($calendar->VEVENT) { |
|
| 64 | + foreach ($calendar->VEVENT as $calendarEvent) { |
|
| 65 | + $this->emitFromObject($calendarEvent, $user); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + } catch (Throwable $e) { |
|
| 69 | + $this->logger->warning('Could not read calendar data for interaction events: ' . $e->getMessage(), [ |
|
| 70 | + 'exception' => $e, |
|
| 71 | + ]); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ($event instanceof CalendarShareUpdatedEvent && !empty($event->getAdded())) { |
|
| 77 | + // group: href => principal:principals/groups/admin |
|
| 78 | + // users: href => principal:principals/users/admin |
|
| 79 | + foreach ($event->getAdded() as $added) { |
|
| 80 | + if (!isset($added['href'])) { |
|
| 81 | + // Nothing to work with |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 84 | + $this->emitFromUri($added['href'], $user); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + private function emitFromUri(string $uri, IUser $user): void { |
|
| 90 | + $principal = $this->principalConnector->findByUri( |
|
| 91 | + $uri, |
|
| 92 | + $this->principalConnector->getPrincipalPrefix() |
|
| 93 | + ); |
|
| 94 | + if ($principal === null) { |
|
| 95 | + // Invalid principal |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + if (!str_starts_with($principal, self::URI_USERS)) { |
|
| 99 | + // Not a user principal |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $uid = substr($principal, strlen(self::URI_USERS)); |
|
| 104 | + $this->dispatcher->dispatchTyped( |
|
| 105 | + (new ContactInteractedWithEvent($user))->setUid($uid) |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + private function emitFromObject(VEvent $vevent, IUser $user): void { |
|
| 110 | + if (!$vevent->ATTENDEE) { |
|
| 111 | + // Nothing left to do |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + foreach ($vevent->ATTENDEE as $attendee) { |
|
| 116 | + if (!($attendee instanceof Property)) { |
|
| 117 | + continue; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $cuType = $attendee->offsetGet('CUTYPE'); |
|
| 121 | + if ($cuType instanceof Parameter && $cuType->getValue() !== 'INDIVIDUAL') { |
|
| 122 | + // Don't care about those |
|
| 123 | + continue; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $mailTo = $attendee->getValue(); |
|
| 127 | + if (!str_starts_with($mailTo, 'mailto:')) { |
|
| 128 | + // Doesn't look like an email |
|
| 129 | + continue; |
|
| 130 | + } |
|
| 131 | + $email = substr($mailTo, strlen('mailto:')); |
|
| 132 | + if (!$this->mailer->validateMailAddress($email)) { |
|
| 133 | + // This really isn't a valid email |
|
| 134 | + continue; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $this->dispatcher->dispatchTyped( |
|
| 138 | + (new ContactInteractedWithEvent($user))->setEmail($email) |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | 142 | } |
@@ -30,24 +30,24 @@ |
||
| 30 | 30 | * @template T |
| 31 | 31 | */ |
| 32 | 32 | class ServiceRegistration extends ARegistration { |
| 33 | - /** |
|
| 34 | - * @var string |
|
| 35 | - * @psalm-var class-string<T> |
|
| 36 | - */ |
|
| 37 | - private $service; |
|
| 33 | + /** |
|
| 34 | + * @var string |
|
| 35 | + * @psalm-var class-string<T> |
|
| 36 | + */ |
|
| 37 | + private $service; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @psalm-param class-string<T> $service |
|
| 41 | - */ |
|
| 42 | - public function __construct(string $appId, string $service) { |
|
| 43 | - parent::__construct($appId); |
|
| 44 | - $this->service = $service; |
|
| 45 | - } |
|
| 39 | + /** |
|
| 40 | + * @psalm-param class-string<T> $service |
|
| 41 | + */ |
|
| 42 | + public function __construct(string $appId, string $service) { |
|
| 43 | + parent::__construct($appId); |
|
| 44 | + $this->service = $service; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @psalm-return class-string<T> |
|
| 49 | - */ |
|
| 50 | - public function getService(): string { |
|
| 51 | - return $this->service; |
|
| 52 | - } |
|
| 47 | + /** |
|
| 48 | + * @psalm-return class-string<T> |
|
| 49 | + */ |
|
| 50 | + public function getService(): string { |
|
| 51 | + return $this->service; |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -29,14 +29,14 @@ |
||
| 29 | 29 | use OCP\Files\FileInfo; |
| 30 | 30 | |
| 31 | 31 | class WebP extends Image { |
| 32 | - /** |
|
| 33 | - * {@inheritDoc} |
|
| 34 | - */ |
|
| 35 | - public function getMimeType(): string { |
|
| 36 | - return '/image\/webp/'; |
|
| 37 | - } |
|
| 32 | + /** |
|
| 33 | + * {@inheritDoc} |
|
| 34 | + */ |
|
| 35 | + public function getMimeType(): string { |
|
| 36 | + return '/image\/webp/'; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function isAvailable(FileInfo $file): bool { |
|
| 40 | - return (bool)(imagetypes() & IMG_WEBP); |
|
| 41 | - } |
|
| 39 | + public function isAvailable(FileInfo $file): bool { |
|
| 40 | + return (bool)(imagetypes() & IMG_WEBP); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -37,6 +37,6 @@ |
||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public function isAvailable(FileInfo $file): bool { |
| 40 | - return (bool)(imagetypes() & IMG_WEBP); |
|
| 40 | + return (bool) (imagetypes() & IMG_WEBP); |
|
| 41 | 41 | } |
| 42 | 42 | } |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - throw new \Exception('Could not load ' . $className, 0, $e); |
|
| 264 | + throw new \Exception('Could not load '.$className, 0, $e); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -271,10 +271,10 @@ discard block |
||
| 271 | 271 | * @throws \Exception |
| 272 | 272 | */ |
| 273 | 273 | private function loadSabrePluginsFromInfoXml(array $classes): array { |
| 274 | - return array_map(function (string $className): ServerPlugin { |
|
| 274 | + return array_map(function(string $className): ServerPlugin { |
|
| 275 | 275 | $instance = $this->createClass($className); |
| 276 | 276 | if (!($instance instanceof ServerPlugin)) { |
| 277 | - throw new \Exception('Sabre server plugin ' . $className . ' does not implement the ' . ServerPlugin::class . ' interface'); |
|
| 277 | + throw new \Exception('Sabre server plugin '.$className.' does not implement the '.ServerPlugin::class.' interface'); |
|
| 278 | 278 | } |
| 279 | 279 | return $instance; |
| 280 | 280 | }, $classes); |
@@ -285,10 +285,10 @@ discard block |
||
| 285 | 285 | * @return Collection[] |
| 286 | 286 | */ |
| 287 | 287 | private function loadSabreCollectionsFromInfoXml(array $classes): array { |
| 288 | - return array_map(function (string $className): Collection { |
|
| 288 | + return array_map(function(string $className): Collection { |
|
| 289 | 289 | $instance = $this->createClass($className); |
| 290 | 290 | if (!($instance instanceof Collection)) { |
| 291 | - throw new \Exception('Sabre collection plugin ' . $className . ' does not implement the ' . Collection::class . ' interface'); |
|
| 291 | + throw new \Exception('Sabre collection plugin '.$className.' does not implement the '.Collection::class.' interface'); |
|
| 292 | 292 | } |
| 293 | 293 | return $instance; |
| 294 | 294 | }, $classes); |
@@ -299,10 +299,10 @@ discard block |
||
| 299 | 299 | * @return IAddressBookProvider[] |
| 300 | 300 | */ |
| 301 | 301 | private function loadSabreAddressBookPluginsFromInfoXml(array $classes): array { |
| 302 | - return array_map(function (string $className): IAddressBookProvider { |
|
| 302 | + return array_map(function(string $className): IAddressBookProvider { |
|
| 303 | 303 | $instance = $this->createClass($className); |
| 304 | 304 | if (!($instance instanceof IAddressBookProvider)) { |
| 305 | - throw new \Exception('Sabre address book plugin class ' . $className . ' does not implement the ' . IAddressBookProvider::class . ' interface'); |
|
| 305 | + throw new \Exception('Sabre address book plugin class '.$className.' does not implement the '.IAddressBookProvider::class.' interface'); |
|
| 306 | 306 | } |
| 307 | 307 | return $instance; |
| 308 | 308 | }, $classes); |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | * @return ICalendarProvider[] |
| 314 | 314 | */ |
| 315 | 315 | private function loadSabreCalendarPluginsFromInfoXml(array $classes): array { |
| 316 | - return array_map(function (string $className): ICalendarProvider { |
|
| 316 | + return array_map(function(string $className): ICalendarProvider { |
|
| 317 | 317 | $instance = $this->createClass($className); |
| 318 | 318 | if (!($instance instanceof ICalendarProvider)) { |
| 319 | - throw new \Exception('Sabre calendar plugin class ' . $className . ' does not implement the ' . ICalendarProvider::class . ' interface'); |
|
| 319 | + throw new \Exception('Sabre calendar plugin class '.$className.' does not implement the '.ICalendarProvider::class.' interface'); |
|
| 320 | 320 | } |
| 321 | 321 | return $instance; |
| 322 | 322 | }, $classes); |
@@ -27,272 +27,272 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class PluginManager { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * App plugins |
|
| 32 | - * |
|
| 33 | - * @var ServerPlugin[] |
|
| 34 | - */ |
|
| 35 | - private $plugins = []; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * App collections |
|
| 39 | - * |
|
| 40 | - * @var Collection[] |
|
| 41 | - */ |
|
| 42 | - private $collections = []; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Address book plugins |
|
| 46 | - * |
|
| 47 | - * @var IAddressBookProvider[] |
|
| 48 | - */ |
|
| 49 | - private $addressBookPlugins = []; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Calendar plugins |
|
| 53 | - * |
|
| 54 | - * @var ICalendarProvider[] |
|
| 55 | - */ |
|
| 56 | - private $calendarPlugins = []; |
|
| 57 | - |
|
| 58 | - /** @var bool */ |
|
| 59 | - private $populated = false; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Contstruct a PluginManager |
|
| 63 | - * |
|
| 64 | - * @param ServerContainer $container server container for resolving plugin classes |
|
| 65 | - * @param IAppManager $appManager app manager to loading apps and their info |
|
| 66 | - */ |
|
| 67 | - public function __construct( |
|
| 68 | - private ServerContainer $container, |
|
| 69 | - private IAppManager $appManager, |
|
| 70 | - ) { |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Returns an array of app-registered plugins |
|
| 75 | - * |
|
| 76 | - * @return ServerPlugin[] |
|
| 77 | - */ |
|
| 78 | - public function getAppPlugins() { |
|
| 79 | - $this->populate(); |
|
| 80 | - return $this->plugins; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Returns an array of app-registered collections |
|
| 85 | - * |
|
| 86 | - * @return array |
|
| 87 | - */ |
|
| 88 | - public function getAppCollections() { |
|
| 89 | - $this->populate(); |
|
| 90 | - return $this->collections; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @return IAddressBookProvider[] |
|
| 95 | - */ |
|
| 96 | - public function getAddressBookPlugins(): array { |
|
| 97 | - $this->populate(); |
|
| 98 | - return $this->addressBookPlugins; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Returns an array of app-registered calendar plugins |
|
| 103 | - * |
|
| 104 | - * @return ICalendarProvider[] |
|
| 105 | - */ |
|
| 106 | - public function getCalendarPlugins():array { |
|
| 107 | - $this->populate(); |
|
| 108 | - return $this->calendarPlugins; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Retrieve plugin and collection list and populate attributes |
|
| 113 | - */ |
|
| 114 | - private function populate(): void { |
|
| 115 | - if ($this->populated) { |
|
| 116 | - return; |
|
| 117 | - } |
|
| 118 | - $this->populated = true; |
|
| 119 | - |
|
| 120 | - $this->calendarPlugins[] = $this->container->get(AppCalendarPlugin::class); |
|
| 121 | - |
|
| 122 | - foreach ($this->appManager->getEnabledApps() as $app) { |
|
| 123 | - // load plugins and collections from info.xml |
|
| 124 | - $info = $this->appManager->getAppInfo($app); |
|
| 125 | - if (!isset($info['types']) || !in_array('dav', $info['types'], true)) { |
|
| 126 | - continue; |
|
| 127 | - } |
|
| 128 | - $plugins = $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info)); |
|
| 129 | - foreach ($plugins as $plugin) { |
|
| 130 | - $this->plugins[] = $plugin; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $collections = $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info)); |
|
| 134 | - foreach ($collections as $collection) { |
|
| 135 | - $this->collections[] = $collection; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $addresbookPlugins = $this->loadSabreAddressBookPluginsFromInfoXml($this->extractAddressBookPluginList($info)); |
|
| 139 | - foreach ($addresbookPlugins as $addresbookPlugin) { |
|
| 140 | - $this->addressBookPlugins[] = $addresbookPlugin; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - $calendarPlugins = $this->loadSabreCalendarPluginsFromInfoXml($this->extractCalendarPluginList($info)); |
|
| 144 | - foreach ($calendarPlugins as $calendarPlugin) { |
|
| 145 | - $this->calendarPlugins[] = $calendarPlugin; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param array $array |
|
| 152 | - * @return string[] |
|
| 153 | - */ |
|
| 154 | - private function extractPluginList(array $array): array { |
|
| 155 | - if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 156 | - if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) { |
|
| 157 | - if (isset($array['sabre']['plugins']['plugin'])) { |
|
| 158 | - $items = $array['sabre']['plugins']['plugin']; |
|
| 159 | - if (!is_array($items)) { |
|
| 160 | - $items = [$items]; |
|
| 161 | - } |
|
| 162 | - return $items; |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - return []; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param array $array |
|
| 171 | - * @return string[] |
|
| 172 | - */ |
|
| 173 | - private function extractCollectionList(array $array): array { |
|
| 174 | - if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 175 | - if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) { |
|
| 176 | - if (isset($array['sabre']['collections']['collection'])) { |
|
| 177 | - $items = $array['sabre']['collections']['collection']; |
|
| 178 | - if (!is_array($items)) { |
|
| 179 | - $items = [$items]; |
|
| 180 | - } |
|
| 181 | - return $items; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - return []; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @param array $array |
|
| 190 | - * @return string[] |
|
| 191 | - */ |
|
| 192 | - private function extractAddressBookPluginList(array $array): array { |
|
| 193 | - if (!isset($array['sabre']) || !is_array($array['sabre'])) { |
|
| 194 | - return []; |
|
| 195 | - } |
|
| 196 | - if (!isset($array['sabre']['address-book-plugins']) || !is_array($array['sabre']['address-book-plugins'])) { |
|
| 197 | - return []; |
|
| 198 | - } |
|
| 199 | - if (!isset($array['sabre']['address-book-plugins']['plugin'])) { |
|
| 200 | - return []; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $items = $array['sabre']['address-book-plugins']['plugin']; |
|
| 204 | - if (!is_array($items)) { |
|
| 205 | - $items = [$items]; |
|
| 206 | - } |
|
| 207 | - return $items; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @param array $array |
|
| 212 | - * @return string[] |
|
| 213 | - */ |
|
| 214 | - private function extractCalendarPluginList(array $array): array { |
|
| 215 | - if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 216 | - if (isset($array['sabre']['calendar-plugins']) && is_array($array['sabre']['calendar-plugins'])) { |
|
| 217 | - if (isset($array['sabre']['calendar-plugins']['plugin'])) { |
|
| 218 | - $items = $array['sabre']['calendar-plugins']['plugin']; |
|
| 219 | - if (!is_array($items)) { |
|
| 220 | - $items = [$items]; |
|
| 221 | - } |
|
| 222 | - return $items; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - return []; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - private function createClass(string $className): object { |
|
| 230 | - try { |
|
| 231 | - return $this->container->get($className); |
|
| 232 | - } catch (QueryException $e) { |
|
| 233 | - if (class_exists($className)) { |
|
| 234 | - return new $className(); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - throw new \Exception('Could not load ' . $className, 0, $e); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param string[] $classes |
|
| 244 | - * @return ServerPlugin[] |
|
| 245 | - * @throws \Exception |
|
| 246 | - */ |
|
| 247 | - private function loadSabrePluginsFromInfoXml(array $classes): array { |
|
| 248 | - return array_map(function (string $className): ServerPlugin { |
|
| 249 | - $instance = $this->createClass($className); |
|
| 250 | - if (!($instance instanceof ServerPlugin)) { |
|
| 251 | - throw new \Exception('Sabre server plugin ' . $className . ' does not implement the ' . ServerPlugin::class . ' interface'); |
|
| 252 | - } |
|
| 253 | - return $instance; |
|
| 254 | - }, $classes); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @param string[] $classes |
|
| 259 | - * @return Collection[] |
|
| 260 | - */ |
|
| 261 | - private function loadSabreCollectionsFromInfoXml(array $classes): array { |
|
| 262 | - return array_map(function (string $className): Collection { |
|
| 263 | - $instance = $this->createClass($className); |
|
| 264 | - if (!($instance instanceof Collection)) { |
|
| 265 | - throw new \Exception('Sabre collection plugin ' . $className . ' does not implement the ' . Collection::class . ' interface'); |
|
| 266 | - } |
|
| 267 | - return $instance; |
|
| 268 | - }, $classes); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @param string[] $classes |
|
| 273 | - * @return IAddressBookProvider[] |
|
| 274 | - */ |
|
| 275 | - private function loadSabreAddressBookPluginsFromInfoXml(array $classes): array { |
|
| 276 | - return array_map(function (string $className): IAddressBookProvider { |
|
| 277 | - $instance = $this->createClass($className); |
|
| 278 | - if (!($instance instanceof IAddressBookProvider)) { |
|
| 279 | - throw new \Exception('Sabre address book plugin class ' . $className . ' does not implement the ' . IAddressBookProvider::class . ' interface'); |
|
| 280 | - } |
|
| 281 | - return $instance; |
|
| 282 | - }, $classes); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * @param string[] $classes |
|
| 287 | - * @return ICalendarProvider[] |
|
| 288 | - */ |
|
| 289 | - private function loadSabreCalendarPluginsFromInfoXml(array $classes): array { |
|
| 290 | - return array_map(function (string $className): ICalendarProvider { |
|
| 291 | - $instance = $this->createClass($className); |
|
| 292 | - if (!($instance instanceof ICalendarProvider)) { |
|
| 293 | - throw new \Exception('Sabre calendar plugin class ' . $className . ' does not implement the ' . ICalendarProvider::class . ' interface'); |
|
| 294 | - } |
|
| 295 | - return $instance; |
|
| 296 | - }, $classes); |
|
| 297 | - } |
|
| 30 | + /** |
|
| 31 | + * App plugins |
|
| 32 | + * |
|
| 33 | + * @var ServerPlugin[] |
|
| 34 | + */ |
|
| 35 | + private $plugins = []; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * App collections |
|
| 39 | + * |
|
| 40 | + * @var Collection[] |
|
| 41 | + */ |
|
| 42 | + private $collections = []; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Address book plugins |
|
| 46 | + * |
|
| 47 | + * @var IAddressBookProvider[] |
|
| 48 | + */ |
|
| 49 | + private $addressBookPlugins = []; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Calendar plugins |
|
| 53 | + * |
|
| 54 | + * @var ICalendarProvider[] |
|
| 55 | + */ |
|
| 56 | + private $calendarPlugins = []; |
|
| 57 | + |
|
| 58 | + /** @var bool */ |
|
| 59 | + private $populated = false; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Contstruct a PluginManager |
|
| 63 | + * |
|
| 64 | + * @param ServerContainer $container server container for resolving plugin classes |
|
| 65 | + * @param IAppManager $appManager app manager to loading apps and their info |
|
| 66 | + */ |
|
| 67 | + public function __construct( |
|
| 68 | + private ServerContainer $container, |
|
| 69 | + private IAppManager $appManager, |
|
| 70 | + ) { |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Returns an array of app-registered plugins |
|
| 75 | + * |
|
| 76 | + * @return ServerPlugin[] |
|
| 77 | + */ |
|
| 78 | + public function getAppPlugins() { |
|
| 79 | + $this->populate(); |
|
| 80 | + return $this->plugins; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Returns an array of app-registered collections |
|
| 85 | + * |
|
| 86 | + * @return array |
|
| 87 | + */ |
|
| 88 | + public function getAppCollections() { |
|
| 89 | + $this->populate(); |
|
| 90 | + return $this->collections; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @return IAddressBookProvider[] |
|
| 95 | + */ |
|
| 96 | + public function getAddressBookPlugins(): array { |
|
| 97 | + $this->populate(); |
|
| 98 | + return $this->addressBookPlugins; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Returns an array of app-registered calendar plugins |
|
| 103 | + * |
|
| 104 | + * @return ICalendarProvider[] |
|
| 105 | + */ |
|
| 106 | + public function getCalendarPlugins():array { |
|
| 107 | + $this->populate(); |
|
| 108 | + return $this->calendarPlugins; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Retrieve plugin and collection list and populate attributes |
|
| 113 | + */ |
|
| 114 | + private function populate(): void { |
|
| 115 | + if ($this->populated) { |
|
| 116 | + return; |
|
| 117 | + } |
|
| 118 | + $this->populated = true; |
|
| 119 | + |
|
| 120 | + $this->calendarPlugins[] = $this->container->get(AppCalendarPlugin::class); |
|
| 121 | + |
|
| 122 | + foreach ($this->appManager->getEnabledApps() as $app) { |
|
| 123 | + // load plugins and collections from info.xml |
|
| 124 | + $info = $this->appManager->getAppInfo($app); |
|
| 125 | + if (!isset($info['types']) || !in_array('dav', $info['types'], true)) { |
|
| 126 | + continue; |
|
| 127 | + } |
|
| 128 | + $plugins = $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info)); |
|
| 129 | + foreach ($plugins as $plugin) { |
|
| 130 | + $this->plugins[] = $plugin; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $collections = $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info)); |
|
| 134 | + foreach ($collections as $collection) { |
|
| 135 | + $this->collections[] = $collection; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $addresbookPlugins = $this->loadSabreAddressBookPluginsFromInfoXml($this->extractAddressBookPluginList($info)); |
|
| 139 | + foreach ($addresbookPlugins as $addresbookPlugin) { |
|
| 140 | + $this->addressBookPlugins[] = $addresbookPlugin; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + $calendarPlugins = $this->loadSabreCalendarPluginsFromInfoXml($this->extractCalendarPluginList($info)); |
|
| 144 | + foreach ($calendarPlugins as $calendarPlugin) { |
|
| 145 | + $this->calendarPlugins[] = $calendarPlugin; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param array $array |
|
| 152 | + * @return string[] |
|
| 153 | + */ |
|
| 154 | + private function extractPluginList(array $array): array { |
|
| 155 | + if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 156 | + if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) { |
|
| 157 | + if (isset($array['sabre']['plugins']['plugin'])) { |
|
| 158 | + $items = $array['sabre']['plugins']['plugin']; |
|
| 159 | + if (!is_array($items)) { |
|
| 160 | + $items = [$items]; |
|
| 161 | + } |
|
| 162 | + return $items; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + return []; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param array $array |
|
| 171 | + * @return string[] |
|
| 172 | + */ |
|
| 173 | + private function extractCollectionList(array $array): array { |
|
| 174 | + if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 175 | + if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) { |
|
| 176 | + if (isset($array['sabre']['collections']['collection'])) { |
|
| 177 | + $items = $array['sabre']['collections']['collection']; |
|
| 178 | + if (!is_array($items)) { |
|
| 179 | + $items = [$items]; |
|
| 180 | + } |
|
| 181 | + return $items; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + return []; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @param array $array |
|
| 190 | + * @return string[] |
|
| 191 | + */ |
|
| 192 | + private function extractAddressBookPluginList(array $array): array { |
|
| 193 | + if (!isset($array['sabre']) || !is_array($array['sabre'])) { |
|
| 194 | + return []; |
|
| 195 | + } |
|
| 196 | + if (!isset($array['sabre']['address-book-plugins']) || !is_array($array['sabre']['address-book-plugins'])) { |
|
| 197 | + return []; |
|
| 198 | + } |
|
| 199 | + if (!isset($array['sabre']['address-book-plugins']['plugin'])) { |
|
| 200 | + return []; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $items = $array['sabre']['address-book-plugins']['plugin']; |
|
| 204 | + if (!is_array($items)) { |
|
| 205 | + $items = [$items]; |
|
| 206 | + } |
|
| 207 | + return $items; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @param array $array |
|
| 212 | + * @return string[] |
|
| 213 | + */ |
|
| 214 | + private function extractCalendarPluginList(array $array): array { |
|
| 215 | + if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
| 216 | + if (isset($array['sabre']['calendar-plugins']) && is_array($array['sabre']['calendar-plugins'])) { |
|
| 217 | + if (isset($array['sabre']['calendar-plugins']['plugin'])) { |
|
| 218 | + $items = $array['sabre']['calendar-plugins']['plugin']; |
|
| 219 | + if (!is_array($items)) { |
|
| 220 | + $items = [$items]; |
|
| 221 | + } |
|
| 222 | + return $items; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + return []; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + private function createClass(string $className): object { |
|
| 230 | + try { |
|
| 231 | + return $this->container->get($className); |
|
| 232 | + } catch (QueryException $e) { |
|
| 233 | + if (class_exists($className)) { |
|
| 234 | + return new $className(); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + throw new \Exception('Could not load ' . $className, 0, $e); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param string[] $classes |
|
| 244 | + * @return ServerPlugin[] |
|
| 245 | + * @throws \Exception |
|
| 246 | + */ |
|
| 247 | + private function loadSabrePluginsFromInfoXml(array $classes): array { |
|
| 248 | + return array_map(function (string $className): ServerPlugin { |
|
| 249 | + $instance = $this->createClass($className); |
|
| 250 | + if (!($instance instanceof ServerPlugin)) { |
|
| 251 | + throw new \Exception('Sabre server plugin ' . $className . ' does not implement the ' . ServerPlugin::class . ' interface'); |
|
| 252 | + } |
|
| 253 | + return $instance; |
|
| 254 | + }, $classes); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @param string[] $classes |
|
| 259 | + * @return Collection[] |
|
| 260 | + */ |
|
| 261 | + private function loadSabreCollectionsFromInfoXml(array $classes): array { |
|
| 262 | + return array_map(function (string $className): Collection { |
|
| 263 | + $instance = $this->createClass($className); |
|
| 264 | + if (!($instance instanceof Collection)) { |
|
| 265 | + throw new \Exception('Sabre collection plugin ' . $className . ' does not implement the ' . Collection::class . ' interface'); |
|
| 266 | + } |
|
| 267 | + return $instance; |
|
| 268 | + }, $classes); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @param string[] $classes |
|
| 273 | + * @return IAddressBookProvider[] |
|
| 274 | + */ |
|
| 275 | + private function loadSabreAddressBookPluginsFromInfoXml(array $classes): array { |
|
| 276 | + return array_map(function (string $className): IAddressBookProvider { |
|
| 277 | + $instance = $this->createClass($className); |
|
| 278 | + if (!($instance instanceof IAddressBookProvider)) { |
|
| 279 | + throw new \Exception('Sabre address book plugin class ' . $className . ' does not implement the ' . IAddressBookProvider::class . ' interface'); |
|
| 280 | + } |
|
| 281 | + return $instance; |
|
| 282 | + }, $classes); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * @param string[] $classes |
|
| 287 | + * @return ICalendarProvider[] |
|
| 288 | + */ |
|
| 289 | + private function loadSabreCalendarPluginsFromInfoXml(array $classes): array { |
|
| 290 | + return array_map(function (string $className): ICalendarProvider { |
|
| 291 | + $instance = $this->createClass($className); |
|
| 292 | + if (!($instance instanceof ICalendarProvider)) { |
|
| 293 | + throw new \Exception('Sabre calendar plugin class ' . $className . ' does not implement the ' . ICalendarProvider::class . ' interface'); |
|
| 294 | + } |
|
| 295 | + return $instance; |
|
| 296 | + }, $classes); |
|
| 297 | + } |
|
| 298 | 298 | } |
@@ -35,61 +35,61 @@ |
||
| 35 | 35 | * @since 22.0.0 |
| 36 | 36 | */ |
| 37 | 37 | class AbstractCacheEvent extends Event implements ICacheEvent { |
| 38 | - protected $storage; |
|
| 39 | - protected $path; |
|
| 40 | - protected $fileId; |
|
| 41 | - protected $storageId; |
|
| 38 | + protected $storage; |
|
| 39 | + protected $path; |
|
| 40 | + protected $fileId; |
|
| 41 | + protected $storageId; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param IStorage $storage |
|
| 45 | - * @param string $path |
|
| 46 | - * @param int $fileId |
|
| 47 | - * @since 22.0.0 |
|
| 48 | - */ |
|
| 49 | - public function __construct(IStorage $storage, string $path, int $fileId, int $storageId) { |
|
| 50 | - $this->storage = $storage; |
|
| 51 | - $this->path = $path; |
|
| 52 | - $this->fileId = $fileId; |
|
| 53 | - $this->storageId = $storageId; |
|
| 54 | - } |
|
| 43 | + /** |
|
| 44 | + * @param IStorage $storage |
|
| 45 | + * @param string $path |
|
| 46 | + * @param int $fileId |
|
| 47 | + * @since 22.0.0 |
|
| 48 | + */ |
|
| 49 | + public function __construct(IStorage $storage, string $path, int $fileId, int $storageId) { |
|
| 50 | + $this->storage = $storage; |
|
| 51 | + $this->path = $path; |
|
| 52 | + $this->fileId = $fileId; |
|
| 53 | + $this->storageId = $storageId; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @return IStorage |
|
| 58 | - * @since 22.0.0 |
|
| 59 | - */ |
|
| 60 | - public function getStorage(): IStorage { |
|
| 61 | - return $this->storage; |
|
| 62 | - } |
|
| 56 | + /** |
|
| 57 | + * @return IStorage |
|
| 58 | + * @since 22.0.0 |
|
| 59 | + */ |
|
| 60 | + public function getStorage(): IStorage { |
|
| 61 | + return $this->storage; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return string |
|
| 66 | - * @since 22.0.0 |
|
| 67 | - */ |
|
| 68 | - public function getPath(): string { |
|
| 69 | - return $this->path; |
|
| 70 | - } |
|
| 64 | + /** |
|
| 65 | + * @return string |
|
| 66 | + * @since 22.0.0 |
|
| 67 | + */ |
|
| 68 | + public function getPath(): string { |
|
| 69 | + return $this->path; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @param string $path |
|
| 74 | - * @since 22.0.0 |
|
| 75 | - */ |
|
| 76 | - public function setPath(string $path): void { |
|
| 77 | - $this->path = $path; |
|
| 78 | - } |
|
| 72 | + /** |
|
| 73 | + * @param string $path |
|
| 74 | + * @since 22.0.0 |
|
| 75 | + */ |
|
| 76 | + public function setPath(string $path): void { |
|
| 77 | + $this->path = $path; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @return int |
|
| 82 | - * @since 22.0.0 |
|
| 83 | - */ |
|
| 84 | - public function getFileId(): int { |
|
| 85 | - return $this->fileId; |
|
| 86 | - } |
|
| 80 | + /** |
|
| 81 | + * @return int |
|
| 82 | + * @since 22.0.0 |
|
| 83 | + */ |
|
| 84 | + public function getFileId(): int { |
|
| 85 | + return $this->fileId; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @return int |
|
| 90 | - * @since 22.0.0 |
|
| 91 | - */ |
|
| 92 | - public function getStorageId(): int { |
|
| 93 | - return $this->storageId; |
|
| 94 | - } |
|
| 88 | + /** |
|
| 89 | + * @return int |
|
| 90 | + * @since 22.0.0 |
|
| 91 | + */ |
|
| 92 | + public function getStorageId(): int { |
|
| 93 | + return $this->storageId; |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -38,41 +38,41 @@ |
||
| 38 | 38 | * Auto-generated migration step: Please modify to your needs! |
| 39 | 39 | */ |
| 40 | 40 | class Version1011Date20190806104428 extends SimpleMigrationStep { |
| 41 | - /** |
|
| 42 | - * @param IOutput $output |
|
| 43 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 44 | - * @param array $options |
|
| 45 | - * @return null|ISchemaWrapper |
|
| 46 | - */ |
|
| 47 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
| 48 | - /** @var ISchemaWrapper $schema */ |
|
| 49 | - $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 | + */ |
|
| 47 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
| 48 | + /** @var ISchemaWrapper $schema */ |
|
| 49 | + $schema = $schemaClosure(); |
|
| 50 | 50 | |
| 51 | - $table = $schema->createTable('dav_cal_proxy'); |
|
| 52 | - $table->addColumn('id', Types::BIGINT, [ |
|
| 53 | - 'autoincrement' => true, |
|
| 54 | - 'notnull' => true, |
|
| 55 | - 'length' => 11, |
|
| 56 | - 'unsigned' => true, |
|
| 57 | - ]); |
|
| 58 | - $table->addColumn('owner_id', Types::STRING, [ |
|
| 59 | - 'notnull' => true, |
|
| 60 | - 'length' => 64, |
|
| 61 | - ]); |
|
| 62 | - $table->addColumn('proxy_id', Types::STRING, [ |
|
| 63 | - 'notnull' => true, |
|
| 64 | - 'length' => 64, |
|
| 65 | - ]); |
|
| 66 | - $table->addColumn('permissions', Types::INTEGER, [ |
|
| 67 | - 'notnull' => false, |
|
| 68 | - 'length' => 4, |
|
| 69 | - 'unsigned' => true, |
|
| 70 | - ]); |
|
| 51 | + $table = $schema->createTable('dav_cal_proxy'); |
|
| 52 | + $table->addColumn('id', Types::BIGINT, [ |
|
| 53 | + 'autoincrement' => true, |
|
| 54 | + 'notnull' => true, |
|
| 55 | + 'length' => 11, |
|
| 56 | + 'unsigned' => true, |
|
| 57 | + ]); |
|
| 58 | + $table->addColumn('owner_id', Types::STRING, [ |
|
| 59 | + 'notnull' => true, |
|
| 60 | + 'length' => 64, |
|
| 61 | + ]); |
|
| 62 | + $table->addColumn('proxy_id', Types::STRING, [ |
|
| 63 | + 'notnull' => true, |
|
| 64 | + 'length' => 64, |
|
| 65 | + ]); |
|
| 66 | + $table->addColumn('permissions', Types::INTEGER, [ |
|
| 67 | + 'notnull' => false, |
|
| 68 | + 'length' => 4, |
|
| 69 | + 'unsigned' => true, |
|
| 70 | + ]); |
|
| 71 | 71 | |
| 72 | - $table->setPrimaryKey(['id']); |
|
| 73 | - $table->addUniqueIndex(['owner_id', 'proxy_id', 'permissions'], 'dav_cal_proxy_uidx'); |
|
| 74 | - $table->addIndex(['proxy_id'], 'dav_cal_proxy_ipid'); |
|
| 72 | + $table->setPrimaryKey(['id']); |
|
| 73 | + $table->addUniqueIndex(['owner_id', 'proxy_id', 'permissions'], 'dav_cal_proxy_uidx'); |
|
| 74 | + $table->addIndex(['proxy_id'], 'dav_cal_proxy_ipid'); |
|
| 75 | 75 | |
| 76 | - return $schema; |
|
| 77 | - } |
|
| 76 | + return $schema; |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -35,21 +35,21 @@ |
||
| 35 | 35 | * Auto-generated migration step: Please modify to your needs! |
| 36 | 36 | */ |
| 37 | 37 | class Version1017Date20210216083742 extends SimpleMigrationStep { |
| 38 | - /** |
|
| 39 | - * @param IOutput $output |
|
| 40 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 41 | - * @param array $options |
|
| 42 | - * @return null|ISchemaWrapper |
|
| 43 | - */ |
|
| 44 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 45 | - /** @var ISchemaWrapper $schema */ |
|
| 46 | - $schema = $schemaClosure(); |
|
| 38 | + /** |
|
| 39 | + * @param IOutput $output |
|
| 40 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 41 | + * @param array $options |
|
| 42 | + * @return null|ISchemaWrapper |
|
| 43 | + */ |
|
| 44 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 45 | + /** @var ISchemaWrapper $schema */ |
|
| 46 | + $schema = $schemaClosure(); |
|
| 47 | 47 | |
| 48 | - $table = $schema->getTable('dav_cal_proxy'); |
|
| 49 | - if ($table->hasIndex('dav_cal_proxy_ioid')) { |
|
| 50 | - $table->dropIndex('dav_cal_proxy_ioid'); |
|
| 51 | - } |
|
| 48 | + $table = $schema->getTable('dav_cal_proxy'); |
|
| 49 | + if ($table->hasIndex('dav_cal_proxy_ioid')) { |
|
| 50 | + $table->dropIndex('dav_cal_proxy_ioid'); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - return $schema; |
|
| 54 | - } |
|
| 53 | + return $schema; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -35,21 +35,21 @@ |
||
| 35 | 35 | * Auto-generated migration step: Please modify to your needs! |
| 36 | 36 | */ |
| 37 | 37 | class Version22000Date20210216084241 extends SimpleMigrationStep { |
| 38 | - /** |
|
| 39 | - * @param IOutput $output |
|
| 40 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 41 | - * @param array $options |
|
| 42 | - * @return null|ISchemaWrapper |
|
| 43 | - */ |
|
| 44 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 45 | - /** @var ISchemaWrapper $schema */ |
|
| 46 | - $schema = $schemaClosure(); |
|
| 38 | + /** |
|
| 39 | + * @param IOutput $output |
|
| 40 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 41 | + * @param array $options |
|
| 42 | + * @return null|ISchemaWrapper |
|
| 43 | + */ |
|
| 44 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
| 45 | + /** @var ISchemaWrapper $schema */ |
|
| 46 | + $schema = $schemaClosure(); |
|
| 47 | 47 | |
| 48 | - $table = $schema->getTable('share_external'); |
|
| 49 | - if ($table->hasIndex('sh_external_user')) { |
|
| 50 | - $table->dropIndex('sh_external_user'); |
|
| 51 | - } |
|
| 48 | + $table = $schema->getTable('share_external'); |
|
| 49 | + if ($table->hasIndex('sh_external_user')) { |
|
| 50 | + $table->dropIndex('sh_external_user'); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - return $schema; |
|
| 54 | - } |
|
| 53 | + return $schema; |
|
| 54 | + } |
|
| 55 | 55 | } |