You've already forked onlyoffice-owncloud
mirror of
https://github.com/ONLYOFFICE/onlyoffice-owncloud.git
synced 2025-07-30 10:43:07 +03:00
save version author
This commit is contained in:
committed by
Sergey Linnik
parent
41ec95619f
commit
79c205beca
@ -547,6 +547,10 @@ class CallbackController extends Controller {
|
|||||||
FileVersions::saveHistory($file->getFileInfo(), $history, $changes, $prevVersion);
|
FileVersions::saveHistory($file->getFileInfo(), $history, $changes, $prevVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($user)) {
|
||||||
|
FileVersions::saveAuthor($file->getFileInfo(), $user);
|
||||||
|
}
|
||||||
|
|
||||||
$result = 0;
|
$result = 0;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->logException($e, ["message" => "Track: $fileId status $status error", "app" => $this->appName]);
|
$this->logger->logException($e, ["message" => "Track: $fileId status $status error", "app" => $this->appName]);
|
||||||
|
@ -23,6 +23,7 @@ use OC\Files\Node\File;
|
|||||||
use OC\Files\View;
|
use OC\Files\View;
|
||||||
|
|
||||||
use OCP\Files\FileInfo;
|
use OCP\Files\FileInfo;
|
||||||
|
use OCP\IUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File versions
|
* File versions
|
||||||
@ -52,6 +53,13 @@ class FileVersions {
|
|||||||
*/
|
*/
|
||||||
private static $historyExt = ".json";
|
private static $historyExt = ".json";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File name contain author
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $authorExt = "_author.json";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split file path and version id
|
* Split file path and version id
|
||||||
*
|
*
|
||||||
@ -327,4 +335,44 @@ class FileVersions {
|
|||||||
$logger->debug("deleteVersion $changesPath", ["app" => self::$appName]);
|
$logger->debug("deleteVersion $changesPath", ["app" => self::$appName]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save file author
|
||||||
|
*
|
||||||
|
* @param FileInfo $fileInfo - file info
|
||||||
|
* @param IUser $author - version author
|
||||||
|
*/
|
||||||
|
public static function saveAuthor($fileInfo, $author) {
|
||||||
|
$logger = \OC::$server->getLogger();
|
||||||
|
|
||||||
|
if ($fileInfo === null || $author === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$owner = $fileInfo->getOwner();
|
||||||
|
if ($owner === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ownerId = $owner->getUID();
|
||||||
|
$fileId = $fileInfo->getId();
|
||||||
|
$versionId = $fileInfo->getMtime();
|
||||||
|
|
||||||
|
list ($view, $path) = self::getView($ownerId, $fileId, true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$authorPath = $path . "/" . $versionId . self::$authorExt;
|
||||||
|
$view->touch($authorPath);
|
||||||
|
|
||||||
|
$authorData = [
|
||||||
|
"id" => $author->getUID(),
|
||||||
|
"name" => $author->getDisplayName()
|
||||||
|
];
|
||||||
|
$view->file_put_contents($authorPath, json_encode($authorData));
|
||||||
|
|
||||||
|
$logger->debug("saveAuthor: $fileId for $ownerId stored author $authorPath", ["app" => self::$appName]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$logger->logException($e, ["message" => "saveAuthor: save $fileId author error", "app" => self::$appName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user