|
89 | 89 | $localColumns = []; // column names on local side to prepare SQL statements |
90 | 90 |
|
91 | 91 | // fetch the API result |
92 | | - $results = $doGet($client, $settings['endpoint']); |
93 | | - if ($results === false) { |
94 | | - $io->error(sprintf('Failed to sync data for endpoint: %s', $settings['endpoint'])); |
95 | | - } |
| 92 | + $page = 1; |
| 93 | + while (true) { |
| 94 | + $separator = (strpos($settings['endpoint'], '?') === false) ? '?' : '&'; |
| 95 | + $url = sprintf('%s%spage=%s&size=500', $settings['endpoint'], $separator, $page); |
| 96 | + $results = $doGet($client, $url); |
| 97 | + |
| 98 | + if ($results === false) { |
| 99 | + $io->error(sprintf('Failed to sync data for endpoint: %s', $settings['endpoint'])); |
| 100 | + break; |
| 101 | + } |
96 | 102 |
|
97 | | - // prepare the array of all entities for the local database by mapping columns |
98 | | - foreach ($results as $entity) { |
99 | | - $newEntity = []; |
100 | | - foreach ($settings['mapping'] as $kimaiField => $localField) { |
101 | | - $key = $localField; |
102 | | - $value = $entity[$kimaiField]; |
103 | | - // some values need to be converted to local format (eg. datetime) |
104 | | - if (is_callable($localField)) { |
105 | | - $tmp = call_user_func($localField, $entity, $kimaiField); |
106 | | - $key = $tmp[0]; |
107 | | - $value = $tmp[1]; |
108 | | - } |
109 | | - $newEntity[$key] = $value; |
| 103 | + if (empty($results)) { |
| 104 | + break; |
110 | 105 | } |
111 | | - if (count($localColumns) === 0) { |
112 | | - $localColumns = array_keys($newEntity); |
| 106 | + |
| 107 | + // prepare the array of all entities for the local database by mapping columns |
| 108 | + foreach ($results as $entity) { |
| 109 | + $newEntity = []; |
| 110 | + foreach ($settings['mapping'] as $kimaiField => $localField) { |
| 111 | + $key = $localField; |
| 112 | + $value = $entity[$kimaiField]; |
| 113 | + // some values need to be converted to local format (eg. datetime) |
| 114 | + if (is_callable($localField)) { |
| 115 | + $tmp = call_user_func($localField, $entity, $kimaiField); |
| 116 | + $key = $tmp[0]; |
| 117 | + $value = $tmp[1]; |
| 118 | + } |
| 119 | + $newEntity[$key] = $value; |
| 120 | + } |
| 121 | + if (count($localColumns) === 0) { |
| 122 | + $localColumns = array_keys($newEntity); |
| 123 | + } |
| 124 | + $apiEntities[$entity['id']] = $newEntity; |
113 | 125 | } |
114 | | - $apiEntities[$entity['id']] = $newEntity; |
115 | | - } |
116 | 126 |
|
117 | | - unset($results); |
| 127 | + $page++; |
| 128 | + unset($results); |
| 129 | + } |
118 | 130 |
|
119 | 131 | if (count($apiEntities) === 0) { |
120 | 132 | $io->success('No data found to sync: ' . $title); |
|
238 | 250 |
|
239 | 251 | $syncConfig['Timesheets'] = [ |
240 | 252 | 'table' => 'timesheet', |
241 | | - 'endpoint' => 'timesheets?user=all&modified_after=' . $since->format('Y-m-d\TH:i:s') . '&size=' . PHP_INT_MAX, |
| 253 | + 'endpoint' => 'timesheets?user=all&modified_after=' . $since->format('Y-m-d\TH:i:s'), |
242 | 254 | 'mapping' => [ |
243 | 255 | 'id' => 'kimai_id', |
244 | 256 | 'activity' => 'activity', |
|
0 commit comments