From a982190fa4ed1bae0d4ae19fb5c9f206d42cd48e Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Tue, 26 Nov 2024 14:23:58 +0100 Subject: [PATCH 1/5] Add an array for follow-up synchronizations --- lib/Db/Synchronization.php | 3 +++ lib/Migration/Version1Date20241126074122.php | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/Db/Synchronization.php b/lib/Db/Synchronization.php index d3316c3..208bef2 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 8649927..76a3586 100644 --- a/lib/Migration/Version1Date20241126074122.php +++ b/lib/Migration/Version1Date20241126074122.php @@ -47,6 +47,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; From 3e2c830f716e880d17625bf032ff7ebe7e2da6dc Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Tue, 26 Nov 2024 14:24:24 +0100 Subject: [PATCH 2/5] Run follow up synchronizations after sync --- lib/Service/SynchronizationService.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Service/SynchronizationService.php b/lib/Service/SynchronizationService.php index 9fb8312..c618bc3 100644 --- a/lib/Service/SynchronizationService.php +++ b/lib/Service/SynchronizationService.php @@ -91,6 +91,8 @@ public function synchronize(Synchronization $synchronization, ?bool $isTest = fa $objectList = $this->getAllObjectsFromSource(synchronization: $synchronization, isTest: $isTest); +// var_dump(count($objectList)); + foreach ($objectList as $key => $object) { // If the source configuration contains a dot notation for the id position, we need to extract the id from the source object $originId = $this->getOriginId($synchronization, $object); @@ -104,7 +106,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 +137,12 @@ public function synchronize(Synchronization $synchronization, ?bool $isTest = fa $this->synchronizationContractMapper->update($synchronizationContract); } + foreach($synchronization->getFollowUps() as $followUp) { + var_dump($followUp); + $followUpSynchronization = $this->synchronizationMapper->find($followUp); + $this->synchronize($followUpSynchronization, $isTest); + } + return $objectList; } @@ -246,7 +253,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 From d37d6d9bbb6344fc1c171e16d1d18f131b217249 Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Tue, 26 Nov 2024 14:37:01 +0100 Subject: [PATCH 3/5] remove debug var_dump --- lib/Service/SynchronizationService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Service/SynchronizationService.php b/lib/Service/SynchronizationService.php index c618bc3..d463808 100644 --- a/lib/Service/SynchronizationService.php +++ b/lib/Service/SynchronizationService.php @@ -138,7 +138,6 @@ public function synchronize(Synchronization $synchronization, ?bool $isTest = fa } foreach($synchronization->getFollowUps() as $followUp) { - var_dump($followUp); $followUpSynchronization = $this->synchronizationMapper->find($followUp); $this->synchronize($followUpSynchronization, $isTest); } From f134125321e82cf34798b9ccdea6cf13f3abd2e7 Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Tue, 26 Nov 2024 14:49:21 +0100 Subject: [PATCH 4/5] Fix PR comments --- lib/Service/SynchronizationService.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Service/SynchronizationService.php b/lib/Service/SynchronizationService.php index d463808..bddba5f 100644 --- a/lib/Service/SynchronizationService.php +++ b/lib/Service/SynchronizationService.php @@ -91,8 +91,6 @@ public function synchronize(Synchronization $synchronization, ?bool $isTest = fa $objectList = $this->getAllObjectsFromSource(synchronization: $synchronization, isTest: $isTest); -// var_dump(count($objectList)); - foreach ($objectList as $key => $object) { // If the source configuration contains a dot notation for the id position, we need to extract the id from the source object $originId = $this->getOriginId($synchronization, $object); @@ -137,7 +135,7 @@ public function synchronize(Synchronization $synchronization, ?bool $isTest = fa $this->synchronizationContractMapper->update($synchronizationContract); } - foreach($synchronization->getFollowUps() as $followUp) { + foreach ($synchronization->getFollowUps() as $followUp) { $followUpSynchronization = $this->synchronizationMapper->find($followUp); $this->synchronize($followUpSynchronization, $isTest); } From aceb6f4d09798516f86274bce5c802ddb7e43edc Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Tue, 26 Nov 2024 15:03:21 +0100 Subject: [PATCH 5/5] Add description to migration --- lib/Migration/Version1Date20241126074122.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Migration/Version1Date20241126074122.php b/lib/Migration/Version1Date20241126074122.php index 76a3586..71edeb9 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 {