2023-06-08 18:23:09 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\GroupfolderFilesystemSnapshots\Manager;
|
|
|
|
|
2023-08-08 11:52:21 +02:00
|
|
|
use OCA\GroupfolderFilesystemSnapshots\Manager\PathManager;
|
|
|
|
use OCA\GroupfolderFilesystemSnapshots\Manager\DiffManager;
|
|
|
|
|
|
|
|
use OCA\GroupfolderFilesystemSnapshots\Entity\Snapshot;
|
|
|
|
|
2023-06-08 18:23:09 +02:00
|
|
|
class SnapshotManager {
|
2023-08-08 11:52:21 +02:00
|
|
|
private PathManager $pathManager;
|
|
|
|
private DiffManager $diffManager;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct(PathManager $pathManager, DiffManager $diffManager){
|
|
|
|
$this->pathManager = $pathManager;
|
|
|
|
$this->diffManager = $diffManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function validSnapshotId(string $snapshotId) {
|
|
|
|
return (preg_match("/^[a-zA-Z0-9-_]+$/", $snapshotId) == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function snapshotExists(string $snapshotId): bool {
|
|
|
|
if($this->validSnapshotId($snapshotId)) {
|
|
|
|
$path = $this->pathManager->getSnapshotPath($snapshotId);
|
|
|
|
return (file_exists($path) && is_dir($path));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get(string $snapshotId) {
|
|
|
|
if(self::snapshotExists($snapshotId)) {
|
|
|
|
return new Snapshot($snapshotId);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-06-08 18:23:09 +02:00
|
|
|
|
2023-08-08 11:52:21 +02:00
|
|
|
function getAll() {
|
|
|
|
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotPath());
|
2023-06-08 18:23:09 +02:00
|
|
|
foreach ($iterator as $fileinfo) {
|
|
|
|
if(!$fileinfo->isDir()) continue;
|
2023-08-08 11:52:21 +02:00
|
|
|
yield new Snapshot($fileinfo->getFilename());
|
2023-06-08 18:23:09 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:52:21 +02:00
|
|
|
|
|
|
|
function getDiff(int $groupfolderId, string $snapshotId) {
|
|
|
|
$groupfolderPath = $this->pathManager->getGroupFolderDirectory($groupfolderId);
|
|
|
|
$snapshotPath = $this->pathManager->getGroupFolderSnapshotDirectory($groupfolderId, $snapshotId);
|
|
|
|
|
|
|
|
return $this->diffManager->diffDirectories($snapshotPath, $groupfolderPath);
|
|
|
|
}
|
2023-06-08 18:23:09 +02:00
|
|
|
}
|