Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
vMap
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Marty Fabien
vMap
Commits
3c1f6127
Commit
3c1f6127
authored
6 years ago
by
Frédéric Carretero
Browse files
Options
Downloads
Patches
Plain Diff
deleteDirectoryInWsDataDir() -> Supprime un répertoire dans "ws_data"
parent
cf7c2b91
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
vas/rest/class/vmlib/phpUtil.inc
+68
-0
68 additions, 0 deletions
vas/rest/class/vmlib/phpUtil.inc
with
68 additions
and
0 deletions
vas/rest/class/vmlib/phpUtil.inc
+
68
−
0
View file @
3c1f6127
...
@@ -1498,4 +1498,72 @@ function createEmptyFileInWsDataDir($sModule, $sObject, $mId, $sField = '', $sFi
...
@@ -1498,4 +1498,72 @@ function createEmptyFileInWsDataDir($sModule, $sObject, $mId, $sField = '', $sFi
}
}
return
$sErrorMsg
;
return
$sErrorMsg
;
}
}
/**
*This method delete a directory in ws_data.
*@file vmlib/phpUtil.inc
*@param $sModule Name of the module.
*@param $sObject Name of the object.
*@param $mId Id of the current object.
*@param $sField field name (generally DB column name).
*@param $sDirectoryName Name of the directory to delete.
*@return $sErrorMsg The error message.
*/
function
deleteDirectoryInWsDataDir
(
$sModule
,
$sObject
,
$mId
,
$sField
=
''
,
$sDirectoryName
=
''
)
{
global
$properties
;
$sErrorMsg
=
''
;
$sDestDir
=
$properties
[
'ws_data_dir'
]
.
"/"
.
$sModule
.
"/"
.
$sObject
.
"/"
.
$mId
;
if
(
!
empty
(
$sField
))
$sDestDir
.
=
"/"
.
$sField
;
if
(
$properties
[
'fileS3Uploader'
]
===
true
)
{
require_once
(
"aws_sdk/aws-autoloader.php"
);
$s3
=
new
Aws\S3\S3Client
(
array
(
'version'
=>
'latest'
,
'region'
=>
$properties
[
'fileS3UploaderRegion'
],
'profile'
=>
$properties
[
'fileS3UploaderProfil'
],
'debug'
=>
false
));
$sBucket
=
$properties
[
'fileS3UploaderBucket'
];
$sPrefix
=
""
;
if
(
strpos
(
$sBucket
,
"/"
)
>
-
1
){
$aBucket
=
explode
(
"/"
,
$sBucket
);
$sBucket
=
$aBucket
[
0
];
$sPrefix
=
implode
(
"/"
,
array_slice
(
$aBucket
,
1
));
}
$sServerPath
=
str_replace
(
$properties
[
"vas_home"
],
$sPrefix
,
$sDestDir
);
// Suppression du slash de début de ligne (sinon création d'un répertoire vide sur S3).
if
(
strpos
(
$sServerPath
,
'/'
)
===
0
)
$sServerPath
=
substr
(
$sServerPath
,
1
);
if
(
!
empty
(
$sDirectoryName
))
$sServerPath
.
=
'/'
.
$sDirectoryName
;
// Suppression du répertoire.
try
{
$oAwsResult
=
$s3
->
listObjects
(
array
(
'Bucket'
=>
$sBucket
,
'Prefix'
=>
$sServerPath
));
// Suppression de chaque fichier.
foreach
(
$oAwsResult
->
get
(
'Contents'
)
as
$aKey
)
{
$aResult
=
$s3
->
deleteObject
(
array
(
'Bucket'
=>
$sBucket
,
'Key'
=>
$aKey
[
'Key'
]
));
}
}
catch
(
Aws\S3\Exception\S3Exception
$e
)
{
writeToErrorLog
(
$e
->
getMessage
());
}
}
else
{
// Suppression du répertoire.
$sDirectoryPath
=
$sDestDir
.
'/'
.
$sDirectoryName
;
if
(
is_dir
(
$sDirectoryPath
))
{
if
(
!
cleardir
(
$sDirectoryPath
))
{
writeToErrorLog
(
ERROR_DELETING_DIRECTORY
.
$sDestDir
);
return
ERROR_DELETING_DIRECTORY
.
$sDestDir
;
}
}
}
return
$sErrorMsg
;
}
?>
?>
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