Refactor CAdvowareAkten and CDokumente hooks; update localization and metadata; adjust microtime values in config and state files

This commit is contained in:
2026-03-25 22:01:58 +01:00
parent 7d55075490
commit 4a302542b7
14 changed files with 99 additions and 124 deletions

View File

@@ -3,10 +3,21 @@
namespace Espo\Custom\Hooks\CDokumente;
use Espo\ORM\Entity;
use Espo\ORM\Repository\Option\SaveOptions;
use Espo\Core\Hook\Hook\BeforeSave;
class CDokumente extends \Espo\Core\Hooks\Base
/**
* Hook: Berechnet Dokumenten-Hashes und setzt fileStatus
*
* Verwendet Blake3 als Hash-Algorithmus für optimale Performance
*/
class CDokumente implements BeforeSave
{
public function beforeSave(Entity $entity, array $options = [])
public function __construct(
private \Espo\ORM\EntityManager $entityManager
) {}
public function beforeSave(Entity $entity, SaveOptions $options): void
{
// Problem: isAttributeChanged('dokument') erkennt Datei-Änderungen nicht,
// da EspoCRM Datei-Uploads nicht als Feld-Änderung markiert.
@@ -14,23 +25,20 @@ class CDokumente extends \Espo\Core\Hooks\Base
// um sicherzustellen, dass Hashes bei Datei-Änderungen berechnet werden.
// Optimierung wäre wünschenswert, aber nicht möglich mit aktueller API.
$dokument = $entity->get('dokument');
$dokumentId = $entity->get('dokumentId');
if (!$dokument) {
if (!$dokumentId) {
return;
}
if (is_object($dokument)) {
$attachment = $dokument;
} else {
$attachment = $this->getEntityManager()->getEntity('Attachment', $dokument);
}
// Verwende EntityManager zur korrekten Relation-Verwaltung
$attachment = $this->entityManager->getEntityById('Attachment', $dokumentId);
if (!$attachment) {
return;
}
$filePath = 'data/upload/' . $attachment->get('id');
$filePath = 'data/upload/' . $attachment->getId();
if (!file_exists($filePath)) {
return;
}
@@ -41,7 +49,8 @@ class CDokumente extends \Espo\Core\Hooks\Base
return;
}
$newBlake3 = \blake3($fileContent);
// Blake3 Hashing - schneller als SHA3 und kryptographisch sicher
$newBlake3 = blake3($fileContent);
// Setze Hash
$entity->set('blake3hash', $newBlake3);