Moritz Schmidt 10 år sedan
förälder
incheckning
ddfa016c4b
3 ändrade filer med 26 tillägg och 2 borttagningar
  1. 7 2
      cron.php
  2. 16 0
      includes/document.inc.php
  3. 3 0
      includes/functions.inc.php

+ 7 - 2
cron.php

@@ -16,10 +16,15 @@ $db = new Database($CONFIG['dbHost'], $CONFIG['dbUser'], $CONFIG['dbPassword'],
 $files = recursiveScanDir($CONFIG['documentPath']);
 $allDocuments = getObjectsAsArray(Document::getAllDocuments(), array("id", "fileName", "path", "labelId", "draft", "created", "lastChange", "type", "mailUid"));
 
-
 handleFile($files, $allDocuments);
 
-//searchMails();
+if(sizeof($allDocuments) > 0) { // Documents got removed
+    foreach($allDocuments as $document) {
+        Document::removeDocumentByID($document['id']);
+    }
+}
+
+//searchMails(); // Mails -> eigene klasse
 
 
 ?>

+ 16 - 0
includes/document.inc.php

@@ -175,6 +175,22 @@ class Document {
         $db->insertQuery($query);
     }
 
+    /**
+     * Remove a Document from DB by documentID
+     *
+     * @param int $documentID  ID of Document
+     *
+     * @return void
+     *
+     */
+
+    public static function removeDocumentByID($documentID) {
+        global $db;
+
+        $db->removeQuery("DELETE FROM `documents` WHERE `id` = " . $documentID . ";");
+
+    }
+
     /**
      * Get all Drafts
      *

+ 3 - 0
includes/functions.inc.php

@@ -95,6 +95,9 @@ function handleFile($filename, &$allDocuments) {
 			unset($path[0]);
 			unset($path[sizeof($path)]);
 			$path = implode('/', $path) . '/';
+			if($path == '/') {
+				$path = "";
+			}
 
 			Document::addDocument('file', explode('/', $filename)[sizeof(explode('/', $filename)) - 1], $path, Label::getLabelByPath($labelPath)->getId(), '', $fileTime, $fileTime);
 		}