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
8a6bb796
Commit
8a6bb796
authored
12 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
add Cache::move
parent
e312c142
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
lib/files/cache/cache.php
+27
-2
27 additions, 2 deletions
lib/files/cache/cache.php
tests/lib/files/cache/cache.php
+26
-0
26 additions, 0 deletions
tests/lib/files/cache/cache.php
with
53 additions
and
2 deletions
lib/files/cache/cache.php
+
27
−
2
View file @
8a6bb796
...
...
@@ -242,6 +242,32 @@ class Cache {
$query
->
execute
(
array
(
$entry
[
'fileid'
]));
}
/**
* Move a file or folder in the cache
*
* @param string $source
* @param string $target
*/
public
function
move
(
$source
,
$target
)
{
$sourceId
=
$this
->
getId
(
$source
);
$newParentId
=
$this
->
getParentId
(
$target
);
//find all child entries
$query
=
\OC_DB
::
prepare
(
'SELECT `path`, `fileid` FROM `*PREFIX*filecache` WHERE `path` LIKE ?'
);
$result
=
$query
->
execute
(
array
(
$source
.
'/%'
));
$childEntries
=
$result
->
fetchAll
();
$sourceLength
=
strlen
(
$source
);
$query
=
\OC_DB
::
prepare
(
'UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ? WHERE `fileid` = ?'
);
foreach
(
$childEntries
as
$child
)
{
$targetPath
=
$target
.
substr
(
$child
[
'path'
],
$sourceLength
);
$query
->
execute
(
array
(
$targetPath
,
md5
(
$targetPath
),
$child
[
'fileid'
]));
}
$query
=
\OC_DB
::
prepare
(
'UPDATE `*PREFIX*filecache` SET `path` = ?, `path_hash` = ?, `parent` =? WHERE `fileid` = ?'
);
$query
->
execute
(
array
(
$target
,
md5
(
$target
),
$newParentId
,
$sourceId
));
}
/**
* remove all entries for files that are stored on the storage from the cache
*/
...
...
@@ -296,8 +322,7 @@ class Cache {
/**
* search for files by mimetype
*
* @param string $part1
* @param string $part2
* @param string $mimetype
* @return array
*/
public
function
searchByMime
(
$mimetype
)
{
...
...
This diff is collapsed.
Click to expand it.
tests/lib/files/cache/cache.php
+
26
−
0
View file @
8a6bb796
...
...
@@ -149,6 +149,32 @@ class Cache extends \UnitTestCase {
$this
->
assertEquals
(
2
,
count
(
$this
->
cache
->
searchByMime
(
'foo/file'
)));
}
function
testMove
()
{
$file1
=
'folder'
;
$file2
=
'folder/bar'
;
$file3
=
'folder/foo'
;
$file4
=
'folder/foo/1'
;
$file5
=
'folder/foo/2'
;
$data
=
array
(
'size'
=>
100
,
'mtime'
=>
50
,
'mimetype'
=>
'foo/bar'
);
$this
->
cache
->
put
(
$file1
,
$data
);
$this
->
cache
->
put
(
$file2
,
$data
);
$this
->
cache
->
put
(
$file3
,
$data
);
$this
->
cache
->
put
(
$file4
,
$data
);
$this
->
cache
->
put
(
$file5
,
$data
);
$this
->
cache
->
move
(
'folder/foo'
,
'folder/foobar'
);
$this
->
assertFalse
(
$this
->
cache
->
inCache
(
'folder/foo'
));
$this
->
assertFalse
(
$this
->
cache
->
inCache
(
'folder/foo/1'
));
$this
->
assertFalse
(
$this
->
cache
->
inCache
(
'folder/foo/2'
));
$this
->
assertTrue
(
$this
->
cache
->
inCache
(
'folder/bar'
));
$this
->
assertTrue
(
$this
->
cache
->
inCache
(
'folder/foobar'
));
$this
->
assertTrue
(
$this
->
cache
->
inCache
(
'folder/foobar/1'
));
$this
->
assertTrue
(
$this
->
cache
->
inCache
(
'folder/foobar/2'
));
}
public
function
tearDown
()
{
$this
->
cache
->
clear
();
}
...
...
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