function processDir($dirResource, $root) { global $mysqli; while (false !== ($entry = readdir($dirResource))) { if ($entry != '.' && $entry != '..') { if (is_dir($root . '/' . $entry)) { $dirToProcess = opendir($root . '/' . $entry); processDir($dirToProcess, $root . '/' . $entry); } elseif (is_file($root . '/' . $entry)) { $filedata = stat($root . '/' . $entry); if (!fileEntryExists($root . '/' . $entry, $filedata, $mysqli)) { createFileEntry($root . '/' . $entry, $filedata, $mysqli); $mysqli->query("INSERT INTO dicom_file_queue (filename, detected_date, last_modified_date, status_id) VALUES ('" . $root . '/' . $entry . "', now(), now(), (SELECT id FROM dicom_process_status WHERE name = 'new'))"); } } } } }
function checkExistingFiles() { global $fam_res; global $logger; global $dicomConfig; $mysqli = connectDatabase(); $newfile = false; while (fam_pending($fam_res)) { $arr = fam_next_event($fam_res); var_dump($arr); // FAMExists == 8 if ($arr['code'] == 8) { if (is_file($dicomConfig['biometry']['inputFolder'] . '/' . $arr['filename'])) { // we need file size and date data for all existing files $existingFilesData[$dicomConfig['biometry']['inputFolder'] . '/' . $arr['filename']] = stat($dicomConfig['biometry']['inputFolder'] . '/' . $arr['filename']); } } } if (isset($existingFilesData) && is_array($existingFilesData) && count($existingFilesData) > 0) { $processedFiles = array(); $processedFilesQ = $mysqli->query('SELECT id,filename, filesize, filedate FROM dicom_files'); while ($filerow = $processedFilesQ->fetch_assoc()) { $processedFiles[$filerow['filename']] = $filerow; } $notProcessed = checkNotProcessed($existingFilesData, $processedFiles); var_dump($notProcessed); foreach ($notProcessed as $filename => $filedata) { createFileEntry($filename, $filedata, $mysqli); } } $mysqli->close(); }