Add sync status and last sync fields to CAIKnowledge and CAdvowareAkten entities, update layouts and metadata. Implement hooks for global sync status management.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Espo\Custom\Hooks\CAIKnowledge;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\Hook\Hook\AfterRelate;
|
||||
|
||||
/**
|
||||
* Hook: Setzt Dokument-Sync-Status auf "new" beim Verknüpfen und
|
||||
* globalen syncStatus auf "unclean"
|
||||
*/
|
||||
class DokumenteSyncStatus implements AfterRelate
|
||||
{
|
||||
public function __construct(
|
||||
private \Espo\ORM\EntityManager $entityManager
|
||||
) {}
|
||||
|
||||
public function afterRelate(
|
||||
Entity $entity,
|
||||
string $relationName,
|
||||
Entity $foreignEntity,
|
||||
array $columnData,
|
||||
\Espo\ORM\Repository\Option\RelateOptions $options
|
||||
): void {
|
||||
// Nur für dokumentes-Beziehung
|
||||
if ($relationName !== 'dokumentes') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Setze Sync-Status des Dokuments in der Junction-Tabelle auf "new"
|
||||
$repository = $this->entityManager->getRDBRepository('CAIKnowledge');
|
||||
|
||||
try {
|
||||
$repository->getRelation($entity, 'dokumentes')->updateColumns(
|
||||
$foreignEntity,
|
||||
['syncstatus' => 'new']
|
||||
);
|
||||
|
||||
// Setze globalen syncStatus auf "unclean"
|
||||
$entity->set('syncStatus', 'unclean');
|
||||
$this->entityManager->saveEntity($entity, ['silent' => true, 'skipHooks' => true]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Fehler loggen, aber nicht werfen (um Verknüpfung nicht zu blockieren)
|
||||
$GLOBALS['log']->error('CAIKnowledge DokumenteSyncStatus Hook Error: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user