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
Code
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
Open source
vMap
Commits
916bfb9e
Commit
916bfb9e
authored
6 years ago
by
Frédéric Carretero
Browse files
Options
Downloads
Patches
Plain Diff
fileExistsInWsDataDir() -> Teste si un fichier existe dans "ws_data"
parent
fa7e9ab5
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
+59
-0
59 additions, 0 deletions
vas/rest/class/vmlib/phpUtil.inc
with
59 additions
and
0 deletions
vas/rest/class/vmlib/phpUtil.inc
+
59
−
0
View file @
916bfb9e
...
...
@@ -1709,4 +1709,63 @@ function isDirInWsDataDir($sModule, $sObject, $mId, $sDirectoryName = '') {
return
false
;
}
}
/**
*This method return the content of a file 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 $sDirectory directory name (optionnal).
*@param $sFileName Name of the file to read.
*@return true or false.
*/
function
fileExistsInWsDataDir
(
$sModule
,
$sObject
,
$mId
,
$sDirectory
=
''
,
$sFileName
)
{
global
$properties
;
$sDestDir
=
$properties
[
'ws_data_dir'
]
.
"/"
.
$sModule
.
"/"
.
$sObject
.
"/"
.
$mId
;
if
(
!
empty
(
$sDirectory
))
$sDestDir
.
=
"/"
.
$sDirectory
;
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
(
$sFileName
))
$sServerPath
.
=
'/'
.
$sFileName
;
// Lecture du fichier.
try
{
$oAwsResult
=
$s3
->
getObject
(
array
(
'Bucket'
=>
$sBucket
,
'Key'
=>
$sServerPath
));
return
true
;
}
catch
(
Aws\S3\Exception\S3Exception
$e
)
{
writeToErrorLog
(
$e
->
getMessage
());
return
false
;
}
}
else
{
// Teste si le fichier existe.
$sFilePath
=
$sDestDir
.
'/'
.
$sFileName
;
if
(
file_exists
(
$sFilePath
))
return
true
;
else
return
false
;
}
}
?>
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