aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/composer/composer/autoload_classmap.php1
-rw-r--r--apps/files_versions/composer/composer/autoload_static.php1
-rw-r--r--apps/files_versions/l10n/uk.js1
-rw-r--r--apps/files_versions/l10n/uk.json1
-rw-r--r--apps/files_versions/lib/Events/VersionCreatedEvent.php39
-rw-r--r--apps/files_versions/lib/Versions/INeedSyncVersionBackend.php7
-rw-r--r--apps/files_versions/lib/Versions/LegacyVersionsBackend.php7
-rw-r--r--apps/files_versions/lib/Versions/VersionManager.php13
8 files changed, 65 insertions, 5 deletions
diff --git a/apps/files_versions/composer/composer/autoload_classmap.php b/apps/files_versions/composer/composer/autoload_classmap.php
index 9c83924ab7c..27e68decdcc 100644
--- a/apps/files_versions/composer/composer/autoload_classmap.php
+++ b/apps/files_versions/composer/composer/autoload_classmap.php
@@ -17,6 +17,7 @@ return array(
'OCA\\Files_Versions\\Db\\VersionEntity' => $baseDir . '/../lib/Db/VersionEntity.php',
'OCA\\Files_Versions\\Db\\VersionsMapper' => $baseDir . '/../lib/Db/VersionsMapper.php',
'OCA\\Files_Versions\\Events\\CreateVersionEvent' => $baseDir . '/../lib/Events/CreateVersionEvent.php',
+ 'OCA\\Files_Versions\\Events\\VersionCreatedEvent' => $baseDir . '/../lib/Events/VersionCreatedEvent.php',
'OCA\\Files_Versions\\Events\\VersionRestoredEvent' => $baseDir . '/../lib/Events/VersionRestoredEvent.php',
'OCA\\Files_Versions\\Expiration' => $baseDir . '/../lib/Expiration.php',
'OCA\\Files_Versions\\Listener\\FileEventsListener' => $baseDir . '/../lib/Listener/FileEventsListener.php',
diff --git a/apps/files_versions/composer/composer/autoload_static.php b/apps/files_versions/composer/composer/autoload_static.php
index 1d95663ac55..8ecc1cb0137 100644
--- a/apps/files_versions/composer/composer/autoload_static.php
+++ b/apps/files_versions/composer/composer/autoload_static.php
@@ -32,6 +32,7 @@ class ComposerStaticInitFiles_Versions
'OCA\\Files_Versions\\Db\\VersionEntity' => __DIR__ . '/..' . '/../lib/Db/VersionEntity.php',
'OCA\\Files_Versions\\Db\\VersionsMapper' => __DIR__ . '/..' . '/../lib/Db/VersionsMapper.php',
'OCA\\Files_Versions\\Events\\CreateVersionEvent' => __DIR__ . '/..' . '/../lib/Events/CreateVersionEvent.php',
+ 'OCA\\Files_Versions\\Events\\VersionCreatedEvent' => __DIR__ . '/..' . '/../lib/Events/VersionCreatedEvent.php',
'OCA\\Files_Versions\\Events\\VersionRestoredEvent' => __DIR__ . '/..' . '/../lib/Events/VersionRestoredEvent.php',
'OCA\\Files_Versions\\Expiration' => __DIR__ . '/..' . '/../lib/Expiration.php',
'OCA\\Files_Versions\\Listener\\FileEventsListener' => __DIR__ . '/..' . '/../lib/Listener/FileEventsListener.php',
diff --git a/apps/files_versions/l10n/uk.js b/apps/files_versions/l10n/uk.js
index e2a6801b0af..8b98d0f28c6 100644
--- a/apps/files_versions/l10n/uk.js
+++ b/apps/files_versions/l10n/uk.js
@@ -3,6 +3,7 @@ OC.L10N.register(
{
"Versions" : "Версії",
"This application automatically maintains older versions of files that are changed." : "Цей застосунок підтримує роботу з попередніми версіями файлів, які було змінено.",
+ "This application automatically maintains older versions of files that are changed. When enabled, a hidden versions folder is provisioned in every user's directory and is used to store old file versions. A user can revert to an older version through the web interface at any time, with the replaced file becoming a version. The app automatically manages the versions folder to ensure the account does not run out of Quota because of versions.\n\t\tIn addition to the expiry of versions, the versions app makes certain never to use more than 50% of the account's currently available free space. If stored versions exceed this limit, the app will delete the oldest versions first until it meets this limit. More information is available in the Versions documentation." : "Ця програма автоматично зберігає старі версії файлів, які були змінені. Коли ця функція увімкнена, у каталозі кожного користувача створюється прихований каталог «версії», яка використовується для зберігання старих версій файлів. Користувач може в будь-який час повернутися до старішої версії через веб-інтерфейс, а замінений файл стане версією. Програма автоматично керує каталогом «версії», щоб уникнути перевищення квоти облікового запису через версії.\n\nОкрім терміну дії версій, програма «Версії» гарантує, що ніколи не буде використовуватися більше 50% вільного місця, доступного на даний момент в обліковому записі. Якщо збережені версії перевищують цей ліміт, програма спочатку видалить найстаріші версії, доки не буде досягнуто цього ліміту. Більше інформації можна знайти в документації «Версії».",
"Current version" : "Поточна версія",
"Initial version" : "Початкова версія",
"You" : "Ви",
diff --git a/apps/files_versions/l10n/uk.json b/apps/files_versions/l10n/uk.json
index 7ff4719704e..e9ec39ed3d9 100644
--- a/apps/files_versions/l10n/uk.json
+++ b/apps/files_versions/l10n/uk.json
@@ -1,6 +1,7 @@
{ "translations": {
"Versions" : "Версії",
"This application automatically maintains older versions of files that are changed." : "Цей застосунок підтримує роботу з попередніми версіями файлів, які було змінено.",
+ "This application automatically maintains older versions of files that are changed. When enabled, a hidden versions folder is provisioned in every user's directory and is used to store old file versions. A user can revert to an older version through the web interface at any time, with the replaced file becoming a version. The app automatically manages the versions folder to ensure the account does not run out of Quota because of versions.\n\t\tIn addition to the expiry of versions, the versions app makes certain never to use more than 50% of the account's currently available free space. If stored versions exceed this limit, the app will delete the oldest versions first until it meets this limit. More information is available in the Versions documentation." : "Ця програма автоматично зберігає старі версії файлів, які були змінені. Коли ця функція увімкнена, у каталозі кожного користувача створюється прихований каталог «версії», яка використовується для зберігання старих версій файлів. Користувач може в будь-який час повернутися до старішої версії через веб-інтерфейс, а замінений файл стане версією. Програма автоматично керує каталогом «версії», щоб уникнути перевищення квоти облікового запису через версії.\n\nОкрім терміну дії версій, програма «Версії» гарантує, що ніколи не буде використовуватися більше 50% вільного місця, доступного на даний момент в обліковому записі. Якщо збережені версії перевищують цей ліміт, програма спочатку видалить найстаріші версії, доки не буде досягнуто цього ліміту. Більше інформації можна знайти в документації «Версії».",
"Current version" : "Поточна версія",
"Initial version" : "Початкова версія",
"You" : "Ви",
diff --git a/apps/files_versions/lib/Events/VersionCreatedEvent.php b/apps/files_versions/lib/Events/VersionCreatedEvent.php
new file mode 100644
index 00000000000..4dc7a7cb505
--- /dev/null
+++ b/apps/files_versions/lib/Events/VersionCreatedEvent.php
@@ -0,0 +1,39 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Files_Versions\Events;
+
+use OCA\Files_Versions\Versions\IVersion;
+use OCP\EventDispatcher\Event;
+use OCP\Files\Node;
+
+/**
+ * Event dispatched after a successful creation of a version
+ */
+class VersionCreatedEvent extends Event {
+ public function __construct(
+ private Node $node,
+ private IVersion $version,
+ ) {
+ parent::__construct();
+ }
+
+ /**
+ * Node of the file that has been versioned
+ */
+ public function getNode(): Node {
+ return $this->node;
+ }
+
+ /**
+ * Version of the file that was created
+ */
+ public function getVersion(): IVersion {
+ return $this->version;
+ }
+}
diff --git a/apps/files_versions/lib/Versions/INeedSyncVersionBackend.php b/apps/files_versions/lib/Versions/INeedSyncVersionBackend.php
index 4faeaa48513..e52e2f8e8bc 100644
--- a/apps/files_versions/lib/Versions/INeedSyncVersionBackend.php
+++ b/apps/files_versions/lib/Versions/INeedSyncVersionBackend.php
@@ -8,13 +8,18 @@ declare(strict_types=1);
*/
namespace OCA\Files_Versions\Versions;
+use OCA\Files_Versions\Db\VersionEntity;
use OCP\Files\File;
/**
* @since 28.0.0
*/
interface INeedSyncVersionBackend {
- public function createVersionEntity(File $file): void;
+ /**
+ * TODO: Convert return type to strong type once all implementations are fixed.
+ * @return null|VersionEntity
+ */
+ public function createVersionEntity(File $file);
public function updateVersionEntity(File $sourceFile, int $revision, array $properties): void;
public function deleteVersionsEntity(File $file): void;
}
diff --git a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
index 40180674b7c..48d69d31629 100644
--- a/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
+++ b/apps/files_versions/lib/Versions/LegacyVersionsBackend.php
@@ -229,7 +229,7 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend
$this->versionsMapper->delete($versionEntity);
}
- public function createVersionEntity(File $file): void {
+ public function createVersionEntity(File $file): ?VersionEntity {
$versionEntity = new VersionEntity();
$versionEntity->setFileId($file->getId());
$versionEntity->setTimestamp($file->getMTime());
@@ -241,8 +241,7 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend
while ($tries < 5) {
try {
$this->versionsMapper->insert($versionEntity);
- /* No errors, get out of the method */
- return;
+ return $versionEntity;
} catch (\OCP\DB\Exception $e) {
if (!in_array($e->getReason(), [
\OCP\DB\Exception::REASON_CONSTRAINT_VIOLATION,
@@ -257,6 +256,8 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend
$this->logger->warning('Constraint violation while inserting version, retrying with increased timestamp', ['exception' => $e]);
}
}
+
+ return null;
}
public function updateVersionEntity(File $sourceFile, int $revision, array $properties): void {
diff --git a/apps/files_versions/lib/Versions/VersionManager.php b/apps/files_versions/lib/Versions/VersionManager.php
index f72e451f368..9acea8c6513 100644
--- a/apps/files_versions/lib/Versions/VersionManager.php
+++ b/apps/files_versions/lib/Versions/VersionManager.php
@@ -8,6 +8,8 @@ declare(strict_types=1);
*/
namespace OCA\Files_Versions\Versions;
+use OCA\Files_Versions\Db\VersionEntity;
+use OCA\Files_Versions\Events\VersionCreatedEvent;
use OCA\Files_Versions\Events\VersionRestoredEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
@@ -129,7 +131,16 @@ class VersionManager implements IVersionManager, IDeletableVersionBackend, INeed
public function createVersionEntity(File $file): void {
$backend = $this->getBackendForStorage($file->getStorage());
if ($backend instanceof INeedSyncVersionBackend) {
- $backend->createVersionEntity($file);
+ $versionEntity = $backend->createVersionEntity($file);
+
+ if ($versionEntity instanceof VersionEntity) {
+ foreach ($backend->getVersionsForFile($file->getOwner(), $file) as $version) {
+ if ($version->getRevisionId() === $versionEntity->getTimestamp()) {
+ $this->dispatcher->dispatchTyped(new VersionCreatedEvent($file, $version));
+ break;
+ }
+ }
+ }
}
}