@@ -830,10 +830,30 @@ private function isAccessibleResult($data) {
830830 return true ;
831831 }
832832
833- /**
834- * @inheritdoc
835- */
836833 public function getSharedWith ($ userId , $ shareType , $ node , $ limit , $ offset ) {
834+ return $ this ->_getSharedWith ($ userId , $ shareType , $ limit , $ offset , $ node );
835+ }
836+
837+ public function getSharedWithByPath (
838+ string $ userId ,
839+ int $ shareType ,
840+ string $ path ,
841+ bool $ forChildren ,
842+ int $ limit ,
843+ int $ offset ,
844+ ): iterable {
845+ return $ this ->_getSharedWith ($ userId , $ shareType , $ limit , $ offset , null , $ path , $ forChildren );
846+ }
847+
848+ private function _getSharedWith (
849+ string $ userId ,
850+ int $ shareType ,
851+ int $ limit ,
852+ int $ offset ,
853+ ?Node $ node = null ,
854+ ?string $ path = null ,
855+ ?bool $ forChildren = false ,
856+ ): iterable {
837857 /** @var Share[] $shares */
838858 $ shares = [];
839859
@@ -868,6 +888,14 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
868888 $ qb ->andWhere ($ qb ->expr ()->eq ('file_source ' , $ qb ->createNamedParameter ($ node ->getId ())));
869889 }
870890
891+ if ($ path !== null ) {
892+ if ($ forChildren ) {
893+ $ qb ->andWhere ($ qb ->expr ()->like ('file_target ' , $ qb ->createNamedParameter ($ this ->dbConn ->escapeLikeParameter ($ path ) . '_% ' )));
894+ } else {
895+ $ qb ->andWhere ($ qb ->expr ()->eq ('file_target ' , $ qb ->createNamedParameter ($ path )));
896+ }
897+ }
898+
871899 $ cursor = $ qb ->executeQuery ();
872900
873901 while ($ data = $ cursor ->fetch ()) {
@@ -919,6 +947,18 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
919947 $ qb ->andWhere ($ qb ->expr ()->eq ('file_source ' , $ qb ->createNamedParameter ($ node ->getId ())));
920948 }
921949
950+ if ($ path !== null ) {
951+ $ qb ->leftJoin ('s ' , 'share ' , 'sc ' , $ qb ->expr ()->eq ('sc.parent ' , 's.id ' ))
952+ ->andWhere ($ qb ->expr ()->eq ('sc.share_type ' , $ qb ->createNamedParameter (IShare::TYPE_USERGROUP )))
953+ ->where ($ qb ->expr ()->eq ('sc.share_with ' , $ qb ->createNamedParameter ($ userId )));
954+
955+ if ($ forChildren ) {
956+ $ qb ->andWhere ($ qb ->expr ()->like ('sc.file_target ' , $ qb ->createNamedParameter ($ this ->dbConn ->escapeLikeParameter ($ path ) . '_% ' )));
957+ } else {
958+ $ qb ->andWhere ($ qb ->expr ()->eq ('sc.file_target ' , $ qb ->createNamedParameter ($ path )));
959+ }
960+ }
961+
922962 $ groups = array_filter ($ groups );
923963
924964 $ qb ->andWhere ($ qb ->expr ()->eq ('share_type ' , $ qb ->createNamedParameter (IShare::TYPE_GROUP )))
@@ -955,112 +995,6 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
955995 return $ shares ;
956996 }
957997
958- /**
959- * @inheritDoc
960- */
961- public function getSharedWithByPath (
962- string $ userId ,
963- int $ shareType ,
964- string $ path ,
965- bool $ forChildren ,
966- int $ limit ,
967- int $ offset ,
968- ): iterable {
969- $ shares = [];
970-
971- if ($ shareType === IShare::TYPE_USER ) {
972- //Get shares directly with this user
973- $ qb = $ this ->dbConn ->getQueryBuilder ();
974- $ qb ->select ('s.* ' ,
975- 'f.fileid ' , 'f.path ' , 'f.permissions AS f_permissions ' , 'f.storage ' , 'f.path_hash ' ,
976- 'f.parent AS f_parent ' , 'f.name ' , 'f.mimetype ' , 'f.mimepart ' , 'f.size ' , 'f.mtime ' , 'f.storage_mtime ' ,
977- 'f.encrypted ' , 'f.unencrypted_size ' , 'f.etag ' , 'f.checksum '
978- )
979- ->selectAlias ('st.id ' , 'storage_string_id ' )
980- ->from ('share ' , 's ' )
981- ->leftJoin ('s ' , 'filecache ' , 'f ' , $ qb ->expr ()->eq ('s.file_source ' , 'f.fileid ' ))
982- ->leftJoin ('f ' , 'storages ' , 'st ' , $ qb ->expr ()->eq ('f.storage ' , 'st.numeric_id ' ));
983-
984- // Order by id
985- $ qb ->orderBy ('s.id ' );
986-
987- // Set limit and offset
988- if ($ limit !== -1 ) {
989- $ qb ->setMaxResults ($ limit );
990- }
991- $ qb ->setFirstResult ($ offset );
992-
993- $ qb ->where ($ qb ->expr ()->eq ('share_type ' , $ qb ->createNamedParameter (IShare::TYPE_USER )))
994- ->andWhere ($ qb ->expr ()->eq ('share_with ' , $ qb ->createNamedParameter ($ userId )))
995- ->andWhere ($ qb ->expr ()->in ('item_type ' , $ qb ->createNamedParameter (['file ' , 'folder ' ], IQueryBuilder::PARAM_STR_ARRAY )));
996-
997- if ($ forChildren ) {
998- $ qb ->andWhere ($ qb ->expr ()->like ('file_target ' , $ qb ->createNamedParameter ($ this ->dbConn ->escapeLikeParameter ($ path ) . '_% ' )));
999- } else {
1000- $ qb ->andWhere ($ qb ->expr ()->eq ('file_target ' , $ qb ->createNamedParameter ($ path )));
1001- }
1002-
1003- $ cursor = $ qb ->executeQuery ();
1004-
1005- while ($ data = $ cursor ->fetch ()) {
1006- if ($ data ['fileid ' ] && $ data ['path ' ] === null ) {
1007- $ data ['path ' ] = (string )$ data ['path ' ];
1008- $ data ['name ' ] = (string )$ data ['name ' ];
1009- $ data ['checksum ' ] = (string )$ data ['checksum ' ];
1010- }
1011- if ($ this ->isAccessibleResult ($ data )) {
1012- $ shares [] = $ this ->createShare ($ data );
1013- }
1014- }
1015- $ cursor ->closeCursor ();
1016- } elseif ($ shareType === IShare::TYPE_GROUP ) {
1017- // get the parent share info (s) along with the child one (s2)
1018- $ qb = $ this ->dbConn ->getQueryBuilder ();
1019- $ qb ->select ('s.* ' , 's2.permissions AS s2_permissions ' , 's2.accepted AS s2_accepted ' , 's2.file_target AS s2_file_target ' , 's2.parent AS s2_parent ' ,
1020- 'f.fileid ' , 'f.path ' , 'f.permissions AS f_permissions ' , 'f.storage ' , 'f.path_hash ' ,
1021- 'f.parent AS f_parent ' , 'f.name ' , 'f.mimetype ' , 'f.mimepart ' , 'f.size ' , 'f.mtime ' , 'f.storage_mtime ' ,
1022- 'f.encrypted ' , 'f.unencrypted_size ' , 'f.etag ' , 'f.checksum '
1023- )
1024- ->selectAlias ('st.id ' , 'storage_string_id ' )
1025- ->from ('share ' , 's2 ' )
1026- ->leftJoin ('s2 ' , 'filecache ' , 'f ' , $ qb ->expr ()->eq ('s2.file_source ' , 'f.fileid ' ))
1027- ->leftJoin ('f ' , 'storages ' , 'st ' , $ qb ->expr ()->eq ('f.storage ' , 'st.numeric_id ' ))
1028- ->leftJoin ('s2 ' , 'share ' , 's ' , $ qb ->expr ()->eq ('s2.parent ' , 's.id ' ))
1029- ->where ($ qb ->expr ()->eq ('s2.share_with ' , $ qb ->createNamedParameter ($ userId )))
1030- ->andWhere ($ qb ->expr ()->eq ('s2.share_type ' , $ qb ->createNamedParameter (IShare::TYPE_USERGROUP )))
1031- ->andWhere ($ qb ->expr ()->in ('s2.item_type ' , $ qb ->createNamedParameter (['file ' , 'folder ' ], IQueryBuilder::PARAM_STR_ARRAY )))
1032- ->orderBy ('s2.id ' )
1033- ->setFirstResult ($ offset );
1034- if ($ limit !== -1 ) {
1035- $ qb ->setMaxResults ($ limit );
1036- }
1037-
1038- if ($ forChildren ) {
1039- $ qb ->andWhere ($ qb ->expr ()->like ('s2.file_target ' , $ qb ->createNamedParameter ($ this ->dbConn ->escapeLikeParameter ($ path ) . '_% ' )));
1040- } else {
1041- $ qb ->andWhere ($ qb ->expr ()->eq ('s2.file_target ' , $ qb ->createNamedParameter ($ path )));
1042- }
1043-
1044- $ cursor = $ qb ->executeQuery ();
1045- while ($ data = $ cursor ->fetch ()) {
1046- if ($ this ->isAccessibleResult ($ data )) {
1047- $ share = $ this ->createShare ($ data );
1048- // patch the parent data with the user-specific changes
1049- $ share ->setPermissions ((int )$ data ['s2_permissions ' ]);
1050- $ share ->setStatus ((int )$ data ['s2_accepted ' ]);
1051- $ share ->setTarget ($ data ['s2_file_target ' ]);
1052- $ share ->setParent ($ data ['s2_parent ' ]);
1053- $ shares [] = $ share ;
1054- }
1055- }
1056- $ cursor ->closeCursor ();
1057- } else {
1058- throw new BackendError ('Invalid backend ' );
1059- }
1060-
1061- return $ shares ;
1062- }
1063-
1064998 /**
1065999 * Get a share by token
10661000 *
0 commit comments