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\Entity\Snapshot;
|
|
|
|
|
2023-06-08 18:23:09 +02:00
|
|
|
class SnapshotManager {
|
2023-08-08 11:52:21 +02:00
|
|
|
private PathManager $pathManager;
|
|
|
|
|
|
|
|
|
2023-09-02 02:48:27 +02:00
|
|
|
public function __construct(PathManager $pathManager){
|
2023-08-08 11:52:21 +02:00
|
|
|
$this->pathManager = $pathManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2024-04-23 19:51:41 +02:00
|
|
|
$iterator = new \FilesystemIterator($this->pathManager->getFilesystemSnapshotsPath());
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|