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

FSHooks.php « Hooks « lib - github.com/CarnetApp/CarnetNextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d2b1f901592a6700989f97ca73c0326b5e06c1ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace OCA\Carnet\Hooks;
use OCP\IUserManager;
use OCA\Carnet\Misc\CacheManager;
use OCA\Carnet\Misc\NoteUtils;
use OCA\Carnet\Controller\NoteController;
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($this->folder))
            $this->folder= NoteUtils::$defaultCarnetNotePath;
        try{
            $this->carnetFolder = $UserFolder->get($this->folder);
        } catch (\OCP\Files\NotFoundException $e){
            $this->carnetFolder = null;
        }
    }
    
    public function postDelete($node){
        if($this->carnetFolder == null)
            return;
        if($this->isMine($node)){
            $cacheManager = new CacheManager($this->db, $this->carnetFolder);
            $cacheManager->deleteFromCache($this->getRelativePath($node->getPath()));
        }   
    }

    private function getSQDNode($node){
        if(substr($node->getName(), -3) === "sqd")
            return $node;
        $parent = $node->getParent();
        if($parent != NULL){
            if($parent->getName() === "data"){
                $parent = $parent->getParent();
            }
            if(substr($parent->getName(), -3) === "sqd"){
                return $parent;
        }
        }
        return false;
    }

    private function isMine($node){
        if(substr($node->getPath(), 0, strlen($this->carnetFolder->getPath())) === $this->carnetFolder->getPath()){
            return true;
        }
        return false;
    }

    private function getRelativePath($fullPath){
        $relativePath = substr($fullPath, strlen($this->carnetFolder->getPath()));
        if(substr($relativePath, 0, 1) === "/")
            $relativePath = substr($relativePath, 1); 
        return $relativePath;
    }

    public function postWrite($node) {
        if($this->carnetFolder == null || substr($_SERVER['REQUEST_URI'], -strlen('carnet/note/saveText')) === 'carnet/note/saveText')
        { //cache is handled on save
            return;
        }
        if($this->isMine($node)){
                try{
                $node = $this->getSQDNode($node);
                if(!$node)
                    return;
                $relativePath = $this->getRelativePath($node->getPath());
                $cacheManager = new CacheManager($this->db, $this->carnetFolder);
                $utils = new NoteUtils();
                $metadata = $utils->getMetadata($this->carnetFolder, $relativePath);
                $cacheManager->addToCache($relativePath, $metadata, $metadata['lastmodfile']);
            } catch(\PhpZip\Exception\ZipException $e){

            }
        }
    }

    public function postWritePath($node) {
       
    }
}

?>