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
33186957
Commit
33186957
authored
10 years ago
by
Georg Ehrke
Browse files
Options
Downloads
Patches
Plain Diff
delete all children's previews when deleting a folder
add phpdoc
parent
3652f02e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/private/preview.php
+94
-16
94 additions, 16 deletions
lib/private/preview.php
with
94 additions
and
16 deletions
lib/private/preview.php
+
94
−
16
View file @
33186957
...
@@ -48,6 +48,7 @@ class Preview {
...
@@ -48,6 +48,7 @@ class Preview {
//filemapper used for deleting previews
//filemapper used for deleting previews
// index is path, value is fileinfo
// index is path, value is fileinfo
static
public
$deleteFileMapper
=
array
();
static
public
$deleteFileMapper
=
array
();
static
public
$deleteChildrenMapper
=
array
();
/**
/**
* preview images object
* preview images object
...
@@ -189,6 +190,21 @@ class Preview {
...
@@ -189,6 +190,21 @@ class Preview {
return
$this
->
info
;
return
$this
->
info
;
}
}
/**
* @return array|null
*/
private
function
getChildren
()
{
$absPath
=
$this
->
fileView
->
getAbsolutePath
(
$this
->
file
);
$absPath
=
Files\Filesystem
::
normalizePath
(
$absPath
);
if
(
array_key_exists
(
$absPath
,
self
::
$deleteChildrenMapper
))
{
return
self
::
$deleteChildrenMapper
[
$absPath
];
}
return
null
;
}
/**
/**
* set the path of the file you want a thumbnail from
* set the path of the file you want a thumbnail from
* @param string $file
* @param string $file
...
@@ -269,6 +285,10 @@ class Preview {
...
@@ -269,6 +285,10 @@ class Preview {
return
$this
;
return
$this
;
}
}
/**
* @param bool $keepAspect
* @return $this
*/
public
function
setKeepAspect
(
$keepAspect
)
{
public
function
setKeepAspect
(
$keepAspect
)
{
$this
->
keepAspect
=
$keepAspect
;
$this
->
keepAspect
=
$keepAspect
;
return
$this
;
return
$this
;
...
@@ -312,20 +332,25 @@ class Preview {
...
@@ -312,20 +332,25 @@ class Preview {
/**
/**
* deletes all previews of a file
* deletes all previews of a file
* @return bool
*/
*/
public
function
deleteAllPreviews
()
{
public
function
deleteAllPreviews
()
{
$file
=
$this
->
getFile
();
$file
=
$this
->
getFile
();
$fileInfo
=
$this
->
getFileInfo
(
$file
);
$fileInfo
=
$this
->
getFileInfo
(
$file
);
if
(
$fileInfo
!==
null
&&
$fileInfo
!==
false
)
{
$fileId
=
$fileInfo
->
getId
();
$toDelete
=
$this
->
getChildren
();
$toDelete
[]
=
$fileInfo
;
foreach
(
$toDelete
as
$delete
)
{
if
(
$delete
!==
null
&&
$delete
!==
false
)
{
/** @var \OCP\Files\FileInfo $delete */
$fileId
=
$delete
->
getId
();
$previewPath
=
$this
->
getPreviewPath
(
$fileId
);
$previewPath
=
$this
->
getPreviewPath
(
$fileId
);
$this
->
userView
->
deleteAll
(
$previewPath
);
$this
->
userView
->
deleteAll
(
$previewPath
);
return
$this
->
userView
->
rmdir
(
$previewPath
);
$this
->
userView
->
rmdir
(
$previewPath
);
}
}
}
return
false
;
}
}
/**
/**
...
@@ -667,8 +692,8 @@ class Preview {
...
@@ -667,8 +692,8 @@ class Preview {
}
}
/**
/**
*
R
egister a new preview provider to be used
*
r
egister a new preview provider to be used
* @param $class
* @param
string
$class
* @param array $options
* @param array $options
*/
*/
public
static
function
registerProvider
(
$class
,
$options
=
array
())
{
public
static
function
registerProvider
(
$class
,
$options
=
array
())
{
...
@@ -737,14 +762,24 @@ class Preview {
...
@@ -737,14 +762,24 @@ class Preview {
}
}
/**
* @param array $args
*/
public
static
function
post_write
(
$args
)
{
public
static
function
post_write
(
$args
)
{
self
::
post_delete
(
$args
,
'files/'
);
self
::
post_delete
(
$args
,
'files/'
);
}
}
/**
* @param array $args
*/
public
static
function
prepare_delete_files
(
$args
)
{
public
static
function
prepare_delete_files
(
$args
)
{
self
::
prepare_delete
(
$args
,
'files/'
);
self
::
prepare_delete
(
$args
,
'files/'
);
}
}
/**
* @param array $args
* @param string $prefix
*/
public
static
function
prepare_delete
(
$args
,
$prefix
=
''
)
{
public
static
function
prepare_delete
(
$args
,
$prefix
=
''
)
{
$path
=
$args
[
'path'
];
$path
=
$args
[
'path'
];
if
(
substr
(
$path
,
0
,
1
)
===
'/'
)
{
if
(
substr
(
$path
,
0
,
1
)
===
'/'
)
{
...
@@ -752,20 +787,63 @@ class Preview {
...
@@ -752,20 +787,63 @@ class Preview {
}
}
$view
=
new
\OC\Files\View
(
'/'
.
\OC_User
::
getUser
()
.
'/'
.
$prefix
);
$view
=
new
\OC\Files\View
(
'/'
.
\OC_User
::
getUser
()
.
'/'
.
$prefix
);
$info
=
$view
->
getFileInfo
(
$path
);
\OC\Preview
::
$deleteFileMapper
=
array_merge
(
$absPath
=
Files\Filesystem
::
normalizePath
(
$view
->
getAbsolutePath
(
$path
));
\OC\Preview
::
$deleteFileMapper
,
self
::
addPathToDeleteFileMapper
(
$absPath
,
$view
->
getFileInfo
(
$path
));
array
(
if
(
$view
->
is_dir
(
$path
))
{
Files\Filesystem
::
normalizePath
(
$view
->
getAbsolutePath
(
$path
))
=>
$info
,
$children
=
self
::
getAllChildren
(
$view
,
$path
);
)
self
::
$deleteChildrenMapper
[
$absPath
]
=
$children
;
}
}
/**
* @param string $absolutePath
* @param \OCP\Files\FileInfo $info
*/
private
static
function
addPathToDeleteFileMapper
(
$absolutePath
,
$info
)
{
self
::
$deleteFileMapper
[
$absolutePath
]
=
$info
;
}
/**
* @param \OC\Files\View $view
* @param string $path
* @return array
*/
private
static
function
getAllChildren
(
$view
,
$path
)
{
$children
=
$view
->
getDirectoryContent
(
$path
);
$childrensFiles
=
array
();
$fakeRootLength
=
strlen
(
$view
->
getRoot
());
for
(
$i
=
0
;
$i
<
count
(
$children
);
$i
++
)
{
$child
=
$children
[
$i
];
$childsPath
=
substr
(
$child
->
getPath
(),
$fakeRootLength
);
if
(
$view
->
is_dir
(
$childsPath
))
{
$children
=
array_merge
(
$children
,
$view
->
getDirectoryContent
(
$childsPath
)
);
);
}
else
{
$childrensFiles
[]
=
$child
;
}
}
}
return
$childrensFiles
;
}
/**
* @param array $args
*/
public
static
function
post_delete_files
(
$args
)
{
public
static
function
post_delete_files
(
$args
)
{
self
::
post_delete
(
$args
,
'files/'
);
self
::
post_delete
(
$args
,
'files/'
);
}
}
/**
* @param array $args
* @param string $prefix
*/
public
static
function
post_delete
(
$args
,
$prefix
=
''
)
{
public
static
function
post_delete
(
$args
,
$prefix
=
''
)
{
$path
=
Files\Filesystem
::
normalizePath
(
$args
[
'path'
]);
$path
=
Files\Filesystem
::
normalizePath
(
$args
[
'path'
]);
...
...
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