1
0

Folder.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. class Folder extends File implements \OCP\Share_Backend_Collection {
  9. public function getChildren($itemSource) {
  10. $children = [];
  11. $parents = [$itemSource];
  12. $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
  13. $qb->select('id')
  14. ->from('mimetypes')
  15. ->where(
  16. $qb->expr()->eq('mimetype', $qb->createNamedParameter('httpd/unix-directory'))
  17. );
  18. $result = $qb->execute();
  19. $row = $result->fetch();
  20. $result->closeCursor();
  21. if ($row = $result->fetchRow()) {
  22. $mimetype = (int) $row['id'];
  23. } else {
  24. $mimetype = -1;
  25. }
  26. while (!empty($parents)) {
  27. $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
  28. $parents = array_map(function ($parent) use ($qb) {
  29. return $qb->createNamedParameter($parent);
  30. }, $parents);
  31. $qb->select('`fileid', 'name', '`mimetype')
  32. ->from('filecache')
  33. ->where(
  34. $qb->expr()->in('parent', $parents)
  35. );
  36. $result = $qb->execute();
  37. $parents = [];
  38. while ($file = $result->fetch()) {
  39. $children[] = ['source' => $file['fileid'], 'file_path' => $file['name']];
  40. // If a child folder is found look inside it
  41. if ((int) $file['mimetype'] === $mimetype) {
  42. $parents[] = $file['fileid'];
  43. }
  44. }
  45. $result->closeCursor();
  46. }
  47. return $children;
  48. }
  49. }