diff options
author | Phie <phie@phie.ovh> | 2019-04-02 02:13:01 +0300 |
---|---|---|
committer | Phie <phie@phie.ovh> | 2019-04-02 02:13:01 +0300 |
commit | aaba3699caf1cb8dfb395dfc13720ee029e454de (patch) | |
tree | 6f2a514f21444b1cb150faca744090c1f4d86c86 /lib/Misc | |
parent | bf4ed375f3ea6e5efd6668e4c1d3a041dcd9be2f (diff) |
cache is back in a secured way + delete from cache when a note is deleted
Diffstat (limited to 'lib/Misc')
-rw-r--r-- | lib/Misc/CacheManager.php | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/Misc/CacheManager.php b/lib/Misc/CacheManager.php index ce79d1b..398bbdb 100644 --- a/lib/Misc/CacheManager.php +++ b/lib/Misc/CacheManager.php @@ -4,15 +4,16 @@ use OCP\IDBConnection; class CacheManager{ private $db; - - public function __construct(IDBConnection $db) { + private $carnetFolder; + public function __construct(IDBConnection $db, $carnetFolder) { $this->db = $db; + $this->carnetFolder = $carnetFolder; } public function addToCache($relativePath, $metadata, $lastmodfile){ $sql = 'INSERT into `*PREFIX*carnet_metadata` VALUES(?, ?, ?)'; $stmt = $this->db->prepare($sql); - $stmt->bindParam(1, $relativePath, \PDO::PARAM_STR); + $stmt->bindParam(1, $this->carnetFolder->getFullPath($relativePath), \PDO::PARAM_STR); if(!is_string($metadata)) $metadata = json_encode($metadata); $stmt->bindParam(2, $metadata, \PDO::PARAM_STR); @@ -24,7 +25,7 @@ class CacheManager{ $sql = 'UPDATE `*PREFIX*carnet_metadata` SET `metadata` = ?, `last_modification_file` = ? WHERE `path` = ?'; $stmt = $this->db->prepare($sql); $stmt->bindParam(1, $metadata, \PDO::PARAM_STR); - $stmt->bindParam(3, $relativePath, \PDO::PARAM_STR); + $stmt->bindParam(3, $this->carnetFolder->getFullPath($relativePath), \PDO::PARAM_STR); $stmt->bindParam(2, $lastmodfile, \PDO::PARAM_INT); $stmt->execute(); @@ -32,13 +33,23 @@ class CacheManager{ } + public function deleteFromCache($relativePath){ + $sql = 'DELETE FROM `*PREFIX*carnet_metadata` WHERE `path` = ?'; + $stmt = $this->db->prepare($sql); + $stmt->bindParam(1, $this->carnetFolder->getFullPath($relativePath), \PDO::PARAM_STR); + $stmt->execute(); + + } + public function getFromCache($arrayRelativePath){ - $sql = 'SELECT * FROM `*PREFIX*carnet_metadata` ' . + $arrayFullPath = array(); + $sql = 'SELECT * FROM `*PREFIX*carnet_metadata` ' . 'WHERE '; for($i = 0; $i < sizeof($arrayRelativePath); $i++){ $sql .= "`path` = ? "; if($i < sizeof($arrayRelativePath)-1) $sql .= "OR "; + array_push($arrayFullPath, $this->carnetFolder->getFullPath($arrayRelativePath[$i])); } $stmt = $this->db->prepare($sql); @@ -47,11 +58,11 @@ class CacheManager{ $i++; }*/ - $stmt->execute($arrayRelativePath); + $stmt->execute($arrayFullPath); $array = array(); $fetched = $stmt->fetchAll(); foreach ($fetched as $row){ - $array[$row['path']] = json_decode($row['metadata']); + $array[substr($row['path'], strlen($this->carnetFolder->getPath())+1)] = json_decode($row['metadata']); } $stmt->closeCursor(); |