1616use OCA \Maps \Service \PhotofilesService ;
1717use OCA \Maps \Service \TracksService ;
1818use OCP \Files \FileInfo ;
19- use OCP \Files \IHomeStorage ;
2019use OCP \Files \IRootFolder ;
2120use OCP \Lock \ILockingProvider ;
2221use OCP \Share ;
2322use OCP \Util ;
23+ use function OCP \Log \logger ;
2424
2525/**
2626 * Handles files events
@@ -44,7 +44,8 @@ public function __construct(IRootFolder $root, PhotofilesService $photofilesServ
4444
4545 public function register () {
4646 $ fileWriteCallback = function (\OCP \Files \Node $ node ) {
47- if ($ this ->isUserNode ($ node ) && $ node ->getSize () > 0 ) {
47+ //logger('maps')->debug("Hook postWrite");
48+ if ($ node ->getType () === FileInfo::TYPE_FILE && $ this ->isUserNode ($ node ) && $ node ->getSize ()) {
4849 $ path = $ node ->getPath ();
4950 if (!$ this ->lockingProvider ->isLocked ($ path , ILockingProvider::LOCK_SHARED )
5051 and !$ this ->lockingProvider ->isLocked ($ path , ILockingProvider::LOCK_EXCLUSIVE )
@@ -59,6 +60,7 @@ public function register() {
5960 $ this ->root ->listen ('\OC\Files ' , 'postWrite ' , $ fileWriteCallback );
6061
6162 $ fileDeletionCallback = function (\OCP \Files \Node $ node ) {
63+ //logger('maps')->debug("Hook preDelete");
6264 if ($ this ->isUserNode ($ node )) {
6365 if ($ node ->getType () === FileInfo::TYPE_FOLDER ) {
6466 $ this ->photofilesService ->deleteByFolder ($ node );
@@ -111,6 +113,7 @@ public function register() {
111113 }
112114
113115 public function postShare ($ params ) {
116+ //logger('maps')->debug("Hook postShare");
114117 if ($ params ['itemType ' ] === 'file ' ) {
115118 //$targetFilePath = $params['itemTarget'];
116119 //$sourceUserId = $params['uidOwner'];
@@ -135,6 +138,7 @@ public function postShare($params) {
135138 }
136139
137140 public function postUnShare ($ params ) {
141+ //logger('maps')->debug("Hook postUnShare");
138142 if ($ params ['shareType ' ] === Share::SHARE_TYPE_USER ) {
139143 if ($ params ['itemType ' ] === 'file ' ) {
140144 $ targetUserId = $ params ['shareWith ' ];
@@ -146,6 +150,7 @@ public function postUnShare($params) {
146150 }
147151
148152 public function preUnShare ($ params ) {
153+ //logger('maps')->debug("Hook preUnShare");
149154 if ($ params ['shareType ' ] === Share::SHARE_TYPE_USER ) {
150155 if ($ params ['itemType ' ] === 'folder ' ) {
151156 $ targetUserId = $ params ['shareWith ' ];
@@ -176,7 +181,12 @@ private function getNodeForPath($path) {
176181 }
177182
178183 private function isUserNode (\OCP \Files \Node $ node ): bool {
179- return $ node ->getStorage ()->instanceOfStorage (IHomeStorage::class);
184+ //return $node->getStorage()->instanceOfStorage("\OCP\Files\IHomeStorage")
185+ $ owner = $ node ->getStorage ()->getOwner ('' );
186+ if (! $ owner ) {
187+ return false ;
188+ }
189+ return str_starts_with ($ node ->getPath (), '/ ' . $ owner . '/ ' );
180190 }
181191
182192}
0 commit comments