@@ -31,20 +31,20 @@ |
||
31 | 31 | use OCP\EventDispatcher\IEventListener; |
32 | 32 | |
33 | 33 | class LoadAdditionalScriptsListener implements IEventListener { |
34 | - /** @var FederatedShareProvider */ |
|
35 | - protected $federatedShareProvider; |
|
34 | + /** @var FederatedShareProvider */ |
|
35 | + protected $federatedShareProvider; |
|
36 | 36 | |
37 | - public function __construct(FederatedShareProvider $federatedShareProvider) { |
|
38 | - $this->federatedShareProvider = $federatedShareProvider; |
|
39 | - } |
|
37 | + public function __construct(FederatedShareProvider $federatedShareProvider) { |
|
38 | + $this->federatedShareProvider = $federatedShareProvider; |
|
39 | + } |
|
40 | 40 | |
41 | - public function handle(Event $event): void { |
|
42 | - if (!$event instanceof LoadAdditionalScriptsEvent) { |
|
43 | - return; |
|
44 | - } |
|
41 | + public function handle(Event $event): void { |
|
42 | + if (!$event instanceof LoadAdditionalScriptsEvent) { |
|
43 | + return; |
|
44 | + } |
|
45 | 45 | |
46 | - if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled()) { |
|
47 | - \OCP\Util::addScript('federatedfilesharing', 'external'); |
|
48 | - } |
|
49 | - } |
|
46 | + if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled()) { |
|
47 | + \OCP\Util::addScript('federatedfilesharing', 'external'); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | } |
@@ -35,25 +35,25 @@ |
||
35 | 35 | |
36 | 36 | class LegacyBeforeTemplateRenderedListener implements IEventListener { |
37 | 37 | |
38 | - /** @var SymfonyAdapter */ |
|
39 | - private $dispatcher; |
|
38 | + /** @var SymfonyAdapter */ |
|
39 | + private $dispatcher; |
|
40 | 40 | |
41 | - public function __construct(SymfonyAdapter $dispatcher) { |
|
42 | - $this->dispatcher = $dispatcher; |
|
43 | - } |
|
41 | + public function __construct(SymfonyAdapter $dispatcher) { |
|
42 | + $this->dispatcher = $dispatcher; |
|
43 | + } |
|
44 | 44 | |
45 | - public function handle(Event $event): void { |
|
46 | - if (!($event instanceof BeforeTemplateRenderedEvent)) { |
|
47 | - return; |
|
48 | - } |
|
45 | + public function handle(Event $event): void { |
|
46 | + if (!($event instanceof BeforeTemplateRenderedEvent)) { |
|
47 | + return; |
|
48 | + } |
|
49 | 49 | |
50 | - $eventName = 'OCA\Files_Sharing::loadAdditionalScripts'; |
|
50 | + $eventName = 'OCA\Files_Sharing::loadAdditionalScripts'; |
|
51 | 51 | |
52 | - if ($event->getScope() !== null) { |
|
53 | - $eventName .= '::' . $event->getScope(); |
|
54 | - } |
|
52 | + if ($event->getScope() !== null) { |
|
53 | + $eventName .= '::' . $event->getScope(); |
|
54 | + } |
|
55 | 55 | |
56 | - $legacyEvent = new GenericEvent(null, ['share' => $event->getShare()]); |
|
57 | - $this->dispatcher->dispatch($eventName, $legacyEvent); |
|
58 | - } |
|
56 | + $legacyEvent = new GenericEvent(null, ['share' => $event->getShare()]); |
|
57 | + $this->dispatcher->dispatch($eventName, $legacyEvent); |
|
58 | + } |
|
59 | 59 | } |
@@ -36,37 +36,37 @@ |
||
36 | 36 | * @since 20.0.0 |
37 | 37 | */ |
38 | 38 | class BeforeTemplateRenderedEvent extends Event { |
39 | - /** |
|
40 | - * @since 20.0.0 |
|
41 | - */ |
|
42 | - public const SCOPE_PUBLIC_SHARE_AUTH = 'publicShareAuth'; |
|
39 | + /** |
|
40 | + * @since 20.0.0 |
|
41 | + */ |
|
42 | + public const SCOPE_PUBLIC_SHARE_AUTH = 'publicShareAuth'; |
|
43 | 43 | |
44 | - /** @var IShare */ |
|
45 | - private $share; |
|
46 | - /** @var string|null */ |
|
47 | - private $scope; |
|
44 | + /** @var IShare */ |
|
45 | + private $share; |
|
46 | + /** @var string|null */ |
|
47 | + private $scope; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @since 20.0.0 |
|
51 | - */ |
|
52 | - public function __construct(IShare $share, ?string $scope = null) { |
|
53 | - parent::__construct(); |
|
49 | + /** |
|
50 | + * @since 20.0.0 |
|
51 | + */ |
|
52 | + public function __construct(IShare $share, ?string $scope = null) { |
|
53 | + parent::__construct(); |
|
54 | 54 | |
55 | - $this->share = $share; |
|
56 | - $this->scope = $scope; |
|
57 | - } |
|
55 | + $this->share = $share; |
|
56 | + $this->scope = $scope; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @since 20.0.0 |
|
61 | - */ |
|
62 | - public function getShare(): IShare { |
|
63 | - return $this->share; |
|
64 | - } |
|
59 | + /** |
|
60 | + * @since 20.0.0 |
|
61 | + */ |
|
62 | + public function getShare(): IShare { |
|
63 | + return $this->share; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @since 20.0.0 |
|
68 | - */ |
|
69 | - public function getScope(): ?string { |
|
70 | - return $this->scope; |
|
71 | - } |
|
66 | + /** |
|
67 | + * @since 20.0.0 |
|
68 | + */ |
|
69 | + public function getScope(): ?string { |
|
70 | + return $this->scope; |
|
71 | + } |
|
72 | 72 | } |
@@ -34,113 +34,113 @@ |
||
34 | 34 | use Symfony\Component\Console\Output\OutputInterface; |
35 | 35 | |
36 | 36 | class Size extends Base { |
37 | - private $config; |
|
38 | - private $userManager; |
|
39 | - private $commandBus; |
|
37 | + private $config; |
|
38 | + private $userManager; |
|
39 | + private $commandBus; |
|
40 | 40 | |
41 | - public function __construct( |
|
42 | - IConfig $config, |
|
43 | - IUserManager $userManager, |
|
44 | - IBus $commandBus |
|
45 | - ) { |
|
46 | - parent::__construct(); |
|
41 | + public function __construct( |
|
42 | + IConfig $config, |
|
43 | + IUserManager $userManager, |
|
44 | + IBus $commandBus |
|
45 | + ) { |
|
46 | + parent::__construct(); |
|
47 | 47 | |
48 | - $this->config = $config; |
|
49 | - $this->userManager = $userManager; |
|
50 | - $this->commandBus = $commandBus; |
|
51 | - } |
|
48 | + $this->config = $config; |
|
49 | + $this->userManager = $userManager; |
|
50 | + $this->commandBus = $commandBus; |
|
51 | + } |
|
52 | 52 | |
53 | - protected function configure() { |
|
54 | - parent::configure(); |
|
55 | - $this |
|
56 | - ->setName('trashbin:size') |
|
57 | - ->setDescription('Configure the target trashbin size') |
|
58 | - ->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'configure the target size for the provided user, if no user is given the default size is configured') |
|
59 | - ->addArgument( |
|
60 | - 'size', |
|
61 | - InputArgument::OPTIONAL, |
|
62 | - 'the target size for the trashbin, if not provided the current trashbin size will be returned' |
|
63 | - ); |
|
64 | - } |
|
53 | + protected function configure() { |
|
54 | + parent::configure(); |
|
55 | + $this |
|
56 | + ->setName('trashbin:size') |
|
57 | + ->setDescription('Configure the target trashbin size') |
|
58 | + ->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'configure the target size for the provided user, if no user is given the default size is configured') |
|
59 | + ->addArgument( |
|
60 | + 'size', |
|
61 | + InputArgument::OPTIONAL, |
|
62 | + 'the target size for the trashbin, if not provided the current trashbin size will be returned' |
|
63 | + ); |
|
64 | + } |
|
65 | 65 | |
66 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
67 | - $user = $input->getOption('user'); |
|
68 | - $size = $input->getArgument('size'); |
|
66 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
67 | + $user = $input->getOption('user'); |
|
68 | + $size = $input->getArgument('size'); |
|
69 | 69 | |
70 | - if ($size) { |
|
71 | - $parsedSize = \OC_Helper::computerFileSize($size); |
|
72 | - if ($parsedSize === false) { |
|
73 | - $output->writeln("<error>Failed to parse input size</error>"); |
|
74 | - return -1; |
|
75 | - } |
|
76 | - if ($user) { |
|
77 | - $this->config->setUserValue($user, 'files_trashbin', 'trashbin_size', (string)$parsedSize); |
|
78 | - $this->commandBus->push(new Expire($user)); |
|
79 | - } else { |
|
80 | - $this->config->setAppValue('files_trashbin', 'trashbin_size', (string)$parsedSize); |
|
81 | - $output->writeln("<info>Warning: changing the default trashbin size will automatically trigger cleanup of existing trashbins,</info>"); |
|
82 | - $output->writeln("<info>a users trashbin can exceed the configured size until they move a new file to the trashbin.</info>"); |
|
83 | - } |
|
84 | - } else { |
|
85 | - $this->printTrashbinSize($input, $output, $user); |
|
86 | - } |
|
70 | + if ($size) { |
|
71 | + $parsedSize = \OC_Helper::computerFileSize($size); |
|
72 | + if ($parsedSize === false) { |
|
73 | + $output->writeln("<error>Failed to parse input size</error>"); |
|
74 | + return -1; |
|
75 | + } |
|
76 | + if ($user) { |
|
77 | + $this->config->setUserValue($user, 'files_trashbin', 'trashbin_size', (string)$parsedSize); |
|
78 | + $this->commandBus->push(new Expire($user)); |
|
79 | + } else { |
|
80 | + $this->config->setAppValue('files_trashbin', 'trashbin_size', (string)$parsedSize); |
|
81 | + $output->writeln("<info>Warning: changing the default trashbin size will automatically trigger cleanup of existing trashbins,</info>"); |
|
82 | + $output->writeln("<info>a users trashbin can exceed the configured size until they move a new file to the trashbin.</info>"); |
|
83 | + } |
|
84 | + } else { |
|
85 | + $this->printTrashbinSize($input, $output, $user); |
|
86 | + } |
|
87 | 87 | |
88 | - return 0; |
|
89 | - } |
|
88 | + return 0; |
|
89 | + } |
|
90 | 90 | |
91 | - private function printTrashbinSize(InputInterface $input, OutputInterface $output, ?string $user) { |
|
92 | - $globalSize = (int)$this->config->getAppValue('files_trashbin', 'trashbin_size', '-1'); |
|
93 | - if ($globalSize < 0) { |
|
94 | - $globalHumanSize = "default (50% of available space)"; |
|
95 | - } else { |
|
96 | - $globalHumanSize = \OC_Helper::humanFileSize($globalSize); |
|
97 | - } |
|
91 | + private function printTrashbinSize(InputInterface $input, OutputInterface $output, ?string $user) { |
|
92 | + $globalSize = (int)$this->config->getAppValue('files_trashbin', 'trashbin_size', '-1'); |
|
93 | + if ($globalSize < 0) { |
|
94 | + $globalHumanSize = "default (50% of available space)"; |
|
95 | + } else { |
|
96 | + $globalHumanSize = \OC_Helper::humanFileSize($globalSize); |
|
97 | + } |
|
98 | 98 | |
99 | - if ($user) { |
|
100 | - $userSize = (int)$this->config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1'); |
|
99 | + if ($user) { |
|
100 | + $userSize = (int)$this->config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1'); |
|
101 | 101 | |
102 | - if ($userSize < 0) { |
|
103 | - $userHumanSize = ($globalSize < 0) ? $globalHumanSize : "default($globalHumanSize)"; |
|
104 | - } else { |
|
105 | - $userHumanSize = \OC_Helper::humanFileSize($userSize); |
|
106 | - } |
|
102 | + if ($userSize < 0) { |
|
103 | + $userHumanSize = ($globalSize < 0) ? $globalHumanSize : "default($globalHumanSize)"; |
|
104 | + } else { |
|
105 | + $userHumanSize = \OC_Helper::humanFileSize($userSize); |
|
106 | + } |
|
107 | 107 | |
108 | - if ($input->getOption('output') == self::OUTPUT_FORMAT_PLAIN) { |
|
109 | - $output->writeln($userHumanSize); |
|
110 | - } else { |
|
111 | - $userValue = ($userSize < 0) ? 'default' : $userSize; |
|
112 | - $globalValue = ($globalSize < 0) ? 'default' : $globalSize; |
|
113 | - $this->writeArrayInOutputFormat($input, $output, [ |
|
114 | - 'user_size' => $userValue, |
|
115 | - 'global_size' => $globalValue, |
|
116 | - 'effective_size' => ($userSize < 0) ? $globalValue : $userValue, |
|
117 | - ]); |
|
118 | - } |
|
119 | - } else { |
|
120 | - $users = []; |
|
121 | - $this->userManager->callForSeenUsers(function (IUser $user) use (&$users) { |
|
122 | - $users[] = $user->getUID(); |
|
123 | - }); |
|
124 | - $userValues = $this->config->getUserValueForUsers('files_trashbin', 'trashbin_size', $users); |
|
108 | + if ($input->getOption('output') == self::OUTPUT_FORMAT_PLAIN) { |
|
109 | + $output->writeln($userHumanSize); |
|
110 | + } else { |
|
111 | + $userValue = ($userSize < 0) ? 'default' : $userSize; |
|
112 | + $globalValue = ($globalSize < 0) ? 'default' : $globalSize; |
|
113 | + $this->writeArrayInOutputFormat($input, $output, [ |
|
114 | + 'user_size' => $userValue, |
|
115 | + 'global_size' => $globalValue, |
|
116 | + 'effective_size' => ($userSize < 0) ? $globalValue : $userValue, |
|
117 | + ]); |
|
118 | + } |
|
119 | + } else { |
|
120 | + $users = []; |
|
121 | + $this->userManager->callForSeenUsers(function (IUser $user) use (&$users) { |
|
122 | + $users[] = $user->getUID(); |
|
123 | + }); |
|
124 | + $userValues = $this->config->getUserValueForUsers('files_trashbin', 'trashbin_size', $users); |
|
125 | 125 | |
126 | - if ($input->getOption('output') == self::OUTPUT_FORMAT_PLAIN) { |
|
127 | - $output->writeln("Default size: $globalHumanSize"); |
|
128 | - $output->writeln(""); |
|
129 | - if (count($userValues)) { |
|
130 | - $output->writeln("Per-user sizes:"); |
|
131 | - $this->writeArrayInOutputFormat($input, $output, array_map(function ($size) { |
|
132 | - return \OC_Helper::humanFileSize($size); |
|
133 | - }, $userValues)); |
|
134 | - } else { |
|
135 | - $output->writeln("No per-user sizes configured"); |
|
136 | - } |
|
137 | - } else { |
|
138 | - $globalValue = ($globalSize < 0) ? 'default' : $globalSize; |
|
139 | - $this->writeArrayInOutputFormat($input, $output, [ |
|
140 | - 'global_size' => $globalValue, |
|
141 | - 'user_sizes' => $userValues, |
|
142 | - ]); |
|
143 | - } |
|
144 | - } |
|
145 | - } |
|
126 | + if ($input->getOption('output') == self::OUTPUT_FORMAT_PLAIN) { |
|
127 | + $output->writeln("Default size: $globalHumanSize"); |
|
128 | + $output->writeln(""); |
|
129 | + if (count($userValues)) { |
|
130 | + $output->writeln("Per-user sizes:"); |
|
131 | + $this->writeArrayInOutputFormat($input, $output, array_map(function ($size) { |
|
132 | + return \OC_Helper::humanFileSize($size); |
|
133 | + }, $userValues)); |
|
134 | + } else { |
|
135 | + $output->writeln("No per-user sizes configured"); |
|
136 | + } |
|
137 | + } else { |
|
138 | + $globalValue = ($globalSize < 0) ? 'default' : $globalSize; |
|
139 | + $this->writeArrayInOutputFormat($input, $output, [ |
|
140 | + 'global_size' => $globalValue, |
|
141 | + 'user_sizes' => $userValues, |
|
142 | + ]); |
|
143 | + } |
|
144 | + } |
|
145 | + } |
|
146 | 146 | } |
@@ -31,22 +31,22 @@ |
||
31 | 31 | use OCP\AppFramework\Bootstrap\IRegistrationContext; |
32 | 32 | |
33 | 33 | class Application extends App implements IBootstrap { |
34 | - public function __construct(array $urlParams = []) { |
|
35 | - parent::__construct('testing', $urlParams); |
|
36 | - } |
|
34 | + public function __construct(array $urlParams = []) { |
|
35 | + parent::__construct('testing', $urlParams); |
|
36 | + } |
|
37 | 37 | |
38 | - public function register(IRegistrationContext $context): void { |
|
39 | - } |
|
38 | + public function register(IRegistrationContext $context): void { |
|
39 | + } |
|
40 | 40 | |
41 | - public function boot(IBootContext $context): void { |
|
42 | - $server = $context->getServerContainer(); |
|
43 | - $config = $server->getConfig(); |
|
44 | - if ($config->getAppValue('testing', 'enable_alt_user_backend', 'no') === 'yes') { |
|
45 | - $userManager = $server->getUserManager(); |
|
41 | + public function boot(IBootContext $context): void { |
|
42 | + $server = $context->getServerContainer(); |
|
43 | + $config = $server->getConfig(); |
|
44 | + if ($config->getAppValue('testing', 'enable_alt_user_backend', 'no') === 'yes') { |
|
45 | + $userManager = $server->getUserManager(); |
|
46 | 46 | |
47 | - // replace all user backends with this one |
|
48 | - $userManager->clearBackends(); |
|
49 | - $userManager->registerBackend($context->getAppContainer()->get(AlternativeHomeUserBackend::class)); |
|
50 | - } |
|
51 | - } |
|
47 | + // replace all user backends with this one |
|
48 | + $userManager->clearBackends(); |
|
49 | + $userManager->registerBackend($context->getAppContainer()->get(AlternativeHomeUserBackend::class)); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |
@@ -32,12 +32,12 @@ |
||
32 | 32 | * SSO providers that also have a SSO logout url |
33 | 33 | */ |
34 | 34 | interface ICustomLogout { |
35 | - /** |
|
36 | - * @since 20.0.0 |
|
37 | - * |
|
38 | - * The url to redirect to for logout |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function getLogoutUrl(): string; |
|
35 | + /** |
|
36 | + * @since 20.0.0 |
|
37 | + * |
|
38 | + * The url to redirect to for logout |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function getLogoutUrl(): string; |
|
43 | 43 | } |
@@ -37,29 +37,29 @@ |
||
37 | 37 | */ |
38 | 38 | class UserDeletedListener implements IEventListener { |
39 | 39 | |
40 | - /** @var StatusService */ |
|
41 | - private $service; |
|
40 | + /** @var StatusService */ |
|
41 | + private $service; |
|
42 | 42 | |
43 | - /** |
|
44 | - * UserDeletedListener constructor. |
|
45 | - * |
|
46 | - * @param StatusService $service |
|
47 | - */ |
|
48 | - public function __construct(StatusService $service) { |
|
49 | - $this->service = $service; |
|
50 | - } |
|
43 | + /** |
|
44 | + * UserDeletedListener constructor. |
|
45 | + * |
|
46 | + * @param StatusService $service |
|
47 | + */ |
|
48 | + public function __construct(StatusService $service) { |
|
49 | + $this->service = $service; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @inheritDoc |
|
55 | - */ |
|
56 | - public function handle(Event $event): void { |
|
57 | - if (!($event instanceof UserDeletedEvent)) { |
|
58 | - // Unrelated |
|
59 | - return; |
|
60 | - } |
|
53 | + /** |
|
54 | + * @inheritDoc |
|
55 | + */ |
|
56 | + public function handle(Event $event): void { |
|
57 | + if (!($event instanceof UserDeletedEvent)) { |
|
58 | + // Unrelated |
|
59 | + return; |
|
60 | + } |
|
61 | 61 | |
62 | - $user = $event->getUser(); |
|
63 | - $this->service->removeUserStatus($user->getUID()); |
|
64 | - } |
|
62 | + $user = $event->getUser(); |
|
63 | + $this->service->removeUserStatus($user->getUID()); |
|
64 | + } |
|
65 | 65 | } |
@@ -39,100 +39,100 @@ |
||
39 | 39 | */ |
40 | 40 | abstract class ACalendarSearchProvider implements IProvider { |
41 | 41 | |
42 | - /** @var IAppManager */ |
|
43 | - protected $appManager; |
|
44 | - |
|
45 | - /** @var IL10N */ |
|
46 | - protected $l10n; |
|
47 | - |
|
48 | - /** @var IURLGenerator */ |
|
49 | - protected $urlGenerator; |
|
50 | - |
|
51 | - /** @var CalDavBackend */ |
|
52 | - protected $backend; |
|
53 | - |
|
54 | - /** |
|
55 | - * ACalendarSearchProvider constructor. |
|
56 | - * |
|
57 | - * @param IAppManager $appManager |
|
58 | - * @param IL10N $l10n |
|
59 | - * @param IURLGenerator $urlGenerator |
|
60 | - * @param CalDavBackend $backend |
|
61 | - */ |
|
62 | - public function __construct(IAppManager $appManager, |
|
63 | - IL10N $l10n, |
|
64 | - IURLGenerator $urlGenerator, |
|
65 | - CalDavBackend $backend) { |
|
66 | - $this->appManager = $appManager; |
|
67 | - $this->l10n = $l10n; |
|
68 | - $this->urlGenerator = $urlGenerator; |
|
69 | - $this->backend = $backend; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Get an associative array of calendars |
|
74 | - * calendarId => calendar |
|
75 | - * |
|
76 | - * @param string $principalUri |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - protected function getSortedCalendars(string $principalUri): array { |
|
80 | - $calendars = $this->backend->getCalendarsForUser($principalUri); |
|
81 | - $calendarsById = []; |
|
82 | - foreach ($calendars as $calendar) { |
|
83 | - $calendarsById[(int) $calendar['id']] = $calendar; |
|
84 | - } |
|
85 | - |
|
86 | - return $calendarsById; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Get an associative array of subscriptions |
|
91 | - * subscriptionId => subscription |
|
92 | - * |
|
93 | - * @param string $principalUri |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - protected function getSortedSubscriptions(string $principalUri): array { |
|
97 | - $subscriptions = $this->backend->getSubscriptionsForUser($principalUri); |
|
98 | - $subscriptionsById = []; |
|
99 | - foreach ($subscriptions as $subscription) { |
|
100 | - $subscriptionsById[(int) $subscription['id']] = $subscription; |
|
101 | - } |
|
102 | - |
|
103 | - return $subscriptionsById; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Returns the primary VEvent / VJournal / VTodo component |
|
108 | - * If it's a component with recurrence-ids, it will return |
|
109 | - * the primary component |
|
110 | - * |
|
111 | - * TODO: It would be a nice enhancement to show recurrence-exceptions |
|
112 | - * as individual search-results. |
|
113 | - * For now we will just display the primary element of a recurrence-set. |
|
114 | - * |
|
115 | - * @param string $calendarData |
|
116 | - * @param string $componentName |
|
117 | - * @return Component |
|
118 | - */ |
|
119 | - protected function getPrimaryComponent(string $calendarData, string $componentName): Component { |
|
120 | - $vCalendar = Reader::read($calendarData, Reader::OPTION_FORGIVING); |
|
121 | - |
|
122 | - $components = $vCalendar->select($componentName); |
|
123 | - if (count($components) === 1) { |
|
124 | - return $components[0]; |
|
125 | - } |
|
126 | - |
|
127 | - // If it's a recurrence-set, take the primary element |
|
128 | - foreach ($components as $component) { |
|
129 | - /** @var Component $component */ |
|
130 | - if (!$component->{'RECURRENCE-ID'}) { |
|
131 | - return $component; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - // In case of error, just fallback to the first element in the set |
|
136 | - return $components[0]; |
|
137 | - } |
|
42 | + /** @var IAppManager */ |
|
43 | + protected $appManager; |
|
44 | + |
|
45 | + /** @var IL10N */ |
|
46 | + protected $l10n; |
|
47 | + |
|
48 | + /** @var IURLGenerator */ |
|
49 | + protected $urlGenerator; |
|
50 | + |
|
51 | + /** @var CalDavBackend */ |
|
52 | + protected $backend; |
|
53 | + |
|
54 | + /** |
|
55 | + * ACalendarSearchProvider constructor. |
|
56 | + * |
|
57 | + * @param IAppManager $appManager |
|
58 | + * @param IL10N $l10n |
|
59 | + * @param IURLGenerator $urlGenerator |
|
60 | + * @param CalDavBackend $backend |
|
61 | + */ |
|
62 | + public function __construct(IAppManager $appManager, |
|
63 | + IL10N $l10n, |
|
64 | + IURLGenerator $urlGenerator, |
|
65 | + CalDavBackend $backend) { |
|
66 | + $this->appManager = $appManager; |
|
67 | + $this->l10n = $l10n; |
|
68 | + $this->urlGenerator = $urlGenerator; |
|
69 | + $this->backend = $backend; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Get an associative array of calendars |
|
74 | + * calendarId => calendar |
|
75 | + * |
|
76 | + * @param string $principalUri |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + protected function getSortedCalendars(string $principalUri): array { |
|
80 | + $calendars = $this->backend->getCalendarsForUser($principalUri); |
|
81 | + $calendarsById = []; |
|
82 | + foreach ($calendars as $calendar) { |
|
83 | + $calendarsById[(int) $calendar['id']] = $calendar; |
|
84 | + } |
|
85 | + |
|
86 | + return $calendarsById; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Get an associative array of subscriptions |
|
91 | + * subscriptionId => subscription |
|
92 | + * |
|
93 | + * @param string $principalUri |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + protected function getSortedSubscriptions(string $principalUri): array { |
|
97 | + $subscriptions = $this->backend->getSubscriptionsForUser($principalUri); |
|
98 | + $subscriptionsById = []; |
|
99 | + foreach ($subscriptions as $subscription) { |
|
100 | + $subscriptionsById[(int) $subscription['id']] = $subscription; |
|
101 | + } |
|
102 | + |
|
103 | + return $subscriptionsById; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Returns the primary VEvent / VJournal / VTodo component |
|
108 | + * If it's a component with recurrence-ids, it will return |
|
109 | + * the primary component |
|
110 | + * |
|
111 | + * TODO: It would be a nice enhancement to show recurrence-exceptions |
|
112 | + * as individual search-results. |
|
113 | + * For now we will just display the primary element of a recurrence-set. |
|
114 | + * |
|
115 | + * @param string $calendarData |
|
116 | + * @param string $componentName |
|
117 | + * @return Component |
|
118 | + */ |
|
119 | + protected function getPrimaryComponent(string $calendarData, string $componentName): Component { |
|
120 | + $vCalendar = Reader::read($calendarData, Reader::OPTION_FORGIVING); |
|
121 | + |
|
122 | + $components = $vCalendar->select($componentName); |
|
123 | + if (count($components) === 1) { |
|
124 | + return $components[0]; |
|
125 | + } |
|
126 | + |
|
127 | + // If it's a recurrence-set, take the primary element |
|
128 | + foreach ($components as $component) { |
|
129 | + /** @var Component $component */ |
|
130 | + if (!$component->{'RECURRENCE-ID'}) { |
|
131 | + return $component; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + // In case of error, just fallback to the first element in the set |
|
136 | + return $components[0]; |
|
137 | + } |
|
138 | 138 | } |
@@ -28,87 +28,87 @@ |
||
28 | 28 | use OCP\Search\ISearchQuery; |
29 | 29 | |
30 | 30 | class SearchQuery implements ISearchQuery { |
31 | - public const LIMIT_DEFAULT = 5; |
|
32 | - |
|
33 | - /** @var string */ |
|
34 | - private $term; |
|
35 | - |
|
36 | - /** @var int */ |
|
37 | - private $sortOrder; |
|
38 | - |
|
39 | - /** @var int */ |
|
40 | - private $limit; |
|
41 | - |
|
42 | - /** @var int|string|null */ |
|
43 | - private $cursor; |
|
44 | - |
|
45 | - /** @var string */ |
|
46 | - private $route; |
|
47 | - |
|
48 | - /** @var array */ |
|
49 | - private $routeParameters; |
|
50 | - |
|
51 | - /** |
|
52 | - * @param string $term |
|
53 | - * @param int $sortOrder |
|
54 | - * @param int $limit |
|
55 | - * @param int|string|null $cursor |
|
56 | - * @param string $route |
|
57 | - * @param array $routeParameters |
|
58 | - */ |
|
59 | - public function __construct(string $term, |
|
60 | - int $sortOrder = ISearchQuery::SORT_DATE_DESC, |
|
61 | - int $limit = self::LIMIT_DEFAULT, |
|
62 | - $cursor = null, |
|
63 | - string $route = '', |
|
64 | - array $routeParameters = []) { |
|
65 | - $this->term = $term; |
|
66 | - $this->sortOrder = $sortOrder; |
|
67 | - $this->limit = $limit; |
|
68 | - $this->cursor = $cursor; |
|
69 | - $this->route = $route; |
|
70 | - $this->routeParameters = $routeParameters; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @inheritDoc |
|
75 | - */ |
|
76 | - public function getTerm(): string { |
|
77 | - return $this->term; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @inheritDoc |
|
82 | - */ |
|
83 | - public function getSortOrder(): int { |
|
84 | - return $this->sortOrder; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @inheritDoc |
|
89 | - */ |
|
90 | - public function getLimit(): int { |
|
91 | - return $this->limit; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @inheritDoc |
|
96 | - */ |
|
97 | - public function getCursor() { |
|
98 | - return $this->cursor; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @inheritDoc |
|
103 | - */ |
|
104 | - public function getRoute(): string { |
|
105 | - return $this->route; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @inheritDoc |
|
110 | - */ |
|
111 | - public function getRouteParameters(): array { |
|
112 | - return $this->routeParameters; |
|
113 | - } |
|
31 | + public const LIMIT_DEFAULT = 5; |
|
32 | + |
|
33 | + /** @var string */ |
|
34 | + private $term; |
|
35 | + |
|
36 | + /** @var int */ |
|
37 | + private $sortOrder; |
|
38 | + |
|
39 | + /** @var int */ |
|
40 | + private $limit; |
|
41 | + |
|
42 | + /** @var int|string|null */ |
|
43 | + private $cursor; |
|
44 | + |
|
45 | + /** @var string */ |
|
46 | + private $route; |
|
47 | + |
|
48 | + /** @var array */ |
|
49 | + private $routeParameters; |
|
50 | + |
|
51 | + /** |
|
52 | + * @param string $term |
|
53 | + * @param int $sortOrder |
|
54 | + * @param int $limit |
|
55 | + * @param int|string|null $cursor |
|
56 | + * @param string $route |
|
57 | + * @param array $routeParameters |
|
58 | + */ |
|
59 | + public function __construct(string $term, |
|
60 | + int $sortOrder = ISearchQuery::SORT_DATE_DESC, |
|
61 | + int $limit = self::LIMIT_DEFAULT, |
|
62 | + $cursor = null, |
|
63 | + string $route = '', |
|
64 | + array $routeParameters = []) { |
|
65 | + $this->term = $term; |
|
66 | + $this->sortOrder = $sortOrder; |
|
67 | + $this->limit = $limit; |
|
68 | + $this->cursor = $cursor; |
|
69 | + $this->route = $route; |
|
70 | + $this->routeParameters = $routeParameters; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @inheritDoc |
|
75 | + */ |
|
76 | + public function getTerm(): string { |
|
77 | + return $this->term; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @inheritDoc |
|
82 | + */ |
|
83 | + public function getSortOrder(): int { |
|
84 | + return $this->sortOrder; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @inheritDoc |
|
89 | + */ |
|
90 | + public function getLimit(): int { |
|
91 | + return $this->limit; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @inheritDoc |
|
96 | + */ |
|
97 | + public function getCursor() { |
|
98 | + return $this->cursor; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @inheritDoc |
|
103 | + */ |
|
104 | + public function getRoute(): string { |
|
105 | + return $this->route; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @inheritDoc |
|
110 | + */ |
|
111 | + public function getRouteParameters(): array { |
|
112 | + return $this->routeParameters; |
|
113 | + } |
|
114 | 114 | } |