1616use OC \Files \Search \SearchComparison ;
1717use OC \Files \Search \SearchQuery ;
1818use OCP \DB \QueryBuilder \IQueryBuilder ;
19+ use OCP \Files \File ;
1920use OCP \Files \FileInfo ;
2021use OCP \Files \Folder ;
2122use OCP \Files \IRootFolder ;
@@ -61,9 +62,8 @@ public function addByFile(Node $file) {
6162
6263 // add the file for its owner and users that have access
6364 // check if it's already in DB before adding
64- public function safeAddByFile (Node $ file ) {
65+ public function safeAddByFile (File $ file ): bool {
6566 $ ownerId = $ file ->getOwner ()->getUID ();
66- $ userFolder = $ this ->root ->getUserFolder ($ ownerId );
6767 if ($ this ->isTrack ($ file )) {
6868 $ this ->safeAddTrack ($ file , $ ownerId );
6969 // is the file accessible to other users ?
@@ -106,7 +106,7 @@ public function safeAddByFolderIdUserId($folderId, $userId) {
106106 }
107107
108108 // avoid adding track if it already exists in the DB
109- private function safeAddTrack ($ track , $ userId ) {
109+ private function safeAddTrack (File $ track , string $ userId ): void {
110110 // filehooks are triggered several times (2 times for file creation)
111111 // so we need to be sure it's not inserted several times
112112 // by checking if it already exists in DB
@@ -117,7 +117,7 @@ private function safeAddTrack($track, $userId) {
117117 }
118118
119119 // add all tracks of a folder taking care of shared accesses
120- public function safeAddByFolder ($ folder ) {
120+ public function safeAddByFolder (Folder $ folder ): void {
121121 $ tracks = $ this ->gatherTrackFiles ($ folder , true );
122122 foreach ($ tracks as $ track ) {
123123 $ this ->safeAddByFile ($ track );
@@ -165,11 +165,11 @@ public function safeDeleteByFolderIdUserId($folderId, $userId) {
165165 }
166166 }
167167
168- private function gatherTrackFiles ($ folder , $ recursive ) {
168+ private function gatherTrackFiles (Folder $ folder , bool $ recursive ) {
169169 $ notes = [];
170170 $ nodes = $ folder ->getDirectoryListing ();
171171 foreach ($ nodes as $ node ) {
172- if ($ node-> getType () === FileInfo:: TYPE_FOLDER and $ recursive ) {
172+ if ($ node instanceof Folder and $ recursive ) {
173173 try {
174174 $ notes = array_merge ($ notes , $ this ->gatherTrackFiles ($ node , $ recursive ));
175175 } catch (\OCP \Files \StorageNotAvailableException |\Exception $ e ) {
@@ -186,14 +186,11 @@ private function gatherTrackFiles($folder, $recursive) {
186186 return $ notes ;
187187 }
188188
189- private function isTrack ($ file ) {
190- if ($ file-> getType () !== \ OCP \ Files \FileInfo:: TYPE_FILE ) {
189+ private function isTrack (Node $ file ): bool {
190+ if (! $ file instanceof File ) {
191191 return false ;
192192 }
193- if (!in_array ($ file ->getMimetype (), self ::TRACK_MIME_TYPES )) {
194- return false ;
195- }
196- return true ;
193+ return in_array ($ file ->getMimetype (), self ::TRACK_MIME_TYPES );
197194 }
198195
199196 private function dbRowToTrack ($ row , $ folder , $ userFolder , $ defaultMap , $ ignoredPaths ) {
@@ -415,7 +412,7 @@ public function getTrackByFileIDFromDB(int $fileId, ?string $userId = null) {
415412 return $ track ;
416413 }
417414
418- public function addTrackToDB ($ userId , $ fileId , $ file ) {
415+ public function addTrackToDB (string $ userId , int $ fileId , File $ file ): int {
419416 $ metadata = '' ;
420417 $ etag = $ file ->getEtag ();
421418 $ qb = $ this ->dbconnection ->getQueryBuilder ();
0 commit comments