|
|
@@ -30,34 +30,30 @@ function getObjectsAsArray($objects, $keys) {
|
|
|
return $return;
|
|
|
}
|
|
|
|
|
|
-function searchNewFiles($scanDir) {
|
|
|
+function scanDocuments($path) {
|
|
|
global $db;
|
|
|
global $CONFIG;
|
|
|
|
|
|
- $oldDocuments = Document::getDocumentsByLabelPath($scanDir);
|
|
|
- $files = scandir($CONFIG['documentPath'] . $scanDir);
|
|
|
|
|
|
- foreach($files as $file) {
|
|
|
- $existed = false;
|
|
|
- if($file === '.' || $file === '..') {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- foreach($oldDocuments as $oldDocument) {
|
|
|
- if($oldDocument->getFileName() === $file) {
|
|
|
- $existed = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- if($existed) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ $files = recursiveScanDir($path);
|
|
|
+ $allDocuments = getObjectsAsArray(Document::getAllDocuments(), array("id", "fileName", "path", "labelId", "draft", "created", "lastChange", "type", "mailUid"));
|
|
|
|
|
|
- Document::addDocument('file', $file, '/', Label::getLabelByPath($scanDir)->getId(), '', 'NOW()', 'NOW()');
|
|
|
+ handleFile($files, $allDocuments);
|
|
|
|
|
|
+ if(sizeof($allDocuments) > 0) { // Documents got removed
|
|
|
+ foreach($allDocuments as $document) {
|
|
|
+ Document::removeDocumentByID($document['id']);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ $newDocumentsNumber = sizeof($allDocuments);
|
|
|
+
|
|
|
+ return array(
|
|
|
+ "new" => $newDocumentsNumber
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
function handleFile($filename, &$allDocuments) {
|