-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Revert backups endpoints #10958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert backups endpoints #10958
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,8 +52,6 @@ class Migrations extends Action | |
|
|
||
| protected array $plan; | ||
|
|
||
| protected array $platform; | ||
|
|
||
| /** | ||
| * @var array<string, int> | ||
| */ | ||
|
|
@@ -108,7 +106,6 @@ public function action( | |
| $this->deviceForMigrations = $deviceForMigrations; | ||
| $this->deviceForFiles = $deviceForFiles; | ||
| $this->plan = $plan; | ||
| $this->platform = $payload['platform'] ?? []; | ||
|
|
||
| if (empty($payload)) { | ||
| throw new Exception('Missing payload'); | ||
|
|
@@ -144,10 +141,15 @@ protected function processSource(Document $migration): Source | |
| $credentials = $migration->getAttribute('credentials'); | ||
| $migrationOptions = $migration->getAttribute('options'); | ||
| $dataSource = Appwrite::SOURCE_API; | ||
| $endpoint = $this->platform['endpoint'] ?: ($credentials['endpoint'] ?? 'http://appwrite.test/v1'); | ||
| $database = null; | ||
| $queries = []; | ||
|
|
||
| if ($credentials['endpoint'] === 'http://localhost/v1') { | ||
| $platform = Config::getParam('platform', []); | ||
| $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; | ||
| $credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1'; | ||
| } | ||
|
|
||
| if ($source === Appwrite::getName() && $destination === DestinationCSV::getName()) { | ||
| $dataSource = Appwrite::SOURCE_DATABASE; | ||
| $database = $this->dbForProject; | ||
|
|
@@ -178,7 +180,7 @@ protected function processSource(Document $migration): Source | |
| ), | ||
| SourceAppwrite::getName() => new SourceAppwrite( | ||
| $credentials['projectId'], | ||
| $endpoint, | ||
| $credentials['endpoint'], | ||
| $credentials['apiKey'], | ||
| $dataSource, | ||
| $database, | ||
|
|
@@ -206,10 +208,13 @@ protected function processDestination(Document $migration, string $apiKey): Dest | |
| $destination = $migration->getAttribute('destination'); | ||
| $options = $migration->getAttribute('options', []); | ||
|
|
||
| $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; | ||
| $platform = Config::getParam('platform', []); | ||
|
|
||
| return match ($destination) { | ||
| DestinationAppwrite::getName() => new DestinationAppwrite( | ||
| $this->project->getId(), | ||
| $this->platform['endpoint'], | ||
| $protocol . '://' . $platform['apiHostname'] . '/v1', | ||
| $apiKey, | ||
| $this->dbForProject, | ||
| Config::getParam('collections', [])['databases']['collections'], | ||
|
|
@@ -306,15 +311,22 @@ protected function processMigration( | |
|
|
||
| $transfer = $source = $destination = null; | ||
|
|
||
|
|
||
|
|
||
| try { | ||
| if ( | ||
| $migration->getAttribute('source') === SourceAppwrite::getName() && | ||
| empty($migration->getAttribute('credentials', [])) | ||
| ) { | ||
| $credentials = $migration->getAttribute('credentials', []); | ||
| $credentials['projectId'] = $credentials['projectId'] ?? $project->getId(); | ||
| $credentials['endpoint'] = $credentials['endpoint'] ?? $this->platform['endpoint']; | ||
| $credentials['apiKey'] = $credentials['apiKey'] ?? $tempAPIKey; | ||
|
|
||
| if (empty($credentials['endpoint'])) { | ||
| $platform = Config::getParam('platform', []); | ||
| $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; | ||
| $credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1'; | ||
| } | ||
|
Comment on lines
+324
to
+329
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent endpoint handling logic. This is the third instance of duplicated endpoint construction, but the conditional logic differs from After extracting the endpoint construction to a helper method (as suggested for lines 147-151), ensure consistent logic across both locations: if (empty($credentials['endpoint'])) {
- $platform = Config::getParam('platform', []);
- $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
- $credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1';
+ $credentials['endpoint'] = $this->buildEndpoint();
}Consider whether both the
🤖 Prompt for AI Agents |
||
| $migration->setAttribute('credentials', $credentials); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add validation for platform configuration and extract duplicated endpoint construction logic.
This endpoint construction logic is duplicated in three locations (lines 147-151, 211-217, and 325-329). Additionally,
$platform['apiHostname']is accessed without verifying the key exists, which could cause undefined array key errors if the platform configuration is malformed.Consider extracting this into a helper method:
Then use it consistently:
if ($credentials['endpoint'] === 'http://localhost/v1') { - $platform = Config::getParam('platform', []); - $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; - $credentials['endpoint'] = $protocol . '://' . $platform['apiHostname'] . '/v1'; + $credentials['endpoint'] = $this->buildEndpoint(); }🤖 Prompt for AI Agents