Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flysystem
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
flysystem
Commits
d382f0b8
Commit
d382f0b8
authored
9 months ago
by
Lisa Harrison
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3195832
: Added Flysystem Filesystem Trait class, complete with logging statements
parent
34182053
No related branches found
No related tags found
1 merge request
!79
Issue #3195832: Converting existing Bridge and Factory to StreamWrapper and...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Decorator/FlysystemFileSystemTrait.php
+30
-12
30 additions, 12 deletions
src/Decorator/FlysystemFileSystemTrait.php
with
30 additions
and
12 deletions
src/Decorator/FlysystemFileSystemTrait.php
+
30
−
12
View file @
d382f0b8
...
@@ -31,7 +31,7 @@ trait FlysystemFileSystemTrait {
...
@@ -31,7 +31,7 @@ trait FlysystemFileSystemTrait {
* TRUE for success, FALSE in the event of an error.
* TRUE for success, FALSE in the event of an error.
*/
*/
protected
function
chmodFs
(
$wrapper
,
$uri
,
$mode
=
NULL
):
bool
{
protected
function
chmodFs
(
$wrapper
,
$uri
,
$mode
=
NULL
):
bool
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', uri: '
.
$uri
);
try
{
try
{
$drupalMode
=
NULL
;
$drupalMode
=
NULL
;
if
(
$wrapper
->
filesystem
->
directoryExists
(
$uri
))
{
if
(
$wrapper
->
filesystem
->
directoryExists
(
$uri
))
{
...
@@ -76,7 +76,11 @@ trait FlysystemFileSystemTrait {
...
@@ -76,7 +76,11 @@ trait FlysystemFileSystemTrait {
* @todo finish writing, see inline todo comments.
* @todo finish writing, see inline todo comments.
*/
*/
protected
function
mkdirFs
(
$wrapper
,
$uri
,
$mode
=
NULL
,
$recursive
=
FALSE
,
$context
=
NULL
):
bool
{
protected
function
mkdirFs
(
$wrapper
,
$uri
,
$mode
=
NULL
,
$recursive
=
FALSE
,
$context
=
NULL
):
bool
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', uri: '
.
$uri
);
if
(
!
isset
(
$mode
))
{
$mode
=
$this
->
settings
->
get
(
'file_chmod_directory'
,
static
::
CHMOD_DIRECTORY
);
}
try
{
try
{
// @todo figure out how to utilize directory permissions, see notes on
// @todo figure out how to utilize directory permissions, see notes on
// Flysystem VisibilityConverter.
// Flysystem VisibilityConverter.
...
@@ -109,7 +113,7 @@ trait FlysystemFileSystemTrait {
...
@@ -109,7 +113,7 @@ trait FlysystemFileSystemTrait {
* @todo finish writing, see inline todo comments.
* @todo finish writing, see inline todo comments.
*/
*/
protected
function
rmdirFs
(
$wrapper
,
$uri
,
$context
=
NULL
):
bool
{
protected
function
rmdirFs
(
$wrapper
,
$uri
,
$context
=
NULL
):
bool
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', uri: '
.
$uri
);
try
{
try
{
// @todo figure out how to utilize directory permissions, see notes on
// @todo figure out how to utilize directory permissions, see notes on
// Flysystem VisibilityConverter.
// Flysystem VisibilityConverter.
...
@@ -144,7 +148,7 @@ trait FlysystemFileSystemTrait {
...
@@ -144,7 +148,7 @@ trait FlysystemFileSystemTrait {
* @todo Rewrite to leverage Flysystem (yes)
* @todo Rewrite to leverage Flysystem (yes)
*/
*/
protected
function
copyFs
(
$wrapper
,
$source
,
$destination
,
$fileExists
):
string
{
protected
function
copyFs
(
$wrapper
,
$source
,
$destination
,
$fileExists
):
string
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', source: '
.
$source
.
', destination: '
.
$destination
);
try
{
try
{
// @todo figure out how to utilize directory permissions, see notes on
// @todo figure out how to utilize directory permissions, see notes on
// Flysystem VisibilityConverter.
// Flysystem VisibilityConverter.
...
@@ -174,7 +178,7 @@ trait FlysystemFileSystemTrait {
...
@@ -174,7 +178,7 @@ trait FlysystemFileSystemTrait {
* @todo finish writing, see inline todo comments.
* @todo finish writing, see inline todo comments.
*/
*/
protected
function
deleteFs
(
$wrapper
,
$path
)
{
protected
function
deleteFs
(
$wrapper
,
$path
)
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', path: '
.
$path
);
if
(
$wrapper
->
filesystem
->
directoryExists
(
$path
))
{
if
(
$wrapper
->
filesystem
->
directoryExists
(
$path
))
{
throw
new
NotRegularFileException
(
"Cannot delete '
$path
' because it is a directory. Use deleteRecursive() instead."
);
throw
new
NotRegularFileException
(
"Cannot delete '
$path
' because it is a directory. Use deleteRecursive() instead."
);
}
}
...
@@ -208,7 +212,7 @@ trait FlysystemFileSystemTrait {
...
@@ -208,7 +212,7 @@ trait FlysystemFileSystemTrait {
* TRUE if successful, FALSE if not.
* TRUE if successful, FALSE if not.
*/
*/
protected
function
deleteRecursiveFs
(
$wrapper
,
$path
,
callable
$callback
=
NULL
):
bool
{
protected
function
deleteRecursiveFs
(
$wrapper
,
$path
,
callable
$callback
=
NULL
):
bool
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', path: '
.
$path
);
if
(
!
$wrapper
->
filesystem
->
fileExists
(
$path
))
{
if
(
!
$wrapper
->
filesystem
->
fileExists
(
$path
))
{
return
TRUE
;
return
TRUE
;
}
}
...
@@ -244,7 +248,7 @@ trait FlysystemFileSystemTrait {
...
@@ -244,7 +248,7 @@ trait FlysystemFileSystemTrait {
* @todo finish writing, see inline todo comments.
* @todo finish writing, see inline todo comments.
*/
*/
protected
function
moveFs
(
$wrapper
,
$source
,
$destination
,
$fileExists
):
string
{
protected
function
moveFs
(
$wrapper
,
$source
,
$destination
,
$fileExists
):
string
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', source: '
.
$source
.
', destination: '
.
$destination
);
try
{
try
{
// @todo figure out how to utilize directory permissions, see notes on
// @todo figure out how to utilize directory permissions, see notes on
// Flysystem VisibilityConverter.
// Flysystem VisibilityConverter.
...
@@ -281,7 +285,7 @@ trait FlysystemFileSystemTrait {
...
@@ -281,7 +285,7 @@ trait FlysystemFileSystemTrait {
* @todo finish writing, see inline todo comments.
* @todo finish writing, see inline todo comments.
*/
*/
protected
function
saveDataFs
(
$wrapper
,
$temp_nam
,
$destination
,
$fileExists
)
{
protected
function
saveDataFs
(
$wrapper
,
$temp_nam
,
$destination
,
$fileExists
)
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', temp_nam: '
.
$temp_nam
.
', destination: '
.
$destination
);
// Move the file to its final destination.
// Move the file to its final destination.
try
{
try
{
// @todo figure out how to utilize directory permissions, see notes on
// @todo figure out how to utilize directory permissions, see notes on
...
@@ -320,7 +324,11 @@ trait FlysystemFileSystemTrait {
...
@@ -320,7 +324,11 @@ trait FlysystemFileSystemTrait {
* @see \League\Flysystem\FilesystemOperator::directoryExists()
* @see \League\Flysystem\FilesystemOperator::directoryExists()
*/
*/
protected
function
prepareDirectoryFs
(
$wrapper
,
&
$directory
,
$options
)
:
bool
{
protected
function
prepareDirectoryFs
(
$wrapper
,
&
$directory
,
$options
)
:
bool
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', directory: '
.
$directory
);
if
(
!
$this
->
streamWrapperManager
->
isValidUri
(
$directory
))
{
// Only trim if we're not dealing with a stream.
$directory
=
rtrim
(
$directory
,
'/\\'
);
}
// How do we use the flags, self::MODIFY_PERMISSIONS and
// How do we use the flags, self::MODIFY_PERMISSIONS and
// static::CREATE_DIRECTORY here?
// static::CREATE_DIRECTORY here?
// @see Drupal\Core\File\FileSystemInterface::prepareDirectory().
// @see Drupal\Core\File\FileSystemInterface::prepareDirectory().
...
@@ -331,6 +339,12 @@ trait FlysystemFileSystemTrait {
...
@@ -331,6 +339,12 @@ trait FlysystemFileSystemTrait {
if
(
$success
)
{
if
(
$success
)
{
return
TRUE
;
return
TRUE
;
}
}
// If the operation failed, check again if the directory was created
// by another process/server, only report a failure if not. In this case
// we still need to ensure the directory is writable.
if
(
!
is_dir
(
$directory
))
{
return
FALSE
;
}
}
}
catch
(
\Exception
$e
)
{
catch
(
\Exception
$e
)
{
\Drupal
::
logger
(
'FlyStreamWrapper'
)
->
error
(
'Exception: '
.
$e
->
getMessage
());
\Drupal
::
logger
(
'FlyStreamWrapper'
)
->
error
(
'Exception: '
.
$e
->
getMessage
());
...
@@ -343,7 +357,11 @@ trait FlysystemFileSystemTrait {
...
@@ -343,7 +357,11 @@ trait FlysystemFileSystemTrait {
if
(
!
$wrapper
->
filesystem
->
directoryExists
(
$directory
))
{
if
(
!
$wrapper
->
filesystem
->
directoryExists
(
$directory
))
{
return
FALSE
;
return
FALSE
;
}
}
return
$this
->
chmod
(
$directory
);
$writable
=
is_writable
(
$directory
);
if
(
!
$writable
&&
(
$options
&
static
::
MODIFY_PERMISSIONS
))
{
return
$this
->
chmod
(
$directory
);
}
return
$writeable
;
}
}
/**
/**
...
@@ -368,7 +386,7 @@ trait FlysystemFileSystemTrait {
...
@@ -368,7 +386,7 @@ trait FlysystemFileSystemTrait {
* @todo reevaluate against \Drupal\Core\File\FileSystem::createFilename().
* @todo reevaluate against \Drupal\Core\File\FileSystem::createFilename().
*/
*/
protected
function
createFilenameFs
(
$wrapper
,
$separator
,
$destination
,
$basename
,
$directory
):
string
{
protected
function
createFilenameFs
(
$wrapper
,
$separator
,
$destination
,
$basename
,
$directory
):
string
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', separator: '
.
$separator
.
', destination: '
.
$destination
.
', basename: '
.
$basename
.
', directory: '
.
$directory
);
try
{
try
{
$exists
=
$wrapper
->
filesystem
->
fileExists
(
$destination
);
$exists
=
$wrapper
->
filesystem
->
fileExists
(
$destination
);
if
(
$exists
)
{
if
(
$exists
)
{
...
@@ -417,7 +435,7 @@ trait FlysystemFileSystemTrait {
...
@@ -417,7 +435,7 @@ trait FlysystemFileSystemTrait {
* @todo finish writing, see inline todo comments.
* @todo finish writing, see inline todo comments.
*/
*/
protected
function
getDestinationFilenameFs
(
$wrapper
,
$basename
,
$destination
,
$fileExists
):
string
|
bool
{
protected
function
getDestinationFilenameFs
(
$wrapper
,
$basename
,
$destination
,
$fileExists
):
string
|
bool
{
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
);
\Drupal
::
logger
(
'flysystem'
)
->
notice
(
'Calling '
.
__METHOD__
.
', basename: '
.
$basename
.
', destination: '
.
$destination
);
try
{
try
{
if
(
$wrapper
->
filesystem
->
fileExists
(
$destination
))
{
if
(
$wrapper
->
filesystem
->
fileExists
(
$destination
))
{
switch
(
$fileExists
)
{
switch
(
$fileExists
)
{
...
...
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