diff options
author | Sergey Linnik <sergey.linnik@onlyoffice.com> | 2020-09-08 12:31:31 +0300 |
---|---|---|
committer | Sergey Linnik <sergey.linnik@onlyoffice.com> | 2020-09-15 11:26:34 +0300 |
commit | 57e7141ae580414a0902c0805fb19d7c9dfab524 (patch) | |
tree | 82d35713ceca284115245420f1d97fdabb8f8aa7 /lib/keymanager.php | |
parent | e65c8910f3d3ae8d588549710752d00c7a895f07 (diff) |
storing key in db
Diffstat (limited to 'lib/keymanager.php')
-rw-r--r-- | lib/keymanager.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/keymanager.php b/lib/keymanager.php new file mode 100644 index 0000000..627953e --- /dev/null +++ b/lib/keymanager.php @@ -0,0 +1,74 @@ +<?php +/** + * + * (c) Copyright Ascensio System SIA 2020 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace OCA\Onlyoffice; + + +/** + * Key manager + * + * @package OCA\Onlyoffice + */ +class KeyManager { + + /** + * Table name + */ + private const TableName_Key = "onlyoffice_filekey"; + + /** + * Get document identifier + * + * @param integer $fileId - file identifier + * + * @return string + */ + public static function get($fileId) { + $connection = \OC::$server->getDatabaseConnection(); + $select = $connection->prepare(" + SELECT `key` + FROM `*PREFIX*" . self::TableName_Key . "` + WHERE `file_id` = ? + "); + $result = $select->execute([$fileId]); + + $keys = $result ? $select->fetch() : []; + $key = is_array($keys) && isset($keys["key"]) ? $keys["key"] : ""; + + return $key; + } + + /** + * Store document identifier + * + * @param integer $fileId - file identifier + * @param integer $key - file key + * + * @return bool + */ + public static function set($fileId, $key) { + $connection = \OC::$server->getDatabaseConnection(); + $insert = $connection->prepare(" + INSERT INTO `*PREFIX*" . self::TableName_Key . "` + (`file_id`, `key`) + VALUES (?, ?) + "); + return (bool)$insert->execute([$fileId, $key]); + } +} |