getId(); KeyManager::delete($fileId); \OCP\Log\logger('onlyoffice')->debug("Hook fileUpdate " . json_encode($params), ["app" => self::$appName]); } /** * Erase versions of deleted file * * @param array $params - hook params */ public static function fileDelete($params) { $filePath = $params[Filesystem::signal_param_path]; if (empty($filePath)) { return; } try { $fileInfo = Filesystem::getFileInfo($filePath); if ($fileInfo === false) { return; } $owner = $fileInfo->getOwner(); if (empty($owner)) { return; } $ownerId = $owner->getUID(); $fileId = $fileInfo->getId(); KeyManager::delete($fileId, true); FileVersions::deleteAllVersions($ownerId, $fileInfo); $root = \OC::$server->get(\OCP\Files\IRootFolder::class); $folder = $root->getUserFolder($ownerId); $files = $folder->getById($fileId); if (!empty($files)) { $shares = []; $shareTypes = [ IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK, IShare::TYPE_ROOM, ]; $node = $files[0]; $shareManager = \OC::$server->get(\OCP\Share\IManager::class); foreach ($shareTypes as $shareType) { $shares = array_merge($shares, $shareManager->getSharesBy($ownerId, $shareType, $node)); } $shareIds = array_map(fn(IShare $share) => $share->getId(), $shares); if (!empty($shareIds)) { ExtraPermissions::deleteList($shareIds); } } } catch (\Exception $e) { \OCP\Log\logger('onlyoffice')->error("Hook: fileDelete " . json_encode($params), ['exception' => $e]); } } /** * Erase versions of deleted version of file * * @param array $params - hook param */ public static function fileVersionDelete($params) { $pathVersion = $params["path"]; if (empty($pathVersion)) { return; } try { list($filePath, $versionId) = FileVersions::splitPathVersion($pathVersion); if (empty($filePath)) { return; } $fileInfo = Filesystem::getFileInfo($filePath); if ($fileInfo === false) { return; } $owner = $fileInfo->getOwner(); if (empty($owner)) { return; } $ownerId = $owner->getUID(); $fileId = $fileInfo->getId(); FileVersions::deleteVersion($ownerId, $fileInfo, $versionId); FileVersions::deleteAuthor($ownerId, $fileInfo, $versionId); } catch (\Exception $e) { \OCP\Log\logger('onlyoffice')->error("Hook: fileVersionDelete " . json_encode($params), ['exception' => $e]); } } /** * Erase versions of restored version of file * * @param array $params - hook param */ public static function fileVersionRestore($params) { $node = $params["node"]; if (empty($node) || !($node instanceof File)) { return; } $filePath = preg_replace('/^\/\w+\/files\//', '', $params["node"]->getPath()); if (empty($filePath)) { return; } $versionId = $params["revision"]; try { $fileInfo = Filesystem::getFileInfo($filePath); if ($fileInfo === false) { return; } $owner = $fileInfo->getOwner(); if (empty($owner)) { return; } $ownerId = $owner->getUID(); $fileId = $fileInfo->getId(); KeyManager::delete($fileId); FileVersions::deleteVersion($ownerId, $fileInfo, $versionId); } catch (\Exception $e) { \OCP\Log\logger('onlyoffice')->error("Hook: fileVersionRestore " . json_encode($params), ['exception' => $e]); } } /** * Erase extra permissions of deleted share * * @param array $params - hook param */ public static function extraPermissionsDelete($params) { $shares = $params["deletedShares"]; if (empty($shares)) { return; } try { $shareIds = []; foreach ($shares as $share) { array_push($shareIds, $share["id"]); } ExtraPermissions::deleteList($shareIds); } catch (\Exception $e) { \OCP\Log\logger('onlyoffice')->error("Hook: extraPermissionsDelete " . json_encode($params), ['exception' => $e]); } } }