@@ -2,10 +2,10 @@ |
||
2 | 2 | <div id="nojavascript"> |
3 | 3 | <div> |
4 | 4 | <?php print_unescaped(str_replace( |
5 | - ['{linkstart}', '{linkend}'], |
|
6 | - ['<a href="https://www.enable-javascript.com/" target="_blank" rel="noreferrer noopener">', '</a>'], |
|
7 | - $l->t('This application requires JavaScript for correct operation. Please {linkstart}enable JavaScript{linkend} and reload the page.') |
|
8 | - )); ?> |
|
5 | + ['{linkstart}', '{linkend}'], |
|
6 | + ['<a href="https://www.enable-javascript.com/" target="_blank" rel="noreferrer noopener">', '</a>'], |
|
7 | + $l->t('This application requires JavaScript for correct operation. Please {linkstart}enable JavaScript{linkend} and reload the page.') |
|
8 | + )); ?> |
|
9 | 9 | </div> |
10 | 10 | </div> |
11 | 11 | </noscript> |
@@ -165,15 +165,20 @@ |
||
165 | 165 | <span class="crondate" title="<?php p($absolute_time);?>"> |
166 | 166 | <?php p($l->t("Last job ran %s.", [$relative_time]));?> |
167 | 167 | </span> |
168 | - <?php else: ?> |
|
168 | + <?php else { |
|
169 | + : ?> |
|
169 | 170 | <span class="status error"></span> |
170 | - <span class="crondate" title="<?php p($absolute_time);?>"> |
|
171 | + <span class="crondate" title="<?php p($absolute_time); |
|
172 | +} |
|
173 | +?>"> |
|
171 | 174 | <?php p($l->t("Last job execution ran %s. Something seems wrong.", [$relative_time]));?> |
172 | 175 | </span> |
173 | 176 | <?php endif; |
174 | - else: ?> |
|
177 | + else { |
|
178 | + : ?> |
|
175 | 179 | <span class="status error"></span> |
176 | 180 | <?php p($l->t("Background job didn’t run yet!")); |
181 | + } |
|
177 | 182 | endif; ?> |
178 | 183 | </p> |
179 | 184 | <a target="_blank" rel="noreferrer noopener" class="icon-info" |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | <h2 class="inlineblock"><?php p($l->t('Background jobs'));?></h2> |
31 | 31 | <p class="cronlog inlineblock"> |
32 | 32 | <?php if ($_['lastcron'] !== false): |
33 | - $relative_time = relative_modified_date($_['lastcron']); |
|
33 | + $relative_time = relative_modified_date($_['lastcron']); |
|
34 | 34 | |
35 | - $formatter = \OC::$server->getDateTimeFormatter(); |
|
36 | - $absolute_time = $formatter->formatDateTime($_['lastcron'], 'long', 'long'); |
|
37 | - if (time() - $_['lastcron'] <= 3600): ?> |
|
35 | + $formatter = \OC::$server->getDateTimeFormatter(); |
|
36 | + $absolute_time = $formatter->formatDateTime($_['lastcron'], 'long', 'long'); |
|
37 | + if (time() - $_['lastcron'] <= 3600): ?> |
|
38 | 38 | <span class="status success"></span> |
39 | 39 | <span class="crondate" title="<?php p($absolute_time);?>"> |
40 | 40 | <?php p($l->t("Last job ran %s.", [$relative_time]));?> |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | <?php p($l->t("Last job execution ran %s. Something seems wrong.", [$relative_time]));?> |
46 | 46 | </span> |
47 | 47 | <?php endif; |
48 | - else: ?> |
|
48 | + else: ?> |
|
49 | 49 | <span class="status error"></span> |
50 | 50 | <?php p($l->t("Background job didn’t run yet!")); |
51 | - endif; ?> |
|
51 | + endif; ?> |
|
52 | 52 | </p> |
53 | 53 | <a target="_blank" rel="noreferrer noopener" class="icon-info" |
54 | 54 | title="<?php p($l->t('Open documentation'));?>" |
@@ -58,38 +58,38 @@ discard block |
||
58 | 58 | <p> |
59 | 59 | <input type="radio" name="mode" value="ajax" class="radio" |
60 | 60 | id="backgroundjobs_ajax" <?php if ($_['backgroundjobs_mode'] === "ajax") { |
61 | - print_unescaped('checked="checked"'); |
|
62 | - } ?>> |
|
61 | + print_unescaped('checked="checked"'); |
|
62 | + } ?>> |
|
63 | 63 | <label for="backgroundjobs_ajax">AJAX</label><br/> |
64 | 64 | <em><?php p($l->t("Execute one task with each page loaded")); ?></em> |
65 | 65 | </p> |
66 | 66 | <p> |
67 | 67 | <input type="radio" name="mode" value="webcron" class="radio" |
68 | 68 | id="backgroundjobs_webcron" <?php if ($_['backgroundjobs_mode'] === "webcron") { |
69 | - print_unescaped('checked="checked"'); |
|
70 | - } ?>> |
|
69 | + print_unescaped('checked="checked"'); |
|
70 | + } ?>> |
|
71 | 71 | <label for="backgroundjobs_webcron">Webcron</label><br/> |
72 | 72 | <em><?php p($l->t("cron.php is registered at a webcron service to call cron.php every 15 minutes over HTTP.")); ?></em> |
73 | 73 | </p> |
74 | 74 | <p> |
75 | 75 | <input type="radio" name="mode" value="cron" class="radio" |
76 | 76 | id="backgroundjobs_cron" <?php if ($_['backgroundjobs_mode'] === "cron") { |
77 | - print_unescaped('checked="checked"'); |
|
78 | - } |
|
79 | - if (!$_['cli_based_cron_possible']) { |
|
80 | - print_unescaped('disabled'); |
|
81 | - }?>> |
|
77 | + print_unescaped('checked="checked"'); |
|
78 | + } |
|
79 | + if (!$_['cli_based_cron_possible']) { |
|
80 | + print_unescaped('disabled'); |
|
81 | + }?>> |
|
82 | 82 | <label for="backgroundjobs_cron">Cron</label><br/> |
83 | 83 | <em><?php p($l->t("Use system cron service to call the cron.php file every 15 minutes.")); ?> |
84 | 84 | <?php if($_['cli_based_cron_possible']) { |
85 | - p($l->t('The cron.php needs to be executed by the system user "%s".', [$_['cli_based_cron_user']])); |
|
86 | - } else { |
|
87 | - print_unescaped(str_replace( |
|
88 | - ['{linkstart}', '{linkend}'], |
|
89 | - ['<a href="http://php.net/manual/en/book.posix.php">', ' ↗</a>'], |
|
90 | - $l->t('To run this you need the PHP POSIX extension. See {linkstart}PHP documentation{linkend} for more details.') |
|
91 | - )); |
|
92 | - } ?></em> |
|
85 | + p($l->t('The cron.php needs to be executed by the system user "%s".', [$_['cli_based_cron_user']])); |
|
86 | + } else { |
|
87 | + print_unescaped(str_replace( |
|
88 | + ['{linkstart}', '{linkend}'], |
|
89 | + ['<a href="http://php.net/manual/en/book.posix.php">', ' ↗</a>'], |
|
90 | + $l->t('To run this you need the PHP POSIX extension. See {linkstart}PHP documentation{linkend} for more details.') |
|
91 | + )); |
|
92 | + } ?></em> |
|
93 | 93 | |
94 | 94 | </p> |
95 | 95 | </div> |
96 | 96 | \ No newline at end of file |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | ?> |
28 | 28 | |
29 | 29 | <div class="section" id="backgroundjobs"> |
30 | - <h2 class="inlineblock"><?php p($l->t('Background jobs'));?></h2> |
|
30 | + <h2 class="inlineblock"><?php p($l->t('Background jobs')); ?></h2> |
|
31 | 31 | <p class="cronlog inlineblock"> |
32 | 32 | <?php if ($_['lastcron'] !== false): |
33 | 33 | $relative_time = relative_modified_date($_['lastcron']); |
@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | $absolute_time = $formatter->formatDateTime($_['lastcron'], 'long', 'long'); |
37 | 37 | if (time() - $_['lastcron'] <= 3600): ?> |
38 | 38 | <span class="status success"></span> |
39 | - <span class="crondate" title="<?php p($absolute_time);?>"> |
|
40 | - <?php p($l->t("Last job ran %s.", [$relative_time]));?> |
|
39 | + <span class="crondate" title="<?php p($absolute_time); ?>"> |
|
40 | + <?php p($l->t("Last job ran %s.", [$relative_time])); ?> |
|
41 | 41 | </span> |
42 | 42 | <?php else: ?> |
43 | 43 | <span class="status error"></span> |
44 | - <span class="crondate" title="<?php p($absolute_time);?>"> |
|
45 | - <?php p($l->t("Last job execution ran %s. Something seems wrong.", [$relative_time]));?> |
|
44 | + <span class="crondate" title="<?php p($absolute_time); ?>"> |
|
45 | + <?php p($l->t("Last job execution ran %s. Something seems wrong.", [$relative_time])); ?> |
|
46 | 46 | </span> |
47 | 47 | <?php endif; |
48 | 48 | else: ?> |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | endif; ?> |
52 | 52 | </p> |
53 | 53 | <a target="_blank" rel="noreferrer noopener" class="icon-info" |
54 | - title="<?php p($l->t('Open documentation'));?>" |
|
54 | + title="<?php p($l->t('Open documentation')); ?>" |
|
55 | 55 | href="<?php p(link_to_docs('admin-background-jobs')); ?>"></a> |
56 | 56 | |
57 | - <p class="settings-hint"><?php p($l->t('For optimal performance it\'s important to configure background jobs correctly. For bigger instances \'Cron\' is the recommended setting. Please see the documentation for more information.'));?></p> |
|
57 | + <p class="settings-hint"><?php p($l->t('For optimal performance it\'s important to configure background jobs correctly. For bigger instances \'Cron\' is the recommended setting. Please see the documentation for more information.')); ?></p> |
|
58 | 58 | <p> |
59 | 59 | <input type="radio" name="mode" value="ajax" class="radio" |
60 | 60 | id="backgroundjobs_ajax" <?php if ($_['backgroundjobs_mode'] === "ajax") { |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | }?>> |
82 | 82 | <label for="backgroundjobs_cron">Cron</label><br/> |
83 | 83 | <em><?php p($l->t("Use system cron service to call the cron.php file every 15 minutes.")); ?> |
84 | - <?php if($_['cli_based_cron_possible']) { |
|
84 | + <?php if ($_['cli_based_cron_possible']) { |
|
85 | 85 | p($l->t('The cron.php needs to be executed by the system user "%s".', [$_['cli_based_cron_user']])); |
86 | 86 | } else { |
87 | 87 | print_unescaped(str_replace( |
@@ -33,18 +33,18 @@ |
||
33 | 33 | */ |
34 | 34 | interface ISorter { |
35 | 35 | |
36 | - /** |
|
37 | - * @return string The ID of the sorter, e.g. commenters |
|
38 | - * @since 13.0.0 |
|
39 | - */ |
|
40 | - public function getId(); |
|
36 | + /** |
|
37 | + * @return string The ID of the sorter, e.g. commenters |
|
38 | + * @since 13.0.0 |
|
39 | + */ |
|
40 | + public function getId(); |
|
41 | 41 | |
42 | - /** |
|
43 | - * executes the sort action |
|
44 | - * |
|
45 | - * @param array $sortArray the array to be sorted, provided as reference |
|
46 | - * @param array $context carries key 'itemType' and 'itemId' of the source object (e.g. a file) |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function sort(array &$sortArray, array $context); |
|
42 | + /** |
|
43 | + * executes the sort action |
|
44 | + * |
|
45 | + * @param array $sortArray the array to be sorted, provided as reference |
|
46 | + * @param array $context carries key 'itemType' and 'itemId' of the source object (e.g. a file) |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function sort(array &$sortArray, array $context); |
|
50 | 50 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | */ |
23 | 23 | |
24 | 24 | script('dav', [ |
25 | - 'settings-admin-caldav' |
|
25 | + 'settings-admin-caldav' |
|
26 | 26 | ]); |
27 | 27 | |
28 | 28 | /** @var \OCP\IL10N $l */ |
@@ -31,42 +31,42 @@ |
||
31 | 31 | * Mount provider for custom cache storages |
32 | 32 | */ |
33 | 33 | class CacheMountProvider implements IMountProvider { |
34 | - /** |
|
35 | - * @var IConfig |
|
36 | - */ |
|
37 | - private $config; |
|
34 | + /** |
|
35 | + * @var IConfig |
|
36 | + */ |
|
37 | + private $config; |
|
38 | 38 | |
39 | - /** |
|
40 | - * ObjectStoreHomeMountProvider constructor. |
|
41 | - * |
|
42 | - * @param IConfig $config |
|
43 | - */ |
|
44 | - public function __construct(IConfig $config) { |
|
45 | - $this->config = $config; |
|
46 | - } |
|
39 | + /** |
|
40 | + * ObjectStoreHomeMountProvider constructor. |
|
41 | + * |
|
42 | + * @param IConfig $config |
|
43 | + */ |
|
44 | + public function __construct(IConfig $config) { |
|
45 | + $this->config = $config; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Get the cache mount for a user |
|
50 | - * |
|
51 | - * @param IUser $user |
|
52 | - * @param IStorageFactory $loader |
|
53 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
54 | - */ |
|
55 | - public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
56 | - $cacheBaseDir = $this->config->getSystemValue('cache_path', ''); |
|
57 | - if ($cacheBaseDir !== '') { |
|
58 | - $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); |
|
59 | - if (!file_exists($cacheDir)) { |
|
60 | - mkdir($cacheDir, 0770, true); |
|
61 | - mkdir($cacheDir . '/uploads', 0770, true); |
|
62 | - } |
|
48 | + /** |
|
49 | + * Get the cache mount for a user |
|
50 | + * |
|
51 | + * @param IUser $user |
|
52 | + * @param IStorageFactory $loader |
|
53 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
54 | + */ |
|
55 | + public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
56 | + $cacheBaseDir = $this->config->getSystemValue('cache_path', ''); |
|
57 | + if ($cacheBaseDir !== '') { |
|
58 | + $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); |
|
59 | + if (!file_exists($cacheDir)) { |
|
60 | + mkdir($cacheDir, 0770, true); |
|
61 | + mkdir($cacheDir . '/uploads', 0770, true); |
|
62 | + } |
|
63 | 63 | |
64 | - return [ |
|
65 | - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir, $loader]), |
|
66 | - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads', $loader]) |
|
67 | - ]; |
|
68 | - } else { |
|
69 | - return []; |
|
70 | - } |
|
71 | - } |
|
64 | + return [ |
|
65 | + new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir, $loader]), |
|
66 | + new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads', $loader]) |
|
67 | + ]; |
|
68 | + } else { |
|
69 | + return []; |
|
70 | + } |
|
71 | + } |
|
72 | 72 | } |
@@ -55,15 +55,15 @@ |
||
55 | 55 | public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
56 | 56 | $cacheBaseDir = $this->config->getSystemValue('cache_path', ''); |
57 | 57 | if ($cacheBaseDir !== '') { |
58 | - $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID(); |
|
58 | + $cacheDir = rtrim($cacheBaseDir, '/').'/'.$user->getUID(); |
|
59 | 59 | if (!file_exists($cacheDir)) { |
60 | 60 | mkdir($cacheDir, 0770, true); |
61 | - mkdir($cacheDir . '/uploads', 0770, true); |
|
61 | + mkdir($cacheDir.'/uploads', 0770, true); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | return [ |
65 | - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/cache', ['datadir' => $cacheDir, $loader]), |
|
66 | - new MountPoint('\OC\Files\Storage\Local', '/' . $user->getUID() . '/uploads', ['datadir' => $cacheDir . '/uploads', $loader]) |
|
65 | + new MountPoint('\OC\Files\Storage\Local', '/'.$user->getUID().'/cache', ['datadir' => $cacheDir, $loader]), |
|
66 | + new MountPoint('\OC\Files\Storage\Local', '/'.$user->getUID().'/uploads', ['datadir' => $cacheDir.'/uploads', $loader]) |
|
67 | 67 | ]; |
68 | 68 | } else { |
69 | 69 | return []; |
@@ -11,32 +11,32 @@ |
||
11 | 11 | */ |
12 | 12 | class Version13000Date20170926101637 extends BigIntMigration { |
13 | 13 | |
14 | - /** |
|
15 | - * @return array Returns an array with the following structure |
|
16 | - * ['table1' => ['column1', 'column2'], ...] |
|
17 | - * @since 13.0.0 |
|
18 | - */ |
|
19 | - protected function getColumnsByTable() { |
|
20 | - return [ |
|
21 | - 'admin_settings' => ['id'], |
|
22 | - 'authtoken' => ['id'], |
|
23 | - 'bruteforce_attempts' => ['id'], |
|
24 | - 'comments' => ['id', 'parent_id', 'topmost_parent_id'], |
|
25 | - // Disabled for now 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart'], |
|
26 | - 'file_locks' => ['id'], |
|
27 | - 'jobs' => ['id'], |
|
28 | - // Disabled for now 'mimetypes' => ['id'], |
|
29 | - 'mounts' => ['id'], |
|
30 | - 'personal_settings' => ['id'], |
|
31 | - 'properties' => ['id'], |
|
32 | - 'share' => ['id', 'parent', 'file_source'], |
|
33 | - // Disabled for now 'storages' => ['numeric_id'], |
|
34 | - 'systemtag' => ['id'], |
|
35 | - 'systemtag_group' => ['systemtagid'], |
|
36 | - 'systemtag_object_mapping' => ['systemtagid'], |
|
37 | - 'vcategory' => ['id'], |
|
38 | - 'vcategory_to_object' => ['objid', 'categoryid'], |
|
39 | - ]; |
|
40 | - } |
|
14 | + /** |
|
15 | + * @return array Returns an array with the following structure |
|
16 | + * ['table1' => ['column1', 'column2'], ...] |
|
17 | + * @since 13.0.0 |
|
18 | + */ |
|
19 | + protected function getColumnsByTable() { |
|
20 | + return [ |
|
21 | + 'admin_settings' => ['id'], |
|
22 | + 'authtoken' => ['id'], |
|
23 | + 'bruteforce_attempts' => ['id'], |
|
24 | + 'comments' => ['id', 'parent_id', 'topmost_parent_id'], |
|
25 | + // Disabled for now 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart'], |
|
26 | + 'file_locks' => ['id'], |
|
27 | + 'jobs' => ['id'], |
|
28 | + // Disabled for now 'mimetypes' => ['id'], |
|
29 | + 'mounts' => ['id'], |
|
30 | + 'personal_settings' => ['id'], |
|
31 | + 'properties' => ['id'], |
|
32 | + 'share' => ['id', 'parent', 'file_source'], |
|
33 | + // Disabled for now 'storages' => ['numeric_id'], |
|
34 | + 'systemtag' => ['id'], |
|
35 | + 'systemtag_group' => ['systemtagid'], |
|
36 | + 'systemtag_object_mapping' => ['systemtagid'], |
|
37 | + 'vcategory' => ['id'], |
|
38 | + 'vcategory_to_object' => ['objid', 'categoryid'], |
|
39 | + ]; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
@@ -79,7 +79,7 @@ |
||
79 | 79 | $column->setType(Type::getType(Type::BIGINT)); |
80 | 80 | $column->setOptions(['length' => 20]); |
81 | 81 | |
82 | - $updates[] = $tableName . '.' . $columnName; |
|
82 | + $updates[] = $tableName.'.'.$columnName; |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | } |
@@ -33,75 +33,75 @@ |
||
33 | 33 | |
34 | 34 | class ConvertFilecacheBigInt extends Command { |
35 | 35 | |
36 | - /** @var IDBConnection */ |
|
37 | - private $connection; |
|
38 | - |
|
39 | - /** |
|
40 | - * @param IDBConnection $connection |
|
41 | - */ |
|
42 | - public function __construct(IDBConnection $connection) { |
|
43 | - $this->connection = $connection; |
|
44 | - parent::__construct(); |
|
45 | - } |
|
46 | - |
|
47 | - protected function configure() { |
|
48 | - $this |
|
49 | - ->setName('db:convert-filecache-bigint') |
|
50 | - ->setDescription('Convert the ID columns of the filecache to BigInt'); |
|
51 | - } |
|
52 | - |
|
53 | - protected function getColumnsByTable() { |
|
54 | - return [ |
|
55 | - 'activity' => ['activity_id', 'object_id'], |
|
56 | - 'activity_mq' => ['mail_id'], |
|
57 | - 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'], |
|
58 | - 'mimetypes' => ['id'], |
|
59 | - 'storages' => ['numeric_id'], |
|
60 | - ]; |
|
61 | - } |
|
62 | - |
|
63 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
64 | - |
|
65 | - $schema = new SchemaWrapper($this->connection); |
|
66 | - $updates = []; |
|
67 | - |
|
68 | - $tables = $this->getColumnsByTable(); |
|
69 | - foreach ($tables as $tableName => $columns) { |
|
70 | - if (!$schema->hasTable($tableName)) { |
|
71 | - continue; |
|
72 | - } |
|
73 | - |
|
74 | - $table = $schema->getTable($tableName); |
|
75 | - |
|
76 | - foreach ($columns as $columnName) { |
|
77 | - $column = $table->getColumn($columnName); |
|
78 | - if ($column->getType()->getName() !== Type::BIGINT) { |
|
79 | - $column->setType(Type::getType(Type::BIGINT)); |
|
80 | - $column->setOptions(['length' => 20]); |
|
81 | - |
|
82 | - $updates[] = $tableName . '.' . $columnName; |
|
83 | - } |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - if (empty($updates)) { |
|
88 | - $output->writeln('<info>All tables already up to date!</info>'); |
|
89 | - return 0; |
|
90 | - } |
|
91 | - |
|
92 | - $output->writeln('<comment>This can take up to hours, depending on the number of files in your instance!</comment>'); |
|
93 | - |
|
94 | - if ($input->isInteractive()) { |
|
95 | - $helper = $this->getHelper('question'); |
|
96 | - $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false); |
|
97 | - |
|
98 | - if (!$helper->ask($input, $output, $question)) { |
|
99 | - return 1; |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
104 | - |
|
105 | - return 0; |
|
106 | - } |
|
36 | + /** @var IDBConnection */ |
|
37 | + private $connection; |
|
38 | + |
|
39 | + /** |
|
40 | + * @param IDBConnection $connection |
|
41 | + */ |
|
42 | + public function __construct(IDBConnection $connection) { |
|
43 | + $this->connection = $connection; |
|
44 | + parent::__construct(); |
|
45 | + } |
|
46 | + |
|
47 | + protected function configure() { |
|
48 | + $this |
|
49 | + ->setName('db:convert-filecache-bigint') |
|
50 | + ->setDescription('Convert the ID columns of the filecache to BigInt'); |
|
51 | + } |
|
52 | + |
|
53 | + protected function getColumnsByTable() { |
|
54 | + return [ |
|
55 | + 'activity' => ['activity_id', 'object_id'], |
|
56 | + 'activity_mq' => ['mail_id'], |
|
57 | + 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'], |
|
58 | + 'mimetypes' => ['id'], |
|
59 | + 'storages' => ['numeric_id'], |
|
60 | + ]; |
|
61 | + } |
|
62 | + |
|
63 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
64 | + |
|
65 | + $schema = new SchemaWrapper($this->connection); |
|
66 | + $updates = []; |
|
67 | + |
|
68 | + $tables = $this->getColumnsByTable(); |
|
69 | + foreach ($tables as $tableName => $columns) { |
|
70 | + if (!$schema->hasTable($tableName)) { |
|
71 | + continue; |
|
72 | + } |
|
73 | + |
|
74 | + $table = $schema->getTable($tableName); |
|
75 | + |
|
76 | + foreach ($columns as $columnName) { |
|
77 | + $column = $table->getColumn($columnName); |
|
78 | + if ($column->getType()->getName() !== Type::BIGINT) { |
|
79 | + $column->setType(Type::getType(Type::BIGINT)); |
|
80 | + $column->setOptions(['length' => 20]); |
|
81 | + |
|
82 | + $updates[] = $tableName . '.' . $columnName; |
|
83 | + } |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + if (empty($updates)) { |
|
88 | + $output->writeln('<info>All tables already up to date!</info>'); |
|
89 | + return 0; |
|
90 | + } |
|
91 | + |
|
92 | + $output->writeln('<comment>This can take up to hours, depending on the number of files in your instance!</comment>'); |
|
93 | + |
|
94 | + if ($input->isInteractive()) { |
|
95 | + $helper = $this->getHelper('question'); |
|
96 | + $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false); |
|
97 | + |
|
98 | + if (!$helper->ask($input, $output, $question)) { |
|
99 | + return 1; |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + $this->connection->migrateToSchema($schema->getWrappedSchema()); |
|
104 | + |
|
105 | + return 0; |
|
106 | + } |
|
107 | 107 | } |
@@ -30,141 +30,141 @@ |
||
30 | 30 | */ |
31 | 31 | class PluginManager { |
32 | 32 | |
33 | - /** |
|
34 | - * @var ServerContainer |
|
35 | - */ |
|
36 | - private $container; |
|
33 | + /** |
|
34 | + * @var ServerContainer |
|
35 | + */ |
|
36 | + private $container; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var IAppManager |
|
40 | - */ |
|
41 | - private $appManager; |
|
38 | + /** |
|
39 | + * @var IAppManager |
|
40 | + */ |
|
41 | + private $appManager; |
|
42 | 42 | |
43 | - /** |
|
44 | - * App plugins |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - private $plugins = null; |
|
43 | + /** |
|
44 | + * App plugins |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + private $plugins = null; |
|
49 | 49 | |
50 | - /** |
|
51 | - * App collections |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - private $collections = null; |
|
50 | + /** |
|
51 | + * App collections |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + private $collections = null; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Contstruct a PluginManager |
|
59 | - * |
|
60 | - * @param ServerContainer $container server container for resolving plugin classes |
|
61 | - * @param IAppManager $appManager app manager to loading apps and their info |
|
62 | - */ |
|
63 | - public function __construct(ServerContainer $container, IAppManager $appManager) { |
|
64 | - $this->container = $container; |
|
65 | - $this->appManager = $appManager; |
|
66 | - } |
|
57 | + /** |
|
58 | + * Contstruct a PluginManager |
|
59 | + * |
|
60 | + * @param ServerContainer $container server container for resolving plugin classes |
|
61 | + * @param IAppManager $appManager app manager to loading apps and their info |
|
62 | + */ |
|
63 | + public function __construct(ServerContainer $container, IAppManager $appManager) { |
|
64 | + $this->container = $container; |
|
65 | + $this->appManager = $appManager; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Returns an array of app-registered plugins |
|
70 | - * |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public function getAppPlugins() { |
|
74 | - if (null === $this->plugins) { |
|
75 | - $this->populate(); |
|
76 | - } |
|
77 | - return $this->plugins; |
|
78 | - } |
|
68 | + /** |
|
69 | + * Returns an array of app-registered plugins |
|
70 | + * |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public function getAppPlugins() { |
|
74 | + if (null === $this->plugins) { |
|
75 | + $this->populate(); |
|
76 | + } |
|
77 | + return $this->plugins; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Returns an array of app-registered collections |
|
82 | - * |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - public function getAppCollections() { |
|
86 | - if (null === $this->collections) { |
|
87 | - $this->populate(); |
|
88 | - } |
|
89 | - return $this->collections; |
|
90 | - } |
|
80 | + /** |
|
81 | + * Returns an array of app-registered collections |
|
82 | + * |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + public function getAppCollections() { |
|
86 | + if (null === $this->collections) { |
|
87 | + $this->populate(); |
|
88 | + } |
|
89 | + return $this->collections; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Retrieve plugin and collection list and populate attributes |
|
94 | - */ |
|
95 | - private function populate() { |
|
96 | - $this->plugins = []; |
|
97 | - $this->collections = []; |
|
98 | - foreach ($this->appManager->getInstalledApps() as $app) { |
|
99 | - // load plugins and collections from info.xml |
|
100 | - $info = $this->appManager->getAppInfo($app); |
|
101 | - if (!isset($info['types']) || !in_array('dav', $info['types'], true)) { |
|
102 | - continue; |
|
103 | - } |
|
104 | - // FIXME: switch to public API once available |
|
105 | - // load app to make sure its classes are available |
|
106 | - \OC_App::loadApp($app); |
|
107 | - $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info)); |
|
108 | - $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info)); |
|
109 | - } |
|
110 | - } |
|
92 | + /** |
|
93 | + * Retrieve plugin and collection list and populate attributes |
|
94 | + */ |
|
95 | + private function populate() { |
|
96 | + $this->plugins = []; |
|
97 | + $this->collections = []; |
|
98 | + foreach ($this->appManager->getInstalledApps() as $app) { |
|
99 | + // load plugins and collections from info.xml |
|
100 | + $info = $this->appManager->getAppInfo($app); |
|
101 | + if (!isset($info['types']) || !in_array('dav', $info['types'], true)) { |
|
102 | + continue; |
|
103 | + } |
|
104 | + // FIXME: switch to public API once available |
|
105 | + // load app to make sure its classes are available |
|
106 | + \OC_App::loadApp($app); |
|
107 | + $this->loadSabrePluginsFromInfoXml($this->extractPluginList($info)); |
|
108 | + $this->loadSabreCollectionsFromInfoXml($this->extractCollectionList($info)); |
|
109 | + } |
|
110 | + } |
|
111 | 111 | |
112 | - private function extractPluginList(array $array) { |
|
113 | - if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
114 | - if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) { |
|
115 | - if (isset($array['sabre']['plugins']['plugin'])) { |
|
116 | - $items = $array['sabre']['plugins']['plugin']; |
|
117 | - if (!is_array($items)) { |
|
118 | - $items = [$items]; |
|
119 | - } |
|
120 | - return $items; |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
124 | - return []; |
|
125 | - } |
|
112 | + private function extractPluginList(array $array) { |
|
113 | + if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
114 | + if (isset($array['sabre']['plugins']) && is_array($array['sabre']['plugins'])) { |
|
115 | + if (isset($array['sabre']['plugins']['plugin'])) { |
|
116 | + $items = $array['sabre']['plugins']['plugin']; |
|
117 | + if (!is_array($items)) { |
|
118 | + $items = [$items]; |
|
119 | + } |
|
120 | + return $items; |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | + return []; |
|
125 | + } |
|
126 | 126 | |
127 | - private function extractCollectionList(array $array) { |
|
128 | - if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
129 | - if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) { |
|
130 | - if (isset($array['sabre']['collections']['collection'])) { |
|
131 | - $items = $array['sabre']['collections']['collection']; |
|
132 | - if (!is_array($items)) { |
|
133 | - $items = [$items]; |
|
134 | - } |
|
135 | - return $items; |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - return []; |
|
140 | - } |
|
127 | + private function extractCollectionList(array $array) { |
|
128 | + if (isset($array['sabre']) && is_array($array['sabre'])) { |
|
129 | + if (isset($array['sabre']['collections']) && is_array($array['sabre']['collections'])) { |
|
130 | + if (isset($array['sabre']['collections']['collection'])) { |
|
131 | + $items = $array['sabre']['collections']['collection']; |
|
132 | + if (!is_array($items)) { |
|
133 | + $items = [$items]; |
|
134 | + } |
|
135 | + return $items; |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + return []; |
|
140 | + } |
|
141 | 141 | |
142 | - private function loadSabrePluginsFromInfoXml(array $plugins) { |
|
143 | - foreach ($plugins as $plugin) { |
|
144 | - try { |
|
145 | - $this->plugins[] = $this->container->query($plugin); |
|
146 | - } catch (QueryException $e) { |
|
147 | - if (class_exists($plugin)) { |
|
148 | - $this->plugins[] = new $plugin(); |
|
149 | - } else { |
|
150 | - throw new \Exception("Sabre plugin class '$plugin' is unknown and could not be loaded"); |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
142 | + private function loadSabrePluginsFromInfoXml(array $plugins) { |
|
143 | + foreach ($plugins as $plugin) { |
|
144 | + try { |
|
145 | + $this->plugins[] = $this->container->query($plugin); |
|
146 | + } catch (QueryException $e) { |
|
147 | + if (class_exists($plugin)) { |
|
148 | + $this->plugins[] = new $plugin(); |
|
149 | + } else { |
|
150 | + throw new \Exception("Sabre plugin class '$plugin' is unknown and could not be loaded"); |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + } |
|
155 | 155 | |
156 | - private function loadSabreCollectionsFromInfoXml(array $collections) { |
|
157 | - foreach ($collections as $collection) { |
|
158 | - try { |
|
159 | - $this->collections[] = $this->container->query($collection); |
|
160 | - } catch (QueryException $e) { |
|
161 | - if (class_exists($collection)) { |
|
162 | - $this->collections[] = new $collection(); |
|
163 | - } else { |
|
164 | - throw new \Exception("Sabre collection class '$collection' is unknown and could not be loaded"); |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
156 | + private function loadSabreCollectionsFromInfoXml(array $collections) { |
|
157 | + foreach ($collections as $collection) { |
|
158 | + try { |
|
159 | + $this->collections[] = $this->container->query($collection); |
|
160 | + } catch (QueryException $e) { |
|
161 | + if (class_exists($collection)) { |
|
162 | + $this->collections[] = new $collection(); |
|
163 | + } else { |
|
164 | + throw new \Exception("Sabre collection class '$collection' is unknown and could not be loaded"); |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | 169 | |
170 | 170 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | foreach ($users as $user) { |
134 | 134 | $event->setAffectedUser($user) |
135 | 135 | ->setSubject( |
136 | - $user === $currentUser ? $action . '_self' : $action, |
|
136 | + $user === $currentUser ? $action.'_self' : $action, |
|
137 | 137 | [ |
138 | 138 | 'actor' => $currentUser, |
139 | 139 | 'calendar' => [ |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $event, |
187 | 187 | $calendarData, |
188 | 188 | Calendar::SUBJECT_UNSHARE_USER, |
189 | - Calendar::SUBJECT_DELETE . '_self' |
|
189 | + Calendar::SUBJECT_DELETE.'_self' |
|
190 | 190 | ); |
191 | 191 | |
192 | 192 | if ($owner !== $principal[2]) { |
@@ -201,15 +201,15 @@ discard block |
||
201 | 201 | ]; |
202 | 202 | |
203 | 203 | if ($owner === $event->getAuthor()) { |
204 | - $subject = Calendar::SUBJECT_UNSHARE_USER . '_you'; |
|
204 | + $subject = Calendar::SUBJECT_UNSHARE_USER.'_you'; |
|
205 | 205 | } else if ($principal[2] === $event->getAuthor()) { |
206 | - $subject = Calendar::SUBJECT_UNSHARE_USER . '_self'; |
|
206 | + $subject = Calendar::SUBJECT_UNSHARE_USER.'_self'; |
|
207 | 207 | } else { |
208 | 208 | $event->setAffectedUser($event->getAuthor()) |
209 | - ->setSubject(Calendar::SUBJECT_UNSHARE_USER . '_you', $parameters); |
|
209 | + ->setSubject(Calendar::SUBJECT_UNSHARE_USER.'_you', $parameters); |
|
210 | 210 | $this->activityManager->publish($event); |
211 | 211 | |
212 | - $subject = Calendar::SUBJECT_UNSHARE_USER . '_by'; |
|
212 | + $subject = Calendar::SUBJECT_UNSHARE_USER.'_by'; |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | $event->setAffectedUser($owner) |
@@ -230,13 +230,13 @@ discard block |
||
230 | 230 | ]; |
231 | 231 | |
232 | 232 | if ($owner === $event->getAuthor()) { |
233 | - $subject = Calendar::SUBJECT_UNSHARE_GROUP . '_you'; |
|
233 | + $subject = Calendar::SUBJECT_UNSHARE_GROUP.'_you'; |
|
234 | 234 | } else { |
235 | 235 | $event->setAffectedUser($event->getAuthor()) |
236 | - ->setSubject(Calendar::SUBJECT_UNSHARE_GROUP . '_you', $parameters); |
|
236 | + ->setSubject(Calendar::SUBJECT_UNSHARE_GROUP.'_you', $parameters); |
|
237 | 237 | $this->activityManager->publish($event); |
238 | 238 | |
239 | - $subject = Calendar::SUBJECT_UNSHARE_GROUP . '_by'; |
|
239 | + $subject = Calendar::SUBJECT_UNSHARE_GROUP.'_by'; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | $event->setAffectedUser($owner) |
@@ -272,13 +272,13 @@ discard block |
||
272 | 272 | ]; |
273 | 273 | |
274 | 274 | if ($owner === $event->getAuthor()) { |
275 | - $subject = Calendar::SUBJECT_SHARE_USER . '_you'; |
|
275 | + $subject = Calendar::SUBJECT_SHARE_USER.'_you'; |
|
276 | 276 | } else { |
277 | 277 | $event->setAffectedUser($event->getAuthor()) |
278 | - ->setSubject(Calendar::SUBJECT_SHARE_USER . '_you', $parameters); |
|
278 | + ->setSubject(Calendar::SUBJECT_SHARE_USER.'_you', $parameters); |
|
279 | 279 | $this->activityManager->publish($event); |
280 | 280 | |
281 | - $subject = Calendar::SUBJECT_SHARE_USER . '_by'; |
|
281 | + $subject = Calendar::SUBJECT_SHARE_USER.'_by'; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | $event->setAffectedUser($owner) |
@@ -299,13 +299,13 @@ discard block |
||
299 | 299 | ]; |
300 | 300 | |
301 | 301 | if ($owner === $event->getAuthor()) { |
302 | - $subject = Calendar::SUBJECT_SHARE_GROUP . '_you'; |
|
302 | + $subject = Calendar::SUBJECT_SHARE_GROUP.'_you'; |
|
303 | 303 | } else { |
304 | 304 | $event->setAffectedUser($event->getAuthor()) |
305 | - ->setSubject(Calendar::SUBJECT_SHARE_GROUP . '_you', $parameters); |
|
305 | + ->setSubject(Calendar::SUBJECT_SHARE_GROUP.'_you', $parameters); |
|
306 | 306 | $this->activityManager->publish($event); |
307 | 307 | |
308 | - $subject = Calendar::SUBJECT_SHARE_GROUP . '_by'; |
|
308 | + $subject = Calendar::SUBJECT_SHARE_GROUP.'_by'; |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | $event->setAffectedUser($owner) |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | } |
404 | 404 | |
405 | 405 | $object = $this->getObjectNameAndType($objectData); |
406 | - $action = $action . '_' . $object['type']; |
|
406 | + $action = $action.'_'.$object['type']; |
|
407 | 407 | |
408 | 408 | if ($object['type'] === 'todo' && strpos($action, Event::SUBJECT_OBJECT_UPDATE) === 0 && $object['status'] === 'COMPLETED') { |
409 | 409 | $action .= '_completed'; |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | foreach ($users as $user) { |
424 | 424 | $event->setAffectedUser($user) |
425 | 425 | ->setSubject( |
426 | - $user === $currentUser ? $action . '_self' : $action, |
|
426 | + $user === $currentUser ? $action.'_self' : $action, |
|
427 | 427 | [ |
428 | 428 | 'actor' => $event->getAuthor(), |
429 | 429 | 'calendar' => [ |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | protected function getObjectNameAndType(array $objectData) { |
449 | 449 | $vObject = Reader::read($objectData['calendardata']); |
450 | 450 | $component = $componentType = null; |
451 | - foreach($vObject->getComponents() as $component) { |
|
451 | + foreach ($vObject->getComponents() as $component) { |
|
452 | 452 | if (in_array($component->name, ['VEVENT', 'VTODO'])) { |
453 | 453 | $componentType = $component->name; |
454 | 454 | break; |
@@ -42,471 +42,471 @@ |
||
42 | 42 | */ |
43 | 43 | class Backend { |
44 | 44 | |
45 | - /** @var IActivityManager */ |
|
46 | - protected $activityManager; |
|
47 | - |
|
48 | - /** @var IGroupManager */ |
|
49 | - protected $groupManager; |
|
50 | - |
|
51 | - /** @var IUserSession */ |
|
52 | - protected $userSession; |
|
53 | - |
|
54 | - /** |
|
55 | - * @param IActivityManager $activityManager |
|
56 | - * @param IGroupManager $groupManager |
|
57 | - * @param IUserSession $userSession |
|
58 | - */ |
|
59 | - public function __construct(IActivityManager $activityManager, IGroupManager $groupManager, IUserSession $userSession) { |
|
60 | - $this->activityManager = $activityManager; |
|
61 | - $this->groupManager = $groupManager; |
|
62 | - $this->userSession = $userSession; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Creates activities when a calendar was creates |
|
67 | - * |
|
68 | - * @param array $calendarData |
|
69 | - */ |
|
70 | - public function onCalendarAdd(array $calendarData) { |
|
71 | - $this->triggerCalendarActivity(Calendar::SUBJECT_ADD, $calendarData); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Creates activities when a calendar was updated |
|
76 | - * |
|
77 | - * @param array $calendarData |
|
78 | - * @param array $shares |
|
79 | - * @param array $properties |
|
80 | - */ |
|
81 | - public function onCalendarUpdate(array $calendarData, array $shares, array $properties) { |
|
82 | - $this->triggerCalendarActivity(Calendar::SUBJECT_UPDATE, $calendarData, $shares, $properties); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Creates activities when a calendar was deleted |
|
87 | - * |
|
88 | - * @param array $calendarData |
|
89 | - * @param array $shares |
|
90 | - */ |
|
91 | - public function onCalendarDelete(array $calendarData, array $shares) { |
|
92 | - $this->triggerCalendarActivity(Calendar::SUBJECT_DELETE, $calendarData, $shares); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Creates activities when a calendar was (un)published |
|
97 | - * |
|
98 | - * @param array $calendarData |
|
99 | - * @param bool $publishStatus |
|
100 | - */ |
|
101 | - public function onCalendarPublication(array $calendarData, $publishStatus) { |
|
102 | - $this->triggerCalendarActivity($publishStatus ? Calendar::SUBJECT_PUBLISH : Calendar::SUBJECT_UNPUBLISH, $calendarData); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Creates activities for all related users when a calendar was touched |
|
107 | - * |
|
108 | - * @param string $action |
|
109 | - * @param array $calendarData |
|
110 | - * @param array $shares |
|
111 | - * @param array $changedProperties |
|
112 | - */ |
|
113 | - protected function triggerCalendarActivity($action, array $calendarData, array $shares = [], array $changedProperties = []) { |
|
114 | - if (!isset($calendarData['principaluri'])) { |
|
115 | - return; |
|
116 | - } |
|
117 | - |
|
118 | - $principal = explode('/', $calendarData['principaluri']); |
|
119 | - $owner = array_pop($principal); |
|
120 | - |
|
121 | - $currentUser = $this->userSession->getUser(); |
|
122 | - if ($currentUser instanceof IUser) { |
|
123 | - $currentUser = $currentUser->getUID(); |
|
124 | - } else { |
|
125 | - $currentUser = $owner; |
|
126 | - } |
|
127 | - |
|
128 | - $event = $this->activityManager->generateEvent(); |
|
129 | - $event->setApp('dav') |
|
130 | - ->setObject('calendar', (int) $calendarData['id']) |
|
131 | - ->setType('calendar') |
|
132 | - ->setAuthor($currentUser); |
|
133 | - |
|
134 | - $changedVisibleInformation = array_intersect([ |
|
135 | - '{DAV:}displayname', |
|
136 | - '{http://apple.com/ns/ical/}calendar-color' |
|
137 | - ], array_keys($changedProperties)); |
|
138 | - |
|
139 | - if (empty($shares) || ($action === Calendar::SUBJECT_UPDATE && empty($changedVisibleInformation))) { |
|
140 | - $users = [$owner]; |
|
141 | - } else { |
|
142 | - $users = $this->getUsersForShares($shares); |
|
143 | - $users[] = $owner; |
|
144 | - } |
|
145 | - |
|
146 | - foreach ($users as $user) { |
|
147 | - $event->setAffectedUser($user) |
|
148 | - ->setSubject( |
|
149 | - $user === $currentUser ? $action . '_self' : $action, |
|
150 | - [ |
|
151 | - 'actor' => $currentUser, |
|
152 | - 'calendar' => [ |
|
153 | - 'id' => (int) $calendarData['id'], |
|
154 | - 'uri' => $calendarData['uri'], |
|
155 | - 'name' => $calendarData['{DAV:}displayname'], |
|
156 | - ], |
|
157 | - ] |
|
158 | - ); |
|
159 | - $this->activityManager->publish($event); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Creates activities for all related users when a calendar was (un-)shared |
|
165 | - * |
|
166 | - * @param array $calendarData |
|
167 | - * @param array $shares |
|
168 | - * @param array $add |
|
169 | - * @param array $remove |
|
170 | - */ |
|
171 | - public function onCalendarUpdateShares(array $calendarData, array $shares, array $add, array $remove) { |
|
172 | - $principal = explode('/', $calendarData['principaluri']); |
|
173 | - $owner = $principal[2]; |
|
174 | - |
|
175 | - $currentUser = $this->userSession->getUser(); |
|
176 | - if ($currentUser instanceof IUser) { |
|
177 | - $currentUser = $currentUser->getUID(); |
|
178 | - } else { |
|
179 | - $currentUser = $owner; |
|
180 | - } |
|
181 | - |
|
182 | - $event = $this->activityManager->generateEvent(); |
|
183 | - $event->setApp('dav') |
|
184 | - ->setObject('calendar', (int) $calendarData['id']) |
|
185 | - ->setType('calendar') |
|
186 | - ->setAuthor($currentUser); |
|
187 | - |
|
188 | - foreach ($remove as $principal) { |
|
189 | - // principal:principals/users/test |
|
190 | - $parts = explode(':', $principal, 2); |
|
191 | - if ($parts[0] !== 'principal') { |
|
192 | - continue; |
|
193 | - } |
|
194 | - $principal = explode('/', $parts[1]); |
|
195 | - |
|
196 | - if ($principal[1] === 'users') { |
|
197 | - $this->triggerActivityUser( |
|
198 | - $principal[2], |
|
199 | - $event, |
|
200 | - $calendarData, |
|
201 | - Calendar::SUBJECT_UNSHARE_USER, |
|
202 | - Calendar::SUBJECT_DELETE . '_self' |
|
203 | - ); |
|
204 | - |
|
205 | - if ($owner !== $principal[2]) { |
|
206 | - $parameters = [ |
|
207 | - 'actor' => $event->getAuthor(), |
|
208 | - 'calendar' => [ |
|
209 | - 'id' => (int) $calendarData['id'], |
|
210 | - 'uri' => $calendarData['uri'], |
|
211 | - 'name' => $calendarData['{DAV:}displayname'], |
|
212 | - ], |
|
213 | - 'user' => $principal[2], |
|
214 | - ]; |
|
215 | - |
|
216 | - if ($owner === $event->getAuthor()) { |
|
217 | - $subject = Calendar::SUBJECT_UNSHARE_USER . '_you'; |
|
218 | - } else if ($principal[2] === $event->getAuthor()) { |
|
219 | - $subject = Calendar::SUBJECT_UNSHARE_USER . '_self'; |
|
220 | - } else { |
|
221 | - $event->setAffectedUser($event->getAuthor()) |
|
222 | - ->setSubject(Calendar::SUBJECT_UNSHARE_USER . '_you', $parameters); |
|
223 | - $this->activityManager->publish($event); |
|
224 | - |
|
225 | - $subject = Calendar::SUBJECT_UNSHARE_USER . '_by'; |
|
226 | - } |
|
227 | - |
|
228 | - $event->setAffectedUser($owner) |
|
229 | - ->setSubject($subject, $parameters); |
|
230 | - $this->activityManager->publish($event); |
|
231 | - } |
|
232 | - } else if ($principal[1] === 'groups') { |
|
233 | - $this->triggerActivityGroup($principal[2], $event, $calendarData, Calendar::SUBJECT_UNSHARE_USER); |
|
234 | - |
|
235 | - $parameters = [ |
|
236 | - 'actor' => $event->getAuthor(), |
|
237 | - 'calendar' => [ |
|
238 | - 'id' => (int) $calendarData['id'], |
|
239 | - 'uri' => $calendarData['uri'], |
|
240 | - 'name' => $calendarData['{DAV:}displayname'], |
|
241 | - ], |
|
242 | - 'group' => $principal[2], |
|
243 | - ]; |
|
244 | - |
|
245 | - if ($owner === $event->getAuthor()) { |
|
246 | - $subject = Calendar::SUBJECT_UNSHARE_GROUP . '_you'; |
|
247 | - } else { |
|
248 | - $event->setAffectedUser($event->getAuthor()) |
|
249 | - ->setSubject(Calendar::SUBJECT_UNSHARE_GROUP . '_you', $parameters); |
|
250 | - $this->activityManager->publish($event); |
|
251 | - |
|
252 | - $subject = Calendar::SUBJECT_UNSHARE_GROUP . '_by'; |
|
253 | - } |
|
254 | - |
|
255 | - $event->setAffectedUser($owner) |
|
256 | - ->setSubject($subject, $parameters); |
|
257 | - $this->activityManager->publish($event); |
|
258 | - } |
|
259 | - } |
|
260 | - |
|
261 | - foreach ($add as $share) { |
|
262 | - if ($this->isAlreadyShared($share['href'], $shares)) { |
|
263 | - continue; |
|
264 | - } |
|
265 | - |
|
266 | - // principal:principals/users/test |
|
267 | - $parts = explode(':', $share['href'], 2); |
|
268 | - if ($parts[0] !== 'principal') { |
|
269 | - continue; |
|
270 | - } |
|
271 | - $principal = explode('/', $parts[1]); |
|
272 | - |
|
273 | - if ($principal[1] === 'users') { |
|
274 | - $this->triggerActivityUser($principal[2], $event, $calendarData, Calendar::SUBJECT_SHARE_USER); |
|
275 | - |
|
276 | - if ($owner !== $principal[2]) { |
|
277 | - $parameters = [ |
|
278 | - 'actor' => $event->getAuthor(), |
|
279 | - 'calendar' => [ |
|
280 | - 'id' => (int) $calendarData['id'], |
|
281 | - 'uri' => $calendarData['uri'], |
|
282 | - 'name' => $calendarData['{DAV:}displayname'], |
|
283 | - ], |
|
284 | - 'user' => $principal[2], |
|
285 | - ]; |
|
286 | - |
|
287 | - if ($owner === $event->getAuthor()) { |
|
288 | - $subject = Calendar::SUBJECT_SHARE_USER . '_you'; |
|
289 | - } else { |
|
290 | - $event->setAffectedUser($event->getAuthor()) |
|
291 | - ->setSubject(Calendar::SUBJECT_SHARE_USER . '_you', $parameters); |
|
292 | - $this->activityManager->publish($event); |
|
293 | - |
|
294 | - $subject = Calendar::SUBJECT_SHARE_USER . '_by'; |
|
295 | - } |
|
296 | - |
|
297 | - $event->setAffectedUser($owner) |
|
298 | - ->setSubject($subject, $parameters); |
|
299 | - $this->activityManager->publish($event); |
|
300 | - } |
|
301 | - } else if ($principal[1] === 'groups') { |
|
302 | - $this->triggerActivityGroup($principal[2], $event, $calendarData, Calendar::SUBJECT_SHARE_USER); |
|
303 | - |
|
304 | - $parameters = [ |
|
305 | - 'actor' => $event->getAuthor(), |
|
306 | - 'calendar' => [ |
|
307 | - 'id' => (int) $calendarData['id'], |
|
308 | - 'uri' => $calendarData['uri'], |
|
309 | - 'name' => $calendarData['{DAV:}displayname'], |
|
310 | - ], |
|
311 | - 'group' => $principal[2], |
|
312 | - ]; |
|
313 | - |
|
314 | - if ($owner === $event->getAuthor()) { |
|
315 | - $subject = Calendar::SUBJECT_SHARE_GROUP . '_you'; |
|
316 | - } else { |
|
317 | - $event->setAffectedUser($event->getAuthor()) |
|
318 | - ->setSubject(Calendar::SUBJECT_SHARE_GROUP . '_you', $parameters); |
|
319 | - $this->activityManager->publish($event); |
|
320 | - |
|
321 | - $subject = Calendar::SUBJECT_SHARE_GROUP . '_by'; |
|
322 | - } |
|
323 | - |
|
324 | - $event->setAffectedUser($owner) |
|
325 | - ->setSubject($subject, $parameters); |
|
326 | - $this->activityManager->publish($event); |
|
327 | - } |
|
328 | - } |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Checks if a calendar is already shared with a principal |
|
333 | - * |
|
334 | - * @param string $principal |
|
335 | - * @param array[] $shares |
|
336 | - * @return bool |
|
337 | - */ |
|
338 | - protected function isAlreadyShared($principal, $shares) { |
|
339 | - foreach ($shares as $share) { |
|
340 | - if ($principal === $share['href']) { |
|
341 | - return true; |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - return false; |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Creates the given activity for all members of the given group |
|
350 | - * |
|
351 | - * @param string $gid |
|
352 | - * @param IEvent $event |
|
353 | - * @param array $properties |
|
354 | - * @param string $subject |
|
355 | - */ |
|
356 | - protected function triggerActivityGroup($gid, IEvent $event, array $properties, $subject) { |
|
357 | - $group = $this->groupManager->get($gid); |
|
358 | - |
|
359 | - if ($group instanceof IGroup) { |
|
360 | - foreach ($group->getUsers() as $user) { |
|
361 | - // Exclude current user |
|
362 | - if ($user->getUID() !== $event->getAuthor()) { |
|
363 | - $this->triggerActivityUser($user->getUID(), $event, $properties, $subject); |
|
364 | - } |
|
365 | - } |
|
366 | - } |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Creates the given activity for the given user |
|
371 | - * |
|
372 | - * @param string $user |
|
373 | - * @param IEvent $event |
|
374 | - * @param array $properties |
|
375 | - * @param string $subject |
|
376 | - * @param string $subjectSelf |
|
377 | - */ |
|
378 | - protected function triggerActivityUser($user, IEvent $event, array $properties, $subject, $subjectSelf = '') { |
|
379 | - $event->setAffectedUser($user) |
|
380 | - ->setSubject( |
|
381 | - $user === $event->getAuthor() && $subjectSelf ? $subjectSelf : $subject, |
|
382 | - [ |
|
383 | - 'actor' => $event->getAuthor(), |
|
384 | - 'calendar' => [ |
|
385 | - 'id' => (int) $properties['id'], |
|
386 | - 'uri' => $properties['uri'], |
|
387 | - 'name' => $properties['{DAV:}displayname'], |
|
388 | - ], |
|
389 | - ] |
|
390 | - ); |
|
391 | - |
|
392 | - $this->activityManager->publish($event); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Creates activities when a calendar object was created/updated/deleted |
|
397 | - * |
|
398 | - * @param string $action |
|
399 | - * @param array $calendarData |
|
400 | - * @param array $shares |
|
401 | - * @param array $objectData |
|
402 | - */ |
|
403 | - public function onTouchCalendarObject($action, array $calendarData, array $shares, array $objectData) { |
|
404 | - if (!isset($calendarData['principaluri'])) { |
|
405 | - return; |
|
406 | - } |
|
407 | - |
|
408 | - $principal = explode('/', $calendarData['principaluri']); |
|
409 | - $owner = array_pop($principal); |
|
410 | - |
|
411 | - $currentUser = $this->userSession->getUser(); |
|
412 | - if ($currentUser instanceof IUser) { |
|
413 | - $currentUser = $currentUser->getUID(); |
|
414 | - } else { |
|
415 | - $currentUser = $owner; |
|
416 | - } |
|
417 | - |
|
418 | - $object = $this->getObjectNameAndType($objectData); |
|
419 | - $action = $action . '_' . $object['type']; |
|
420 | - |
|
421 | - if ($object['type'] === 'todo' && strpos($action, Event::SUBJECT_OBJECT_UPDATE) === 0 && $object['status'] === 'COMPLETED') { |
|
422 | - $action .= '_completed'; |
|
423 | - } else if ($object['type'] === 'todo' && strpos($action, Event::SUBJECT_OBJECT_UPDATE) === 0 && $object['status'] === 'NEEDS-ACTION') { |
|
424 | - $action .= '_needs_action'; |
|
425 | - } |
|
426 | - |
|
427 | - $event = $this->activityManager->generateEvent(); |
|
428 | - $event->setApp('dav') |
|
429 | - ->setObject('calendar', (int) $calendarData['id']) |
|
430 | - ->setType($object['type'] === 'event' ? 'calendar_event' : 'calendar_todo') |
|
431 | - ->setAuthor($currentUser); |
|
432 | - |
|
433 | - $users = $this->getUsersForShares($shares); |
|
434 | - $users[] = $owner; |
|
435 | - |
|
436 | - foreach ($users as $user) { |
|
437 | - $event->setAffectedUser($user) |
|
438 | - ->setSubject( |
|
439 | - $user === $currentUser ? $action . '_self' : $action, |
|
440 | - [ |
|
441 | - 'actor' => $event->getAuthor(), |
|
442 | - 'calendar' => [ |
|
443 | - 'id' => (int) $calendarData['id'], |
|
444 | - 'uri' => $calendarData['uri'], |
|
445 | - 'name' => $calendarData['{DAV:}displayname'], |
|
446 | - ], |
|
447 | - 'object' => [ |
|
448 | - 'id' => $object['id'], |
|
449 | - 'name' => $object['name'], |
|
450 | - ], |
|
451 | - ] |
|
452 | - ); |
|
453 | - $this->activityManager->publish($event); |
|
454 | - } |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * @param array $objectData |
|
459 | - * @return string[]|bool |
|
460 | - */ |
|
461 | - protected function getObjectNameAndType(array $objectData) { |
|
462 | - $vObject = Reader::read($objectData['calendardata']); |
|
463 | - $component = $componentType = null; |
|
464 | - foreach($vObject->getComponents() as $component) { |
|
465 | - if (in_array($component->name, ['VEVENT', 'VTODO'])) { |
|
466 | - $componentType = $component->name; |
|
467 | - break; |
|
468 | - } |
|
469 | - } |
|
470 | - |
|
471 | - if (!$componentType) { |
|
472 | - // Calendar objects must have a VEVENT or VTODO component |
|
473 | - return false; |
|
474 | - } |
|
475 | - |
|
476 | - if ($componentType === 'VEVENT') { |
|
477 | - return ['id' => (string) $component->UID, 'name' => (string) $component->SUMMARY, 'type' => 'event']; |
|
478 | - } |
|
479 | - return ['id' => (string) $component->UID, 'name' => (string) $component->SUMMARY, 'type' => 'todo', 'status' => (string) $component->STATUS]; |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * Get all users that have access to a given calendar |
|
484 | - * |
|
485 | - * @param array $shares |
|
486 | - * @return string[] |
|
487 | - */ |
|
488 | - protected function getUsersForShares(array $shares) { |
|
489 | - $users = $groups = []; |
|
490 | - foreach ($shares as $share) { |
|
491 | - $prinical = explode('/', $share['{http://owncloud.org/ns}principal']); |
|
492 | - if ($prinical[1] === 'users') { |
|
493 | - $users[] = $prinical[2]; |
|
494 | - } else if ($prinical[1] === 'groups') { |
|
495 | - $groups[] = $prinical[2]; |
|
496 | - } |
|
497 | - } |
|
498 | - |
|
499 | - if (!empty($groups)) { |
|
500 | - foreach ($groups as $gid) { |
|
501 | - $group = $this->groupManager->get($gid); |
|
502 | - if ($group instanceof IGroup) { |
|
503 | - foreach ($group->getUsers() as $user) { |
|
504 | - $users[] = $user->getUID(); |
|
505 | - } |
|
506 | - } |
|
507 | - } |
|
508 | - } |
|
509 | - |
|
510 | - return array_unique($users); |
|
511 | - } |
|
45 | + /** @var IActivityManager */ |
|
46 | + protected $activityManager; |
|
47 | + |
|
48 | + /** @var IGroupManager */ |
|
49 | + protected $groupManager; |
|
50 | + |
|
51 | + /** @var IUserSession */ |
|
52 | + protected $userSession; |
|
53 | + |
|
54 | + /** |
|
55 | + * @param IActivityManager $activityManager |
|
56 | + * @param IGroupManager $groupManager |
|
57 | + * @param IUserSession $userSession |
|
58 | + */ |
|
59 | + public function __construct(IActivityManager $activityManager, IGroupManager $groupManager, IUserSession $userSession) { |
|
60 | + $this->activityManager = $activityManager; |
|
61 | + $this->groupManager = $groupManager; |
|
62 | + $this->userSession = $userSession; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Creates activities when a calendar was creates |
|
67 | + * |
|
68 | + * @param array $calendarData |
|
69 | + */ |
|
70 | + public function onCalendarAdd(array $calendarData) { |
|
71 | + $this->triggerCalendarActivity(Calendar::SUBJECT_ADD, $calendarData); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Creates activities when a calendar was updated |
|
76 | + * |
|
77 | + * @param array $calendarData |
|
78 | + * @param array $shares |
|
79 | + * @param array $properties |
|
80 | + */ |
|
81 | + public function onCalendarUpdate(array $calendarData, array $shares, array $properties) { |
|
82 | + $this->triggerCalendarActivity(Calendar::SUBJECT_UPDATE, $calendarData, $shares, $properties); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Creates activities when a calendar was deleted |
|
87 | + * |
|
88 | + * @param array $calendarData |
|
89 | + * @param array $shares |
|
90 | + */ |
|
91 | + public function onCalendarDelete(array $calendarData, array $shares) { |
|
92 | + $this->triggerCalendarActivity(Calendar::SUBJECT_DELETE, $calendarData, $shares); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Creates activities when a calendar was (un)published |
|
97 | + * |
|
98 | + * @param array $calendarData |
|
99 | + * @param bool $publishStatus |
|
100 | + */ |
|
101 | + public function onCalendarPublication(array $calendarData, $publishStatus) { |
|
102 | + $this->triggerCalendarActivity($publishStatus ? Calendar::SUBJECT_PUBLISH : Calendar::SUBJECT_UNPUBLISH, $calendarData); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Creates activities for all related users when a calendar was touched |
|
107 | + * |
|
108 | + * @param string $action |
|
109 | + * @param array $calendarData |
|
110 | + * @param array $shares |
|
111 | + * @param array $changedProperties |
|
112 | + */ |
|
113 | + protected function triggerCalendarActivity($action, array $calendarData, array $shares = [], array $changedProperties = []) { |
|
114 | + if (!isset($calendarData['principaluri'])) { |
|
115 | + return; |
|
116 | + } |
|
117 | + |
|
118 | + $principal = explode('/', $calendarData['principaluri']); |
|
119 | + $owner = array_pop($principal); |
|
120 | + |
|
121 | + $currentUser = $this->userSession->getUser(); |
|
122 | + if ($currentUser instanceof IUser) { |
|
123 | + $currentUser = $currentUser->getUID(); |
|
124 | + } else { |
|
125 | + $currentUser = $owner; |
|
126 | + } |
|
127 | + |
|
128 | + $event = $this->activityManager->generateEvent(); |
|
129 | + $event->setApp('dav') |
|
130 | + ->setObject('calendar', (int) $calendarData['id']) |
|
131 | + ->setType('calendar') |
|
132 | + ->setAuthor($currentUser); |
|
133 | + |
|
134 | + $changedVisibleInformation = array_intersect([ |
|
135 | + '{DAV:}displayname', |
|
136 | + '{http://apple.com/ns/ical/}calendar-color' |
|
137 | + ], array_keys($changedProperties)); |
|
138 | + |
|
139 | + if (empty($shares) || ($action === Calendar::SUBJECT_UPDATE && empty($changedVisibleInformation))) { |
|
140 | + $users = [$owner]; |
|
141 | + } else { |
|
142 | + $users = $this->getUsersForShares($shares); |
|
143 | + $users[] = $owner; |
|
144 | + } |
|
145 | + |
|
146 | + foreach ($users as $user) { |
|
147 | + $event->setAffectedUser($user) |
|
148 | + ->setSubject( |
|
149 | + $user === $currentUser ? $action . '_self' : $action, |
|
150 | + [ |
|
151 | + 'actor' => $currentUser, |
|
152 | + 'calendar' => [ |
|
153 | + 'id' => (int) $calendarData['id'], |
|
154 | + 'uri' => $calendarData['uri'], |
|
155 | + 'name' => $calendarData['{DAV:}displayname'], |
|
156 | + ], |
|
157 | + ] |
|
158 | + ); |
|
159 | + $this->activityManager->publish($event); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Creates activities for all related users when a calendar was (un-)shared |
|
165 | + * |
|
166 | + * @param array $calendarData |
|
167 | + * @param array $shares |
|
168 | + * @param array $add |
|
169 | + * @param array $remove |
|
170 | + */ |
|
171 | + public function onCalendarUpdateShares(array $calendarData, array $shares, array $add, array $remove) { |
|
172 | + $principal = explode('/', $calendarData['principaluri']); |
|
173 | + $owner = $principal[2]; |
|
174 | + |
|
175 | + $currentUser = $this->userSession->getUser(); |
|
176 | + if ($currentUser instanceof IUser) { |
|
177 | + $currentUser = $currentUser->getUID(); |
|
178 | + } else { |
|
179 | + $currentUser = $owner; |
|
180 | + } |
|
181 | + |
|
182 | + $event = $this->activityManager->generateEvent(); |
|
183 | + $event->setApp('dav') |
|
184 | + ->setObject('calendar', (int) $calendarData['id']) |
|
185 | + ->setType('calendar') |
|
186 | + ->setAuthor($currentUser); |
|
187 | + |
|
188 | + foreach ($remove as $principal) { |
|
189 | + // principal:principals/users/test |
|
190 | + $parts = explode(':', $principal, 2); |
|
191 | + if ($parts[0] !== 'principal') { |
|
192 | + continue; |
|
193 | + } |
|
194 | + $principal = explode('/', $parts[1]); |
|
195 | + |
|
196 | + if ($principal[1] === 'users') { |
|
197 | + $this->triggerActivityUser( |
|
198 | + $principal[2], |
|
199 | + $event, |
|
200 | + $calendarData, |
|
201 | + Calendar::SUBJECT_UNSHARE_USER, |
|
202 | + Calendar::SUBJECT_DELETE . '_self' |
|
203 | + ); |
|
204 | + |
|
205 | + if ($owner !== $principal[2]) { |
|
206 | + $parameters = [ |
|
207 | + 'actor' => $event->getAuthor(), |
|
208 | + 'calendar' => [ |
|
209 | + 'id' => (int) $calendarData['id'], |
|
210 | + 'uri' => $calendarData['uri'], |
|
211 | + 'name' => $calendarData['{DAV:}displayname'], |
|
212 | + ], |
|
213 | + 'user' => $principal[2], |
|
214 | + ]; |
|
215 | + |
|
216 | + if ($owner === $event->getAuthor()) { |
|
217 | + $subject = Calendar::SUBJECT_UNSHARE_USER . '_you'; |
|
218 | + } else if ($principal[2] === $event->getAuthor()) { |
|
219 | + $subject = Calendar::SUBJECT_UNSHARE_USER . '_self'; |
|
220 | + } else { |
|
221 | + $event->setAffectedUser($event->getAuthor()) |
|
222 | + ->setSubject(Calendar::SUBJECT_UNSHARE_USER . '_you', $parameters); |
|
223 | + $this->activityManager->publish($event); |
|
224 | + |
|
225 | + $subject = Calendar::SUBJECT_UNSHARE_USER . '_by'; |
|
226 | + } |
|
227 | + |
|
228 | + $event->setAffectedUser($owner) |
|
229 | + ->setSubject($subject, $parameters); |
|
230 | + $this->activityManager->publish($event); |
|
231 | + } |
|
232 | + } else if ($principal[1] === 'groups') { |
|
233 | + $this->triggerActivityGroup($principal[2], $event, $calendarData, Calendar::SUBJECT_UNSHARE_USER); |
|
234 | + |
|
235 | + $parameters = [ |
|
236 | + 'actor' => $event->getAuthor(), |
|
237 | + 'calendar' => [ |
|
238 | + 'id' => (int) $calendarData['id'], |
|
239 | + 'uri' => $calendarData['uri'], |
|
240 | + 'name' => $calendarData['{DAV:}displayname'], |
|
241 | + ], |
|
242 | + 'group' => $principal[2], |
|
243 | + ]; |
|
244 | + |
|
245 | + if ($owner === $event->getAuthor()) { |
|
246 | + $subject = Calendar::SUBJECT_UNSHARE_GROUP . '_you'; |
|
247 | + } else { |
|
248 | + $event->setAffectedUser($event->getAuthor()) |
|
249 | + ->setSubject(Calendar::SUBJECT_UNSHARE_GROUP . '_you', $parameters); |
|
250 | + $this->activityManager->publish($event); |
|
251 | + |
|
252 | + $subject = Calendar::SUBJECT_UNSHARE_GROUP . '_by'; |
|
253 | + } |
|
254 | + |
|
255 | + $event->setAffectedUser($owner) |
|
256 | + ->setSubject($subject, $parameters); |
|
257 | + $this->activityManager->publish($event); |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + foreach ($add as $share) { |
|
262 | + if ($this->isAlreadyShared($share['href'], $shares)) { |
|
263 | + continue; |
|
264 | + } |
|
265 | + |
|
266 | + // principal:principals/users/test |
|
267 | + $parts = explode(':', $share['href'], 2); |
|
268 | + if ($parts[0] !== 'principal') { |
|
269 | + continue; |
|
270 | + } |
|
271 | + $principal = explode('/', $parts[1]); |
|
272 | + |
|
273 | + if ($principal[1] === 'users') { |
|
274 | + $this->triggerActivityUser($principal[2], $event, $calendarData, Calendar::SUBJECT_SHARE_USER); |
|
275 | + |
|
276 | + if ($owner !== $principal[2]) { |
|
277 | + $parameters = [ |
|
278 | + 'actor' => $event->getAuthor(), |
|
279 | + 'calendar' => [ |
|
280 | + 'id' => (int) $calendarData['id'], |
|
281 | + 'uri' => $calendarData['uri'], |
|
282 | + 'name' => $calendarData['{DAV:}displayname'], |
|
283 | + ], |
|
284 | + 'user' => $principal[2], |
|
285 | + ]; |
|
286 | + |
|
287 | + if ($owner === $event->getAuthor()) { |
|
288 | + $subject = Calendar::SUBJECT_SHARE_USER . '_you'; |
|
289 | + } else { |
|
290 | + $event->setAffectedUser($event->getAuthor()) |
|
291 | + ->setSubject(Calendar::SUBJECT_SHARE_USER . '_you', $parameters); |
|
292 | + $this->activityManager->publish($event); |
|
293 | + |
|
294 | + $subject = Calendar::SUBJECT_SHARE_USER . '_by'; |
|
295 | + } |
|
296 | + |
|
297 | + $event->setAffectedUser($owner) |
|
298 | + ->setSubject($subject, $parameters); |
|
299 | + $this->activityManager->publish($event); |
|
300 | + } |
|
301 | + } else if ($principal[1] === 'groups') { |
|
302 | + $this->triggerActivityGroup($principal[2], $event, $calendarData, Calendar::SUBJECT_SHARE_USER); |
|
303 | + |
|
304 | + $parameters = [ |
|
305 | + 'actor' => $event->getAuthor(), |
|
306 | + 'calendar' => [ |
|
307 | + 'id' => (int) $calendarData['id'], |
|
308 | + 'uri' => $calendarData['uri'], |
|
309 | + 'name' => $calendarData['{DAV:}displayname'], |
|
310 | + ], |
|
311 | + 'group' => $principal[2], |
|
312 | + ]; |
|
313 | + |
|
314 | + if ($owner === $event->getAuthor()) { |
|
315 | + $subject = Calendar::SUBJECT_SHARE_GROUP . '_you'; |
|
316 | + } else { |
|
317 | + $event->setAffectedUser($event->getAuthor()) |
|
318 | + ->setSubject(Calendar::SUBJECT_SHARE_GROUP . '_you', $parameters); |
|
319 | + $this->activityManager->publish($event); |
|
320 | + |
|
321 | + $subject = Calendar::SUBJECT_SHARE_GROUP . '_by'; |
|
322 | + } |
|
323 | + |
|
324 | + $event->setAffectedUser($owner) |
|
325 | + ->setSubject($subject, $parameters); |
|
326 | + $this->activityManager->publish($event); |
|
327 | + } |
|
328 | + } |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Checks if a calendar is already shared with a principal |
|
333 | + * |
|
334 | + * @param string $principal |
|
335 | + * @param array[] $shares |
|
336 | + * @return bool |
|
337 | + */ |
|
338 | + protected function isAlreadyShared($principal, $shares) { |
|
339 | + foreach ($shares as $share) { |
|
340 | + if ($principal === $share['href']) { |
|
341 | + return true; |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + return false; |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Creates the given activity for all members of the given group |
|
350 | + * |
|
351 | + * @param string $gid |
|
352 | + * @param IEvent $event |
|
353 | + * @param array $properties |
|
354 | + * @param string $subject |
|
355 | + */ |
|
356 | + protected function triggerActivityGroup($gid, IEvent $event, array $properties, $subject) { |
|
357 | + $group = $this->groupManager->get($gid); |
|
358 | + |
|
359 | + if ($group instanceof IGroup) { |
|
360 | + foreach ($group->getUsers() as $user) { |
|
361 | + // Exclude current user |
|
362 | + if ($user->getUID() !== $event->getAuthor()) { |
|
363 | + $this->triggerActivityUser($user->getUID(), $event, $properties, $subject); |
|
364 | + } |
|
365 | + } |
|
366 | + } |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Creates the given activity for the given user |
|
371 | + * |
|
372 | + * @param string $user |
|
373 | + * @param IEvent $event |
|
374 | + * @param array $properties |
|
375 | + * @param string $subject |
|
376 | + * @param string $subjectSelf |
|
377 | + */ |
|
378 | + protected function triggerActivityUser($user, IEvent $event, array $properties, $subject, $subjectSelf = '') { |
|
379 | + $event->setAffectedUser($user) |
|
380 | + ->setSubject( |
|
381 | + $user === $event->getAuthor() && $subjectSelf ? $subjectSelf : $subject, |
|
382 | + [ |
|
383 | + 'actor' => $event->getAuthor(), |
|
384 | + 'calendar' => [ |
|
385 | + 'id' => (int) $properties['id'], |
|
386 | + 'uri' => $properties['uri'], |
|
387 | + 'name' => $properties['{DAV:}displayname'], |
|
388 | + ], |
|
389 | + ] |
|
390 | + ); |
|
391 | + |
|
392 | + $this->activityManager->publish($event); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Creates activities when a calendar object was created/updated/deleted |
|
397 | + * |
|
398 | + * @param string $action |
|
399 | + * @param array $calendarData |
|
400 | + * @param array $shares |
|
401 | + * @param array $objectData |
|
402 | + */ |
|
403 | + public function onTouchCalendarObject($action, array $calendarData, array $shares, array $objectData) { |
|
404 | + if (!isset($calendarData['principaluri'])) { |
|
405 | + return; |
|
406 | + } |
|
407 | + |
|
408 | + $principal = explode('/', $calendarData['principaluri']); |
|
409 | + $owner = array_pop($principal); |
|
410 | + |
|
411 | + $currentUser = $this->userSession->getUser(); |
|
412 | + if ($currentUser instanceof IUser) { |
|
413 | + $currentUser = $currentUser->getUID(); |
|
414 | + } else { |
|
415 | + $currentUser = $owner; |
|
416 | + } |
|
417 | + |
|
418 | + $object = $this->getObjectNameAndType($objectData); |
|
419 | + $action = $action . '_' . $object['type']; |
|
420 | + |
|
421 | + if ($object['type'] === 'todo' && strpos($action, Event::SUBJECT_OBJECT_UPDATE) === 0 && $object['status'] === 'COMPLETED') { |
|
422 | + $action .= '_completed'; |
|
423 | + } else if ($object['type'] === 'todo' && strpos($action, Event::SUBJECT_OBJECT_UPDATE) === 0 && $object['status'] === 'NEEDS-ACTION') { |
|
424 | + $action .= '_needs_action'; |
|
425 | + } |
|
426 | + |
|
427 | + $event = $this->activityManager->generateEvent(); |
|
428 | + $event->setApp('dav') |
|
429 | + ->setObject('calendar', (int) $calendarData['id']) |
|
430 | + ->setType($object['type'] === 'event' ? 'calendar_event' : 'calendar_todo') |
|
431 | + ->setAuthor($currentUser); |
|
432 | + |
|
433 | + $users = $this->getUsersForShares($shares); |
|
434 | + $users[] = $owner; |
|
435 | + |
|
436 | + foreach ($users as $user) { |
|
437 | + $event->setAffectedUser($user) |
|
438 | + ->setSubject( |
|
439 | + $user === $currentUser ? $action . '_self' : $action, |
|
440 | + [ |
|
441 | + 'actor' => $event->getAuthor(), |
|
442 | + 'calendar' => [ |
|
443 | + 'id' => (int) $calendarData['id'], |
|
444 | + 'uri' => $calendarData['uri'], |
|
445 | + 'name' => $calendarData['{DAV:}displayname'], |
|
446 | + ], |
|
447 | + 'object' => [ |
|
448 | + 'id' => $object['id'], |
|
449 | + 'name' => $object['name'], |
|
450 | + ], |
|
451 | + ] |
|
452 | + ); |
|
453 | + $this->activityManager->publish($event); |
|
454 | + } |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * @param array $objectData |
|
459 | + * @return string[]|bool |
|
460 | + */ |
|
461 | + protected function getObjectNameAndType(array $objectData) { |
|
462 | + $vObject = Reader::read($objectData['calendardata']); |
|
463 | + $component = $componentType = null; |
|
464 | + foreach($vObject->getComponents() as $component) { |
|
465 | + if (in_array($component->name, ['VEVENT', 'VTODO'])) { |
|
466 | + $componentType = $component->name; |
|
467 | + break; |
|
468 | + } |
|
469 | + } |
|
470 | + |
|
471 | + if (!$componentType) { |
|
472 | + // Calendar objects must have a VEVENT or VTODO component |
|
473 | + return false; |
|
474 | + } |
|
475 | + |
|
476 | + if ($componentType === 'VEVENT') { |
|
477 | + return ['id' => (string) $component->UID, 'name' => (string) $component->SUMMARY, 'type' => 'event']; |
|
478 | + } |
|
479 | + return ['id' => (string) $component->UID, 'name' => (string) $component->SUMMARY, 'type' => 'todo', 'status' => (string) $component->STATUS]; |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * Get all users that have access to a given calendar |
|
484 | + * |
|
485 | + * @param array $shares |
|
486 | + * @return string[] |
|
487 | + */ |
|
488 | + protected function getUsersForShares(array $shares) { |
|
489 | + $users = $groups = []; |
|
490 | + foreach ($shares as $share) { |
|
491 | + $prinical = explode('/', $share['{http://owncloud.org/ns}principal']); |
|
492 | + if ($prinical[1] === 'users') { |
|
493 | + $users[] = $prinical[2]; |
|
494 | + } else if ($prinical[1] === 'groups') { |
|
495 | + $groups[] = $prinical[2]; |
|
496 | + } |
|
497 | + } |
|
498 | + |
|
499 | + if (!empty($groups)) { |
|
500 | + foreach ($groups as $gid) { |
|
501 | + $group = $this->groupManager->get($gid); |
|
502 | + if ($group instanceof IGroup) { |
|
503 | + foreach ($group->getUsers() as $user) { |
|
504 | + $users[] = $user->getUID(); |
|
505 | + } |
|
506 | + } |
|
507 | + } |
|
508 | + } |
|
509 | + |
|
510 | + return array_unique($users); |
|
511 | + } |
|
512 | 512 | } |