diff --git a/custom/Espo/Custom/Hooks/CDokumente/CDokumente.php b/custom/Espo/Custom/Hooks/CDokumente/CDokumente.php new file mode 100644 index 00000000..2c4da7c8 --- /dev/null +++ b/custom/Espo/Custom/Hooks/CDokumente/CDokumente.php @@ -0,0 +1,60 @@ +isNew() && !$entity->isAttributeChanged('dokument')) { + return; + } + + $dokument = $entity->get('dokument'); + + if (!$dokument) { + return; + } + + if (is_object($dokument)) { + $attachment = $dokument; + } else { + $attachment = $this->getEntityManager()->getEntity('Attachment', $dokument); + } + + if (!$attachment) { + return; + } + + $filePath = 'data/upload/' . $attachment->get('id'); + if (!file_exists($filePath)) { + return; + } + + // Berechne neue Hashes + $newMd5 = hash_file('md5', $filePath); + $newSha256 = hash_file('sha256', $filePath); + + // Setze Hashes + $entity->set('md5sum', $newMd5); + $entity->set('sha256', $newSha256); + + // Bestimme Status + if ($entity->isNew()) { + $entity->set('fileStatus', 'new'); + } else { + $oldMd5 = $entity->getFetched('md5sum'); + $oldSha256 = $entity->getFetched('sha256'); + + if ($oldMd5 !== $newMd5 || $oldSha256 !== $newSha256) { + $entity->set('fileStatus', 'changed'); + } else { + $entity->set('fileStatus', 'unchanged'); + } + } + } +} \ No newline at end of file diff --git a/custom/Espo/Custom/Resources/i18n/de_DE/CDokumente.json b/custom/Espo/Custom/Resources/i18n/de_DE/CDokumente.json index a77162a7..59a050c4 100644 --- a/custom/Espo/Custom/Resources/i18n/de_DE/CDokumente.json +++ b/custom/Espo/Custom/Resources/i18n/de_DE/CDokumente.json @@ -11,6 +11,7 @@ "xaiId": "x.AI ID", "xaiCollections": "x.AI Collections", "xaiSyncStatus": "Sync-Status", + "fileStatus": "Datei-Status", "contactsvmhdokumente": "Freigegebene Nutzer", "vmhMietverhltnisesDokumente": "Mietverhältnisse", "vmhErstgespraechsdokumente": "Erstgespräche", @@ -41,7 +42,8 @@ "syncStatus": "Status der Synchronisation: pending_sync = Warte auf Sync, clean = erfolgreich, unclean = Abweichungen, failed = Fehler", "xaiId": "Eindeutige ID für x.AI Synchronisation", "xaiCollections": "Liste der x.AI Collections für dieses Dokument", - "xaiSyncStatus": "Status der x.AI Synchronisation: pending_sync = Warte auf Sync, clean = erfolgreich, unclean = Abweichungen, failed = Fehler" + "xaiSyncStatus": "Status der x.AI Synchronisation: pending_sync = Warte auf Sync, clean = erfolgreich, unclean = Abweichungen, failed = Fehler", + "fileStatus": "Status der Datei: new = neu hochgeladen, changed = geändert, unchanged = unverändert" }, "options": { "syncStatus": { @@ -55,6 +57,11 @@ "clean": "Synchronisiert", "unclean": "Abweichungen", "failed": "Fehlgeschlagen" + }, + "fileStatus": { + "new": "Neu", + "changed": "Geändert", + "unchanged": "Unverändert" } } } \ No newline at end of file diff --git a/custom/Espo/Custom/Resources/i18n/en_US/CDokumente.json b/custom/Espo/Custom/Resources/i18n/en_US/CDokumente.json index 14869dbd..f978351f 100644 --- a/custom/Espo/Custom/Resources/i18n/en_US/CDokumente.json +++ b/custom/Espo/Custom/Resources/i18n/en_US/CDokumente.json @@ -19,7 +19,8 @@ "syncStatus": "Sync Status", "xaiId": "x.AI ID", "xaiCollections": "x.AI Collections", - "xaiSyncStatus": "Sync Status" + "xaiSyncStatus": "Sync Status", + "fileStatus": "File Status" }, "links": { "contactsvmhdokumente": "Portal Users", @@ -44,7 +45,8 @@ "syncStatus": "Synchronization status: pending_sync = Waiting for sync, clean = successful, unclean = discrepancies, failed = error", "xaiId": "Unique ID for x.AI synchronization", "xaiCollections": "List of x.AI collections for this document", - "xaiSyncStatus": "x.AI synchronization status: pending_sync = Waiting for sync, clean = successful, unclean = discrepancies, failed = error" + "xaiSyncStatus": "x.AI synchronization status: pending_sync = Waiting for sync, clean = successful, unclean = discrepancies, failed = error", + "fileStatus": "File status: new = newly uploaded, changed = modified, unchanged = unchanged" }, "options": { "syncStatus": { @@ -58,6 +60,11 @@ "clean": "Synchronized", "unclean": "Discrepancies", "failed": "Failed" + }, + "fileStatus": { + "new": "New", + "changed": "Changed", + "unchanged": "Unchanged" } } } \ No newline at end of file diff --git a/custom/Espo/Custom/Resources/layouts/CDokumente/detail.json b/custom/Espo/Custom/Resources/layouts/CDokumente/detail.json index 5da41172..21f01b04 100644 --- a/custom/Espo/Custom/Resources/layouts/CDokumente/detail.json +++ b/custom/Espo/Custom/Resources/layouts/CDokumente/detail.json @@ -63,6 +63,11 @@ { "name": "sha256" } + ], + [ + { + "name": "fileStatus" + } ] ], "dynamicLogicVisible": null, diff --git a/custom/Espo/Custom/Resources/metadata/entityDefs/CDokumente.json b/custom/Espo/Custom/Resources/metadata/entityDefs/CDokumente.json index 11d77c76..63f483ed 100644 --- a/custom/Espo/Custom/Resources/metadata/entityDefs/CDokumente.json +++ b/custom/Espo/Custom/Resources/metadata/entityDefs/CDokumente.json @@ -138,6 +138,24 @@ "default": "pending_sync", "tooltip": true, "isCustom": true + }, + "fileStatus": { + "type": "enum", + "required": false, + "options": [ + "new", + "changed", + "unchanged" + ], + "style": { + "new": "info", + "changed": "warning", + "unchanged": "success" + }, + "default": "new", + "readOnly": true, + "tooltip": true, + "isCustom": true } }, "links": { diff --git a/data/config.php b/data/config.php index b2e128c3..e0844506 100644 --- a/data/config.php +++ b/data/config.php @@ -358,7 +358,7 @@ return [ 0 => 'youtube.com', 1 => 'google.com' ], - 'microtime' => 1772471137.489776, + 'microtime' => 1772522154.570041, 'siteUrl' => 'https://crm.bitbylaw.com', 'fullTextSearchMinLength' => 4, 'webSocketUrl' => 'ws://api.bitbylaw.com:5000/espocrm/ws', diff --git a/data/state.php b/data/state.php index 044be63d..e9e5750e 100644 --- a/data/state.php +++ b/data/state.php @@ -1,7 +1,7 @@ 1772471137, - 'microtimeState' => 1772471137.62098, + 'cacheTimestamp' => 1772522193, + 'microtimeState' => 1772522193.960869, 'currencyRates' => [ 'EUR' => 1.0 ],