55 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66 * SPDX-License-Identifier: AGPL-3.0-only
77 */
8+
89namespace OC \Share20 ;
910
1011use OC \Files \Cache \Cache ;
3132use OCP \Share \IManager ;
3233use OCP \Share \IShare ;
3334use OCP \Share \IShareProviderSupportsAccept ;
35+ use OCP \Share \IShareProviderSupportsAllSharesInFolder ;
3436use OCP \Share \IShareProviderWithNotification ;
3537use Psr \Log \LoggerInterface ;
3638use function str_starts_with ;
4042 *
4143 * @package OC\Share20
4244 */
43- class DefaultShareProvider implements IShareProviderWithNotification, IShareProviderSupportsAccept {
45+ class DefaultShareProvider implements IShareProviderWithNotification, IShareProviderSupportsAccept, IShareProviderSupportsAllSharesInFolder {
4446 // Special share type for user modified group shares
4547 public const SHARE_TYPE_USERGROUP = 2 ;
4648
@@ -603,6 +605,17 @@ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = t
603605 throw new \Exception ('non-shallow getSharesInFolder is no longer supported ' );
604606 }
605607
608+ return $ this ->getSharesInFolderInternal ($ userId , $ node , $ reshares );
609+ }
610+
611+ public function getAllSharesInFolder (Folder $ node ): array {
612+ return $ this ->getSharesInFolderInternal (null , $ node , null );
613+ }
614+
615+ /**
616+ * @return array<int, list<IShare>>
617+ */
618+ private function getSharesInFolderInternal (?string $ userId , Folder $ node , ?bool $ reshares ): array {
606619 $ qb = $ this ->dbConn ->getQueryBuilder ();
607620 $ qb ->select ('s.* ' ,
608621 'f.fileid ' , 'f.path ' , 'f.permissions AS f_permissions ' , 'f.storage ' , 'f.path_hash ' ,
@@ -613,18 +626,20 @@ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = t
613626
614627 $ qb ->andWhere ($ qb ->expr ()->in ('share_type ' , $ qb ->createNamedParameter ([IShare::TYPE_USER , IShare::TYPE_GROUP , IShare::TYPE_LINK ], IQueryBuilder::PARAM_INT_ARRAY )));
615628
616- /**
617- * Reshares for this user are shares where they are the owner.
618- */
619- if ($ reshares === false ) {
620- $ qb ->andWhere ($ qb ->expr ()->eq ('uid_initiator ' , $ qb ->createNamedParameter ($ userId )));
621- } else {
622- $ qb ->andWhere (
623- $ qb ->expr ()->orX (
624- $ qb ->expr ()->eq ('uid_owner ' , $ qb ->createNamedParameter ($ userId )),
625- $ qb ->expr ()->eq ('uid_initiator ' , $ qb ->createNamedParameter ($ userId ))
626- )
627- );
629+ if ($ userId !== null ) {
630+ /**
631+ * Reshares for this user are shares where they are the owner.
632+ */
633+ if ($ reshares !== true ) {
634+ $ qb ->andWhere ($ qb ->expr ()->eq ('uid_initiator ' , $ qb ->createNamedParameter ($ userId )));
635+ } else {
636+ $ qb ->andWhere (
637+ $ qb ->expr ()->orX (
638+ $ qb ->expr ()->eq ('uid_owner ' , $ qb ->createNamedParameter ($ userId )),
639+ $ qb ->expr ()->eq ('uid_initiator ' , $ qb ->createNamedParameter ($ userId ))
640+ )
641+ );
642+ }
628643 }
629644
630645 // todo? maybe get these from the oc_mounts table
@@ -656,7 +671,6 @@ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = t
656671
657672 foreach ($ chunks as $ chunk ) {
658673 $ qb ->setParameter ('chunk ' , $ chunk , IQueryBuilder::PARAM_INT_ARRAY );
659- $ a = $ qb ->getSQL ();
660674 $ cursor = $ qb ->executeQuery ();
661675 while ($ data = $ cursor ->fetch ()) {
662676 $ shares [$ data ['fileid ' ]][] = $ this ->createShare ($ data );
0 commit comments