Compare commits
1 commit
main
...
renovate/n
Author | SHA1 | Date | |
---|---|---|---|
3958f9181f |
27 changed files with 397 additions and 609 deletions
|
@ -1,2 +0,0 @@
|
||||||
js/
|
|
||||||
vendor/
|
|
|
@ -5,7 +5,7 @@
|
||||||
<name>Groupfolder Filesystem Snapshots</name>
|
<name>Groupfolder Filesystem Snapshots</name>
|
||||||
<summary>Allows restoring a groupfolder to a previous snapshot in the filesystem</summary>
|
<summary>Allows restoring a groupfolder to a previous snapshot in the filesystem</summary>
|
||||||
<description>App proving a PHP API for other apps, that allows (partially) restoring a groupfolder to a previous snapshot in the filesystem. Requires a filesystem with snapshot support (tested with and made for ZFS). It is made for other apps to integrate with, IT DOES NOT WORK STANDALONE</description>
|
<description>App proving a PHP API for other apps, that allows (partially) restoring a groupfolder to a previous snapshot in the filesystem. Requires a filesystem with snapshot support (tested with and made for ZFS). It is made for other apps to integrate with, IT DOES NOT WORK STANDALONE</description>
|
||||||
<version>1.4.1</version>
|
<version>1.3.1</version>
|
||||||
<licence>agpl</licence>
|
<licence>agpl</licence>
|
||||||
<author homepage="https://verdigado.com/">verdigado eG</author>
|
<author homepage="https://verdigado.com/">verdigado eG</author>
|
||||||
<author mail="jonathan.treffler@verdigado.com">Jonathan Treffler</author>
|
<author mail="jonathan.treffler@verdigado.com">Jonathan Treffler</author>
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
<category>files</category>
|
<category>files</category>
|
||||||
<bugs>https://git.verdigado.com/verdigado-public/nextcloud_groupfolder_filesystem_snapshots/issues</bugs>
|
<bugs>https://git.verdigado.com/verdigado-public/nextcloud_groupfolder_filesystem_snapshots/issues</bugs>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<nextcloud min-version="29" max-version="30"/>
|
<nextcloud min-version="28" max-version="29"/>
|
||||||
<database>pgsql</database>
|
<database>pgsql</database>
|
||||||
<database>sqlite</database>
|
<database>sqlite</database>
|
||||||
<database>mysql</database>
|
<database>mysql</database>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
before_cmds = [
|
before_cmds = [
|
||||||
"composer install",
|
"composer install",
|
||||||
"npm ci",
|
"npm install",
|
||||||
"npm run build",
|
"npm run build",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
OC.L10N.register(
|
|
||||||
"groupfolder_filesystem_snapshots",
|
|
||||||
{
|
|
||||||
"Automated hourly backup" : "Stündliches automatisches Backup",
|
|
||||||
"Automated daily backup" : "Tägliches automatisches Backup",
|
|
||||||
"Automated weekly backup" : "Wöchentliches automatisches Backup",
|
|
||||||
"Automated monthly backup" : "Monatliches automatisches Backup"
|
|
||||||
},
|
|
||||||
"nplurals=2; plural=(n != 1);");
|
|
|
@ -1,7 +0,0 @@
|
||||||
{ "translations": {
|
|
||||||
"Automated hourly backup" : "Stündliches automatisches Backup",
|
|
||||||
"Automated daily backup" : "Tägliches automatisches Backup",
|
|
||||||
"Automated weekly backup" : "Wöchentliches automatisches Backup",
|
|
||||||
"Automated monthly backup" : "Monatliches automatisches Backup"
|
|
||||||
},"pluralForm" :"nplurals=2; plural=(n != 1);"
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
OC.L10N.register(
|
|
||||||
"groupfolder_filesystem_snapshots",
|
|
||||||
{
|
|
||||||
"Automated hourly backup" : "Stündliches automatisches Backup",
|
|
||||||
"Automated daily backup" : "Tägliches automatisches Backup",
|
|
||||||
"Automated weekly backup" : "Wöchentliches automatisches Backup",
|
|
||||||
"Automated monthly backup" : "Monatliches automatisches Backup"
|
|
||||||
},
|
|
||||||
"nplurals=2; plural=(n != 1);");
|
|
|
@ -1,7 +0,0 @@
|
||||||
{ "translations": {
|
|
||||||
"Automated hourly backup" : "Stündliches automatisches Backup",
|
|
||||||
"Automated daily backup" : "Tägliches automatisches Backup",
|
|
||||||
"Automated weekly backup" : "Wöchentliches automatisches Backup",
|
|
||||||
"Automated monthly backup" : "Monatliches automatisches Backup"
|
|
||||||
},"pluralForm" :"nplurals=2; plural=(n != 1);"
|
|
||||||
}
|
|
|
@ -16,8 +16,6 @@ class DiffTaskResult extends Entity implements JsonSerializable {
|
||||||
protected $beforeSize;
|
protected $beforeSize;
|
||||||
|
|
||||||
protected $currentFileExists;
|
protected $currentFileExists;
|
||||||
protected $currentFileId;
|
|
||||||
|
|
||||||
protected $currentPath;
|
protected $currentPath;
|
||||||
protected $currentSize;
|
protected $currentSize;
|
||||||
protected $reverted;
|
protected $reverted;
|
||||||
|
@ -28,7 +26,6 @@ class DiffTaskResult extends Entity implements JsonSerializable {
|
||||||
$this->addType('beforeFileExists','boolean');
|
$this->addType('beforeFileExists','boolean');
|
||||||
$this->addType('beforeSize','integer');
|
$this->addType('beforeSize','integer');
|
||||||
$this->addType('currentFileExists','boolean');
|
$this->addType('currentFileExists','boolean');
|
||||||
$this->addType('currentFileId','integer');
|
|
||||||
$this->addType('currentSize','integer');
|
$this->addType('currentSize','integer');
|
||||||
$this->addType('reverted','boolean');
|
$this->addType('reverted','boolean');
|
||||||
}
|
}
|
||||||
|
@ -45,7 +42,6 @@ class DiffTaskResult extends Entity implements JsonSerializable {
|
||||||
],
|
],
|
||||||
'current' => [
|
'current' => [
|
||||||
'fileExists' => $this->currentFileExists,
|
'fileExists' => $this->currentFileExists,
|
||||||
'fileId' => $this->currentFileId,
|
|
||||||
'path' => $this->currentPath,
|
'path' => $this->currentPath,
|
||||||
'size' => $this->currentSize,
|
'size' => $this->currentSize,
|
||||||
],
|
],
|
||||||
|
|
|
@ -5,30 +5,16 @@ namespace OCA\GroupfolderFilesystemSnapshots\Entity;
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
|
||||||
class Snapshot implements JsonSerializable {
|
class Snapshot implements JsonSerializable {
|
||||||
public function __construct(
|
/** @var string */
|
||||||
private string $id,
|
private $id;
|
||||||
private string $name,
|
|
||||||
private ?\DateTimeImmutable $createdTimestamp = null,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getId(): string {
|
public function __construct(string $id) {
|
||||||
return $this->id;
|
$this->id = $id;
|
||||||
}
|
|
||||||
|
|
||||||
public function getName(): string {
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCreatedTimestamp(): ?\DateTimeImmutable {
|
|
||||||
return $this->createdTimestamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): mixed {
|
public function jsonSerialize(): mixed {
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id
|
||||||
'name' => $this->name,
|
|
||||||
'createdTimestamp' => $this->createdTimestamp?->getTimestamp(),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,12 +70,12 @@ class PathManager {
|
||||||
private function checkIfGroupfolderExists(int $groupfolderId): bool {
|
private function checkIfGroupfolderExists(int $groupfolderId): bool {
|
||||||
$storageId = $this->getRootFolderStorageId();
|
$storageId = $this->getRootFolderStorageId();
|
||||||
if ($storageId === null) {
|
if ($storageId === null) {
|
||||||
return false;
|
return "storage Id null";
|
||||||
}
|
}
|
||||||
|
|
||||||
$folder = $this->groupfolderFolderManager->getFolder($groupfolderId, $storageId);
|
$folder = $this->groupfolderFolderManager->getFolder($groupfolderId, $storageId);
|
||||||
if ($folder === false) {
|
if ($folder === false) {
|
||||||
return false;
|
return "Folder does not exist";
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -2,21 +2,16 @@
|
||||||
|
|
||||||
namespace OCA\GroupfolderFilesystemSnapshots\Manager;
|
namespace OCA\GroupfolderFilesystemSnapshots\Manager;
|
||||||
|
|
||||||
use OCP\IL10N;
|
|
||||||
|
|
||||||
use OCA\GroupfolderFilesystemSnapshots\Manager\PathManager;
|
use OCA\GroupfolderFilesystemSnapshots\Manager\PathManager;
|
||||||
use OCA\GroupfolderFilesystemSnapshots\Service\SettingsService;
|
|
||||||
use OCA\GroupfolderFilesystemSnapshots\Entity\Snapshot;
|
use OCA\GroupfolderFilesystemSnapshots\Entity\Snapshot;
|
||||||
|
|
||||||
class SnapshotManager {
|
class SnapshotManager {
|
||||||
private string $snapshotNamingScheme = "";
|
private PathManager $pathManager;
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
protected readonly IL10N $l10n,
|
public function __construct(PathManager $pathManager){
|
||||||
private readonly PathManager $pathManager,
|
$this->pathManager = $pathManager;
|
||||||
private readonly SettingsService $settingsService,
|
|
||||||
){
|
|
||||||
$this->snapshotNamingScheme = $this->settingsService->getAppValue("snapshot_naming_scheme");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validSnapshotId(string $snapshotId) {
|
private function validSnapshotId(string $snapshotId) {
|
||||||
|
@ -32,94 +27,20 @@ class SnapshotManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createSnapshotEntity(string $id): Snapshot {
|
|
||||||
if ($this->snapshotNamingScheme === "zfs-auto-snapshot" && str_starts_with($id, "zfs-auto-snap")) {
|
|
||||||
if (str_starts_with($id, "zfs-auto-snap_hourly-")) {
|
|
||||||
$name = $this->l10n->t("Automated hourly backup");
|
|
||||||
$datetimestring = str_replace("zfs-auto-snap_hourly-", "", $id);
|
|
||||||
} elseif (str_starts_with($id, "zfs-auto-snap_daily-")) {
|
|
||||||
$name = $this->l10n->t("Automated daily backup");
|
|
||||||
$datetimestring = str_replace("zfs-auto-snap_daily-", "", $id);
|
|
||||||
} elseif (str_starts_with($id, "zfs-auto-snap_weekly-")) {
|
|
||||||
$name = $this->l10n->t("Automated weekly backup");
|
|
||||||
$datetimestring = str_replace("zfs-auto-snap_weekly-", "", $id);
|
|
||||||
} elseif (str_starts_with($id, "zfs-auto-snap_monthly-")) {
|
|
||||||
$name = $this->l10n->t("Automated monthly backup");
|
|
||||||
$datetimestring = str_replace("zfs-auto-snap_monthly-", "", $id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($datetimestring)) {
|
|
||||||
$datetimearray = explode("-", $datetimestring);
|
|
||||||
$timestring = array_pop($datetimearray);
|
|
||||||
|
|
||||||
$year = (int)$datetimearray[0];
|
|
||||||
$month = (int)$datetimearray[1];
|
|
||||||
$day = (int)$datetimearray[2];
|
|
||||||
$hour = (int)substr($timestring, 0, 2);
|
|
||||||
$minute = (int)substr($timestring, 2, 2);
|
|
||||||
|
|
||||||
$createdTimestamp = (new \DateTimeImmutable())
|
|
||||||
->setDate($year, $month, $day)
|
|
||||||
->setTime($hour, $minute);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Snapshot(
|
|
||||||
id: $id,
|
|
||||||
name: $name ?: $id,
|
|
||||||
createdTimestamp: $createdTimestamp,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return new Snapshot(
|
|
||||||
id: $id,
|
|
||||||
name: $id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function get(string $snapshotId) {
|
function get(string $snapshotId) {
|
||||||
if(self::snapshotExists($snapshotId)) {
|
if(self::snapshotExists($snapshotId)) {
|
||||||
return $this->createSnapshotEntity($snapshotId);
|
return new Snapshot($snapshotId);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAll(): array {
|
function getAll() {
|
||||||
$snapshots = [];
|
|
||||||
|
|
||||||
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotsPath());
|
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotsPath());
|
||||||
|
|
||||||
foreach ($iterator as $fileinfo) {
|
foreach ($iterator as $fileinfo) {
|
||||||
if(!$fileinfo->isDir()) continue;
|
if(!$fileinfo->isDir()) continue;
|
||||||
$snapshots[] = $this->createSnapshotEntity($fileinfo->getFilename());
|
yield new Snapshot($fileinfo->getFilename());
|
||||||
}
|
|
||||||
|
|
||||||
return $snapshots;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAllGenerator(){
|
|
||||||
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotsPath());
|
|
||||||
|
|
||||||
foreach ($iterator as $fileinfo) {
|
|
||||||
if(!$fileinfo->isDir()) continue;
|
|
||||||
yield $this->createSnapshotEntity($fileinfo->getFilename());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var $subPathFilter Only return snapshots that have this subfolder in the specified groupfolder
|
|
||||||
*/
|
|
||||||
function getFilteredGenerator(int $groupfolderId, string $subDirectoryFilter) {
|
|
||||||
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotsPath());
|
|
||||||
|
|
||||||
$groupfolderSubdirectoryPath = $this->pathManager->getGroupFolderDirectory($groupfolderId, $subDirectoryFilter);
|
|
||||||
|
|
||||||
foreach ($iterator as $fileinfo) {
|
|
||||||
if(!$fileinfo->isDir()) continue;
|
|
||||||
$snapshotId = $fileinfo->getFilename();
|
|
||||||
$filterFullPath = $this->pathManager->convertToSnapshotPath($groupfolderSubdirectoryPath, $snapshotId);
|
|
||||||
if(!(is_dir($filterFullPath))) continue;
|
|
||||||
yield $this->createSnapshotEntity($snapshotId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,33 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace OCA\GroupfolderFilesystemSnapshots\Migration;
|
|
||||||
|
|
||||||
use Closure;
|
|
||||||
use OCP\DB\ISchemaWrapper;
|
|
||||||
use OCP\DB\Types;
|
|
||||||
use OCP\Migration\SimpleMigrationStep;
|
|
||||||
use OCP\Migration\IOutput;
|
|
||||||
|
|
||||||
class Version140Date20250701164500 extends SimpleMigrationStep {
|
|
||||||
const RESULTS_TABLE = "groupfolder_snapshots_task_results";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param IOutput $output
|
|
||||||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
|
||||||
* @param array $options
|
|
||||||
* @return null|ISchemaWrapper
|
|
||||||
*/
|
|
||||||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
|
|
||||||
/** @var ISchemaWrapper $schema */
|
|
||||||
$schema = $schemaClosure();
|
|
||||||
$table = $schema->getTable(self::RESULTS_TABLE);
|
|
||||||
|
|
||||||
if(!$table->hasColumn('current_file_id')) {
|
|
||||||
$table->addColumn('current_file_id', Types::BIGINT, [
|
|
||||||
'notnull' => false,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $schema;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,6 +5,15 @@ namespace OCA\GroupfolderFilesystemSnapshots;
|
||||||
use OCA\GroupfolderFilesystemSnapshots\Helpers\FileHelper;
|
use OCA\GroupfolderFilesystemSnapshots\Helpers\FileHelper;
|
||||||
|
|
||||||
class RecursiveDiff {
|
class RecursiveDiff {
|
||||||
|
|
||||||
|
public string $dir1;
|
||||||
|
public string $dir2;
|
||||||
|
|
||||||
|
private $prefix;
|
||||||
|
|
||||||
|
private $newResultCallback;
|
||||||
|
private $progressCallback;
|
||||||
|
|
||||||
private $scan1files = [];
|
private $scan1files = [];
|
||||||
private $scan1folders = [];
|
private $scan1folders = [];
|
||||||
|
|
||||||
|
@ -16,14 +25,14 @@ class RecursiveDiff {
|
||||||
private $subJobProgress = [];
|
private $subJobProgress = [];
|
||||||
private $progress = 0;
|
private $progress = 0;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct($dir1, $dir2, $prefix = "", $newResultCallback, $progressCallback){
|
||||||
public readonly string $dir1,
|
$this->dir1 = $dir1;
|
||||||
public readonly string $dir2,
|
$this->dir2 = $dir2;
|
||||||
private readonly string $prefix = "",
|
$this->prefix = $prefix;
|
||||||
private readonly array $folderBlocklist = [],
|
|
||||||
private $newResultCallback,
|
$this->newResultCallback = $newResultCallback;
|
||||||
private $progressCallback,
|
$this->progressCallback = $progressCallback;
|
||||||
){}
|
}
|
||||||
|
|
||||||
public function scan() {
|
public function scan() {
|
||||||
$scan_num_files = 0;
|
$scan_num_files = 0;
|
||||||
|
@ -45,13 +54,8 @@ class RecursiveDiff {
|
||||||
$subdir1 = $this->dir1 . DIRECTORY_SEPARATOR . $folder;
|
$subdir1 = $this->dir1 . DIRECTORY_SEPARATOR . $folder;
|
||||||
$subdir2 = $this->dir2 . DIRECTORY_SEPARATOR . $folder;
|
$subdir2 = $this->dir2 . DIRECTORY_SEPARATOR . $folder;
|
||||||
$subprefix = $this->prefix . DIRECTORY_SEPARATOR . $folder;
|
$subprefix = $this->prefix . DIRECTORY_SEPARATOR . $folder;
|
||||||
$subFolderBlocklist = $this->folderBlocklist[$folder] ?? [];
|
|
||||||
|
|
||||||
if($subFolderBlocklist === true) {
|
$newJob = new RecursiveDiff($subdir1, $subdir2, $subprefix, $this->newResultCallback, function($numDoneFiles) use ($key) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$newJob = new RecursiveDiff($subdir1, $subdir2, $subprefix, $subFolderBlocklist, $this->newResultCallback, function($numDoneFiles) use ($key) {
|
|
||||||
$this->subJobProgress[$key] = $numDoneFiles;
|
$this->subJobProgress[$key] = $numDoneFiles;
|
||||||
|
|
||||||
$this->updateProgress();
|
$this->updateProgress();
|
||||||
|
|
|
@ -58,7 +58,7 @@ class DiffTaskResultService {
|
||||||
$diffTaskResult = $this->find($id);
|
$diffTaskResult = $this->find($id);
|
||||||
|
|
||||||
if($diffTaskResult->getReverted()) {
|
if($diffTaskResult->getReverted()) {
|
||||||
throw new AlreadyRevertedException();
|
throw new AlreadyRevertedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$taskId = $diffTaskResult->getTaskId();
|
$taskId = $diffTaskResult->getTaskId();
|
||||||
|
@ -66,35 +66,35 @@ class DiffTaskResultService {
|
||||||
|
|
||||||
$snapshotPath = $this->pathManager->getGroupFolderSnapshotDirectory($diffTask->getGroupfolderId(), $diffTask->getRelativePath(), $diffTask->getSnapshotId());
|
$snapshotPath = $this->pathManager->getGroupFolderSnapshotDirectory($diffTask->getGroupfolderId(), $diffTask->getRelativePath(), $diffTask->getSnapshotId());
|
||||||
|
|
||||||
$parentFolder = $this->pathManager->getGroupfolderMountById($diffTask->getGroupfolderId())->get($diffTask->getRelativePath());
|
$gruenerFolder = $this->pathManager->getGroupfolderMountById($diffTask->getGroupfolderId())->get($diffTask->getRelativePath());
|
||||||
|
|
||||||
switch($diffTaskResult->getType()) {
|
switch($diffTaskResult->getType()) {
|
||||||
case "CREATION":
|
case "CREATION":
|
||||||
$currentFile = $this->getSubfolderMustExist($parentFolder, $diffTaskResult->getCurrentPath());
|
$currentFile = $this->getSubfolderMustExist($gruenerFolder, $diffTaskResult->getCurrentPath());
|
||||||
$currentFile->delete();
|
$currentFile->delete();
|
||||||
break;
|
break;
|
||||||
case "RENAME":
|
case "RENAME":
|
||||||
$currentFile = $this->getSubfolderMustExist($parentFolder, $diffTaskResult->getCurrentPath());
|
$currentFile = $this->getSubfolderMustExist($gruenerFolder, $diffTaskResult->getCurrentPath());
|
||||||
$beforeDirectory = $this->getOrCreateSubdirectoryByFilepath($parentFolder, $diffTaskResult->getBeforePath());
|
$beforeDirectory = $this->getOrCreateSubdirectoryByFilepath($gruenerFolder, $diffTaskResult->getBeforePath());
|
||||||
|
|
||||||
$currentFile->move($beforeDirectory->getPath() . DIRECTORY_SEPARATOR . basename($diffTaskResult->getBeforePath()));
|
$currentFile->move($beforeDirectory->getPath() . DIRECTORY_SEPARATOR . basename($diffTaskResult->getBeforePath()));
|
||||||
break;
|
break;
|
||||||
case "DELETION":
|
case "DELETION":
|
||||||
$beforeFileFilesystemPath = $snapshotPath . DIRECTORY_SEPARATOR . $diffTaskResult->getBeforePath();
|
$beforeFileFilesystemPath = $snapshotPath . DIRECTORY_SEPARATOR . $diffTaskResult->getBeforePath();
|
||||||
|
|
||||||
$beforeDirectory = $this->getOrCreateSubdirectoryByFilepath($parentFolder, $diffTaskResult->getBeforePath());
|
$beforeDirectory = $this->getOrCreateSubdirectoryByFilepath($gruenerFolder, $diffTaskResult->getBeforePath());
|
||||||
$restoredFile = $beforeDirectory->newFile(basename($diffTaskResult->getBeforePath()));
|
$restoredFile = $beforeDirectory->newFile(basename($diffTaskResult->getBeforePath()));
|
||||||
|
|
||||||
$this->copyFilesystemFileToNextcloudFile($beforeFileFilesystemPath, $restoredFile);
|
$this->copyFilesystemFileToNextcloudFile($beforeFileFilesystemPath, $restoredFile);
|
||||||
break;
|
break;
|
||||||
case "EDIT":
|
case "EDIT":
|
||||||
$currentFile = $this->getSubfolderMustExist($parentFolder, $diffTaskResult->getCurrentPath());
|
$currentFile = $this->getSubfolderMustExist($gruenerFolder, $diffTaskResult->getCurrentPath());
|
||||||
$beforeFileFilesystemPath = $snapshotPath . DIRECTORY_SEPARATOR . $diffTaskResult->getBeforePath();
|
$beforeFileFilesystemPath = $snapshotPath . DIRECTORY_SEPARATOR . $diffTaskResult->getBeforePath();
|
||||||
|
|
||||||
$this->copyFilesystemFileToNextcloudFile($beforeFileFilesystemPath, $currentFile);
|
$this->copyFilesystemFileToNextcloudFile($beforeFileFilesystemPath, $currentFile);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception();
|
throw new \Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->mapper->markReverted($id);
|
return $this->mapper->markReverted($id);
|
||||||
|
@ -104,7 +104,7 @@ class DiffTaskResultService {
|
||||||
if($parent->nodeExists($path)) {
|
if($parent->nodeExists($path)) {
|
||||||
return $parent->get($path);
|
return $parent->get($path);
|
||||||
} else {
|
} else {
|
||||||
throw new ChangesMadeSinceDiffException();
|
throw new ChangesMadeSinceDiffException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ class DiffTaskResultService {
|
||||||
if($temp instanceof \OCP\Files\Folder) {
|
if($temp instanceof \OCP\Files\Folder) {
|
||||||
$beforeDirectory = $temp;
|
$beforeDirectory = $temp;
|
||||||
} else {
|
} else {
|
||||||
throw new ChangesMadeSinceDiffException();
|
throw new ChangesMadeSinceDiffException;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$beforeDirectory = $beforeDirectory->newFolder($subdir);
|
$beforeDirectory = $beforeDirectory->newFolder($subdir);
|
||||||
|
|
|
@ -58,8 +58,7 @@ class DiffTaskService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function create(string $relativePathInGroupfolder, int $groupfolderId, string $snapshotId, string $userId, array $folderBlocklist, Callable $progressCallback = null): ?DiffTask {
|
function create(string $relativePathInGroupfolder, int $groupfolderId, string $snapshotId, string $userId, Callable $progressCallback = null): ?DiffTask {
|
||||||
$parentNode = $this->pathManager->getGroupfolderMountById($groupfolderId)->get($relativePathInGroupfolder);
|
|
||||||
$snapshotPath = $this->pathManager->getGroupFolderSnapshotDirectory($groupfolderId, $relativePathInGroupfolder, $snapshotId);
|
$snapshotPath = $this->pathManager->getGroupFolderSnapshotDirectory($groupfolderId, $relativePathInGroupfolder, $snapshotId);
|
||||||
$groupfolderPath = $this->pathManager->getGroupFolderDirectory($groupfolderId, $relativePathInGroupfolder);
|
$groupfolderPath = $this->pathManager->getGroupFolderDirectory($groupfolderId, $relativePathInGroupfolder);
|
||||||
|
|
||||||
|
@ -81,25 +80,16 @@ class DiffTaskService {
|
||||||
$snapshotPath,
|
$snapshotPath,
|
||||||
$groupfolderPath,
|
$groupfolderPath,
|
||||||
"",
|
"",
|
||||||
$folderBlocklist,
|
function(string $type, bool $beforeFileExists, ?string $beforePath, ?int $beforeSize, bool $currentFileExists, ?string $currentPath, ?int $currentSize) use ($task) {
|
||||||
function(string $type, bool $beforeFileExists, ?string $beforePath, ?int $beforeSize, bool $currentFileExists, ?string $currentPath, ?int $currentSize) use ($task, $parentNode) {
|
|
||||||
$newResult = new DiffTaskResult();
|
$newResult = new DiffTaskResult();
|
||||||
$newResult->setTaskId($task->getId());
|
$newResult->setTaskId($task->getId());
|
||||||
$newResult->setType($type);
|
$newResult->setType($type);
|
||||||
|
|
||||||
$newResult->setBeforeFileExists($beforeFileExists);
|
$newResult->setBeforeFileExists($beforeFileExists);
|
||||||
if($beforeFileExists) {
|
|
||||||
$newResult->setBeforePath($beforePath);
|
$newResult->setBeforePath($beforePath);
|
||||||
$newResult->setBeforeSize($beforeSize);
|
$newResult->setBeforeSize($beforeSize);
|
||||||
}
|
|
||||||
|
|
||||||
$newResult->setCurrentFileExists($currentFileExists);
|
$newResult->setCurrentFileExists($currentFileExists);
|
||||||
if($currentFileExists) {
|
|
||||||
$newResult->setCurrentFileId($parentNode->get($currentPath)?->getId());
|
|
||||||
$newResult->setCurrentPath($currentPath);
|
$newResult->setCurrentPath($currentPath);
|
||||||
$newResult->setCurrentSize($currentSize);
|
$newResult->setCurrentSize($currentSize);
|
||||||
}
|
|
||||||
|
|
||||||
$newResult = $this->diffTaskResultMapper->insert($newResult);
|
$newResult = $this->diffTaskResultMapper->insert($newResult);
|
||||||
},
|
},
|
||||||
function($numDoneFiles) use ($progressCallback, &$numFiles) {
|
function($numDoneFiles) use ($progressCallback, &$numFiles) {
|
||||||
|
@ -107,7 +97,8 @@ class DiffTaskService {
|
||||||
($progressCallback)([
|
($progressCallback)([
|
||||||
"overallFiles" => $numFiles,
|
"overallFiles" => $numFiles,
|
||||||
"doneFiles" => $numDoneFiles,
|
"doneFiles" => $numDoneFiles,
|
||||||
"progress" => floor(($numDoneFiles / $numFiles) * 100) / 100,
|
"progress" => number_format(($numDoneFiles / $numFiles),2),
|
||||||
|
"progressPercent" => (number_format(($numDoneFiles / $numFiles),2) * 100) . "%",
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -122,6 +113,7 @@ class DiffTaskService {
|
||||||
"overallFiles" => $numFiles,
|
"overallFiles" => $numFiles,
|
||||||
"doneFiles" => $numFiles,
|
"doneFiles" => $numFiles,
|
||||||
"progress" => 1.0,
|
"progress" => 1.0,
|
||||||
|
"progressPercent" => "100.00%",
|
||||||
"result" => $task,
|
"result" => $task,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ use OCP\IConfig;
|
||||||
|
|
||||||
class SettingsService {
|
class SettingsService {
|
||||||
|
|
||||||
private static array $VALID_APP_SETTINGS = ["filesystem_mountpoint_path", "filesystem_snapshots_path", "snapshot_naming_scheme"];
|
private static array $VALID_APP_SETTINGS = ["filesystem_mountpoint_path", "filesystem_snapshots_path"];
|
||||||
|
|
||||||
public function __construct(private IConfig $config) {
|
public function __construct(private IConfig $config) {
|
||||||
}
|
}
|
||||||
|
|
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -22,7 +22,7 @@
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^16.0.0",
|
"node": "^16.0.0",
|
||||||
"npm": "^7.0.0 || ^8.0.0"
|
"npm": "^11.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@ampproject/remapping": {
|
"node_modules/@ampproject/remapping": {
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
],
|
],
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^16.0.0",
|
"node": "^16.0.0",
|
||||||
"npm": "^7.0.0 || ^8.0.0"
|
"npm": "^11.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nextcloud/babel-config": "^1.2.0",
|
"@nextcloud/babel-config": "^1.2.0",
|
||||||
|
|
|
@ -4,13 +4,12 @@
|
||||||
name="Groupfolder Filesystem Snapshots"
|
name="Groupfolder Filesystem Snapshots"
|
||||||
:limit-width="false">
|
:limit-width="false">
|
||||||
<div v-if="!loading">
|
<div v-if="!loading">
|
||||||
<Field :is="getAppSettingComponent(setting)"
|
<Field :is="setting.sensitive ? NcPasswordField : NcTextField"
|
||||||
v-for="setting in app_settings"
|
v-for="setting in app_settings"
|
||||||
v-bind="getAppSettingProps(setting)"
|
|
||||||
:key="setting.id"
|
:key="setting.id"
|
||||||
class="settings_field"
|
class="settings_field"
|
||||||
:value="settings?.[setting.id]"
|
:value="settings?.[setting.id]"
|
||||||
@update:modelValue="(newValue) => updateSetting(setting.id, newValue)"
|
:label="setting.name"
|
||||||
@update:value="(newValue) => updateSetting(setting.id, newValue)" />
|
@update:value="(newValue) => updateSetting(setting.id, newValue)" />
|
||||||
</div>
|
</div>
|
||||||
</NcSettingsSection>
|
</NcSettingsSection>
|
||||||
|
@ -19,7 +18,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import debounceFunction from 'debounce-fn';
|
import debounceFunction from 'debounce-fn';
|
||||||
import { NcSettingsSection, NcTextField, NcPasswordField, NcSelect } from "@nextcloud/vue"
|
import { NcSettingsSection, NcTextField, NcPasswordField } from "@nextcloud/vue"
|
||||||
|
|
||||||
import { adminSettingsApi } from "./adminSettingsApi.js";
|
import { adminSettingsApi } from "./adminSettingsApi.js";
|
||||||
|
|
||||||
|
@ -27,53 +26,10 @@ let loading = ref(true);
|
||||||
let settings = ref({});
|
let settings = ref({});
|
||||||
|
|
||||||
const app_settings = [
|
const app_settings = [
|
||||||
{id: "filesystem_mountpoint_path", name: "Filesystem Mountpoint Path", type: "text" },
|
{id: "filesystem_mountpoint_path", name: "Filesystem Mountpoint Path"},
|
||||||
{id: "filesystem_snapshots_path", name: "Filesystem Snapshots Path", type: "text"},
|
{id: "filesystem_snapshots_path", name: "Filesystem Snapshots Path"},
|
||||||
{
|
|
||||||
id: "snapshot_naming_scheme",
|
|
||||||
name: "Snapshot Naming Scheme",
|
|
||||||
type: "select",
|
|
||||||
options: [
|
|
||||||
{
|
|
||||||
id: '',
|
|
||||||
label: 'None',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'zfs-auto-snapshot',
|
|
||||||
label: 'zfs-auto-snapshot',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const getAppSettingComponent = function(appSetting) {
|
|
||||||
if(appSetting.type === "select") {
|
|
||||||
return NcSelect;
|
|
||||||
} else {
|
|
||||||
if(appSetting?.sensitive) {
|
|
||||||
return NcPasswordField;
|
|
||||||
} else {
|
|
||||||
return NcTextField;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const getAppSettingProps = function(appSetting) {
|
|
||||||
if(appSetting.type === "select") {
|
|
||||||
return {
|
|
||||||
options: appSetting.options,
|
|
||||||
label: "label",
|
|
||||||
inputLabel: appSetting.name,
|
|
||||||
reduce: (option) => ( option.id )
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
label: appSetting.name,
|
|
||||||
clearable: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
adminSettingsApi.getAllSettings().then((result) => {
|
adminSettingsApi.getAllSettings().then((result) => {
|
||||||
settings.value = result;
|
settings.value = result;
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue