Folder.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_Sharing\ShareBackend;
  8. use OCP\Share_Backend_Collection;
  9. class Folder extends File implements Share_Backend_Collection {
  10. public function getChildren($itemSource) {
  11. $children = [];
  12. $parents = [$itemSource];
  13. $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
  14. $qb->select('id')
  15. ->from('mimetypes')
  16. ->where(
  17. $qb->expr()->eq('mimetype', $qb->createNamedParameter('httpd/unix-directory'))
  18. );
  19. $result = $qb->execute();
  20. $row = $result->fetch();
  21. $result->closeCursor();
  22. if ($row = $result->fetchRow()) {
  23. $mimetype = (int)$row['id'];
  24. } else {
  25. $mimetype = -1;
  26. }
  27. while (!empty($parents)) {
  28. $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
  29. $parents = array_map(function ($parent) use ($qb) {
  30. return $qb->createNamedParameter($parent);
  31. }, $parents);
  32. $qb->select('`fileid', 'name', '`mimetype')
  33. ->from('filecache')
  34. ->where(
  35. $qb->expr()->in('parent', $parents)
  36. );
  37. $result = $qb->execute();
  38. $parents = [];
  39. while ($file = $result->fetch()) {
  40. $children[] = ['source' => $file['fileid'], 'file_path' => $file['name']];
  41. // If a child folder is found look inside it
  42. if ((int)$file['mimetype'] === $mimetype) {
  43. $parents[] = $file['fileid'];
  44. }
  45. }
  46. $result->closeCursor();
  47. }
  48. return $children;
  49. }
  50. }