Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CarnetApp/CarnetNextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Misc/CacheManager.php')
-rw-r--r--lib/Misc/CacheManager.php61
1 files changed, 59 insertions, 2 deletions
diff --git a/lib/Misc/CacheManager.php b/lib/Misc/CacheManager.php
index 398bbdb..0585872 100644
--- a/lib/Misc/CacheManager.php
+++ b/lib/Misc/CacheManager.php
@@ -1,6 +1,7 @@
<?php
namespace OCA\Carnet\Misc;
use OCP\IDBConnection;
+use OCA\Carnet\Misc\NoteUtils;
class CacheManager{
private $db;
@@ -11,9 +12,13 @@ class CacheManager{
}
public function addToCache($relativePath, $metadata, $lastmodfile){
+ $this->addToCacheFullPath($this->carnetFolder->getFullPath($relativePath), $metadata, $lastmodfile);
+ }
+
+ public function addToCacheFullPath($fullPath, $metadata, $lastmodfile){
$sql = 'INSERT into `*PREFIX*carnet_metadata` VALUES(?, ?, ?)';
$stmt = $this->db->prepare($sql);
- $stmt->bindParam(1, $this->carnetFolder->getFullPath($relativePath), \PDO::PARAM_STR);
+ $stmt->bindParam(1, $fullPath, \PDO::PARAM_STR);
if(!is_string($metadata))
$metadata = json_encode($metadata);
$stmt->bindParam(2, $metadata, \PDO::PARAM_STR);
@@ -25,7 +30,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, $this->carnetFolder->getFullPath($relativePath), \PDO::PARAM_STR);
+ $stmt->bindParam(3, $fullPath, \PDO::PARAM_STR);
$stmt->bindParam(2, $lastmodfile, \PDO::PARAM_INT);
$stmt->execute();
@@ -33,6 +38,58 @@ class CacheManager{
}
+ public function buildCache($config, $appName, $rootFolder, $users){
+ $arrayFolder = array();
+ $sql = 'SELECT path, last_modification_file FROM `*PREFIX*carnet_metadata`';
+ $stmt = $this->db->prepare($sql);
+ $stmt->execute();
+ $cache = array();
+ $fetched = $stmt->fetchAll();
+ foreach ($fetched as $row){
+ $cache[$row['path']] = $row['last_modification_file'];
+ }
+
+ $stmt->closeCursor();
+ foreach($users as $user){
+ $notePath = $config->getUserValue($user, $appName, "note_folder");
+ if(empty($notePath))
+ $notePath= NoteUtils::$defaultCarnetNotePath;
+ try {
+ echo $notePath."pet";
+ $carnetFolder = $rootFolder->getUserFolder($user)->get($notePath);
+ $this->recursiveAddToCache($carnetFolder, $carnetFolder, $cache);
+ } catch(\OCP\Files\NotFoundException $e) {
+
+ }
+
+ }
+ }
+
+ private function recursiveAddToCache($carnetFolder, $node, $cache){
+ if($node instanceof \OCP\Files\Folder){
+ foreach($node->get($path)->getDirectoryListing() as $inNode){
+ echo $inNode->getPath();
+ $this->recursiveAddToCache($carnetFolder, $inNode, $cache);
+ }
+ } else if(substr($node->getName(), -3) === "sqd"){
+ $inf = $node->getFileInfo();
+ if($cache[$node->getPath()] != null && $inf->getMtime() == $cache[$node->getPath()]){
+ return;
+ }
+ $utils = new NoteUtils();
+ try{
+ $relativePath = substr($node->getPath(), strlen($carnetFolder->getPath()));
+ if(substr($relativePath, 0, 1) === "/")
+ $relativePath = substr($relativePath, 1);
+ $meta = $utils->getMetadata($carnetFolder, $relativePath);
+ $this->addToCacheFullPath($node->getPath(), $meta, $meta['lastmodfile']);
+ } catch(\PhpZip\Exception\ZipException $e){
+
+ }
+ }
+
+ }
+
public function deleteFromCache($relativePath){
$sql = 'DELETE FROM `*PREFIX*carnet_metadata` WHERE `path` = ?';
$stmt = $this->db->prepare($sql);