diff options
author | Phie <phie@phie.ovh> | 2019-03-04 21:35:30 +0300 |
---|---|---|
committer | Phie <phie@phie.ovh> | 2019-03-04 21:35:30 +0300 |
commit | d6695df273f62510b4c6e1004710c51e77b1e926 (patch) | |
tree | d7598c02c600aa26c9cfae489766daf87d15b672 /lib/Hooks | |
parent | beb8a90826666ba41fb2012e2c92e47c7b5f4251 (diff) |
introducing metadata cache
Diffstat (limited to 'lib/Hooks')
-rw-r--r-- | lib/Hooks/FSHooks.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/Hooks/FSHooks.php b/lib/Hooks/FSHooks.php new file mode 100644 index 0000000..5fabc0c --- /dev/null +++ b/lib/Hooks/FSHooks.php @@ -0,0 +1,54 @@ +<?php +namespace OCA\Carnet\Hooks; +use OCP\IUserManager; +use OCA\Carnet\Misc\CacheManager; +use OCA\Carnet\Misc\NoteUtils; + +use OCP\IDBConnection; + +class FSHooks { + private $userFolder; + private $Config; + private $userId; + private $appName; + private $db; + private $folder; + private $carnetFolder; + public function __construct($UserFolder, $UserId, $Config, $appName, IDBConnection $connection){ + $this->userFolder = $UserFolder; + $this->Config = $Config; + $this->userId = $UserId; + $this->appName = $appName; + $this->db = $connection; + $this->folder = $this->Config->getUserValue($this->userId, $this->appName, "note_folder"); + if(empty($folder)) + $folder= 'Documents/QuickNote'; + $this->carnetFolder = $UserFolder->get($folder); + } + + public function postWrite($node) { + + if(substr($node->getName(), -3) === "sqd"){ // to avoid getting carnet's path each time a file is writen + //we check if is in our path + + if(substr($node->getPath(), 0, strlen($this->folder)) === $this->folder){ + $relativePath = substr($node->getPath(), strlen($this->carnetFolder->getPath())); + if(substr($relativePath, 0, 1) === "/") + $relativePath = substr($relativePath, 1); + $cacheManager = new CacheManager($this->db); + $utils = new NoteUtils(); + $metadata = $utils->getMetadata($this->carnetFolder, $relativePath); + $cacheManager->addToCache($relativePath, $metadata, $metadata['lastmodfile']); + } + } + + + } + + public function postWritePath($node) { + if($node != Null) + file_put_contents("dump.txt", $node."\n", FILE_APPEND); + } +} + +?>
\ No newline at end of file |