-
Notifications
You must be signed in to change notification settings - Fork 30
Enhancement: Make tables import asynchronous #1801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Tables\Activity; | ||
|
||
class ActivityConstants { | ||
/***** | ||
* Types can have different Settings for Mail/Notifications. | ||
*/ | ||
public const TYPE_IMPORT_FINISHED = 'tables_import_finished'; | ||
|
||
/***** | ||
* Subjects are internal 'types', that get interpreted by our own Provider. | ||
*/ | ||
|
||
/** | ||
* Somebody shared a form to a selected user | ||
* Needs Params: | ||
* "user": The userId of the user who shared. | ||
* "formTitle": The hash of the shared form. | ||
* "formHash": The hash of the shared form | ||
*/ | ||
public const SUBJECT_IMPORT_FINISHED = 'import_finished_subject'; | ||
|
||
public const MESSAGE_IMPORT_FINISHED = 'import_finished_message'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Tables\Activity; | ||
|
||
use OCA\Tables\AppInfo\Application; | ||
use OCA\Tables\Model\ImportStats; | ||
use OCP\Activity\IManager; | ||
|
||
class ActivityManager { | ||
public function __construct( | ||
protected IManager $activityManager, | ||
) { | ||
} | ||
|
||
public function notifyImportFinished(string $userId, int $tableId, ImportStats $importStats): void { | ||
|
||
$activity = $this->activityManager->generateEvent(); | ||
$activity->setApp(Application::APP_ID) | ||
->setType(ActivityConstants::TYPE_IMPORT_FINISHED) | ||
->setAuthor($userId) | ||
->setObject('table', $tableId) | ||
->setAffectedUser($userId) | ||
->setSubject(ActivityConstants::SUBJECT_IMPORT_FINISHED, [ | ||
'actor' => $userId, | ||
'tableId' => $tableId, | ||
]) | ||
->setMessage(ActivityConstants::MESSAGE_IMPORT_FINISHED, [ | ||
'actor' => $userId, | ||
'tableId' => $tableId, | ||
] + (array)$importStats); | ||
|
||
$this->activityManager->publish($activity); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Tables\Activity; | ||
|
||
use OCA\Tables\AppInfo\Application; | ||
use OCP\Activity\IFilter; | ||
use OCP\IL10N; | ||
use OCP\IURLGenerator; | ||
|
||
class Filter implements IFilter { | ||
public function __construct( | ||
protected IL10N $l, | ||
protected IURLGenerator $url, | ||
) { | ||
} | ||
|
||
public function getIdentifier(): string { | ||
return Application::APP_ID; | ||
} | ||
|
||
public function getName(): string { | ||
return $this->l->t('Tables'); | ||
} | ||
|
||
public function getPriority(): int { | ||
return 40; | ||
} | ||
|
||
public function getIcon(): string { | ||
return $this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')); | ||
} | ||
|
||
public function filterTypes(array $types): array { | ||
return $types; | ||
} | ||
|
||
public function allowedApps(): array { | ||
return [Application::APP_ID]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Tables\Activity; | ||
|
||
use OCA\Tables\AppInfo\Application; | ||
use OCP\Activity\Exceptions\UnknownActivityException; | ||
use OCP\Activity\IEvent; | ||
use OCP\Activity\IManager; | ||
use OCP\Activity\IProvider; | ||
use OCP\Comments\ICommentsManager; | ||
use OCP\IL10N; | ||
use OCP\IURLGenerator; | ||
use OCP\IUserManager; | ||
use OCP\L10N\IFactory; | ||
|
||
class Provider implements IProvider { | ||
protected ?IL10N $l = null; | ||
|
||
public function __construct( | ||
protected IFactory $languageFactory, | ||
protected IURLGenerator $url, | ||
protected ICommentsManager $commentsManager, | ||
protected IUserManager $userManager, | ||
protected IManager $activityManager, | ||
) { | ||
} | ||
|
||
/** | ||
* @param string $language | ||
* @param IEvent $event | ||
* @param IEvent|null $previousEvent | ||
* @return IEvent | ||
* @throws UnknownActivityException | ||
Check failure on line 37 in lib/Activity/Provider.php
|
||
*/ | ||
public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent { | ||
if ($event->getApp() !== Application::APP_ID) { | ||
throw new UnknownActivityException(); | ||
Check failure on line 41 in lib/Activity/Provider.php
|
||
} | ||
|
||
$this->l = $this->languageFactory->get(Application::APP_ID, $language); | ||
|
||
if ($event->getSubject() === ActivityConstants::SUBJECT_IMPORT_FINISHED) { | ||
// $event->setParsedMessage($comment->getMessage()) | ||
// ->setRichMessage($message, $mentions); | ||
|
||
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg'))); | ||
|
||
if ($this->activityManager->isFormattingFilteredObject()) { | ||
try { | ||
return $this->parseShortVersion($event); | ||
} catch (UnknownActivityException) { | ||
Check failure on line 55 in lib/Activity/Provider.php
|
||
// Ignore and simply use the long version... | ||
} | ||
} | ||
|
||
return $this->parseLongVersion($event); | ||
} | ||
|
||
throw new UnknownActivityException(); | ||
Check failure on line 63 in lib/Activity/Provider.php
|
||
} | ||
|
||
/** | ||
* @throws UnknownActivityException | ||
Check failure on line 67 in lib/Activity/Provider.php
|
||
*/ | ||
protected function parseShortVersion(IEvent $event): IEvent { | ||
$subjectParameters = $this->getSubjectParameters($event); | ||
|
||
if ($event->getSubject() === ActivityConstants::SUBJECT_IMPORT_FINISHED) { | ||
$event->setRichSubject($this->l->t('You commented'), []); | ||
} else { | ||
throw new UnknownActivityException(); | ||
Check failure on line 75 in lib/Activity/Provider.php
|
||
} | ||
|
||
return $event; | ||
} | ||
|
||
/** | ||
* @throws UnknownActivityException | ||
Check failure on line 82 in lib/Activity/Provider.php
|
||
*/ | ||
protected function parseLongVersion(IEvent $event): IEvent { | ||
$subjectParameters = $this->getSubjectParameters($event); | ||
|
||
if ($event->getSubject() === ActivityConstants::SUBJECT_IMPORT_FINISHED) { | ||
$event->setParsedSubject($this->l->t('You commented on %1$s', [ | ||
$subjectParameters['filePath'], | ||
])) | ||
->setRichSubject($this->l->t('You commented on {file}'), [ | ||
'file' => $this->generateFileParameter($subjectParameters['fileId'], $subjectParameters['filePath']), | ||
]); | ||
} else { | ||
throw new UnknownActivityException(); | ||
Check failure on line 95 in lib/Activity/Provider.php
|
||
} | ||
|
||
return $event; | ||
} | ||
|
||
protected function getSubjectParameters(IEvent $event): array { | ||
$subjectParameters = $event->getSubjectParameters(); | ||
if (isset($subjectParameters['fileId'])) { | ||
return $subjectParameters; | ||
} | ||
|
||
return [ | ||
'actor' => $subjectParameters[0], | ||
'fileId' => $event->getObjectId(), | ||
'filePath' => trim($subjectParameters[1], '/'), | ||
]; | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
protected function generateFileParameter(int $id, string $path): array { | ||
return [ | ||
'type' => 'file', | ||
'id' => (string)$id, | ||
'name' => basename($path), | ||
'path' => $path, | ||
'link' => $this->url->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $id]), | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\Tables\Activity; | ||
|
||
use OCA\Tables\AppInfo\Application; | ||
use OCP\Activity\ActivitySettings; | ||
use OCP\IL10N; | ||
|
||
class Setting extends ActivitySettings { | ||
public function __construct( | ||
protected IL10N $l, | ||
) { | ||
} | ||
|
||
public function getIdentifier(): string { | ||
return ActivityConstants::TYPE_IMPORT_FINISHED; | ||
} | ||
|
||
public function getName(): string { | ||
return $this->l->t('<strong>Import</strong> of a file has finished'); | ||
} | ||
|
||
public function getGroupIdentifier() { | ||
return Application::APP_ID; | ||
} | ||
|
||
public function getGroupName() { | ||
return $this->l->t('Tables'); | ||
} | ||
|
||
public function getPriority(): int { | ||
return 50; | ||
} | ||
|
||
public function canChangeStream(): bool { | ||
return true; | ||
} | ||
|
||
public function isDefaultEnabledStream(): bool { | ||
return true; | ||
} | ||
|
||
public function canChangeMail(): bool { | ||
return true; | ||
} | ||
|
||
public function isDefaultEnabledMail(): bool { | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The underlying file does not seem to be committed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this exception should be located somewhere in the core. I've just stolen code to publish/parse activity from another module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, indeed. But this is available only as of NC 30, on main we still support 29.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, how to deal with that? Can we just bump minimum NC supported version to 30? Like in other modules: Collectives, Forms, etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We weed need to branch-off, which of course is possible. We were aiming for September originally. Related changes (version bump and housekeeping) would happen in a separate PR. I'll get back about it.