Skip to content

Commit

Permalink
Merge pull request #94 from ConductionNL/feature/axcvdwof-36/chained-…
Browse files Browse the repository at this point in the history
…sync

Follow up synchronizations
  • Loading branch information
rjzondervan authored Nov 26, 2024
2 parents a81b3e9 + aceb6f4 commit f54aee9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/Db/Synchronization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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,
];
}
}
10 changes: 9 additions & 1 deletion lib/Migration/Version1Date20241126074122.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f54aee9

Please sign in to comment.