@@ -41,114 +41,114 @@ |
||
41 | 41 | |
42 | 42 | class RefreshWebcalJob extends Job { |
43 | 43 | |
44 | - /** |
|
45 | - * @var RefreshWebcalService |
|
46 | - */ |
|
47 | - private $refreshWebcalService; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var IConfig |
|
51 | - */ |
|
52 | - private $config; |
|
53 | - |
|
54 | - /** @var ILogger */ |
|
55 | - private $logger; |
|
56 | - |
|
57 | - /** @var ITimeFactory */ |
|
58 | - private $timeFactory; |
|
59 | - |
|
60 | - /** |
|
61 | - * RefreshWebcalJob constructor. |
|
62 | - * |
|
63 | - * @param RefreshWebcalService $refreshWebcalService |
|
64 | - * @param IConfig $config |
|
65 | - * @param ILogger $logger |
|
66 | - * @param ITimeFactory $timeFactory |
|
67 | - */ |
|
68 | - public function __construct(RefreshWebcalService $refreshWebcalService, IConfig $config, ILogger $logger, ITimeFactory $timeFactory) { |
|
69 | - parent::__construct($timeFactory); |
|
70 | - $this->refreshWebcalService = $refreshWebcalService; |
|
71 | - $this->config = $config; |
|
72 | - $this->logger = $logger; |
|
73 | - $this->timeFactory = $timeFactory; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * this function is called at most every hour |
|
78 | - * |
|
79 | - * @inheritdoc |
|
80 | - */ |
|
81 | - public function execute(IJobList $jobList, ILogger $logger = null) { |
|
82 | - $subscription = $this->refreshWebcalService->getSubscription($this->argument['principaluri'], $this->argument['uri']); |
|
83 | - if (!$subscription) { |
|
84 | - return; |
|
85 | - } |
|
86 | - |
|
87 | - $this->fixSubscriptionRowTyping($subscription); |
|
88 | - |
|
89 | - // if no refresh rate was configured, just refresh once a week |
|
90 | - $defaultRefreshRate = $this->config->getAppValue('dav', 'calendarSubscriptionRefreshRate', 'P1W'); |
|
91 | - $refreshRate = $subscription[RefreshWebcalService::REFRESH_RATE] ?? $defaultRefreshRate; |
|
92 | - |
|
93 | - $subscriptionId = $subscription['id']; |
|
94 | - |
|
95 | - try { |
|
96 | - /** @var DateInterval $dateInterval */ |
|
97 | - $dateInterval = DateTimeParser::parseDuration($refreshRate); |
|
98 | - } catch (InvalidDataException $ex) { |
|
99 | - $this->logger->logException($ex); |
|
100 | - $this->logger->warning("Subscription $subscriptionId could not be refreshed, refreshrate in database is invalid"); |
|
101 | - return; |
|
102 | - } |
|
103 | - |
|
104 | - $interval = $this->getIntervalFromDateInterval($dateInterval); |
|
105 | - if (($this->timeFactory->getTime() - $this->lastRun) <= $interval) { |
|
106 | - return; |
|
107 | - } |
|
108 | - |
|
109 | - parent::execute($jobList, $logger); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @param array $argument |
|
114 | - */ |
|
115 | - protected function run($argument) { |
|
116 | - $this->refreshWebcalService->refreshSubscription($argument['principaluri'], $argument['uri']); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * get total number of seconds from DateInterval object |
|
121 | - * |
|
122 | - * @param DateInterval $interval |
|
123 | - * @return int |
|
124 | - */ |
|
125 | - private function getIntervalFromDateInterval(DateInterval $interval):int { |
|
126 | - return $interval->s |
|
127 | - + ($interval->i * 60) |
|
128 | - + ($interval->h * 60 * 60) |
|
129 | - + ($interval->d * 60 * 60 * 24) |
|
130 | - + ($interval->m * 60 * 60 * 24 * 30) |
|
131 | - + ($interval->y * 60 * 60 * 24 * 365); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Fixes types of rows |
|
136 | - * |
|
137 | - * @param array $row |
|
138 | - */ |
|
139 | - private function fixSubscriptionRowTyping(array &$row):void { |
|
140 | - $forceInt = [ |
|
141 | - 'id', |
|
142 | - 'lastmodified', |
|
143 | - RefreshWebcalService::STRIP_ALARMS, |
|
144 | - RefreshWebcalService::STRIP_ATTACHMENTS, |
|
145 | - RefreshWebcalService::STRIP_TODOS, |
|
146 | - ]; |
|
147 | - |
|
148 | - foreach ($forceInt as $column) { |
|
149 | - if (isset($row[$column])) { |
|
150 | - $row[$column] = (int) $row[$column]; |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
44 | + /** |
|
45 | + * @var RefreshWebcalService |
|
46 | + */ |
|
47 | + private $refreshWebcalService; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var IConfig |
|
51 | + */ |
|
52 | + private $config; |
|
53 | + |
|
54 | + /** @var ILogger */ |
|
55 | + private $logger; |
|
56 | + |
|
57 | + /** @var ITimeFactory */ |
|
58 | + private $timeFactory; |
|
59 | + |
|
60 | + /** |
|
61 | + * RefreshWebcalJob constructor. |
|
62 | + * |
|
63 | + * @param RefreshWebcalService $refreshWebcalService |
|
64 | + * @param IConfig $config |
|
65 | + * @param ILogger $logger |
|
66 | + * @param ITimeFactory $timeFactory |
|
67 | + */ |
|
68 | + public function __construct(RefreshWebcalService $refreshWebcalService, IConfig $config, ILogger $logger, ITimeFactory $timeFactory) { |
|
69 | + parent::__construct($timeFactory); |
|
70 | + $this->refreshWebcalService = $refreshWebcalService; |
|
71 | + $this->config = $config; |
|
72 | + $this->logger = $logger; |
|
73 | + $this->timeFactory = $timeFactory; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * this function is called at most every hour |
|
78 | + * |
|
79 | + * @inheritdoc |
|
80 | + */ |
|
81 | + public function execute(IJobList $jobList, ILogger $logger = null) { |
|
82 | + $subscription = $this->refreshWebcalService->getSubscription($this->argument['principaluri'], $this->argument['uri']); |
|
83 | + if (!$subscription) { |
|
84 | + return; |
|
85 | + } |
|
86 | + |
|
87 | + $this->fixSubscriptionRowTyping($subscription); |
|
88 | + |
|
89 | + // if no refresh rate was configured, just refresh once a week |
|
90 | + $defaultRefreshRate = $this->config->getAppValue('dav', 'calendarSubscriptionRefreshRate', 'P1W'); |
|
91 | + $refreshRate = $subscription[RefreshWebcalService::REFRESH_RATE] ?? $defaultRefreshRate; |
|
92 | + |
|
93 | + $subscriptionId = $subscription['id']; |
|
94 | + |
|
95 | + try { |
|
96 | + /** @var DateInterval $dateInterval */ |
|
97 | + $dateInterval = DateTimeParser::parseDuration($refreshRate); |
|
98 | + } catch (InvalidDataException $ex) { |
|
99 | + $this->logger->logException($ex); |
|
100 | + $this->logger->warning("Subscription $subscriptionId could not be refreshed, refreshrate in database is invalid"); |
|
101 | + return; |
|
102 | + } |
|
103 | + |
|
104 | + $interval = $this->getIntervalFromDateInterval($dateInterval); |
|
105 | + if (($this->timeFactory->getTime() - $this->lastRun) <= $interval) { |
|
106 | + return; |
|
107 | + } |
|
108 | + |
|
109 | + parent::execute($jobList, $logger); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @param array $argument |
|
114 | + */ |
|
115 | + protected function run($argument) { |
|
116 | + $this->refreshWebcalService->refreshSubscription($argument['principaluri'], $argument['uri']); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * get total number of seconds from DateInterval object |
|
121 | + * |
|
122 | + * @param DateInterval $interval |
|
123 | + * @return int |
|
124 | + */ |
|
125 | + private function getIntervalFromDateInterval(DateInterval $interval):int { |
|
126 | + return $interval->s |
|
127 | + + ($interval->i * 60) |
|
128 | + + ($interval->h * 60 * 60) |
|
129 | + + ($interval->d * 60 * 60 * 24) |
|
130 | + + ($interval->m * 60 * 60 * 24 * 30) |
|
131 | + + ($interval->y * 60 * 60 * 24 * 365); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Fixes types of rows |
|
136 | + * |
|
137 | + * @param array $row |
|
138 | + */ |
|
139 | + private function fixSubscriptionRowTyping(array &$row):void { |
|
140 | + $forceInt = [ |
|
141 | + 'id', |
|
142 | + 'lastmodified', |
|
143 | + RefreshWebcalService::STRIP_ALARMS, |
|
144 | + RefreshWebcalService::STRIP_ATTACHMENTS, |
|
145 | + RefreshWebcalService::STRIP_TODOS, |
|
146 | + ]; |
|
147 | + |
|
148 | + foreach ($forceInt as $column) { |
|
149 | + if (isset($row[$column])) { |
|
150 | + $row[$column] = (int) $row[$column]; |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | 154 | } |
@@ -33,26 +33,26 @@ |
||
33 | 33 | |
34 | 34 | class SetDefaultProvider implements IRepairStep { |
35 | 35 | |
36 | - /** @var IConfig */ |
|
37 | - private $config; |
|
38 | - |
|
39 | - /** @var Helper */ |
|
40 | - private $helper; |
|
41 | - |
|
42 | - public function __construct(IConfig $config, |
|
43 | - Helper $helper) { |
|
44 | - $this->config = $config; |
|
45 | - $this->helper = $helper; |
|
46 | - } |
|
47 | - |
|
48 | - public function getName(): string { |
|
49 | - return 'Set default LDAP provider'; |
|
50 | - } |
|
51 | - |
|
52 | - public function run(IOutput $output): void { |
|
53 | - $current = $this->config->getSystemValue('ldapProviderFactory', null); |
|
54 | - if ($current === null) { |
|
55 | - $this->config->setSystemValue('ldapProviderFactory', LDAPProviderFactory::class); |
|
56 | - } |
|
57 | - } |
|
36 | + /** @var IConfig */ |
|
37 | + private $config; |
|
38 | + |
|
39 | + /** @var Helper */ |
|
40 | + private $helper; |
|
41 | + |
|
42 | + public function __construct(IConfig $config, |
|
43 | + Helper $helper) { |
|
44 | + $this->config = $config; |
|
45 | + $this->helper = $helper; |
|
46 | + } |
|
47 | + |
|
48 | + public function getName(): string { |
|
49 | + return 'Set default LDAP provider'; |
|
50 | + } |
|
51 | + |
|
52 | + public function run(IOutput $output): void { |
|
53 | + $current = $this->config->getSystemValue('ldapProviderFactory', null); |
|
54 | + if ($current === null) { |
|
55 | + $this->config->setSystemValue('ldapProviderFactory', LDAPProviderFactory::class); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | } |
@@ -33,33 +33,33 @@ |
||
33 | 33 | * @since 16.0.0 |
34 | 34 | */ |
35 | 35 | interface ICacheEvent { |
36 | - /** |
|
37 | - * @return IStorage |
|
38 | - * @since 16.0.0 |
|
39 | - */ |
|
40 | - public function getStorage(): IStorage; |
|
36 | + /** |
|
37 | + * @return IStorage |
|
38 | + * @since 16.0.0 |
|
39 | + */ |
|
40 | + public function getStorage(): IStorage; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return string |
|
44 | - * @since 16.0.0 |
|
45 | - */ |
|
46 | - public function getPath(): string; |
|
42 | + /** |
|
43 | + * @return string |
|
44 | + * @since 16.0.0 |
|
45 | + */ |
|
46 | + public function getPath(): string; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $path |
|
50 | - * @since 19.0.0 |
|
51 | - */ |
|
52 | - public function setPath(string $path): void; |
|
48 | + /** |
|
49 | + * @param string $path |
|
50 | + * @since 19.0.0 |
|
51 | + */ |
|
52 | + public function setPath(string $path): void; |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return int |
|
56 | - * @since 16.0.0 |
|
57 | - */ |
|
58 | - public function getFileId(): int; |
|
54 | + /** |
|
55 | + * @return int |
|
56 | + * @since 16.0.0 |
|
57 | + */ |
|
58 | + public function getFileId(): int; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return int |
|
62 | - * @since 21.0.0 |
|
63 | - */ |
|
64 | - public function getStorageId(): int; |
|
60 | + /** |
|
61 | + * @return int |
|
62 | + * @since 21.0.0 |
|
63 | + */ |
|
64 | + public function getStorageId(): int; |
|
65 | 65 | } |
@@ -32,44 +32,44 @@ |
||
32 | 32 | use OCP\Migration\SimpleMigrationStep; |
33 | 33 | |
34 | 34 | class Version21000Date20201202095923 extends SimpleMigrationStep { |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | 44 | |
45 | - if (!$schema->hasTable('accounts_data')) { |
|
46 | - $table = $schema->createTable('accounts_data'); |
|
47 | - $table->addColumn('id', Types::BIGINT, [ |
|
48 | - 'autoincrement' => true, |
|
49 | - 'notnull' => true, |
|
50 | - 'length' => 20, |
|
51 | - ]); |
|
52 | - $table->addColumn('uid', Types::STRING, [ |
|
53 | - 'notnull' => true, |
|
54 | - 'length' => 64, |
|
55 | - ]); |
|
56 | - $table->addColumn('name', Types::STRING, [ |
|
57 | - 'notnull' => true, |
|
58 | - 'length' => 64, |
|
59 | - ]); |
|
60 | - $table->addColumn('value', Types::STRING, [ |
|
61 | - 'notnull' => false, |
|
62 | - 'length' => 255, |
|
63 | - 'default' => '', |
|
64 | - ]); |
|
65 | - $table->setPrimaryKey(['id']); |
|
66 | - $table->addIndex(['uid'], 'accounts_data_uid'); |
|
67 | - $table->addIndex(['name'], 'accounts_data_name'); |
|
68 | - $table->addIndex(['value'], 'accounts_data_value'); |
|
45 | + if (!$schema->hasTable('accounts_data')) { |
|
46 | + $table = $schema->createTable('accounts_data'); |
|
47 | + $table->addColumn('id', Types::BIGINT, [ |
|
48 | + 'autoincrement' => true, |
|
49 | + 'notnull' => true, |
|
50 | + 'length' => 20, |
|
51 | + ]); |
|
52 | + $table->addColumn('uid', Types::STRING, [ |
|
53 | + 'notnull' => true, |
|
54 | + 'length' => 64, |
|
55 | + ]); |
|
56 | + $table->addColumn('name', Types::STRING, [ |
|
57 | + 'notnull' => true, |
|
58 | + 'length' => 64, |
|
59 | + ]); |
|
60 | + $table->addColumn('value', Types::STRING, [ |
|
61 | + 'notnull' => false, |
|
62 | + 'length' => 255, |
|
63 | + 'default' => '', |
|
64 | + ]); |
|
65 | + $table->setPrimaryKey(['id']); |
|
66 | + $table->addIndex(['uid'], 'accounts_data_uid'); |
|
67 | + $table->addIndex(['name'], 'accounts_data_name'); |
|
68 | + $table->addIndex(['value'], 'accounts_data_value'); |
|
69 | 69 | |
70 | - return $schema; |
|
71 | - } |
|
70 | + return $schema; |
|
71 | + } |
|
72 | 72 | |
73 | - return null; |
|
74 | - } |
|
73 | + return null; |
|
74 | + } |
|
75 | 75 | } |
@@ -35,37 +35,37 @@ |
||
35 | 35 | |
36 | 36 | class Version1011Date20201120125158 extends SimpleMigrationStep { |
37 | 37 | |
38 | - /** @var IDBConnection */ |
|
39 | - private $connection; |
|
38 | + /** @var IDBConnection */ |
|
39 | + private $connection; |
|
40 | 40 | |
41 | - public function __construct(IDBConnection $connection) { |
|
42 | - $this->connection = $connection; |
|
43 | - } |
|
41 | + public function __construct(IDBConnection $connection) { |
|
42 | + $this->connection = $connection; |
|
43 | + } |
|
44 | 44 | |
45 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
46 | - /** @var ISchemaWrapper $schema */ |
|
47 | - $schema = $schemaClosure(); |
|
45 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
46 | + /** @var ISchemaWrapper $schema */ |
|
47 | + $schema = $schemaClosure(); |
|
48 | 48 | |
49 | - if ($schema->hasTable('federated_reshares')) { |
|
50 | - $table = $schema->getTable('federated_reshares'); |
|
51 | - $remoteIdColumn = $table->getColumn('remote_id'); |
|
52 | - if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) { |
|
53 | - $remoteIdColumn->setNotnull(false); |
|
54 | - $remoteIdColumn->setType(Type::getType(Types::STRING)); |
|
55 | - $remoteIdColumn->setOptions(['length' => 255]); |
|
56 | - $remoteIdColumn->setDefault(''); |
|
57 | - return $schema; |
|
58 | - } |
|
59 | - } |
|
49 | + if ($schema->hasTable('federated_reshares')) { |
|
50 | + $table = $schema->getTable('federated_reshares'); |
|
51 | + $remoteIdColumn = $table->getColumn('remote_id'); |
|
52 | + if ($remoteIdColumn && $remoteIdColumn->getType()->getName() !== Types::STRING) { |
|
53 | + $remoteIdColumn->setNotnull(false); |
|
54 | + $remoteIdColumn->setType(Type::getType(Types::STRING)); |
|
55 | + $remoteIdColumn->setOptions(['length' => 255]); |
|
56 | + $remoteIdColumn->setDefault(''); |
|
57 | + return $schema; |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - return null; |
|
62 | - } |
|
61 | + return null; |
|
62 | + } |
|
63 | 63 | |
64 | - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
65 | - $qb = $this->connection->getQueryBuilder(); |
|
66 | - $qb->update('federated_reshares') |
|
67 | - ->set('remote_id', $qb->createNamedParameter('')) |
|
68 | - ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter('-1'))); |
|
69 | - $qb->execute(); |
|
70 | - } |
|
64 | + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { |
|
65 | + $qb = $this->connection->getQueryBuilder(); |
|
66 | + $qb->update('federated_reshares') |
|
67 | + ->set('remote_id', $qb->createNamedParameter('')) |
|
68 | + ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter('-1'))); |
|
69 | + $qb->execute(); |
|
70 | + } |
|
71 | 71 | } |
@@ -32,29 +32,29 @@ |
||
32 | 32 | use OCP\Migration\SimpleMigrationStep; |
33 | 33 | |
34 | 34 | class Version1010Date20200630191755 extends SimpleMigrationStep { |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | 44 | |
45 | - if (!$schema->hasTable('federated_reshares')) { |
|
46 | - $table = $schema->createTable('federated_reshares'); |
|
47 | - $table->addColumn('share_id', Types::BIGINT, [ |
|
48 | - 'notnull' => true, |
|
49 | - ]); |
|
50 | - $table->addColumn('remote_id', Types::STRING, [ |
|
51 | - 'notnull' => false, |
|
52 | - 'length' => 255, |
|
53 | - 'default' => '', |
|
54 | - ]); |
|
55 | - $table->setPrimaryKey(['share_id'], 'federated_res_pk'); |
|
45 | + if (!$schema->hasTable('federated_reshares')) { |
|
46 | + $table = $schema->createTable('federated_reshares'); |
|
47 | + $table->addColumn('share_id', Types::BIGINT, [ |
|
48 | + 'notnull' => true, |
|
49 | + ]); |
|
50 | + $table->addColumn('remote_id', Types::STRING, [ |
|
51 | + 'notnull' => false, |
|
52 | + 'length' => 255, |
|
53 | + 'default' => '', |
|
54 | + ]); |
|
55 | + $table->setPrimaryKey(['share_id'], 'federated_res_pk'); |
|
56 | 56 | // $table->addUniqueIndex(['share_id'], 'share_id_index'); |
57 | - } |
|
58 | - return $schema; |
|
59 | - } |
|
57 | + } |
|
58 | + return $schema; |
|
59 | + } |
|
60 | 60 | } |
@@ -30,467 +30,467 @@ |
||
30 | 30 | use OCP\Migration\SimpleMigrationStep; |
31 | 31 | |
32 | 32 | class Version1004Date20170825134824 extends SimpleMigrationStep { |
33 | - /** |
|
34 | - * @param IOutput $output |
|
35 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
36 | - * @param array $options |
|
37 | - * @return null|ISchemaWrapper |
|
38 | - * @since 13.0.0 |
|
39 | - */ |
|
40 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
41 | - /** @var ISchemaWrapper $schema */ |
|
42 | - $schema = $schemaClosure(); |
|
33 | + /** |
|
34 | + * @param IOutput $output |
|
35 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
36 | + * @param array $options |
|
37 | + * @return null|ISchemaWrapper |
|
38 | + * @since 13.0.0 |
|
39 | + */ |
|
40 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
41 | + /** @var ISchemaWrapper $schema */ |
|
42 | + $schema = $schemaClosure(); |
|
43 | 43 | |
44 | - if (!$schema->hasTable('addressbooks')) { |
|
45 | - $table = $schema->createTable('addressbooks'); |
|
46 | - $table->addColumn('id', 'bigint', [ |
|
47 | - 'autoincrement' => true, |
|
48 | - 'notnull' => true, |
|
49 | - 'length' => 11, |
|
50 | - 'unsigned' => true, |
|
51 | - ]); |
|
52 | - $table->addColumn('principaluri', 'string', [ |
|
53 | - 'notnull' => false, |
|
54 | - 'length' => 255, |
|
55 | - ]); |
|
56 | - $table->addColumn('displayname', 'string', [ |
|
57 | - 'notnull' => false, |
|
58 | - 'length' => 255, |
|
59 | - ]); |
|
60 | - $table->addColumn('uri', 'string', [ |
|
61 | - 'notnull' => false, |
|
62 | - 'length' => 255, |
|
63 | - ]); |
|
64 | - $table->addColumn('description', 'string', [ |
|
65 | - 'notnull' => false, |
|
66 | - 'length' => 255, |
|
67 | - ]); |
|
68 | - $table->addColumn('synctoken', 'integer', [ |
|
69 | - 'notnull' => true, |
|
70 | - 'default' => 1, |
|
71 | - 'length' => 10, |
|
72 | - 'unsigned' => true, |
|
73 | - ]); |
|
74 | - $table->setPrimaryKey(['id']); |
|
75 | - $table->addUniqueIndex(['principaluri', 'uri'], 'addressbook_index'); |
|
76 | - } |
|
44 | + if (!$schema->hasTable('addressbooks')) { |
|
45 | + $table = $schema->createTable('addressbooks'); |
|
46 | + $table->addColumn('id', 'bigint', [ |
|
47 | + 'autoincrement' => true, |
|
48 | + 'notnull' => true, |
|
49 | + 'length' => 11, |
|
50 | + 'unsigned' => true, |
|
51 | + ]); |
|
52 | + $table->addColumn('principaluri', 'string', [ |
|
53 | + 'notnull' => false, |
|
54 | + 'length' => 255, |
|
55 | + ]); |
|
56 | + $table->addColumn('displayname', 'string', [ |
|
57 | + 'notnull' => false, |
|
58 | + 'length' => 255, |
|
59 | + ]); |
|
60 | + $table->addColumn('uri', 'string', [ |
|
61 | + 'notnull' => false, |
|
62 | + 'length' => 255, |
|
63 | + ]); |
|
64 | + $table->addColumn('description', 'string', [ |
|
65 | + 'notnull' => false, |
|
66 | + 'length' => 255, |
|
67 | + ]); |
|
68 | + $table->addColumn('synctoken', 'integer', [ |
|
69 | + 'notnull' => true, |
|
70 | + 'default' => 1, |
|
71 | + 'length' => 10, |
|
72 | + 'unsigned' => true, |
|
73 | + ]); |
|
74 | + $table->setPrimaryKey(['id']); |
|
75 | + $table->addUniqueIndex(['principaluri', 'uri'], 'addressbook_index'); |
|
76 | + } |
|
77 | 77 | |
78 | - if (!$schema->hasTable('cards')) { |
|
79 | - $table = $schema->createTable('cards'); |
|
80 | - $table->addColumn('id', 'bigint', [ |
|
81 | - 'autoincrement' => true, |
|
82 | - 'notnull' => true, |
|
83 | - 'length' => 11, |
|
84 | - 'unsigned' => true, |
|
85 | - ]); |
|
86 | - $table->addColumn('addressbookid', 'integer', [ |
|
87 | - 'notnull' => true, |
|
88 | - 'default' => 0, |
|
89 | - ]); |
|
90 | - $table->addColumn('carddata', 'blob', [ |
|
91 | - 'notnull' => false, |
|
92 | - ]); |
|
93 | - $table->addColumn('uri', 'string', [ |
|
94 | - 'notnull' => false, |
|
95 | - 'length' => 255, |
|
96 | - ]); |
|
97 | - $table->addColumn('lastmodified', 'bigint', [ |
|
98 | - 'notnull' => false, |
|
99 | - 'length' => 11, |
|
100 | - 'unsigned' => true, |
|
101 | - ]); |
|
102 | - $table->addColumn('etag', 'string', [ |
|
103 | - 'notnull' => false, |
|
104 | - 'length' => 32, |
|
105 | - ]); |
|
106 | - $table->addColumn('size', 'bigint', [ |
|
107 | - 'notnull' => true, |
|
108 | - 'length' => 11, |
|
109 | - 'unsigned' => true, |
|
110 | - ]); |
|
111 | - $table->setPrimaryKey(['id']); |
|
112 | - } |
|
78 | + if (!$schema->hasTable('cards')) { |
|
79 | + $table = $schema->createTable('cards'); |
|
80 | + $table->addColumn('id', 'bigint', [ |
|
81 | + 'autoincrement' => true, |
|
82 | + 'notnull' => true, |
|
83 | + 'length' => 11, |
|
84 | + 'unsigned' => true, |
|
85 | + ]); |
|
86 | + $table->addColumn('addressbookid', 'integer', [ |
|
87 | + 'notnull' => true, |
|
88 | + 'default' => 0, |
|
89 | + ]); |
|
90 | + $table->addColumn('carddata', 'blob', [ |
|
91 | + 'notnull' => false, |
|
92 | + ]); |
|
93 | + $table->addColumn('uri', 'string', [ |
|
94 | + 'notnull' => false, |
|
95 | + 'length' => 255, |
|
96 | + ]); |
|
97 | + $table->addColumn('lastmodified', 'bigint', [ |
|
98 | + 'notnull' => false, |
|
99 | + 'length' => 11, |
|
100 | + 'unsigned' => true, |
|
101 | + ]); |
|
102 | + $table->addColumn('etag', 'string', [ |
|
103 | + 'notnull' => false, |
|
104 | + 'length' => 32, |
|
105 | + ]); |
|
106 | + $table->addColumn('size', 'bigint', [ |
|
107 | + 'notnull' => true, |
|
108 | + 'length' => 11, |
|
109 | + 'unsigned' => true, |
|
110 | + ]); |
|
111 | + $table->setPrimaryKey(['id']); |
|
112 | + } |
|
113 | 113 | |
114 | - if (!$schema->hasTable('addressbookchanges')) { |
|
115 | - $table = $schema->createTable('addressbookchanges'); |
|
116 | - $table->addColumn('id', 'bigint', [ |
|
117 | - 'autoincrement' => true, |
|
118 | - 'notnull' => true, |
|
119 | - 'length' => 11, |
|
120 | - 'unsigned' => true, |
|
121 | - ]); |
|
122 | - $table->addColumn('uri', 'string', [ |
|
123 | - 'notnull' => false, |
|
124 | - 'length' => 255, |
|
125 | - ]); |
|
126 | - $table->addColumn('synctoken', 'integer', [ |
|
127 | - 'notnull' => true, |
|
128 | - 'default' => 1, |
|
129 | - 'length' => 10, |
|
130 | - 'unsigned' => true, |
|
131 | - ]); |
|
132 | - $table->addColumn('addressbookid', 'integer', [ |
|
133 | - 'notnull' => true, |
|
134 | - ]); |
|
135 | - $table->addColumn('operation', 'smallint', [ |
|
136 | - 'notnull' => true, |
|
137 | - 'length' => 1, |
|
138 | - ]); |
|
139 | - $table->setPrimaryKey(['id']); |
|
140 | - $table->addIndex(['addressbookid', 'synctoken'], 'addressbookid_synctoken'); |
|
141 | - } |
|
114 | + if (!$schema->hasTable('addressbookchanges')) { |
|
115 | + $table = $schema->createTable('addressbookchanges'); |
|
116 | + $table->addColumn('id', 'bigint', [ |
|
117 | + 'autoincrement' => true, |
|
118 | + 'notnull' => true, |
|
119 | + 'length' => 11, |
|
120 | + 'unsigned' => true, |
|
121 | + ]); |
|
122 | + $table->addColumn('uri', 'string', [ |
|
123 | + 'notnull' => false, |
|
124 | + 'length' => 255, |
|
125 | + ]); |
|
126 | + $table->addColumn('synctoken', 'integer', [ |
|
127 | + 'notnull' => true, |
|
128 | + 'default' => 1, |
|
129 | + 'length' => 10, |
|
130 | + 'unsigned' => true, |
|
131 | + ]); |
|
132 | + $table->addColumn('addressbookid', 'integer', [ |
|
133 | + 'notnull' => true, |
|
134 | + ]); |
|
135 | + $table->addColumn('operation', 'smallint', [ |
|
136 | + 'notnull' => true, |
|
137 | + 'length' => 1, |
|
138 | + ]); |
|
139 | + $table->setPrimaryKey(['id']); |
|
140 | + $table->addIndex(['addressbookid', 'synctoken'], 'addressbookid_synctoken'); |
|
141 | + } |
|
142 | 142 | |
143 | - if (!$schema->hasTable('calendarobjects')) { |
|
144 | - $table = $schema->createTable('calendarobjects'); |
|
145 | - $table->addColumn('id', 'bigint', [ |
|
146 | - 'autoincrement' => true, |
|
147 | - 'notnull' => true, |
|
148 | - 'length' => 11, |
|
149 | - 'unsigned' => true, |
|
150 | - ]); |
|
151 | - $table->addColumn('calendardata', 'blob', [ |
|
152 | - 'notnull' => false, |
|
153 | - ]); |
|
154 | - $table->addColumn('uri', 'string', [ |
|
155 | - 'notnull' => false, |
|
156 | - 'length' => 255, |
|
157 | - ]); |
|
158 | - $table->addColumn('calendarid', 'integer', [ |
|
159 | - 'notnull' => true, |
|
160 | - 'length' => 10, |
|
161 | - 'unsigned' => true, |
|
162 | - ]); |
|
163 | - $table->addColumn('lastmodified', 'integer', [ |
|
164 | - 'notnull' => false, |
|
165 | - 'length' => 10, |
|
166 | - 'unsigned' => true, |
|
167 | - ]); |
|
168 | - $table->addColumn('etag', 'string', [ |
|
169 | - 'notnull' => false, |
|
170 | - 'length' => 32, |
|
171 | - ]); |
|
172 | - $table->addColumn('size', 'bigint', [ |
|
173 | - 'notnull' => true, |
|
174 | - 'length' => 11, |
|
175 | - 'unsigned' => true, |
|
176 | - ]); |
|
177 | - $table->addColumn('componenttype', 'string', [ |
|
178 | - 'notnull' => false, |
|
179 | - 'length' => 8, |
|
180 | - ]); |
|
181 | - $table->addColumn('firstoccurence', 'bigint', [ |
|
182 | - 'notnull' => false, |
|
183 | - 'length' => 11, |
|
184 | - 'unsigned' => true, |
|
185 | - ]); |
|
186 | - $table->addColumn('lastoccurence', 'bigint', [ |
|
187 | - 'notnull' => false, |
|
188 | - 'length' => 11, |
|
189 | - 'unsigned' => true, |
|
190 | - ]); |
|
191 | - $table->addColumn('uid', 'string', [ |
|
192 | - 'notnull' => false, |
|
193 | - 'length' => 255, |
|
194 | - ]); |
|
195 | - $table->addColumn('classification', 'integer', [ |
|
196 | - 'notnull' => false, |
|
197 | - 'default' => 0, |
|
198 | - ]); |
|
199 | - $table->setPrimaryKey(['id']); |
|
200 | - $table->addUniqueIndex(['calendarid', 'uri'], 'calobjects_index'); |
|
201 | - } |
|
143 | + if (!$schema->hasTable('calendarobjects')) { |
|
144 | + $table = $schema->createTable('calendarobjects'); |
|
145 | + $table->addColumn('id', 'bigint', [ |
|
146 | + 'autoincrement' => true, |
|
147 | + 'notnull' => true, |
|
148 | + 'length' => 11, |
|
149 | + 'unsigned' => true, |
|
150 | + ]); |
|
151 | + $table->addColumn('calendardata', 'blob', [ |
|
152 | + 'notnull' => false, |
|
153 | + ]); |
|
154 | + $table->addColumn('uri', 'string', [ |
|
155 | + 'notnull' => false, |
|
156 | + 'length' => 255, |
|
157 | + ]); |
|
158 | + $table->addColumn('calendarid', 'integer', [ |
|
159 | + 'notnull' => true, |
|
160 | + 'length' => 10, |
|
161 | + 'unsigned' => true, |
|
162 | + ]); |
|
163 | + $table->addColumn('lastmodified', 'integer', [ |
|
164 | + 'notnull' => false, |
|
165 | + 'length' => 10, |
|
166 | + 'unsigned' => true, |
|
167 | + ]); |
|
168 | + $table->addColumn('etag', 'string', [ |
|
169 | + 'notnull' => false, |
|
170 | + 'length' => 32, |
|
171 | + ]); |
|
172 | + $table->addColumn('size', 'bigint', [ |
|
173 | + 'notnull' => true, |
|
174 | + 'length' => 11, |
|
175 | + 'unsigned' => true, |
|
176 | + ]); |
|
177 | + $table->addColumn('componenttype', 'string', [ |
|
178 | + 'notnull' => false, |
|
179 | + 'length' => 8, |
|
180 | + ]); |
|
181 | + $table->addColumn('firstoccurence', 'bigint', [ |
|
182 | + 'notnull' => false, |
|
183 | + 'length' => 11, |
|
184 | + 'unsigned' => true, |
|
185 | + ]); |
|
186 | + $table->addColumn('lastoccurence', 'bigint', [ |
|
187 | + 'notnull' => false, |
|
188 | + 'length' => 11, |
|
189 | + 'unsigned' => true, |
|
190 | + ]); |
|
191 | + $table->addColumn('uid', 'string', [ |
|
192 | + 'notnull' => false, |
|
193 | + 'length' => 255, |
|
194 | + ]); |
|
195 | + $table->addColumn('classification', 'integer', [ |
|
196 | + 'notnull' => false, |
|
197 | + 'default' => 0, |
|
198 | + ]); |
|
199 | + $table->setPrimaryKey(['id']); |
|
200 | + $table->addUniqueIndex(['calendarid', 'uri'], 'calobjects_index'); |
|
201 | + } |
|
202 | 202 | |
203 | - if (!$schema->hasTable('calendars')) { |
|
204 | - $table = $schema->createTable('calendars'); |
|
205 | - $table->addColumn('id', 'bigint', [ |
|
206 | - 'autoincrement' => true, |
|
207 | - 'notnull' => true, |
|
208 | - 'length' => 11, |
|
209 | - 'unsigned' => true, |
|
210 | - ]); |
|
211 | - $table->addColumn('principaluri', 'string', [ |
|
212 | - 'notnull' => false, |
|
213 | - 'length' => 255, |
|
214 | - ]); |
|
215 | - $table->addColumn('displayname', 'string', [ |
|
216 | - 'notnull' => false, |
|
217 | - 'length' => 255, |
|
218 | - ]); |
|
219 | - $table->addColumn('uri', 'string', [ |
|
220 | - 'notnull' => false, |
|
221 | - 'length' => 255, |
|
222 | - ]); |
|
223 | - $table->addColumn('synctoken', 'integer', [ |
|
224 | - 'notnull' => true, |
|
225 | - 'default' => 1, |
|
226 | - 'unsigned' => true, |
|
227 | - ]); |
|
228 | - $table->addColumn('description', 'string', [ |
|
229 | - 'notnull' => false, |
|
230 | - 'length' => 255, |
|
231 | - ]); |
|
232 | - $table->addColumn('calendarorder', 'integer', [ |
|
233 | - 'notnull' => true, |
|
234 | - 'default' => 0, |
|
235 | - 'unsigned' => true, |
|
236 | - ]); |
|
237 | - $table->addColumn('calendarcolor', 'string', [ |
|
238 | - 'notnull' => false, |
|
239 | - ]); |
|
240 | - $table->addColumn('timezone', 'text', [ |
|
241 | - 'notnull' => false, |
|
242 | - ]); |
|
243 | - $table->addColumn('components', 'string', [ |
|
244 | - 'notnull' => false, |
|
245 | - 'length' => 64, |
|
246 | - ]); |
|
247 | - $table->addColumn('transparent', 'smallint', [ |
|
248 | - 'notnull' => true, |
|
249 | - 'length' => 1, |
|
250 | - 'default' => 0, |
|
251 | - ]); |
|
252 | - $table->setPrimaryKey(['id']); |
|
253 | - $table->addUniqueIndex(['principaluri', 'uri'], 'calendars_index'); |
|
254 | - } else { |
|
255 | - $table = $schema->getTable('calendars'); |
|
256 | - $table->changeColumn('components', [ |
|
257 | - 'notnull' => false, |
|
258 | - 'length' => 64, |
|
259 | - ]); |
|
260 | - } |
|
203 | + if (!$schema->hasTable('calendars')) { |
|
204 | + $table = $schema->createTable('calendars'); |
|
205 | + $table->addColumn('id', 'bigint', [ |
|
206 | + 'autoincrement' => true, |
|
207 | + 'notnull' => true, |
|
208 | + 'length' => 11, |
|
209 | + 'unsigned' => true, |
|
210 | + ]); |
|
211 | + $table->addColumn('principaluri', 'string', [ |
|
212 | + 'notnull' => false, |
|
213 | + 'length' => 255, |
|
214 | + ]); |
|
215 | + $table->addColumn('displayname', 'string', [ |
|
216 | + 'notnull' => false, |
|
217 | + 'length' => 255, |
|
218 | + ]); |
|
219 | + $table->addColumn('uri', 'string', [ |
|
220 | + 'notnull' => false, |
|
221 | + 'length' => 255, |
|
222 | + ]); |
|
223 | + $table->addColumn('synctoken', 'integer', [ |
|
224 | + 'notnull' => true, |
|
225 | + 'default' => 1, |
|
226 | + 'unsigned' => true, |
|
227 | + ]); |
|
228 | + $table->addColumn('description', 'string', [ |
|
229 | + 'notnull' => false, |
|
230 | + 'length' => 255, |
|
231 | + ]); |
|
232 | + $table->addColumn('calendarorder', 'integer', [ |
|
233 | + 'notnull' => true, |
|
234 | + 'default' => 0, |
|
235 | + 'unsigned' => true, |
|
236 | + ]); |
|
237 | + $table->addColumn('calendarcolor', 'string', [ |
|
238 | + 'notnull' => false, |
|
239 | + ]); |
|
240 | + $table->addColumn('timezone', 'text', [ |
|
241 | + 'notnull' => false, |
|
242 | + ]); |
|
243 | + $table->addColumn('components', 'string', [ |
|
244 | + 'notnull' => false, |
|
245 | + 'length' => 64, |
|
246 | + ]); |
|
247 | + $table->addColumn('transparent', 'smallint', [ |
|
248 | + 'notnull' => true, |
|
249 | + 'length' => 1, |
|
250 | + 'default' => 0, |
|
251 | + ]); |
|
252 | + $table->setPrimaryKey(['id']); |
|
253 | + $table->addUniqueIndex(['principaluri', 'uri'], 'calendars_index'); |
|
254 | + } else { |
|
255 | + $table = $schema->getTable('calendars'); |
|
256 | + $table->changeColumn('components', [ |
|
257 | + 'notnull' => false, |
|
258 | + 'length' => 64, |
|
259 | + ]); |
|
260 | + } |
|
261 | 261 | |
262 | - if (!$schema->hasTable('calendarchanges')) { |
|
263 | - $table = $schema->createTable('calendarchanges'); |
|
264 | - $table->addColumn('id', 'bigint', [ |
|
265 | - 'autoincrement' => true, |
|
266 | - 'notnull' => true, |
|
267 | - 'length' => 11, |
|
268 | - 'unsigned' => true, |
|
269 | - ]); |
|
270 | - $table->addColumn('uri', 'string', [ |
|
271 | - 'notnull' => false, |
|
272 | - 'length' => 255, |
|
273 | - ]); |
|
274 | - $table->addColumn('synctoken', 'integer', [ |
|
275 | - 'notnull' => true, |
|
276 | - 'default' => 1, |
|
277 | - 'length' => 10, |
|
278 | - 'unsigned' => true, |
|
279 | - ]); |
|
280 | - $table->addColumn('calendarid', 'integer', [ |
|
281 | - 'notnull' => true, |
|
282 | - ]); |
|
283 | - $table->addColumn('operation', 'smallint', [ |
|
284 | - 'notnull' => true, |
|
285 | - 'length' => 1, |
|
286 | - ]); |
|
287 | - $table->setPrimaryKey(['id']); |
|
288 | - $table->addIndex(['calendarid', 'synctoken'], 'calendarid_synctoken'); |
|
289 | - } |
|
262 | + if (!$schema->hasTable('calendarchanges')) { |
|
263 | + $table = $schema->createTable('calendarchanges'); |
|
264 | + $table->addColumn('id', 'bigint', [ |
|
265 | + 'autoincrement' => true, |
|
266 | + 'notnull' => true, |
|
267 | + 'length' => 11, |
|
268 | + 'unsigned' => true, |
|
269 | + ]); |
|
270 | + $table->addColumn('uri', 'string', [ |
|
271 | + 'notnull' => false, |
|
272 | + 'length' => 255, |
|
273 | + ]); |
|
274 | + $table->addColumn('synctoken', 'integer', [ |
|
275 | + 'notnull' => true, |
|
276 | + 'default' => 1, |
|
277 | + 'length' => 10, |
|
278 | + 'unsigned' => true, |
|
279 | + ]); |
|
280 | + $table->addColumn('calendarid', 'integer', [ |
|
281 | + 'notnull' => true, |
|
282 | + ]); |
|
283 | + $table->addColumn('operation', 'smallint', [ |
|
284 | + 'notnull' => true, |
|
285 | + 'length' => 1, |
|
286 | + ]); |
|
287 | + $table->setPrimaryKey(['id']); |
|
288 | + $table->addIndex(['calendarid', 'synctoken'], 'calendarid_synctoken'); |
|
289 | + } |
|
290 | 290 | |
291 | - if (!$schema->hasTable('calendarsubscriptions')) { |
|
292 | - $table = $schema->createTable('calendarsubscriptions'); |
|
293 | - $table->addColumn('id', 'bigint', [ |
|
294 | - 'autoincrement' => true, |
|
295 | - 'notnull' => true, |
|
296 | - 'length' => 11, |
|
297 | - 'unsigned' => true, |
|
298 | - ]); |
|
299 | - $table->addColumn('uri', 'string', [ |
|
300 | - 'notnull' => false, |
|
301 | - ]); |
|
302 | - $table->addColumn('principaluri', 'string', [ |
|
303 | - 'notnull' => false, |
|
304 | - 'length' => 255, |
|
305 | - ]); |
|
306 | - $table->addColumn('source', 'string', [ |
|
307 | - 'notnull' => false, |
|
308 | - 'length' => 255, |
|
309 | - ]); |
|
310 | - $table->addColumn('displayname', 'string', [ |
|
311 | - 'notnull' => false, |
|
312 | - 'length' => 100, |
|
313 | - ]); |
|
314 | - $table->addColumn('refreshrate', 'string', [ |
|
315 | - 'notnull' => false, |
|
316 | - 'length' => 10, |
|
317 | - ]); |
|
318 | - $table->addColumn('calendarorder', 'integer', [ |
|
319 | - 'notnull' => true, |
|
320 | - 'default' => 0, |
|
321 | - 'unsigned' => true, |
|
322 | - ]); |
|
323 | - $table->addColumn('calendarcolor', 'string', [ |
|
324 | - 'notnull' => false, |
|
325 | - ]); |
|
326 | - $table->addColumn('striptodos', 'smallint', [ |
|
327 | - 'notnull' => false, |
|
328 | - 'length' => 1, |
|
329 | - ]); |
|
330 | - $table->addColumn('stripalarms', 'smallint', [ |
|
331 | - 'notnull' => false, |
|
332 | - 'length' => 1, |
|
333 | - ]); |
|
334 | - $table->addColumn('stripattachments', 'smallint', [ |
|
335 | - 'notnull' => false, |
|
336 | - 'length' => 1, |
|
337 | - ]); |
|
338 | - $table->addColumn('lastmodified', 'integer', [ |
|
339 | - 'notnull' => false, |
|
340 | - 'unsigned' => true, |
|
341 | - ]); |
|
342 | - $table->setPrimaryKey(['id']); |
|
343 | - $table->addUniqueIndex(['principaluri', 'uri'], 'calsub_index'); |
|
344 | - } else { |
|
345 | - $table = $schema->getTable('calendarsubscriptions'); |
|
346 | - $table->changeColumn('lastmodified', [ |
|
347 | - 'notnull' => false, |
|
348 | - 'unsigned' => true, |
|
349 | - ]); |
|
350 | - } |
|
291 | + if (!$schema->hasTable('calendarsubscriptions')) { |
|
292 | + $table = $schema->createTable('calendarsubscriptions'); |
|
293 | + $table->addColumn('id', 'bigint', [ |
|
294 | + 'autoincrement' => true, |
|
295 | + 'notnull' => true, |
|
296 | + 'length' => 11, |
|
297 | + 'unsigned' => true, |
|
298 | + ]); |
|
299 | + $table->addColumn('uri', 'string', [ |
|
300 | + 'notnull' => false, |
|
301 | + ]); |
|
302 | + $table->addColumn('principaluri', 'string', [ |
|
303 | + 'notnull' => false, |
|
304 | + 'length' => 255, |
|
305 | + ]); |
|
306 | + $table->addColumn('source', 'string', [ |
|
307 | + 'notnull' => false, |
|
308 | + 'length' => 255, |
|
309 | + ]); |
|
310 | + $table->addColumn('displayname', 'string', [ |
|
311 | + 'notnull' => false, |
|
312 | + 'length' => 100, |
|
313 | + ]); |
|
314 | + $table->addColumn('refreshrate', 'string', [ |
|
315 | + 'notnull' => false, |
|
316 | + 'length' => 10, |
|
317 | + ]); |
|
318 | + $table->addColumn('calendarorder', 'integer', [ |
|
319 | + 'notnull' => true, |
|
320 | + 'default' => 0, |
|
321 | + 'unsigned' => true, |
|
322 | + ]); |
|
323 | + $table->addColumn('calendarcolor', 'string', [ |
|
324 | + 'notnull' => false, |
|
325 | + ]); |
|
326 | + $table->addColumn('striptodos', 'smallint', [ |
|
327 | + 'notnull' => false, |
|
328 | + 'length' => 1, |
|
329 | + ]); |
|
330 | + $table->addColumn('stripalarms', 'smallint', [ |
|
331 | + 'notnull' => false, |
|
332 | + 'length' => 1, |
|
333 | + ]); |
|
334 | + $table->addColumn('stripattachments', 'smallint', [ |
|
335 | + 'notnull' => false, |
|
336 | + 'length' => 1, |
|
337 | + ]); |
|
338 | + $table->addColumn('lastmodified', 'integer', [ |
|
339 | + 'notnull' => false, |
|
340 | + 'unsigned' => true, |
|
341 | + ]); |
|
342 | + $table->setPrimaryKey(['id']); |
|
343 | + $table->addUniqueIndex(['principaluri', 'uri'], 'calsub_index'); |
|
344 | + } else { |
|
345 | + $table = $schema->getTable('calendarsubscriptions'); |
|
346 | + $table->changeColumn('lastmodified', [ |
|
347 | + 'notnull' => false, |
|
348 | + 'unsigned' => true, |
|
349 | + ]); |
|
350 | + } |
|
351 | 351 | |
352 | - if (!$schema->hasTable('schedulingobjects')) { |
|
353 | - $table = $schema->createTable('schedulingobjects'); |
|
354 | - $table->addColumn('id', 'bigint', [ |
|
355 | - 'autoincrement' => true, |
|
356 | - 'notnull' => true, |
|
357 | - 'length' => 11, |
|
358 | - 'unsigned' => true, |
|
359 | - ]); |
|
360 | - $table->addColumn('principaluri', 'string', [ |
|
361 | - 'notnull' => false, |
|
362 | - 'length' => 255, |
|
363 | - ]); |
|
364 | - $table->addColumn('calendardata', 'blob', [ |
|
365 | - 'notnull' => false, |
|
366 | - ]); |
|
367 | - $table->addColumn('uri', 'string', [ |
|
368 | - 'notnull' => false, |
|
369 | - 'length' => 255, |
|
370 | - ]); |
|
371 | - $table->addColumn('lastmodified', 'integer', [ |
|
372 | - 'notnull' => false, |
|
373 | - 'unsigned' => true, |
|
374 | - ]); |
|
375 | - $table->addColumn('etag', 'string', [ |
|
376 | - 'notnull' => false, |
|
377 | - 'length' => 32, |
|
378 | - ]); |
|
379 | - $table->addColumn('size', 'bigint', [ |
|
380 | - 'notnull' => true, |
|
381 | - 'length' => 11, |
|
382 | - 'unsigned' => true, |
|
383 | - ]); |
|
384 | - $table->setPrimaryKey(['id']); |
|
385 | - $table->addIndex(['principaluri'], 'schedulobj_principuri_index'); |
|
386 | - } |
|
352 | + if (!$schema->hasTable('schedulingobjects')) { |
|
353 | + $table = $schema->createTable('schedulingobjects'); |
|
354 | + $table->addColumn('id', 'bigint', [ |
|
355 | + 'autoincrement' => true, |
|
356 | + 'notnull' => true, |
|
357 | + 'length' => 11, |
|
358 | + 'unsigned' => true, |
|
359 | + ]); |
|
360 | + $table->addColumn('principaluri', 'string', [ |
|
361 | + 'notnull' => false, |
|
362 | + 'length' => 255, |
|
363 | + ]); |
|
364 | + $table->addColumn('calendardata', 'blob', [ |
|
365 | + 'notnull' => false, |
|
366 | + ]); |
|
367 | + $table->addColumn('uri', 'string', [ |
|
368 | + 'notnull' => false, |
|
369 | + 'length' => 255, |
|
370 | + ]); |
|
371 | + $table->addColumn('lastmodified', 'integer', [ |
|
372 | + 'notnull' => false, |
|
373 | + 'unsigned' => true, |
|
374 | + ]); |
|
375 | + $table->addColumn('etag', 'string', [ |
|
376 | + 'notnull' => false, |
|
377 | + 'length' => 32, |
|
378 | + ]); |
|
379 | + $table->addColumn('size', 'bigint', [ |
|
380 | + 'notnull' => true, |
|
381 | + 'length' => 11, |
|
382 | + 'unsigned' => true, |
|
383 | + ]); |
|
384 | + $table->setPrimaryKey(['id']); |
|
385 | + $table->addIndex(['principaluri'], 'schedulobj_principuri_index'); |
|
386 | + } |
|
387 | 387 | |
388 | - if (!$schema->hasTable('cards_properties')) { |
|
389 | - $table = $schema->createTable('cards_properties'); |
|
390 | - $table->addColumn('id', 'bigint', [ |
|
391 | - 'autoincrement' => true, |
|
392 | - 'notnull' => true, |
|
393 | - 'length' => 11, |
|
394 | - 'unsigned' => true, |
|
395 | - ]); |
|
396 | - $table->addColumn('addressbookid', 'bigint', [ |
|
397 | - 'notnull' => true, |
|
398 | - 'length' => 11, |
|
399 | - 'default' => 0, |
|
400 | - ]); |
|
401 | - $table->addColumn('cardid', 'bigint', [ |
|
402 | - 'notnull' => true, |
|
403 | - 'length' => 11, |
|
404 | - 'default' => 0, |
|
405 | - 'unsigned' => true, |
|
406 | - ]); |
|
407 | - $table->addColumn('name', 'string', [ |
|
408 | - 'notnull' => false, |
|
409 | - 'length' => 64, |
|
410 | - ]); |
|
411 | - $table->addColumn('value', 'string', [ |
|
412 | - 'notnull' => false, |
|
413 | - 'length' => 255, |
|
414 | - ]); |
|
415 | - $table->addColumn('preferred', 'integer', [ |
|
416 | - 'notnull' => true, |
|
417 | - 'length' => 4, |
|
418 | - 'default' => 1, |
|
419 | - ]); |
|
420 | - $table->setPrimaryKey(['id']); |
|
421 | - $table->addIndex(['cardid'], 'card_contactid_index'); |
|
422 | - $table->addIndex(['name'], 'card_name_index'); |
|
423 | - $table->addIndex(['value'], 'card_value_index'); |
|
424 | - } |
|
388 | + if (!$schema->hasTable('cards_properties')) { |
|
389 | + $table = $schema->createTable('cards_properties'); |
|
390 | + $table->addColumn('id', 'bigint', [ |
|
391 | + 'autoincrement' => true, |
|
392 | + 'notnull' => true, |
|
393 | + 'length' => 11, |
|
394 | + 'unsigned' => true, |
|
395 | + ]); |
|
396 | + $table->addColumn('addressbookid', 'bigint', [ |
|
397 | + 'notnull' => true, |
|
398 | + 'length' => 11, |
|
399 | + 'default' => 0, |
|
400 | + ]); |
|
401 | + $table->addColumn('cardid', 'bigint', [ |
|
402 | + 'notnull' => true, |
|
403 | + 'length' => 11, |
|
404 | + 'default' => 0, |
|
405 | + 'unsigned' => true, |
|
406 | + ]); |
|
407 | + $table->addColumn('name', 'string', [ |
|
408 | + 'notnull' => false, |
|
409 | + 'length' => 64, |
|
410 | + ]); |
|
411 | + $table->addColumn('value', 'string', [ |
|
412 | + 'notnull' => false, |
|
413 | + 'length' => 255, |
|
414 | + ]); |
|
415 | + $table->addColumn('preferred', 'integer', [ |
|
416 | + 'notnull' => true, |
|
417 | + 'length' => 4, |
|
418 | + 'default' => 1, |
|
419 | + ]); |
|
420 | + $table->setPrimaryKey(['id']); |
|
421 | + $table->addIndex(['cardid'], 'card_contactid_index'); |
|
422 | + $table->addIndex(['name'], 'card_name_index'); |
|
423 | + $table->addIndex(['value'], 'card_value_index'); |
|
424 | + } |
|
425 | 425 | |
426 | - if (!$schema->hasTable('calendarobjects_props')) { |
|
427 | - $table = $schema->createTable('calendarobjects_props'); |
|
428 | - $table->addColumn('id', 'bigint', [ |
|
429 | - 'autoincrement' => true, |
|
430 | - 'notnull' => true, |
|
431 | - 'length' => 11, |
|
432 | - 'unsigned' => true, |
|
433 | - ]); |
|
434 | - $table->addColumn('calendarid', 'bigint', [ |
|
435 | - 'notnull' => true, |
|
436 | - 'length' => 11, |
|
437 | - 'default' => 0, |
|
438 | - ]); |
|
439 | - $table->addColumn('objectid', 'bigint', [ |
|
440 | - 'notnull' => true, |
|
441 | - 'length' => 11, |
|
442 | - 'default' => 0, |
|
443 | - 'unsigned' => true, |
|
444 | - ]); |
|
445 | - $table->addColumn('name', 'string', [ |
|
446 | - 'notnull' => false, |
|
447 | - 'length' => 64, |
|
448 | - ]); |
|
449 | - $table->addColumn('parameter', 'string', [ |
|
450 | - 'notnull' => false, |
|
451 | - 'length' => 64, |
|
452 | - ]); |
|
453 | - $table->addColumn('value', 'string', [ |
|
454 | - 'notnull' => false, |
|
455 | - 'length' => 255, |
|
456 | - ]); |
|
457 | - $table->setPrimaryKey(['id']); |
|
458 | - $table->addIndex(['objectid'], 'calendarobject_index'); |
|
459 | - $table->addIndex(['name'], 'calendarobject_name_index'); |
|
460 | - $table->addIndex(['value'], 'calendarobject_value_index'); |
|
461 | - } |
|
426 | + if (!$schema->hasTable('calendarobjects_props')) { |
|
427 | + $table = $schema->createTable('calendarobjects_props'); |
|
428 | + $table->addColumn('id', 'bigint', [ |
|
429 | + 'autoincrement' => true, |
|
430 | + 'notnull' => true, |
|
431 | + 'length' => 11, |
|
432 | + 'unsigned' => true, |
|
433 | + ]); |
|
434 | + $table->addColumn('calendarid', 'bigint', [ |
|
435 | + 'notnull' => true, |
|
436 | + 'length' => 11, |
|
437 | + 'default' => 0, |
|
438 | + ]); |
|
439 | + $table->addColumn('objectid', 'bigint', [ |
|
440 | + 'notnull' => true, |
|
441 | + 'length' => 11, |
|
442 | + 'default' => 0, |
|
443 | + 'unsigned' => true, |
|
444 | + ]); |
|
445 | + $table->addColumn('name', 'string', [ |
|
446 | + 'notnull' => false, |
|
447 | + 'length' => 64, |
|
448 | + ]); |
|
449 | + $table->addColumn('parameter', 'string', [ |
|
450 | + 'notnull' => false, |
|
451 | + 'length' => 64, |
|
452 | + ]); |
|
453 | + $table->addColumn('value', 'string', [ |
|
454 | + 'notnull' => false, |
|
455 | + 'length' => 255, |
|
456 | + ]); |
|
457 | + $table->setPrimaryKey(['id']); |
|
458 | + $table->addIndex(['objectid'], 'calendarobject_index'); |
|
459 | + $table->addIndex(['name'], 'calendarobject_name_index'); |
|
460 | + $table->addIndex(['value'], 'calendarobject_value_index'); |
|
461 | + } |
|
462 | 462 | |
463 | - if (!$schema->hasTable('dav_shares')) { |
|
464 | - $table = $schema->createTable('dav_shares'); |
|
465 | - $table->addColumn('id', 'bigint', [ |
|
466 | - 'autoincrement' => true, |
|
467 | - 'notnull' => true, |
|
468 | - 'length' => 11, |
|
469 | - 'unsigned' => true, |
|
470 | - ]); |
|
471 | - $table->addColumn('principaluri', 'string', [ |
|
472 | - 'notnull' => false, |
|
473 | - 'length' => 255, |
|
474 | - ]); |
|
475 | - $table->addColumn('type', 'string', [ |
|
476 | - 'notnull' => false, |
|
477 | - 'length' => 255, |
|
478 | - ]); |
|
479 | - $table->addColumn('access', 'smallint', [ |
|
480 | - 'notnull' => false, |
|
481 | - 'length' => 1, |
|
482 | - ]); |
|
483 | - $table->addColumn('resourceid', 'integer', [ |
|
484 | - 'notnull' => true, |
|
485 | - 'unsigned' => true, |
|
486 | - ]); |
|
487 | - $table->addColumn('publicuri', 'string', [ |
|
488 | - 'notnull' => false, |
|
489 | - 'length' => 255, |
|
490 | - ]); |
|
491 | - $table->setPrimaryKey(['id']); |
|
492 | - $table->addUniqueIndex(['principaluri', 'resourceid', 'type', 'publicuri'], 'dav_shares_index'); |
|
493 | - } |
|
494 | - return $schema; |
|
495 | - } |
|
463 | + if (!$schema->hasTable('dav_shares')) { |
|
464 | + $table = $schema->createTable('dav_shares'); |
|
465 | + $table->addColumn('id', 'bigint', [ |
|
466 | + 'autoincrement' => true, |
|
467 | + 'notnull' => true, |
|
468 | + 'length' => 11, |
|
469 | + 'unsigned' => true, |
|
470 | + ]); |
|
471 | + $table->addColumn('principaluri', 'string', [ |
|
472 | + 'notnull' => false, |
|
473 | + 'length' => 255, |
|
474 | + ]); |
|
475 | + $table->addColumn('type', 'string', [ |
|
476 | + 'notnull' => false, |
|
477 | + 'length' => 255, |
|
478 | + ]); |
|
479 | + $table->addColumn('access', 'smallint', [ |
|
480 | + 'notnull' => false, |
|
481 | + 'length' => 1, |
|
482 | + ]); |
|
483 | + $table->addColumn('resourceid', 'integer', [ |
|
484 | + 'notnull' => true, |
|
485 | + 'unsigned' => true, |
|
486 | + ]); |
|
487 | + $table->addColumn('publicuri', 'string', [ |
|
488 | + 'notnull' => false, |
|
489 | + 'length' => 255, |
|
490 | + ]); |
|
491 | + $table->setPrimaryKey(['id']); |
|
492 | + $table->addUniqueIndex(['principaluri', 'resourceid', 'type', 'publicuri'], 'dav_shares_index'); |
|
493 | + } |
|
494 | + return $schema; |
|
495 | + } |
|
496 | 496 | } |
@@ -41,167 +41,167 @@ |
||
41 | 41 | |
42 | 42 | class ContactsSearchProvider implements IProvider { |
43 | 43 | |
44 | - /** @var IAppManager */ |
|
45 | - private $appManager; |
|
46 | - |
|
47 | - /** @var IL10N */ |
|
48 | - private $l10n; |
|
49 | - |
|
50 | - /** @var IURLGenerator */ |
|
51 | - private $urlGenerator; |
|
52 | - |
|
53 | - /** @var CardDavBackend */ |
|
54 | - private $backend; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var string[] |
|
58 | - */ |
|
59 | - private static $searchProperties = [ |
|
60 | - 'N', |
|
61 | - 'FN', |
|
62 | - 'NICKNAME', |
|
63 | - 'EMAIL', |
|
64 | - 'TEL', |
|
65 | - 'ADR', |
|
66 | - 'TITLE', |
|
67 | - 'ORG', |
|
68 | - 'NOTE', |
|
69 | - ]; |
|
70 | - |
|
71 | - /** |
|
72 | - * ContactsSearchProvider constructor. |
|
73 | - * |
|
74 | - * @param IAppManager $appManager |
|
75 | - * @param IL10N $l10n |
|
76 | - * @param IURLGenerator $urlGenerator |
|
77 | - * @param CardDavBackend $backend |
|
78 | - */ |
|
79 | - public function __construct(IAppManager $appManager, |
|
80 | - IL10N $l10n, |
|
81 | - IURLGenerator $urlGenerator, |
|
82 | - CardDavBackend $backend) { |
|
83 | - $this->appManager = $appManager; |
|
84 | - $this->l10n = $l10n; |
|
85 | - $this->urlGenerator = $urlGenerator; |
|
86 | - $this->backend = $backend; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @inheritDoc |
|
91 | - */ |
|
92 | - public function getId(): string { |
|
93 | - return 'contacts'; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @inheritDoc |
|
98 | - */ |
|
99 | - public function getName(): string { |
|
100 | - return $this->l10n->t('Contacts'); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @inheritDoc |
|
105 | - */ |
|
106 | - public function getOrder(string $route, array $routeParameters): int { |
|
107 | - if ($route === 'contacts.Page.index') { |
|
108 | - return -1; |
|
109 | - } |
|
110 | - return 25; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @inheritDoc |
|
115 | - */ |
|
116 | - public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
117 | - if (!$this->appManager->isEnabledForUser('contacts', $user)) { |
|
118 | - return SearchResult::complete($this->getName(), []); |
|
119 | - } |
|
120 | - |
|
121 | - $principalUri = 'principals/users/' . $user->getUID(); |
|
122 | - $addressBooks = $this->backend->getAddressBooksForUser($principalUri); |
|
123 | - $addressBooksById = []; |
|
124 | - foreach ($addressBooks as $addressBook) { |
|
125 | - $addressBooksById[(int) $addressBook['id']] = $addressBook; |
|
126 | - } |
|
127 | - |
|
128 | - $searchResults = $this->backend->searchPrincipalUri( |
|
129 | - $principalUri, |
|
130 | - $query->getTerm(), |
|
131 | - self::$searchProperties, |
|
132 | - [ |
|
133 | - 'limit' => $query->getLimit(), |
|
134 | - 'offset' => $query->getCursor(), |
|
135 | - ] |
|
136 | - ); |
|
137 | - $formattedResults = \array_map(function (array $contactRow) use ($addressBooksById):SearchResultEntry { |
|
138 | - $addressBook = $addressBooksById[$contactRow['addressbookid']]; |
|
139 | - |
|
140 | - /** @var VCard $vCard */ |
|
141 | - $vCard = Reader::read($contactRow['carddata']); |
|
142 | - $thumbnailUrl = ''; |
|
143 | - if ($vCard->PHOTO) { |
|
144 | - $thumbnailUrl = $this->getDavUrlForContact($addressBook['principaluri'], $addressBook['uri'], $contactRow['uri']) . '?photo'; |
|
145 | - } |
|
146 | - |
|
147 | - $title = (string)$vCard->FN; |
|
148 | - $subline = $this->generateSubline($vCard); |
|
149 | - $resourceUrl = $this->getDeepLinkToContactsApp($addressBook['uri'], (string) $vCard->UID); |
|
150 | - |
|
151 | - return new SearchResultEntry($thumbnailUrl, $title, $subline, $resourceUrl, 'icon-contacts-dark', true); |
|
152 | - }, $searchResults); |
|
153 | - |
|
154 | - return SearchResult::paginated( |
|
155 | - $this->getName(), |
|
156 | - $formattedResults, |
|
157 | - $query->getCursor() + count($formattedResults) |
|
158 | - ); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @param string $principalUri |
|
163 | - * @param string $addressBookUri |
|
164 | - * @param string $contactsUri |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - protected function getDavUrlForContact(string $principalUri, |
|
168 | - string $addressBookUri, |
|
169 | - string $contactsUri): string { |
|
170 | - [, $principalType, $principalId] = explode('/', $principalUri, 3); |
|
171 | - |
|
172 | - return $this->urlGenerator->getAbsoluteURL( |
|
173 | - $this->urlGenerator->linkTo('', 'remote.php') . '/dav/addressbooks/' |
|
174 | - . $principalType . '/' |
|
175 | - . $principalId . '/' |
|
176 | - . $addressBookUri . '/' |
|
177 | - . $contactsUri |
|
178 | - ); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param string $addressBookUri |
|
183 | - * @param string $contactUid |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - protected function getDeepLinkToContactsApp(string $addressBookUri, |
|
187 | - string $contactUid): string { |
|
188 | - return $this->urlGenerator->getAbsoluteURL( |
|
189 | - $this->urlGenerator->linkToRoute('contacts.contacts.direct', [ |
|
190 | - 'contact' => $contactUid . '~' . $addressBookUri |
|
191 | - ]) |
|
192 | - ); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @param VCard $vCard |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - protected function generateSubline(VCard $vCard): string { |
|
200 | - $emailAddresses = $vCard->select('EMAIL'); |
|
201 | - if (!is_array($emailAddresses) || empty($emailAddresses)) { |
|
202 | - return ''; |
|
203 | - } |
|
204 | - |
|
205 | - return (string)$emailAddresses[0]; |
|
206 | - } |
|
44 | + /** @var IAppManager */ |
|
45 | + private $appManager; |
|
46 | + |
|
47 | + /** @var IL10N */ |
|
48 | + private $l10n; |
|
49 | + |
|
50 | + /** @var IURLGenerator */ |
|
51 | + private $urlGenerator; |
|
52 | + |
|
53 | + /** @var CardDavBackend */ |
|
54 | + private $backend; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var string[] |
|
58 | + */ |
|
59 | + private static $searchProperties = [ |
|
60 | + 'N', |
|
61 | + 'FN', |
|
62 | + 'NICKNAME', |
|
63 | + 'EMAIL', |
|
64 | + 'TEL', |
|
65 | + 'ADR', |
|
66 | + 'TITLE', |
|
67 | + 'ORG', |
|
68 | + 'NOTE', |
|
69 | + ]; |
|
70 | + |
|
71 | + /** |
|
72 | + * ContactsSearchProvider constructor. |
|
73 | + * |
|
74 | + * @param IAppManager $appManager |
|
75 | + * @param IL10N $l10n |
|
76 | + * @param IURLGenerator $urlGenerator |
|
77 | + * @param CardDavBackend $backend |
|
78 | + */ |
|
79 | + public function __construct(IAppManager $appManager, |
|
80 | + IL10N $l10n, |
|
81 | + IURLGenerator $urlGenerator, |
|
82 | + CardDavBackend $backend) { |
|
83 | + $this->appManager = $appManager; |
|
84 | + $this->l10n = $l10n; |
|
85 | + $this->urlGenerator = $urlGenerator; |
|
86 | + $this->backend = $backend; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @inheritDoc |
|
91 | + */ |
|
92 | + public function getId(): string { |
|
93 | + return 'contacts'; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @inheritDoc |
|
98 | + */ |
|
99 | + public function getName(): string { |
|
100 | + return $this->l10n->t('Contacts'); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @inheritDoc |
|
105 | + */ |
|
106 | + public function getOrder(string $route, array $routeParameters): int { |
|
107 | + if ($route === 'contacts.Page.index') { |
|
108 | + return -1; |
|
109 | + } |
|
110 | + return 25; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @inheritDoc |
|
115 | + */ |
|
116 | + public function search(IUser $user, ISearchQuery $query): SearchResult { |
|
117 | + if (!$this->appManager->isEnabledForUser('contacts', $user)) { |
|
118 | + return SearchResult::complete($this->getName(), []); |
|
119 | + } |
|
120 | + |
|
121 | + $principalUri = 'principals/users/' . $user->getUID(); |
|
122 | + $addressBooks = $this->backend->getAddressBooksForUser($principalUri); |
|
123 | + $addressBooksById = []; |
|
124 | + foreach ($addressBooks as $addressBook) { |
|
125 | + $addressBooksById[(int) $addressBook['id']] = $addressBook; |
|
126 | + } |
|
127 | + |
|
128 | + $searchResults = $this->backend->searchPrincipalUri( |
|
129 | + $principalUri, |
|
130 | + $query->getTerm(), |
|
131 | + self::$searchProperties, |
|
132 | + [ |
|
133 | + 'limit' => $query->getLimit(), |
|
134 | + 'offset' => $query->getCursor(), |
|
135 | + ] |
|
136 | + ); |
|
137 | + $formattedResults = \array_map(function (array $contactRow) use ($addressBooksById):SearchResultEntry { |
|
138 | + $addressBook = $addressBooksById[$contactRow['addressbookid']]; |
|
139 | + |
|
140 | + /** @var VCard $vCard */ |
|
141 | + $vCard = Reader::read($contactRow['carddata']); |
|
142 | + $thumbnailUrl = ''; |
|
143 | + if ($vCard->PHOTO) { |
|
144 | + $thumbnailUrl = $this->getDavUrlForContact($addressBook['principaluri'], $addressBook['uri'], $contactRow['uri']) . '?photo'; |
|
145 | + } |
|
146 | + |
|
147 | + $title = (string)$vCard->FN; |
|
148 | + $subline = $this->generateSubline($vCard); |
|
149 | + $resourceUrl = $this->getDeepLinkToContactsApp($addressBook['uri'], (string) $vCard->UID); |
|
150 | + |
|
151 | + return new SearchResultEntry($thumbnailUrl, $title, $subline, $resourceUrl, 'icon-contacts-dark', true); |
|
152 | + }, $searchResults); |
|
153 | + |
|
154 | + return SearchResult::paginated( |
|
155 | + $this->getName(), |
|
156 | + $formattedResults, |
|
157 | + $query->getCursor() + count($formattedResults) |
|
158 | + ); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @param string $principalUri |
|
163 | + * @param string $addressBookUri |
|
164 | + * @param string $contactsUri |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + protected function getDavUrlForContact(string $principalUri, |
|
168 | + string $addressBookUri, |
|
169 | + string $contactsUri): string { |
|
170 | + [, $principalType, $principalId] = explode('/', $principalUri, 3); |
|
171 | + |
|
172 | + return $this->urlGenerator->getAbsoluteURL( |
|
173 | + $this->urlGenerator->linkTo('', 'remote.php') . '/dav/addressbooks/' |
|
174 | + . $principalType . '/' |
|
175 | + . $principalId . '/' |
|
176 | + . $addressBookUri . '/' |
|
177 | + . $contactsUri |
|
178 | + ); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param string $addressBookUri |
|
183 | + * @param string $contactUid |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + protected function getDeepLinkToContactsApp(string $addressBookUri, |
|
187 | + string $contactUid): string { |
|
188 | + return $this->urlGenerator->getAbsoluteURL( |
|
189 | + $this->urlGenerator->linkToRoute('contacts.contacts.direct', [ |
|
190 | + 'contact' => $contactUid . '~' . $addressBookUri |
|
191 | + ]) |
|
192 | + ); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @param VCard $vCard |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + protected function generateSubline(VCard $vCard): string { |
|
200 | + $emailAddresses = $vCard->select('EMAIL'); |
|
201 | + if (!is_array($emailAddresses) || empty($emailAddresses)) { |
|
202 | + return ''; |
|
203 | + } |
|
204 | + |
|
205 | + return (string)$emailAddresses[0]; |
|
206 | + } |
|
207 | 207 | } |
@@ -36,26 +36,26 @@ |
||
36 | 36 | * @since 8.0.0 |
37 | 37 | */ |
38 | 38 | class Constants { |
39 | - /** |
|
40 | - * CRUDS permissions. |
|
41 | - * @since 8.0.0 |
|
42 | - */ |
|
43 | - public const PERMISSION_CREATE = 4; |
|
44 | - public const PERMISSION_READ = 1; |
|
45 | - public const PERMISSION_UPDATE = 2; |
|
46 | - public const PERMISSION_DELETE = 8; |
|
47 | - public const PERMISSION_SHARE = 16; |
|
48 | - public const PERMISSION_ALL = 31; |
|
39 | + /** |
|
40 | + * CRUDS permissions. |
|
41 | + * @since 8.0.0 |
|
42 | + */ |
|
43 | + public const PERMISSION_CREATE = 4; |
|
44 | + public const PERMISSION_READ = 1; |
|
45 | + public const PERMISSION_UPDATE = 2; |
|
46 | + public const PERMISSION_DELETE = 8; |
|
47 | + public const PERMISSION_SHARE = 16; |
|
48 | + public const PERMISSION_ALL = 31; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @since 8.0.0 - Updated in 9.0.0 to allow all POSIX chars since we no |
|
52 | - * longer support windows as server platform. |
|
53 | - */ |
|
54 | - public const FILENAME_INVALID_CHARS = "\\/"; |
|
50 | + /** |
|
51 | + * @since 8.0.0 - Updated in 9.0.0 to allow all POSIX chars since we no |
|
52 | + * longer support windows as server platform. |
|
53 | + */ |
|
54 | + public const FILENAME_INVALID_CHARS = "\\/"; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @since 21.0.0 – default value for autocomplete/search results limit, |
|
58 | - * cf. sharing.maxAutocompleteResults in config.sample.php. |
|
59 | - */ |
|
60 | - public const SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT = 25; |
|
56 | + /** |
|
57 | + * @since 21.0.0 – default value for autocomplete/search results limit, |
|
58 | + * cf. sharing.maxAutocompleteResults in config.sample.php. |
|
59 | + */ |
|
60 | + public const SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT = 25; |
|
61 | 61 | } |