Projet

Général

Profil

Fonctionnalité #7546 » Paperstream.php

Henri QUENEAU, 01/06/2018 16:10

 
<?php

class Paperstream
{
private $Batch;

function __construct()
{
$this->Batch = $_SESSION['capture']->Batch;
}
function separateSubjectPDF($ScanSource,$ResultDirectory = false)
{

echo "Init process ...\n";
$_SESSION['capture']->logEvent(
"Init process ... "
);

if (!is_readable($ScanSource)) {
echo "Source directory is not valid !\n";
$_SESSION['capture']->logEvent(
"Source directory is not valid !"
);
exit();
}

if (!is_readable($ScanSource)) {
echo "Result directory is not valid ! \n";
$_SESSION['capture']->logEvent(
"Result directory is not valid !"
);
exit();
}

$files = array_diff(scandir($ScanSource), array('..', '.','FAILED'));
//print_r($files);

if (empty($files)) {
echo "No files to process ! End of process ...\n";
$_SESSION['capture']->logEvent(
"No files to process ! End of process ..."
);
exit();
}

echo "There is ".count($files)." file(s) to process\n";
$_SESSION['capture']->logEvent(
"There is ".count($files)." to process"
);
$num_file = 1;
foreach ($files as $key => $value) {
echo "\n\n * File n°".$num_file.": ".$files[$key]." *\n";
$_SESSION['capture']->logEvent(
"* File n°".$num_file.": ".$files[$key]." *"
);
$array_files = explode('.', $files[$key]);

//Ignore all files except pdf
if (strtolower($array_files[1]) == 'pdf') {

echo "\n\n * Séparation du service et du code barre * \n";
$data = explode('_', $array_files[0]);

$destination = $data[0];
$barcode = $data[1];

echo "\n\n * Le service est ".$destination." *\n";
echo "\n\n * Le codebarre est ".$barcode." *\n";
//add document in folder
$Document = $this->Batch->addDocument($ScanSource.$files[$key]);
//add destination data
$Document->setMetadata(
"destination",
$destination
);
$Document->setMetadata(
"barcode",
$barcode
);
//delete scan in source
unlink ($ScanSource.$files[$key]);
} else {
echo "No pdf format ! skipping ...\n";
$_SESSION['capture']->logEvent(
"No pdf format ! skipping ...\n"
);
}
$num_file++;
}

$files = glob(realpath('tmp').'/*'); // get all file names
foreach($files as $file){ // iterate files
if(is_file($file))
unlink($file); // delete file
}

echo "End of process ...\n";
$_SESSION['capture']->logEvent(
"End of process ..."
);

}

}
(1-1/2)