Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ONLYOFFICE/onlyoffice-nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Linnik <sergey.linnik@onlyoffice.com>2020-07-18 10:43:27 +0300
committerSergey Linnik <sergey.linnik@onlyoffice.com>2020-07-21 10:31:42 +0300
commit3cfb14d4952b73e2005c51361d765c7929683923 (patch)
treeb71574321e69e0ae00654a4d0197da3cd73ffe9e /lib/fileversions.php
parente4ba1fceec601b6262261c48bc7059b1ba0867e2 (diff)
delete version of file hook
Diffstat (limited to 'lib/fileversions.php')
-rw-r--r--lib/fileversions.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/fileversions.php b/lib/fileversions.php
index 1c3a9c0..678d47e 100644
--- a/lib/fileversions.php
+++ b/lib/fileversions.php
@@ -61,6 +61,23 @@ class FileVersions {
private static $historyExt = ".json";
/**
+ * Split file path and version id
+ *
+ * @param string $pathVersion - version path
+ *
+ * @return array
+ */
+ public static function splitPathVersion($pathVersion) {
+ $pos = strrpos($pathVersion, ".v");
+ if ($pos === false) {
+ return false;
+ }
+ $filePath = substr($pathVersion, 0, $pos);
+ $versionId = substr($pathVersion, 2 + $pos - strlen($pathVersion));
+ return [$filePath, $versionId];
+ }
+
+ /**
* Check if folder is not exist
*
* @param string $userId - user id
@@ -277,4 +294,41 @@ class FileVersions {
$view->unlink($path);
}
+
+ /**
+ * Delete changes and history
+ *
+ * @param string $ownerId - file owner id
+ * @param string $fileId - file id
+ * @param string $versionId - file version
+ */
+ public static function deleteVersion($ownerId, $fileId, $versionId) {
+ $logger = \OC::$server->getLogger();
+
+ $logger->debug("deleteVersion $fileId ($versionId)", ["app" => self::$appName]);
+
+ if ($ownerId === null) {
+ return;
+ }
+ if ($fileId === null || empty($versionId)) {
+ return;
+ }
+
+ list ($view, $path) = self::getView($ownerId, $fileId);
+ if ($view === null) {
+ return null;
+ }
+
+ $historyPath = $path . "/" . $versionId . self::$historyExt;
+ if ($view->file_exists($historyPath)) {
+ $view->unlink($historyPath);
+ $logger->debug("deleteVersion $historyPath", ["app" => self::$appName]);
+ }
+
+ $changesPath = $path . "/" . $versionId . self::$changesExt;
+ if ($view->file_exists($changesPath)) {
+ $view->unlink($changesPath);
+ $logger->debug("deleteVersion $changesPath", ["app" => self::$appName]);
+ }
+ }
}