connection->prepare(" SELECT `key` FROM `*PREFIX*" . self::TABLENAME_KEY . "` WHERE `file_id` = ? "); $result = $select->execute([$fileId]); $keys = $result->fetch(); return is_array($keys) && isset($keys["key"]) ? $keys["key"] : ""; } /** * Store document identifier */ public function set(int $fileId, string $key): bool { $insert = $this->connection->prepare(" INSERT INTO `*PREFIX*" . self::TABLENAME_KEY . "` (`file_id`, `key`) VALUES (?, ?) "); return (bool)$insert->execute([$fileId, $key]); } /** * Delete document identifier * * @param integer $fileId - file identifier * @param bool $unlock - delete even with lock label */ public function delete(int $fileId, bool $unlock = false): bool { $delete = $this->connection->prepare( " DELETE FROM `*PREFIX*" . self::TABLENAME_KEY . "` WHERE `file_id` = ? " . ($unlock === false ? "AND `lock` != 1" : "") ); return (bool)$delete->execute([$fileId]); } /** * Change lock status * * @param integer $fileId - file identifier * @param bool $lock - status */ public function lock(int $fileId, bool $lock = true): bool { $update = $this->connection->prepare(" UPDATE `*PREFIX*" . self::TABLENAME_KEY . "` SET `lock` = ? WHERE `file_id` = ? "); return (bool)$update->execute([$lock === true ? 1 : 0, $fileId]); } /** * Change forcesave status * * @param integer $fileId - file identifier * @param bool $fs - status */ public function setForcesave(int $fileId, bool $fs = true): bool { $update = $this->connection->prepare(" UPDATE `*PREFIX*" . self::TABLENAME_KEY . "` SET `fs` = ? WHERE `file_id` = ? "); return (bool)$update->execute([$fs === true ? 1 : 0, $fileId]); } /** * Get forcesave status * * @param integer $fileId - file identifier */ public function wasForcesave(int $fileId): bool { $select = $this->connection->prepare(" SELECT `fs` FROM `*PREFIX*" . self::TABLENAME_KEY . "` WHERE `file_id` = ? "); $result = $select->execute([$fileId]); $rows = $result->fetch(); $fs = is_array($rows) && isset($rows["fs"]) ? $rows["fs"] : 0; return $fs === 1 || $fs === "1"; } }