Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
510488ad
Commit
510488ad
authored
Dec 21, 2014
by
Morris Jobke
Browse files
Options
Downloads
Plain Diff
Merge pull request #12942 from owncloud/favs-missingsharedsubdirs
Fix issues with searchByTag in shared storage
parents
312891c6
11b3aa2d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files_sharing/lib/cache.php
+22
-12
22 additions, 12 deletions
apps/files_sharing/lib/cache.php
apps/files_sharing/tests/cache.php
+56
-1
56 additions, 1 deletion
apps/files_sharing/tests/cache.php
with
78 additions
and
13 deletions
apps/files_sharing/lib/cache.php
+
22
−
12
View file @
510488ad
...
@@ -344,6 +344,20 @@ class Shared_Cache extends Cache {
...
@@ -344,6 +344,20 @@ class Shared_Cache extends Cache {
return
$result
;
return
$result
;
}
}
/**
* Checks whether the given file has the given tag.
*
* @param \OCP\ITags $tagger
* @param array $fileData file data
* @param string $tag tag to check for
* @return boolean true if the given file has the expected tag,
* false otherwise
*/
private
function
hasTag
(
$tagger
,
$fileData
,
$tag
)
{
$tags
=
$tagger
->
getTagsForObjects
(
array
((
int
)
$fileData
[
'fileid'
]));
return
(
!
empty
(
$tags
)
&&
in_array
(
$tag
,
current
(
$tags
)));
}
/**
/**
* search for files by tag
* search for files by tag
*
*
...
@@ -356,28 +370,24 @@ class Shared_Cache extends Cache {
...
@@ -356,28 +370,24 @@ class Shared_Cache extends Cache {
$tagger
=
\OC
::
$server
->
getTagManager
()
->
load
(
'files'
,
null
,
null
,
$userId
);
$tagger
=
\OC
::
$server
->
getTagManager
()
->
load
(
'files'
,
null
,
null
,
$userId
);
$result
=
array
();
$result
=
array
();
$exploreDirs
=
array
(
''
);
$exploreDirs
=
array
(
''
);
// check if root is tagged
$file
=
$this
->
get
(
''
);
if
(
$this
->
hasTag
(
$tagger
,
$file
,
$tag
))
{
$result
[]
=
$file
;
}
// FIXME: this is so wrong and unefficient, need to replace with actual DB queries
// FIXME: this is so wrong and unefficient, need to replace with actual DB queries
while
(
count
(
$exploreDirs
)
>
0
)
{
while
(
count
(
$exploreDirs
)
>
0
)
{
$dir
=
array_pop
(
$exploreDirs
);
$dir
=
array_pop
(
$exploreDirs
);
$files
=
$this
->
getFolderContents
(
$dir
);
$files
=
$this
->
getFolderContents
(
$dir
);
// no results?
if
(
!
$files
)
{
if
(
!
$files
)
{
// maybe it's a single shared file
$file
=
$this
->
get
(
''
);
$tags
=
$tagger
->
getTagsForObjects
(
array
((
int
)
$file
[
'fileid'
]));
if
(
!
empty
(
$tags
)
&&
in_array
(
$tag
,
current
(
$tags
)))
{
$result
[]
=
$file
;
}
continue
;
continue
;
}
}
foreach
(
$files
as
$file
)
{
foreach
(
$files
as
$file
)
{
if
(
$file
[
'mimetype'
]
===
'httpd/unix-directory'
)
{
if
(
$this
->
hasTag
(
$tagger
,
$file
,
$tag
))
{
$exploreDirs
[]
=
ltrim
(
$dir
.
'/'
.
$file
[
'name'
],
'/'
);
}
else
{
$tags
=
$tagger
->
getTagsForObjects
(
array
((
int
)
$file
[
'fileid'
]));
if
(
!
empty
(
$tags
)
&&
in_array
(
$tag
,
current
(
$tags
)))
{
$result
[]
=
$file
;
$result
[]
=
$file
;
}
}
if
(
$file
[
'mimetype'
]
===
'httpd/unix-directory'
)
{
$exploreDirs
[]
=
ltrim
(
$dir
.
'/'
.
$file
[
'name'
],
'/'
);
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
apps/files_sharing/tests/cache.php
+
56
−
1
View file @
510488ad
...
@@ -22,7 +22,6 @@ use OCA\Files_sharing\Tests\TestCase;
...
@@ -22,7 +22,6 @@ use OCA\Files_sharing\Tests\TestCase;
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
*/
class
Test_Files_Sharing_Cache
extends
TestCase
{
class
Test_Files_Sharing_Cache
extends
TestCase
{
/**
/**
...
@@ -238,6 +237,62 @@ class Test_Files_Sharing_Cache extends TestCase {
...
@@ -238,6 +237,62 @@ class Test_Files_Sharing_Cache extends TestCase {
$tagManager
->
delete
(
array
(
'tag1'
,
'tag2'
));
$tagManager
->
delete
(
array
(
'tag1'
,
'tag2'
));
}
}
/**
* Test searching by tag for multiple sections of the tree
*/
function
testSearchByTagTree
()
{
$userId
=
\OC
::
$server
->
getUserSession
()
->
getUser
()
->
getUId
();
$this
->
sharedStorage
->
mkdir
(
'subdir/emptydir'
);
$this
->
sharedStorage
->
mkdir
(
'subdir/emptydir2'
);
$this
->
ownerStorage
->
getScanner
()
->
scan
(
''
);
$allIds
=
array
(
$this
->
sharedCache
->
get
(
''
)[
'fileid'
],
$this
->
sharedCache
->
get
(
'bar.txt'
)[
'fileid'
],
$this
->
sharedCache
->
get
(
'subdir/another too.txt'
)[
'fileid'
],
$this
->
sharedCache
->
get
(
'subdir/not a text file.xml'
)[
'fileid'
],
$this
->
sharedCache
->
get
(
'subdir/another.txt'
)[
'fileid'
],
$this
->
sharedCache
->
get
(
'subdir/emptydir'
)[
'fileid'
],
$this
->
sharedCache
->
get
(
'subdir/emptydir2'
)[
'fileid'
],
);
$tagManager
=
\OC
::
$server
->
getTagManager
()
->
load
(
'files'
,
null
,
null
,
$userId
);
foreach
(
$allIds
as
$id
)
{
$tagManager
->
tagAs
(
$id
,
'tag1'
);
}
$results
=
$this
->
sharedStorage
->
getCache
()
->
searchByTag
(
'tag1'
,
$userId
);
$check
=
array
(
array
(
'name'
=>
'shareddir'
,
'path'
=>
''
),
array
(
'name'
=>
'bar.txt'
,
'path'
=>
'bar.txt'
),
array
(
'name'
=>
'another.txt'
,
'path'
=>
'subdir/another.txt'
),
array
(
'name'
=>
'another too.txt'
,
'path'
=>
'subdir/another too.txt'
),
array
(
'name'
=>
'emptydir'
,
'path'
=>
'subdir/emptydir'
),
array
(
'name'
=>
'emptydir2'
,
'path'
=>
'subdir/emptydir2'
),
array
(
'name'
=>
'not a text file.xml'
,
'path'
=>
'subdir/not a text file.xml'
),
);
$this
->
verifyFiles
(
$check
,
$results
);
$tagManager
->
delete
(
array
(
'tag1'
));
}
function
testGetFolderContentsInRoot
()
{
function
testGetFolderContentsInRoot
()
{
$results
=
$this
->
user2View
->
getDirectoryContent
(
'/'
);
$results
=
$this
->
user2View
->
getDirectoryContent
(
'/'
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment