|
56 | 56 | use Utopia\Migration\Resources\Functions\EnvVar; |
57 | 57 | use Utopia\Migration\Resources\Functions\Func; |
58 | 58 | use Utopia\Migration\Resources\Integrations\ApiKey; |
| 59 | +use Utopia\Migration\Resources\Integrations\ProjectVariable; |
59 | 60 | use Utopia\Migration\Resources\Integrations\Platform; |
60 | 61 | use Utopia\Migration\Resources\Messaging\Message; |
61 | 62 | use Utopia\Migration\Resources\Messaging\Provider; |
@@ -209,6 +210,7 @@ public static function getSupportedResources(): array |
209 | 210 | // Integrations |
210 | 211 | Resource::TYPE_PLATFORM, |
211 | 212 | Resource::TYPE_API_KEY, |
| 213 | + Resource::TYPE_PROJECT_VARIABLE, |
212 | 214 |
|
213 | 215 | // Backups |
214 | 216 | Resource::TYPE_BACKUP_POLICY, |
@@ -2254,6 +2256,19 @@ private function reportIntegrations(array $resources, array &$report, array $res |
2254 | 2256 | $report[Resource::TYPE_API_KEY] = 0; |
2255 | 2257 | } |
2256 | 2258 | } |
| 2259 | + |
| 2260 | + if (\in_array(Resource::TYPE_PROJECT_VARIABLE, $resources)) { |
| 2261 | + $variableQueries = $this->buildQueries( |
| 2262 | + resourceType: Resource::TYPE_PROJECT_VARIABLE, |
| 2263 | + resourceIds: $resourceIds, |
| 2264 | + limit: 1 |
| 2265 | + ); |
| 2266 | + try { |
| 2267 | + $report[Resource::TYPE_PROJECT_VARIABLE] = $this->project->listVariables($variableQueries)->total; |
| 2268 | + } catch (\Throwable) { |
| 2269 | + $report[Resource::TYPE_PROJECT_VARIABLE] = 0; |
| 2270 | + } |
| 2271 | + } |
2257 | 2272 | } |
2258 | 2273 |
|
2259 | 2274 | /** |
@@ -2313,6 +2328,20 @@ protected function exportGroupIntegrations(int $batchSize, array $resources): vo |
2313 | 2328 | )); |
2314 | 2329 | } |
2315 | 2330 | } |
| 2331 | + |
| 2332 | + if (\in_array(Resource::TYPE_PROJECT_VARIABLE, $resources)) { |
| 2333 | + try { |
| 2334 | + $this->exportProjectVariables($batchSize); |
| 2335 | + } catch (\Throwable $e) { |
| 2336 | + $this->addError(new Exception( |
| 2337 | + Resource::TYPE_PROJECT_VARIABLE, |
| 2338 | + Transfer::GROUP_INTEGRATIONS, |
| 2339 | + message: $e->getMessage(), |
| 2340 | + code: $e->getCode(), |
| 2341 | + previous: $e |
| 2342 | + )); |
| 2343 | + } |
| 2344 | + } |
2316 | 2345 | } |
2317 | 2346 |
|
2318 | 2347 | /** |
@@ -2445,6 +2474,53 @@ private function exportApiKeys(int $batchSize): void |
2445 | 2474 | } |
2446 | 2475 | } |
2447 | 2476 |
|
| 2477 | + /** |
| 2478 | + * @throws AppwriteException |
| 2479 | + */ |
| 2480 | + private function exportProjectVariables(int $batchSize): void |
| 2481 | + { |
| 2482 | + $lastId = null; |
| 2483 | + |
| 2484 | + while (true) { |
| 2485 | + $queries = [Query::limit($batchSize)]; |
| 2486 | + |
| 2487 | + if ($this->rootResourceId !== '' && $this->rootResourceType === Resource::TYPE_PROJECT_VARIABLE) { |
| 2488 | + $queries[] = Query::equal('$id', $this->rootResourceId); |
| 2489 | + $queries[] = Query::limit(1); |
| 2490 | + } |
| 2491 | + |
| 2492 | + if ($lastId !== null) { |
| 2493 | + $queries[] = Query::cursorAfter($lastId); |
| 2494 | + } |
| 2495 | + |
| 2496 | + $response = $this->project->listVariables($queries); |
| 2497 | + if ($response->total === 0) { |
| 2498 | + break; |
| 2499 | + } |
| 2500 | + |
| 2501 | + $variables = []; |
| 2502 | + |
| 2503 | + foreach ($response->variables as $variable) { |
| 2504 | + $variables[] = new ProjectVariable( |
| 2505 | + $variable->id, |
| 2506 | + $variable->key, |
| 2507 | + $variable->value, |
| 2508 | + $variable->secret, |
| 2509 | + createdAt: $variable->createdAt, |
| 2510 | + updatedAt: $variable->updatedAt, |
| 2511 | + ); |
| 2512 | + |
| 2513 | + $lastId = $variable->id; |
| 2514 | + } |
| 2515 | + |
| 2516 | + $this->callback($variables); |
| 2517 | + |
| 2518 | + if (\count($response->variables) < $batchSize) { |
| 2519 | + break; |
| 2520 | + } |
| 2521 | + } |
| 2522 | + } |
| 2523 | + |
2448 | 2524 | /** |
2449 | 2525 | * eg.,documents/attributes |
2450 | 2526 | * @param string $databaseType |
|
0 commit comments