diff --git a/lib/Db/Synchronization.php b/lib/Db/Synchronization.php index d3316c35..208bef2c 100644 --- a/lib/Db/Synchronization.php +++ b/lib/Db/Synchronization.php @@ -35,6 +35,7 @@ class Synchronization extends Entity implements JsonSerializable protected ?DateTime $updated = null; // The date and time the synchronization was updated protected array $conditions = []; + protected array $followUps = []; public function __construct() { @@ -61,6 +62,7 @@ public function __construct() { $this->addType('created', 'datetime'); $this->addType('updated', 'datetime'); $this->addType(fieldName:'conditions', type: 'json'); + $this->addType(fieldName:'followUps', type: 'json'); } public function getJsonFields(): array @@ -120,6 +122,7 @@ public function jsonSerialize(): array 'created' => isset($this->created) === true ? $this->created->format('c') : null, 'updated' => isset($this->updated) === true ? $this->updated->format('c') : null, 'conditions' => $this->conditions, + 'followUps' => $this->followUps, ]; } } diff --git a/lib/Migration/Version1Date20241126074122.php b/lib/Migration/Version1Date20241126074122.php index 8649927e..71edeb90 100644 --- a/lib/Migration/Version1Date20241126074122.php +++ b/lib/Migration/Version1Date20241126074122.php @@ -17,7 +17,9 @@ use OCP\Migration\SimpleMigrationStep; /** - * FIXME Auto-generated migration step: Please modify to your needs! + * Adds two columns to the Synchronizations table: + * - conditions for json logic + * - follow_ups for follow up synchronizations */ class Version1Date20241126074122 extends SimpleMigrationStep { @@ -47,6 +49,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt ->setDefault(default: '{}') ->setNotnull(notnull:false); } + if ($table->hasColumn(name: 'follow_ups') === false) { + + $table->addColumn(name: 'follow_ups', typeName: Types::JSON) + ->setDefault(default: '{}') + ->setNotnull(notnull:false); + } } return $schema; diff --git a/lib/Service/SynchronizationService.php b/lib/Service/SynchronizationService.php index 9fb83124..bddba5f9 100644 --- a/lib/Service/SynchronizationService.php +++ b/lib/Service/SynchronizationService.php @@ -104,7 +104,6 @@ public function synchronize(Synchronization $synchronization, ?bool $isTest = fa $synchronizationContract = $this->synchronizationContractMapper->createFromArray([ 'synchronizationId' => $synchronization->getId(), 'originId' => $originId, - 'originHash' => md5(serialize($object)) ]); } else { $synchronizationContract = new SynchronizationContract(); @@ -136,6 +135,11 @@ public function synchronize(Synchronization $synchronization, ?bool $isTest = fa $this->synchronizationContractMapper->update($synchronizationContract); } + foreach ($synchronization->getFollowUps() as $followUp) { + $followUpSynchronization = $this->synchronizationMapper->find($followUp); + $this->synchronize($followUpSynchronization, $isTest); + } + return $objectList; } @@ -246,7 +250,7 @@ public function synchronizeContract(SynchronizationContract $synchronizationCont // Let's prevent pointless updates @todo account for omnidirectional sync, unless the config has been updated since last check then we do want to rebuild and check if the tagert object has changed if ($originHash === $synchronizationContract->getOriginHash() && $synchronization->getUpdated() < $synchronizationContract->getSourceLastChecked()) { // The object has not changed and the config has not been updated since last check - return $synchronizationContract; + return $synchronizationContract; } // The object has changed, oke let do mappig and bla die bla