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
735608f5
Commit
735608f5
authored
Sep 27, 2013
by
Thomas Müller
Browse files
Options
Downloads
Plain Diff
Merge pull request #4207 from owncloud/search_shared_files
add initial search in shared files
parents
f47ff13a
cd2421c7
No related branches found
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
+69
-9
69 additions, 9 deletions
apps/files_sharing/lib/cache.php
lib/public/share.php
+3
-3
3 additions, 3 deletions
lib/public/share.php
with
72 additions
and
12 deletions
apps/files_sharing/lib/cache.php
+
69
−
9
View file @
735608f5
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
*/
*/
namespace
OC\Files\Cache
;
namespace
OC\Files\Cache
;
use
OCP\Share_Backend_Collection
;
/**
/**
* Metadata cache for shared files
* Metadata cache for shared files
...
@@ -226,7 +227,36 @@ class Shared_Cache extends Cache {
...
@@ -226,7 +227,36 @@ class Shared_Cache extends Cache {
* @return array of file data
* @return array of file data
*/
*/
public
function
search
(
$pattern
)
{
public
function
search
(
$pattern
)
{
// TODO
// normalize pattern
$pattern
=
$this
->
normalize
(
$pattern
);
$ids
=
$this
->
getAll
();
$files
=
array
();
// divide into 1k chunks
$chunks
=
array_chunk
(
$ids
,
1000
);
foreach
(
$chunks
as
$chunk
)
{
$placeholders
=
join
(
','
,
array_fill
(
0
,
count
(
$chunk
),
'?'
));
$sql
=
'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
`encrypted`, `unencrypted_size`, `etag`
FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `fileid` IN ('
.
$placeholders
.
')'
;
$result
=
\OC_DB
::
executeAudited
(
$sql
,
array_merge
(
array
(
$pattern
),
$chunk
));
while
(
$row
=
$result
->
fetchRow
())
{
if
(
substr
(
$row
[
'path'
],
0
,
6
)
===
'files/'
)
{
$row
[
'path'
]
=
substr
(
$row
[
'path'
],
6
);
// remove 'files/' from path as it's relative to '/Shared'
}
$row
[
'mimetype'
]
=
$this
->
getMimetype
(
$row
[
'mimetype'
]);
$row
[
'mimepart'
]
=
$this
->
getMimetype
(
$row
[
'mimepart'
]);
$files
[]
=
$row
;
}
}
return
$files
;
}
}
/**
/**
...
@@ -244,13 +274,30 @@ class Shared_Cache extends Cache {
...
@@ -244,13 +274,30 @@ class Shared_Cache extends Cache {
}
}
$mimetype
=
$this
->
getMimetypeId
(
$mimetype
);
$mimetype
=
$this
->
getMimetypeId
(
$mimetype
);
$ids
=
$this
->
getAll
();
$ids
=
$this
->
getAll
();
$files
=
array
();
// divide into 1k chunks
$chunks
=
array_chunk
(
$ids
,
1000
);
foreach
(
$chunks
as
$chunk
)
{
$placeholders
=
join
(
','
,
array_fill
(
0
,
count
(
$ids
),
'?'
));
$placeholders
=
join
(
','
,
array_fill
(
0
,
count
(
$ids
),
'?'
));
$query
=
\OC_DB
::
prepare
(
'
$sql
=
'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`
`encrypted`, `unencrypted_size`, `etag`
FROM `*PREFIX*filecache` WHERE '
.
$where
.
' AND `fileid` IN ('
.
$placeholders
.
')'
FROM `*PREFIX*filecache` WHERE '
.
$where
.
' AND `fileid` IN ('
.
$placeholders
.
')'
;
);
$result
=
$query
->
execute
(
array_merge
(
array
(
$mimetype
),
$ids
));
$result
=
\OC_DB
::
executeAudited
(
$sql
,
array_merge
(
array
(
$mimetype
),
$chunk
));
return
$result
->
fetchAll
();
while
(
$row
=
$result
->
fetchRow
())
{
if
(
substr
(
$row
[
'path'
],
0
,
6
)
===
'files/'
)
{
$row
[
'path'
]
=
substr
(
$row
[
'path'
],
6
);
// remove 'files/' from path as it's relative to '/Shared'
}
$row
[
'mimetype'
]
=
$this
->
getMimetype
(
$row
[
'mimetype'
]);
$row
[
'mimepart'
]
=
$this
->
getMimetype
(
$row
[
'mimepart'
]);
$files
[]
=
$row
;
}
}
return
$files
;
}
}
/**
/**
...
@@ -272,7 +319,20 @@ class Shared_Cache extends Cache {
...
@@ -272,7 +319,20 @@ class Shared_Cache extends Cache {
* @return int[]
* @return int[]
*/
*/
public
function
getAll
()
{
public
function
getAll
()
{
return
\OCP\Share
::
getItemsSharedWith
(
'file'
,
\OC_Share_Backend_File
::
FORMAT_GET_ALL
);
$ids
=
\OCP\Share
::
getItemsSharedWith
(
'file'
,
\OC_Share_Backend_File
::
FORMAT_GET_ALL
);
$folderBackend
=
\OCP\Share
::
getBackend
(
'folder'
);
if
(
$folderBackend
instanceof
Share_Backend_Collection
)
{
foreach
(
$ids
as
$file
)
{
/** @var $folderBackend Share_Backend_Collection */
$children
=
$folderBackend
->
getChildren
(
$file
);
foreach
(
$children
as
$child
)
{
$ids
[]
=
(
int
)
$child
[
'source'
];
}
}
}
return
$ids
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
lib/public/share.php
+
3
−
3
View file @
735608f5
...
@@ -760,10 +760,10 @@ class Share {
...
@@ -760,10 +760,10 @@ class Share {
/**
/**
* @brief Get the backend class for the specified item type
* @brief Get the backend class for the specified item type
* @param string
I
tem
t
ype
* @param string
$i
tem
T
ype
* @return Shar
ing b
ackend
object
* @return Shar
e_B
ackend
*/
*/
p
rivate
static
function
getBackend
(
$itemType
)
{
p
ublic
static
function
getBackend
(
$itemType
)
{
if
(
isset
(
self
::
$backends
[
$itemType
]))
{
if
(
isset
(
self
::
$backends
[
$itemType
]))
{
return
self
::
$backends
[
$itemType
];
return
self
::
$backends
[
$itemType
];
}
else
if
(
isset
(
self
::
$backendTypes
[
$itemType
][
'class'
]))
{
}
else
if
(
isset
(
self
::
$backendTypes
[
$itemType
][
'class'
]))
{
...
...
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