diff options
Diffstat (limited to 'lib/Misc/CacheManager.php')
-rw-r--r-- | lib/Misc/CacheManager.php | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/lib/Misc/CacheManager.php b/lib/Misc/CacheManager.php index 3fe904e..045421d 100644 --- a/lib/Misc/CacheManager.php +++ b/lib/Misc/CacheManager.php @@ -11,27 +11,33 @@ class CacheManager{ $this->carnetFolder = $carnetFolder; } - public function addToCache($relativePath, $metadata, $lastmodfile){ - $this->addToCacheFullPath($this->carnetFolder->getFullPath($relativePath), $metadata, $lastmodfile); + public function addToCache($relativePath, $metadata, $lastmodfile, $text){ + $this->addToCacheFullPath($this->carnetFolder->getFullPath($relativePath), $metadata, $lastmodfile, $low_case_text); } - public function addToCacheFullPath($fullPath, $metadata, $lastmodfile){ - $sql = 'INSERT into `*PREFIX*carnet_metadata` VALUES(?, ?, ?)'; + public function addToCacheFullPath($fullPath, $metadata, $lastmodfile, $text){ + if(isset($metadata['text'])) + unset($metadata['text']); + $low_case_text = strtolower(NoteUtils::removeAccents($text)); + $sql = 'INSERT into `*PREFIX*carnet_metadata` VALUES(?, ?, ?, ?)'; $stmt = $this->db->prepare($sql); $stmt->bindParam(1, $fullPath, \PDO::PARAM_STR); if(!is_string($metadata)) $metadata = json_encode($metadata); $stmt->bindParam(2, $metadata, \PDO::PARAM_STR); $stmt->bindParam(3, $lastmodfile, \PDO::PARAM_INT); + $stmt->bindParam(4, $low_case_text, \PDO::PARAM_STR); + try{ $stmt->execute(); } catch(\Doctrine\DBAL\Exception\UniqueConstraintViolationException $ex){ - $sql = 'UPDATE `*PREFIX*carnet_metadata` SET `metadata` = ?, `last_modification_file` = ? WHERE `path` = ?'; + $sql = 'UPDATE `*PREFIX*carnet_metadata` SET `metadata` = ?, `last_modification_file` = ?, `low_case_text` = ? WHERE `path` = ?'; $stmt = $this->db->prepare($sql); $stmt->bindParam(1, $metadata, \PDO::PARAM_STR); - $stmt->bindParam(3, $fullPath, \PDO::PARAM_STR); $stmt->bindParam(2, $lastmodfile, \PDO::PARAM_INT); + $stmt->bindParam(3, $low_case_text, \PDO::PARAM_STR); + $stmt->bindParam(4, $fullPath, \PDO::PARAM_STR); $stmt->execute(); } @@ -82,7 +88,8 @@ class CacheManager{ if(substr($relativePath, 0, 1) === "/") $relativePath = substr($relativePath, 1); $meta = $utils->getMetadata($carnetFolder, $relativePath); - $this->addToCacheFullPath($node->getPath(), $meta, $meta['lastmodfile']); + $text = $meta['text']; + $this->addToCacheFullPath($node->getPath(), $meta, $meta['lastmodfile'], $text); } catch(\PhpZip\Exception\ZipException $e){ } catch(\OCP\Encryption\Exceptions\GenericEncryptionException $e){ @@ -100,8 +107,11 @@ class CacheManager{ $stmt->execute(); } - public function getFromCache($arrayRelativePath){ + return $this->getFromCache2($arrayRelativePath, false); + } + + public function getFromCache2($arrayRelativePath, $withLowCaseText){ $total = 0; $array = array(); @@ -125,7 +135,15 @@ class CacheManager{ $stmt->execute($arrayFullPath); $fetched = $stmt->fetchAll(); foreach ($fetched as $row){ - $array[substr($row['path'], strlen($this->carnetFolder->getPath())+1)] = json_decode($row['metadata'], true); + $metadata = json_decode($row['metadata'], true); + $item = array(); + if(!$withLowCaseText){ + $item = $metadata; + } else { + $item['metadata'] = $metadata; + $item['low_case_text'] = $row['low_case_text']; + } + $array[substr($row['path'], strlen($this->carnetFolder->getPath())+1)] = $item; } $stmt->closeCursor(); @@ -136,11 +154,12 @@ class CacheManager{ public function search($query){ $arrayFullPath = array(); $sql = 'SELECT * FROM `*PREFIX*carnet_metadata` ' . - 'WHERE path LIKE ? AND metadata LIKE ? '; + 'WHERE path LIKE ? AND (metadata LIKE ? OR low_case_text LIKE ?)'; $args = array(); array_push($args, $this->carnetFolder->getPath()."/%"); - array_push($args, "%".$query."%"); + array_push($args, "%".$query."%"); + $stmt = $this->db->prepare($sql); $stmt->execute($args); $array = array(); |