Skip to content

Conversation

@fulldecent
Copy link

No description provided.

Copilot AI review requested due to automatic review settings December 23, 2025 18:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the sync script to use pagination when fetching data from the Kimai API, replacing the previous approach of requesting all records in a single API call with size=PHP_INT_MAX.

Key changes:

  • Introduces a pagination loop that fetches data in pages of 500 records
  • Removes the hardcoded size=PHP_INT_MAX parameter from the timesheets endpoint
  • Accumulates results across multiple API calls before processing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if ($results === false) {
$io->error(sprintf('Failed to sync data for endpoint: %s', $settings['endpoint']));
break;
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When an API error occurs mid-pagination, the function breaks out of the loop and continues processing with partial data from previous pages. This could lead to incomplete or inconsistent data in the database. Consider returning early or throwing an exception instead of breaking, to prevent processing partial results.

Suggested change
break;
return;

Copilot uses AI. Check for mistakes.
$page = 1;
while (true) {
$separator = (strpos($settings['endpoint'], '?') === false) ? '?' : '&';
$url = sprintf('%s%spage=%s&size=500', $settings['endpoint'], $separator, $page);
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The page size is hardcoded to 500. Consider making this configurable through a constant or configuration parameter to allow flexibility for different environments or API rate limits.

Copilot uses AI. Check for mistakes.
while (true) {
$separator = (strpos($settings['endpoint'], '?') === false) ? '?' : '&';
$url = sprintf('%s%spage=%s&size=500', $settings['endpoint'], $separator, $page);
$results = $doGet($client, $url);
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $doGet function doesn't handle Guzzle HTTP exceptions. If an HTTP error (like 500, 401, 403) or network error occurs during pagination, it will cause an uncaught exception that crashes the entire sync process. This is particularly problematic in a pagination loop where partial data may have already been collected. Consider wrapping the API call in a try-catch block to handle errors gracefully, similar to how it's done at line 312 for the teams sync.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant