2012-07-10 18:56:22 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2012-07-10 18:56:22 -04:00
|
|
|
/**
|
2024-06-06 13:48:28 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-03-26 06:44:34 -04:00
|
|
|
*/
|
2016-08-01 06:49:41 -04:00
|
|
|
namespace OCA\Files_Sharing\ShareBackend;
|
|
|
|
|
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\Server;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCP\Share_Backend_Collection;
|
|
|
|
|
|
|
|
|
|
class Folder extends File implements Share_Backend_Collection {
|
2025-09-12 10:58:19 -04:00
|
|
|
public function getChildren($itemSource): array {
|
2020-03-26 04:30:18 -04:00
|
|
|
$children = [];
|
|
|
|
|
$parents = [$itemSource];
|
2018-03-26 07:07:12 -04:00
|
|
|
|
2025-02-03 09:34:01 -05:00
|
|
|
$qb = Server::get(IDBConnection::class)->getQueryBuilder();
|
2018-03-26 07:07:12 -04:00
|
|
|
$qb->select('id')
|
|
|
|
|
->from('mimetypes')
|
|
|
|
|
->where(
|
|
|
|
|
$qb->expr()->eq('mimetype', $qb->createNamedParameter('httpd/unix-directory'))
|
|
|
|
|
);
|
2025-09-12 10:58:19 -04:00
|
|
|
$result = $qb->executeQuery();
|
2018-03-26 07:07:12 -04:00
|
|
|
|
2025-09-12 11:17:17 -04:00
|
|
|
if (($row = $result->fetch()) !== false) {
|
2017-05-10 08:16:22 -04:00
|
|
|
$mimetype = (int)$row['id'];
|
2013-01-07 20:52:51 -05:00
|
|
|
} else {
|
|
|
|
|
$mimetype = -1;
|
|
|
|
|
}
|
2025-09-12 10:58:19 -04:00
|
|
|
$result->closeCursor();
|
|
|
|
|
|
2012-09-08 23:07:43 -04:00
|
|
|
while (!empty($parents)) {
|
2025-02-03 09:34:01 -05:00
|
|
|
$qb = Server::get(IDBConnection::class)->getQueryBuilder();
|
2018-03-26 07:07:12 -04:00
|
|
|
|
2020-04-09 07:53:40 -04:00
|
|
|
$parents = array_map(function ($parent) use ($qb) {
|
2018-03-26 07:07:12 -04:00
|
|
|
return $qb->createNamedParameter($parent);
|
|
|
|
|
}, $parents);
|
|
|
|
|
|
|
|
|
|
$qb->select('`fileid', 'name', '`mimetype')
|
|
|
|
|
->from('filecache')
|
|
|
|
|
->where(
|
|
|
|
|
$qb->expr()->in('parent', $parents)
|
|
|
|
|
);
|
|
|
|
|
|
2025-09-12 10:58:19 -04:00
|
|
|
$result = $qb->executeQuery();
|
2018-03-26 07:07:12 -04:00
|
|
|
|
2020-03-26 04:30:18 -04:00
|
|
|
$parents = [];
|
2018-03-26 07:07:12 -04:00
|
|
|
while ($file = $result->fetch()) {
|
2020-03-26 04:30:18 -04:00
|
|
|
$children[] = ['source' => $file['fileid'], 'file_path' => $file['name']];
|
2012-10-14 15:04:08 -04:00
|
|
|
// If a child folder is found look inside it
|
2017-05-10 08:16:22 -04:00
|
|
|
if ((int)$file['mimetype'] === $mimetype) {
|
2013-01-07 20:52:51 -05:00
|
|
|
$parents[] = $file['fileid'];
|
2012-09-08 23:07:43 -04:00
|
|
|
}
|
|
|
|
|
}
|
2018-03-26 07:07:12 -04:00
|
|
|
$result->closeCursor();
|
2012-08-06 11:27:13 -04:00
|
|
|
}
|
2012-09-08 23:07:43 -04:00
|
|
|
return $children;
|
2012-07-10 18:56:22 -04:00
|
|
|
}
|
2013-02-14 16:37:49 -05:00
|
|
|
}
|