SplFileinfo

This commit is contained in:
Michael RICOIS 2016-08-01 14:57:51 +02:00
parent 44c837eb97
commit d63623a4b0

View File

@ -242,13 +242,10 @@ class FileController extends AbstractActionController
}
else {
// Get the main directory name in FTP and SFTP
$pathParts = pathinfo($filepath);
$filenameIn = $pathParts['basename'];
$extension = '';
if (array_key_exists('extension', $pathParts)) {
$extension = $pathParts['extension'];
}
$client = basename(dirname($pathParts['dirname']));
$fileinfo = new \SplFileInfo($filepath);
$filenameIn = $fileinfo->getBasename();
$extension = $fileinfo->getExtension();
$client = basename(dirname($fileinfo->getPath()));
// Base path, type and repository
if ($pathConfig['sftp'] == substr($filepath, 0, strlen($pathConfig['sftp']))) {
@ -398,19 +395,16 @@ class FileController extends AbstractActionController
}
else {
// Get the main directory name in FTP and SFTP
$pathParts = pathinfo($filepath);
$filenameIn = $pathParts['basename'];
$extension = '';
if (array_key_exists('extension', $pathParts)) {
$extension = $pathParts['extension'];
}
$fileinfo = new \SplFileInfo($filepath);
$filenameIn = $fileinfo->getBasename();
$extension = $fileinfo->getExtension();
$client = basename(dirname($fileinfo->getPath()));
// Only file with .tck
if ($extension != 'tck') {
exit;
}
$client = basename(dirname($pathParts['dirname']));
$filenameSearch = str_replace('.tck', '', $filenameIn);
// Base path, type and repository
@ -603,9 +597,9 @@ class FileController extends AbstractActionController
$filepath = $request->getParam('filepath');
$event = $request->getParam('event');
$pathParts = pathinfo($filepath);
$filename = $pathParts['basename'];
$extension = $pathParts['extension'];
$fileinfo = new \SplFileInfo($filepath);
$filenameIn = $fileinfo->getBasename();
$extension = $fileinfo->getExtension();
switch($event) {
case 'IN_CLOSE_WRITE':
@ -657,18 +651,16 @@ class FileController extends AbstractActionController
else {
// Get the main directory name in FTP and SFTP
$pathParts = pathinfo($filepath);
$filenameIn = $pathParts['basename'];
$extension = '';
if (array_key_exists('extension', $pathParts)) {
$extension = $pathParts['extension'];
}
$fileinfo = new \SplFileInfo($filepath);
$filenameIn = $fileinfo->getBasename();
$extension = $fileinfo->getExtension();
$client = basename(dirname($fileinfo->getPath()));
// Don't play with *.tck files
if ($extension == 'tck') {
passthru(__DIR__ . '/cli tck '.$filepath.' >> /home/log/tck.log 2>&1');
exit;
}
$client = basename(dirname($pathParts['dirname']));
// Base path, type and repository
if ($pathConfig['sftp'] == substr($filepath, 0, strlen($pathConfig['sftp']))) {
@ -737,32 +729,28 @@ class FileController extends AbstractActionController
// Set directory
$fluxBasePath .= '/'.$repositoryDir;
// Use ".fin" or ".end" files to do something
// Stop with option end file
$runExtensions = array('fin', 'end');
if (in_array($extension, $runExtensions)) {
if ($optionsRunWithEndFile) {
$extToDelete = $extension;
if (file_exists($fluxBasePath . '/' . $filenameIn)) {
$pathParts = pathinfo($fluxBasePath . '/' . $filenameIn);
$filenameIn = $pathParts['basename'];
}
else {
$this->output("Fichier fin inexistant $filenameIn");
exit;
}
}
else {
// Do nothing
if ($optionsRunWithEndFile) {
if (!in_array($extension, $runExtensions)) {
exit;
}
}
// Get the realname of file IN or exit
if ($optionsRunWithEndFile) {
if (in_array($extension, $runExtensions)) {
// A file with ".fin" or ".end" is receive
if (in_array($extension, $runExtensions)) {
if ($optionsRunWithEndFile) {
$extToDelete = $extension;
$extensionLength = strlen($extension)+1;
$filenameIn = substr($filenameIn, 0, strlen($filenameIn) - $extensionLength);
$extension = '';
if (file_exists($fluxBasePath . '/' . $filenameIn)) {
$fileinfo = new \SplFileInfo(fluxBasePath . '/' . $filenameIn);
$extension = $fileinfo->getExtension();
}
else {
$this->output("Fichier inexistant $filenameIn");
exit;
}
}
else {
// Do nothing
@ -776,8 +764,8 @@ class FileController extends AbstractActionController
$lines = file($fluxBasePath . '/' . $filenameIn);
$nbLines = count($lines);
}
$size = filesize($fluxBasePath . '/' . $filenameIn);
$dateFile = date('YmdHis', filectime($fluxBasePath . '/' . $filenameIn));
$size = $fileinfo->getSize();
$dateFile = date('YmdHis', $fileinfo->getCTime());
// Define default out filename
$filenameOut = $filenameIn;
@ -970,12 +958,12 @@ class FileController extends AbstractActionController
$filenameIn = $fileinfo->getFilename();
$extension = $fileinfo->getExtension();
// --- Don't play with *.tck files
// Don't play with *.tck files
if ($extension == 'tck') {
continue;
}
// --- Filters
// Filters
if ($optionsFilterName === true) {
if ( strpos($filenameIn, $prestation) === false ) {
$prestation = null; continue;
@ -987,17 +975,28 @@ class FileController extends AbstractActionController
}
}
// Use ".fin" or ".end" files to do something
// Stop with option end file
$runExtensions = array('fin', 'end');
if ($optionsRunWithEndFile) {
if (!in_array($extension, $runExtensions)) {
exit;
}
}
// A file with ".fin" or ".end" is receive
if (in_array($extension, $runExtensions)) {
if ($optionsRunWithEndFile) {
$extToDelete = $extension;
// Get the realname of file IN or exit
$extensionLength = strlen($extension)+1;
$filenameIn = substr($filenameIn, 0, strlen($filenameIn) - $extensionLength);
if (file_exists($fluxBasePath . '/' . $filenameIn)) {
$pathParts = pathinfo($fluxBasePath . '/' . $filenameIn);
$filenameIn = $pathParts['basename'];
$fileinfo = new \SplFileInfo($fluxBasePath . '/' . $filenameIn);
$filenameIn = $fileinfo->getBasename();
$extension = $fileinfo->getExtension();
}
else {
$this->output("Fichier fin inexistant $filenameIn");
$this->output("Fichier inexistant $filenameIn");
continue;
}
}
@ -1007,26 +1006,14 @@ class FileController extends AbstractActionController
}
}
// Get the realname of file IN or exit
if ($optionsRunWithEndFile) {
if (in_array($extension, $runExtensions)) {
$extensionLength = strlen($extension)+1;
$filenameIn = substr($filenameIn, 0, strlen($filenameIn) - $extensionLength);
$extension = '';
}
else {
continue;
}
}
// Detail du fichier
$nbLines = 0;
if ( strtolower(substr($filenameIn, -3)) == 'csv' ) {
$lines = file($fluxBasePath . '/' . $filenameIn);
$nbLines = count($lines);
}
$size = filesize($fluxBasePath . '/' . $filenameIn);
$dateFile = date('YmdHis', filectime($fluxBasePath . '/' . $filenameIn));
$size = $fileinfo->getSize();
$dateFile = date('YmdHis', $fileinfo->getCTime ());
// Define default out filename
$filenameOut = $filenameIn;