From 71e938eb31c0ca32d03c1954450b328e28b72e45 Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Tue, 10 Dec 2024 16:29:13 +0100 Subject: [PATCH] Fix migrations & docblocks --- lib/Migration/Version1Date20241121160300.php | 11 ----------- lib/Migration/Version1Date20241210120155.php | 16 +++++++++++++++- lib/Service/SynchronizationService.php | 18 +++++++++++++++++- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/Migration/Version1Date20241121160300.php b/lib/Migration/Version1Date20241121160300.php index 66ae4e42..8ea60305 100644 --- a/lib/Migration/Version1Date20241121160300.php +++ b/lib/Migration/Version1Date20241121160300.php @@ -19,7 +19,6 @@ /** * This migration changes the following: * - Adding 4 new columns for the table Source: rateLimitLimit, rateLimitRemaining, rateLimitReset & rateLimitWindow - * - Adding 1 new column for the table Synchronization: CurrentPage */ class Version1Date20241121160300 extends SimpleMigrationStep { @@ -73,16 +72,6 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt ]); } - // Synchronizations table - $table = $schema->getTable('openconnector_synchronizations'); - - if ($table->hasColumn('current_page') === false) { - $table->addColumn('current_page', Types::INTEGER, [ - 'notnull' => false, - 'default' => 1 - ]); - } - return $schema; } diff --git a/lib/Migration/Version1Date20241210120155.php b/lib/Migration/Version1Date20241210120155.php index bca70ed1..f4beb3be 100644 --- a/lib/Migration/Version1Date20241210120155.php +++ b/lib/Migration/Version1Date20241210120155.php @@ -17,7 +17,8 @@ /** * This migration changes the following: - * - Add 1 new column for the table SynchronizationContractLogs: message + * - Adding 1 new column for the table Synchronization: currentPage + * - Adding 1 new column for the table SynchronizationContractLogs: message */ class Version1Date20241210120155 extends SimpleMigrationStep { @@ -41,6 +42,19 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt */ $schema = $schemaClosure(); + // Synchronizations table + if ($schema->hasTable('openconnector_synchronizations') === true) { + $table = $schema->getTable('openconnector_synchronizations'); + + if ($table->hasColumn('current_page') === false) { + $table->addColumn('current_page', Types::INTEGER, [ + 'notnull' => false, + 'default' => 1 + ]); + } + } + + // SynchronizationContractLogs table if ($schema->hasTable('openconnector_synchronization_contract_logs') === true) { $table = $schema->getTable('openconnector_synchronization_contract_logs'); diff --git a/lib/Service/SynchronizationService.php b/lib/Service/SynchronizationService.php index 64b59342..6e67abd3 100644 --- a/lib/Service/SynchronizationService.php +++ b/lib/Service/SynchronizationService.php @@ -681,7 +681,23 @@ public function getAllObjectsFromApi(Synchronization $synchronization, ?bool $is return $objects; } - private function getRateLimitHeaders($source): array + /** + * Retrieves rate limit information from a given source and formats it as HTTP headers. + * + * This function extracts rate limit details from the provided source object and returns them + * as an associative array of headers. The headers can be used for communicating rate limit status + * in API responses or logging purposes. + * + * @param Source $source The source object containing rate limit details, such as limits, remaining requests, and reset times. + * + * @return array An associative array of rate limit headers: + * - 'X-RateLimit-Limit' (int|null): The maximum number of allowed requests. + * - 'X-RateLimit-Remaining' (int|null): The number of requests remaining in the current window. + * - 'X-RateLimit-Reset' (int|null): The Unix timestamp when the rate limit resets. + * - 'X-RateLimit-Used' (int|null): The number of requests used so far. + * - 'X-RateLimit-Window' (int|null): The duration of the rate limit window in seconds. + */ + private function getRateLimitHeaders(Source $source): array { return [ 'X-RateLimit-Limit' => $source->getRateLimitLimit(),