diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96b579c006..5c734df8e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,17 +1,19 @@ name: CI concurrency: - group: ci-${{ github.ref }} - cancel-in-progress: true + group: ci-${{ github.event_name == 'pull_request' && github.ref || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} env: COMPOSE_FILE: docker-compose.yml IMAGE: appwrite-dev - REGISTRY_IMAGE: ghcr.io/${{ github.repository }}/appwrite-dev K6_VERSION: '0.53.0' on: pull_request: + push: + branches: + - 1.9.x workflow_dispatch: inputs: response_format: @@ -89,111 +91,13 @@ jobs: sarif_file: 'trivy-fs-results.sarif' category: 'trivy-source' - composer: - name: Checks / Composer + checks: + name: Checks runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Setup PHP - uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 - with: - php-version: '8.3' - tools: composer:v2 - coverage: none - - - name: Validate - run: composer validate - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --ignore-platform-reqs - - - name: Audit - env: - COMPOSER_NO_AUDIT: 0 - run: composer audit - - format: - name: Checks / Format - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - with: - fetch-depth: 2 - - - run: git checkout HEAD^2 - if: github.event_name == 'pull_request' - - - name: Setup PHP - uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 - with: - php-version: '8.3' - tools: composer:v2 - coverage: none - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --ignore-platform-reqs - - - name: Run Linter - run: composer lint - - refactor: - name: Checks / Refactor - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - name: Setup PHP - uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 - with: - php-version: '8.3' - tools: composer:v2 - coverage: none - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --ignore-platform-reqs - - - name: Run Rector - run: composer refactor:check - - analyze: - name: Checks / Analyze - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - - name: Setup PHP - uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 - with: - php-version: '8.3' - tools: composer:v2 - coverage: none - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --ignore-platform-reqs - - - name: Cache PHPStan result cache - uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 - with: - path: .phpstan-cache - key: phpstan-${{ github.sha }} - restore-keys: | - phpstan- - - - name: Run PHPStan - run: composer analyze -- --no-progress - - specs: - name: Checks / Specs - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Setup PHP uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 with: @@ -202,10 +106,42 @@ jobs: tools: composer:v2 coverage: none + - name: Validate composer.json + run: composer validate + - name: Install dependencies + id: install run: composer install --prefer-dist --no-progress --ignore-platform-reqs + - name: Cache PHPStan result cache + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: .phpstan-cache + key: phpstan-${{ github.sha }} + restore-keys: | + phpstan- + + - name: Audit dependencies + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + env: + COMPOSER_NO_AUDIT: 0 + run: composer audit + + - name: Run Linter + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + run: composer lint + + - name: Run Rector + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + run: composer refactor:check + + - name: Run PHPStan + if: ${{ !cancelled() && steps.install.outcome == 'success' }} + run: composer analyze -- --no-progress + - name: Generate specs + if: ${{ !cancelled() && steps.install.outcome == 'success' }} run: _APP_STORAGE_LIMIT=5368709120 php app/cli.php specs --version=latest --git=no locale: @@ -236,36 +172,36 @@ jobs: uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | - const runner4 = `runs-on=${context.runId}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel`; - const runner8 = `runs-on=${context.runId}/runner=8cpu-linux-x64/volume=120g/spot=false/extras=otel`; + const runner4 = `runs-on=${context.runId}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache`; + const runner8 = `runs-on=${context.runId}/runner=8cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache`; const services = [ - { name: 'Account', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Avatars', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Console', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Databases', runner: runner8, functional: false, processes: 3, timeout: 30 }, - { name: 'TablesDB', runner: runner8, functional: false, processes: 3, timeout: 30 }, - { name: 'Functions', runner: runner4, functional: false, processes: null, timeout: 20 }, - { name: 'FunctionsSchedule', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'GraphQL', runner: runner4, functional: false, processes: null, timeout: 20 }, - { name: 'Health', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Advisor', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Locale', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Projects', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Realtime', runner: runner4, functional: false, processes: null, timeout: 20 }, - { name: 'Sites', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Proxy', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Storage', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Tokens', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Teams', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Users', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'ProjectWebhooks', runner: runner4, functional: false, processes: null, timeout: 20 }, - { name: 'Webhooks', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'VCS', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Messaging', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Migrations', runner: runner4, functional: true, processes: 1, timeout: 20 }, - { name: 'Project', runner: runner4, functional: true, processes: null, timeout: 20 }, - { name: 'Presences', runner: runner4, functional: true, processes: null, timeout: 20 }, + { name: 'Account', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Avatars', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Console', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Databases', runner: runner8, functional: false, processes: 3, timeout: 15 }, + { name: 'TablesDB', runner: runner8, functional: false, processes: 3, timeout: 15 }, + { name: 'Functions', runner: runner4, functional: false, processes: null, timeout: 15 }, + { name: 'FunctionsSchedule', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'GraphQL', runner: runner4, functional: false, processes: null, timeout: 15 }, + { name: 'Health', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Advisor', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Locale', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Projects', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Realtime', runner: runner4, functional: false, processes: null, timeout: 15 }, + { name: 'Sites', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Proxy', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Storage', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Tokens', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Teams', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Users', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'ProjectWebhooks', runner: runner4, functional: false, processes: null, timeout: 15 }, + { name: 'Webhooks', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'VCS', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Messaging', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Migrations', runner: runner4, functional: true, processes: 1, timeout: 15 }, + { name: 'Project', runner: runner4, functional: true, processes: null, timeout: 15 }, + { name: 'Presences', runner: runner4, functional: true, processes: null, timeout: 15 }, ]; core.setOutput('services', JSON.stringify(services)); @@ -300,7 +236,7 @@ jobs: build: name: Build - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+s3-cache+ecr-cache steps: - name: Checkout repository uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -313,13 +249,6 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Set up Docker Buildx uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 @@ -328,9 +257,9 @@ jobs: with: context: . push: true - tags: ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - cache-from: type=gha - cache-to: type=gha,mode=max + tags: ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + cache-from: type=s3,blobs_prefix=cache/${{ github.repository }}/,manifests_prefix=cache/${{ github.repository }}/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }} + cache-to: type=s3,blobs_prefix=cache/${{ github.repository }}/,manifests_prefix=cache/${{ github.repository }}/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }},mode=max target: development build-args: | DEBUG=false @@ -339,7 +268,7 @@ jobs: unit: name: Tests / Unit - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache needs: build permissions: contents: read @@ -355,17 +284,10 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Docker Image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} - name: Load and Start Appwrite timeout-minutes: 5 @@ -377,9 +299,10 @@ jobs: run: docker compose exec -T appwrite vars - name: Run Unit Tests - uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 + timeout-minutes: 15 + uses: itznotabug/php-retry@60547503cb2126eddaa082d0999e99cfca2b3856 # v4 with: - max_attempts: 2 + max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 timeout_minutes: 15 job_id: ${{ job.check_run_id }} @@ -392,7 +315,7 @@ jobs: e2e_general: name: Tests / E2E / General - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache needs: build permissions: contents: read @@ -408,17 +331,10 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Docker Image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} - name: Load and Start Appwrite timeout-minutes: 5 @@ -435,9 +351,10 @@ jobs: done - name: Run General Tests - uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 + timeout-minutes: 15 + uses: itznotabug/php-retry@60547503cb2126eddaa082d0999e99cfca2b3856 # v4 with: - max_attempts: 2 + max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 timeout_minutes: 15 job_id: ${{ job.check_run_id }} @@ -499,17 +416,10 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Docker Image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} - name: Load and Start Appwrite timeout-minutes: 5 @@ -531,9 +441,10 @@ jobs: done - name: Run tests - uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 + timeout-minutes: 15 + uses: itznotabug/php-retry@60547503cb2126eddaa082d0999e99cfca2b3856 # v4 with: - max_attempts: 2 + max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 timeout_minutes: ${{ matrix.service.timeout }} job_id: ${{ job.check_run_id }} @@ -566,7 +477,7 @@ jobs: e2e_abuse: name: Tests / E2E / Abuse (${{ matrix.mode }}) - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache needs: [build, matrix] permissions: contents: read @@ -588,17 +499,10 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Docker Image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} - name: Load and Start Appwrite timeout-minutes: 5 @@ -612,9 +516,10 @@ jobs: docker compose up -d --quiet-pull --wait - name: Run tests - uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 + timeout-minutes: 15 + uses: itznotabug/php-retry@60547503cb2126eddaa082d0999e99cfca2b3856 # v4 with: - max_attempts: 2 + max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 timeout_minutes: 15 job_id: ${{ job.check_run_id }} @@ -633,7 +538,7 @@ jobs: e2e_screenshots: name: Tests / E2E / Screenshots (${{ matrix.mode }}) - runs-on: ubuntu-latest + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache needs: [build, matrix] permissions: contents: read @@ -653,17 +558,10 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Docker Image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} - name: Load and Start Appwrite timeout-minutes: 5 @@ -684,9 +582,10 @@ jobs: done - name: Run tests - uses: itznotabug/php-retry@d6bef45a8bff490babfb613e33b00d133e4062f0 # v3 + timeout-minutes: 15 + uses: itznotabug/php-retry@60547503cb2126eddaa082d0999e99cfca2b3856 # v4 with: - max_attempts: 2 + max_attempts: ${{ github.event_name == 'pull_request' && 2 || 1 }} retry_wait_seconds: 60 timeout_minutes: 15 job_id: ${{ job.check_run_id }} @@ -705,8 +604,8 @@ jobs: benchmark: name: Benchmark - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest + if: github.event_name == 'pull_request' || github.event_name == 'push' + runs-on: runs-on=${{ github.run_id }}/runner=4cpu-linux-x64/volume=120g/spot=false/extras=otel+ecr-cache needs: build permissions: actions: read @@ -726,18 +625,11 @@ jobs: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GHCR - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Pull Appwrite image run: | - docker pull ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }} - docker tag ${{ env.REGISTRY_IMAGE }}:${{ github.sha }} ${{ env.IMAGE }}:after + docker pull ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }} + docker tag ${{ env.RUNS_ON_ECR_CACHE }}:${{ env.IMAGE }}-${{ github.sha }} ${{ env.IMAGE }}:after - name: Setup k6 uses: grafana/setup-k6-action@db07bd9765aac508ef18982e52ab937fe633a065 # v1.2.1 @@ -747,9 +639,11 @@ jobs: - name: Prepare benchmark before id: benchmark_before_prepare continue-on-error: true + env: + BENCHMARK_BEFORE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} run: | - git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }} - git worktree add --detach /tmp/appwrite-benchmark-before ${{ github.event.pull_request.base.sha }} + git fetch --depth=1 origin "${BENCHMARK_BEFORE_SHA}" + git worktree add --detach /tmp/appwrite-benchmark-before "${BENCHMARK_BEFORE_SHA}" docker build \ --cache-from ${{ env.IMAGE }}:after \ --target development \ @@ -871,8 +765,8 @@ jobs: if: always() uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: - BENCHMARK_BASE_REF: ${{ github.event.pull_request.base.ref }} - BENCHMARK_HEAD_REF: ${{ github.event.pull_request.head.ref }} + BENCHMARK_BASE_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.event.before }} + BENCHMARK_HEAD_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.sha }} with: script: | const comment = require('./.github/workflows/benchmark-comment.js'); diff --git a/AGENTS.md b/AGENTS.md index edaeff9ea5..2a73d6d90e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,6 +15,8 @@ Self-hosted Backend-as-a-Service platform. Hybrid monolithic-microservice archit | `composer lint ` | Check formatting of a file | | `composer analyze` | Static analysis (PHPStan level 3) | | `composer check` | Same as `analyze` | +| `composer refactor:check` | Rector dry-run over `tests/` (CI "Refactor" check) | +| `composer refactor` | Apply Rector fixes | ## Stack diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index a050e97b17..5ecae9c635 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -2405,6 +2405,7 @@ Http::post('/v1/account/tokens/magic-url') project: $project, recipient: $email, subject: $subject, + template: MAIL_TEMPLATE_MAGIC_URL, body: $body, preview: $preview, smtp: $smtpConfig, @@ -2751,6 +2752,7 @@ Http::post('/v1/account/tokens/email') project: $project, recipient: $email, subject: $subject, + template: MAIL_TEMPLATE_OTP, bodyTemplate: $bodyTemplate, body: $body, preview: $preview, @@ -3868,6 +3870,7 @@ Http::post('/v1/account/recovery') recipient: $profile->getAttribute('email', ''), name: $profile->getAttribute('name', ''), subject: $subject, + template: MAIL_TEMPLATE_RECOVERY, body: $body, preview: $preview, smtp: $smtpConfig, @@ -4222,6 +4225,7 @@ Http::post('/v1/account/verifications/email') recipient: $user->getAttribute('email'), name: $user->getAttribute('name') ?? '', subject: $subject, + template: MAIL_TEMPLATE_VERIFICATION, bodyTemplate: $bodyTemplate, body: $body, preview: $preview, diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 8ab30fac99..a39ce3c4bd 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -38,27 +38,31 @@ Http::patch('/v1/projects/:projectId/oauth2') ->inject('dbForPlatform') ->action(function (string $projectId, string $provider, ?string $appId, ?string $secret, ?bool $enabled, Response $response, Database $dbForPlatform) { - $project = $dbForPlatform->getDocument('projects', $projectId); + $project = $dbForPlatform->withTransaction(function () use ($dbForPlatform, $projectId, $provider, $appId, $secret, $enabled) { + $project = $dbForPlatform->getDocument('projects', $projectId, forUpdate: true); - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } - $providers = $project->getAttribute('oAuthProviders', []); + $providers = $project->getAttribute('oAuthProviders', []); - if ($appId !== null) { - $providers[$provider . 'Appid'] = $appId; - } + if ($appId !== null) { + $providers[$provider . 'Appid'] = $appId; + } - if ($secret !== null) { - $providers[$provider . 'Secret'] = $secret; - } + if ($secret !== null) { + $providers[$provider . 'Secret'] = $secret; + } - if ($enabled !== null) { - $providers[$provider . 'Enabled'] = $enabled; - } + if ($enabled !== null) { + $providers[$provider . 'Enabled'] = $enabled; + } - $project = $dbForPlatform->updateDocument('projects', $project->getId(), $project->setAttribute('oAuthProviders', $providers)); + return $dbForPlatform->updateDocument('projects', $project->getId(), new Document([ + 'oAuthProviders' => $providers, + ])); + }); $response->dynamic($project, Response::MODEL_PROJECT); }); diff --git a/app/controllers/general.php b/app/controllers/general.php index 94caf4760d..9ff704ca20 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -14,6 +14,7 @@ use Appwrite\Event\Publisher\Delete as DeletePublisher; use Appwrite\Extend\Exception as AppwriteException; use Appwrite\Network\Cors; use Appwrite\Platform\Appwrite; +use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Transformation\Adapter\Preview; @@ -1662,11 +1663,10 @@ Http::get('/v1/ping') namespace: 'ping', group: null, name: 'get', - hide: true, description: << ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], - 'lengths' => $index['lengths'], - 'orders' => $index['orders'], + 'lengths' => $index['lengths'] ?? [], + 'orders' => $index['orders'] ?? [], ]), $collection['indexes']); $database->createCollection($key, $attributes, $indexes); @@ -353,8 +353,8 @@ $http->on(Constant::EVENT_START, function ($http) use ($payloadSize, $totalWorke '$id' => ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], - 'lengths' => $index['lengths'], - 'orders' => $index['orders'], + 'lengths' => $index['lengths'] ?? [], + 'orders' => $index['orders'] ?? [], ]), $files['indexes']); $dbForPlatform->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes); @@ -399,8 +399,8 @@ $http->on(Constant::EVENT_START, function ($http) use ($payloadSize, $totalWorke '$id' => ID::custom($index['$id']), 'type' => $index['type'], 'attributes' => $index['attributes'], - 'lengths' => $index['lengths'], - 'orders' => $index['orders'], + 'lengths' => $index['lengths'] ?? [], + 'orders' => $index['orders'] ?? [], ]), $files['indexes']); $authorization->skip(fn () => $dbForPlatform->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes)); diff --git a/app/init/constants.php b/app/init/constants.php index 8e015a5e29..b4af9356d8 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -272,6 +272,17 @@ const FUNCTION_ALLOWLIST_HEADERS_RESPONSE = ['content-type', 'content-length']; const MESSAGE_TYPE_EMAIL = 'email'; const MESSAGE_TYPE_SMS = 'sms'; const MESSAGE_TYPE_PUSH = 'push'; +const MAIL_TEMPLATE_CERTIFICATE_FAILED = 'certificate-failed'; +const MAIL_TEMPLATE_DATA_EXPORT = 'data-export'; +const MAIL_TEMPLATE_INVITATION = 'invitation'; +const MAIL_TEMPLATE_MAGIC_URL = 'magic-url'; +const MAIL_TEMPLATE_MFA_CHALLENGE = 'mfa-challenge'; +const MAIL_TEMPLATE_OTP = 'otp'; +const MAIL_TEMPLATE_RECOVERY = 'recovery'; +const MAIL_TEMPLATE_SESSION_ALERT = 'session-alert'; +const MAIL_TEMPLATE_SMTP_TEST = 'smtp-test'; +const MAIL_TEMPLATE_VERIFICATION = 'verification'; +const MAIL_TEMPLATE_WEBHOOK_FAILED = 'webhook-failed'; // API key types const API_KEY_STANDARD = 'standard'; const API_KEY_EPHEMERAL = 'ephemeral'; diff --git a/app/init/registers.php b/app/init/registers.php index e7ede8b025..43ae64bc53 100644 --- a/app/init/registers.php +++ b/app/init/registers.php @@ -6,7 +6,6 @@ use Appwrite\Hooks\Hooks; use Appwrite\PubSub\Adapter\Redis as PubSub; use Appwrite\URL\URL as AppwriteURL; use MaxMind\Db\Reader; -use Swoole\Database\PDOProxy; use Utopia\Cache\Adapter\Redis as RedisCache; use Utopia\Config\Config; use Utopia\Console; @@ -291,15 +290,14 @@ $register->set('pools', function () { $resource = match ($dsnScheme) { 'mysql', 'mariadb' => function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { - return new PDOProxy(function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { - return new PDO("mysql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase};charset=utf8mb4", $dsnUser, $dsnPass, [ - \PDO::ATTR_TIMEOUT => 3, // Seconds - \PDO::ATTR_PERSISTENT => false, - \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, - \PDO::ATTR_EMULATE_PREPARES => true, - \PDO::ATTR_STRINGIFY_FETCHES => true - ]); - }); + return new PDO("mysql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase};charset=utf8mb4", $dsnUser, $dsnPass, [ + \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, + \PDO::ATTR_TIMEOUT => 3, // Seconds + \PDO::ATTR_PERSISTENT => false, + \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, + \PDO::ATTR_EMULATE_PREPARES => true, + \PDO::ATTR_STRINGIFY_FETCHES => true + ]); }, 'mongodb' => function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { try { @@ -312,15 +310,14 @@ $register->set('pools', function () { } }, 'postgresql' => function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { - return new PDOProxy(function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) { - return new PDO("pgsql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase};connect_timeout=3", $dsnUser, $dsnPass, array( - \PDO::ATTR_TIMEOUT => 3, // Seconds - \PDO::ATTR_PERSISTENT => false, - \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, - \PDO::ATTR_EMULATE_PREPARES => true, - \PDO::ATTR_STRINGIFY_FETCHES => true - )); - }); + return new PDO("pgsql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase};connect_timeout=3", $dsnUser, $dsnPass, array( + \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, + \PDO::ATTR_TIMEOUT => 3, // Seconds + \PDO::ATTR_PERSISTENT => false, + \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, + \PDO::ATTR_EMULATE_PREPARES => true, + \PDO::ATTR_STRINGIFY_FETCHES => true + )); }, default => function () use ($dsnHost, $dsnPort, $dsnPass) { $redis = new \Redis(); diff --git a/app/init/resources/request.php b/app/init/resources/request.php index 982cd13088..958f1a211a 100644 --- a/app/init/resources/request.php +++ b/app/init/resources/request.php @@ -1108,7 +1108,11 @@ return function (Container $context): void { return new Document([]); } - $token = $authorization->skip(fn () => $dbForProject->getDocument('resourceTokens', $tokenId)); + try { + $token = $authorization->skip(fn () => $dbForProject->getDocument('resourceTokens', $tokenId)); + } catch (\Utopia\Database\Exception\NotFound) { + return new Document([]); + } if ($token->isEmpty()) { return new Document([]); diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index d71ccff0b4..d04baa5e11 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -12,6 +12,7 @@ $version = $this->getParam('version', ''); $organization = $this->getParam('organization', ''); $image = $this->getParam('image', ''); $enableAssistant = $this->getParam('enableAssistant', false); +$executorImages = $this->getParam('executorImages', ''); $dbService = $this->getParam('database', 'mongodb'); $allowedDbServices = ['mariadb', 'mongodb']; if (!\in_array($dbService, $allowedDbServices, true)) { @@ -988,10 +989,9 @@ $hostPath = rtrim($this->getParam('hostPath', ''), '/'); <<: *x-logging restart: unless-stopped stop_signal: SIGINT - image: openruntimes/executor:0.24.1 + image: openruntimes/executor:0.25.1 networks: - appwrite - - runtimes volumes: - /var/run/docker.sock:/var/run/docker.sock - appwrite-builds:/storage/builds:rw @@ -1003,6 +1003,7 @@ $hostPath = rtrim($this->getParam('hostPath', ''), '/'); environment: - OPR_EXECUTOR_CONNECTION_STORAGE=local://localhost - OPR_EXECUTOR_CONNECTION_BUILD_CACHE_STORAGE= + - OPR_EXECUTOR_IMAGES= - OPR_EXECUTOR_INACTIVE_TRESHOLD=$_APP_COMPUTE_INACTIVE_THRESHOLD - OPR_EXECUTOR_MAINTENANCE_INTERVAL=$_APP_COMPUTE_MAINTENANCE_INTERVAL - OPR_EXECUTOR_NETWORK=$_APP_COMPUTE_RUNTIMES_NETWORK diff --git a/composer.json b/composer.json index af7575c671..f952d94d89 100644 --- a/composer.json +++ b/composer.json @@ -53,17 +53,17 @@ "ext-sockets": "*", "appwrite/php-runtimes": "0.20.*", "appwrite/php-clamav": "2.0.*", - "utopia-php/abuse": "1.3.*", + "utopia-php/abuse": "1.4.*", "utopia-php/agents": "2.*", "utopia-php/analytics": "0.15.*", - "utopia-php/audit": "^2.4", - "utopia-php/auth": "0.5.*", + "utopia-php/audit": "2.6.*", + "utopia-php/auth": "^0.6", "utopia-php/cache": "^3.0", "utopia-php/cli": "^0.24", "utopia-php/compression": "0.1.*", "utopia-php/config": "1.*", "utopia-php/console": "0.1.*", - "utopia-php/database": "5.*", + "utopia-php/database": "6.0.*", "utopia-php/detector": "0.2.*", "utopia-php/domains": "^2.2", "utopia-php/emails": "0.7.*", @@ -76,8 +76,8 @@ "utopia-php/locale": "0.8.*", "utopia-php/lock": "0.2.*", "utopia-php/logger": "0.8.*", - "utopia-php/messaging": "1.0.*", - "utopia-php/migration": "1.*", + "utopia-php/messaging": "^1.1", + "utopia-php/migration": "1.14.*", "utopia-php/platform": "^1.0@RC", "utopia-php/pools": "1.*", "utopia-php/span": "3.0.*", diff --git a/composer.lock b/composer.lock index 703189e5f9..969d2985ee 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fe6368e3d42f385c63d7e5e2e911febd", + "content-hash": "bf0c07c029c54b225566c1a731fccae0", "packages": [ { "name": "adhocore/jwt", @@ -69,16 +69,16 @@ }, { "name": "appwrite/appwrite", - "version": "24.2.0", + "version": "26.1.0", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-for-php.git", - "reference": "d3217b6524b9d174ab91fb7ffc555c68bfa1da97" + "reference": "533865f24f306cf6ac6f1737965553a5c54672e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/d3217b6524b9d174ab91fb7ffc555c68bfa1da97", - "reference": "d3217b6524b9d174ab91fb7ffc555c68bfa1da97", + "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/533865f24f306cf6ac6f1737965553a5c54672e0", + "reference": "533865f24f306cf6ac6f1737965553a5c54672e0", "shasum": "" }, "require": { @@ -88,7 +88,7 @@ }, "require-dev": { "mockery/mockery": "1.6.12", - "phpunit/phpunit": "^10" + "phpunit/phpunit": "^12" }, "type": "library", "autoload": { @@ -104,10 +104,10 @@ "support": { "email": "team@appwrite.io", "issues": "https://github.com/appwrite/sdk-for-php/issues", - "source": "https://github.com/appwrite/sdk-for-php/tree/24.2.0", + "source": "https://github.com/appwrite/sdk-for-php/tree/26.1.0", "url": "https://appwrite.io/support" }, - "time": "2026-05-21T18:56:51+00:00" + "time": "2026-06-19T08:16:32+00:00" }, { "name": "appwrite/php-clamav", @@ -3118,25 +3118,25 @@ }, { "name": "utopia-php/abuse", - "version": "1.3.1", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "00e59c89a1ac5f4ad771695e5dbee020b3c7ac44" + "reference": "8f5df0274869cf9022eea7d8030ca1a0d458b3b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/00e59c89a1ac5f4ad771695e5dbee020b3c7ac44", - "reference": "00e59c89a1ac5f4ad771695e5dbee020b3c7ac44", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/8f5df0274869cf9022eea7d8030ca1a0d458b3b2", + "reference": "8f5df0274869cf9022eea7d8030ca1a0d458b3b2", "shasum": "" }, "require": { - "appwrite/appwrite": "24.*", + "appwrite/appwrite": "^26.0", "ext-curl": "*", "ext-pdo": "*", "ext-redis": "*", "php": ">=8.2", - "utopia-php/database": "5.*" + "utopia-php/database": "^6.0.0" }, "require-dev": { "laravel/pint": "1.*", @@ -3164,9 +3164,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/1.3.1" + "source": "https://github.com/utopia-php/abuse/tree/1.4.1" }, - "time": "2026-06-03T07:30:05+00:00" + "time": "2026-06-18T11:18:52+00:00" }, { "name": "utopia-php/agents", @@ -3269,21 +3269,21 @@ }, { "name": "utopia-php/audit", - "version": "2.4.2", + "version": "2.6.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "6f15caaac5455c98cec06e02fe8da3af9477ff38" + "reference": "f5bb07841e335e9ea7d4bd5860da1f580447014a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/6f15caaac5455c98cec06e02fe8da3af9477ff38", - "reference": "6f15caaac5455c98cec06e02fe8da3af9477ff38", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/f5bb07841e335e9ea7d4bd5860da1f580447014a", + "reference": "f5bb07841e335e9ea7d4bd5860da1f580447014a", "shasum": "" }, "require": { "php": ">=8.4", - "utopia-php/database": "5.*", + "utopia-php/database": "^6.0.0", "utopia-php/fetch": "^1.1", "utopia-php/query": "0.1.*", "utopia-php/validators": "0.2.*" @@ -3313,22 +3313,22 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/2.4.2" + "source": "https://github.com/utopia-php/audit/tree/2.6.0" }, - "time": "2026-06-03T03:42:22+00:00" + "time": "2026-06-22T03:33:28+00:00" }, { "name": "utopia-php/auth", - "version": "0.5.1", + "version": "0.6.1", "source": { "type": "git", "url": "https://github.com/utopia-php/auth.git", - "reference": "9245a6342ed94f00425aef6963a32b8af9b0dc9d" + "reference": "8323a51314f6988c62926117ed642588ca8e8c4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/auth/zipball/9245a6342ed94f00425aef6963a32b8af9b0dc9d", - "reference": "9245a6342ed94f00425aef6963a32b8af9b0dc9d", + "url": "https://api.github.com/repos/utopia-php/auth/zipball/8323a51314f6988c62926117ed642588ca8e8c4a", + "reference": "8323a51314f6988c62926117ed642588ca8e8c4a", "shasum": "" }, "require": { @@ -3338,12 +3338,6 @@ "ext-sodium": "*", "php": ">=8.0" }, - "require-dev": { - "laravel/pint": "1.2.*", - "phpstan/phpstan": "1.9.x-dev", - "phpunit/phpunit": "^9.3", - "vimeo/psalm": "4.0.1" - }, "type": "library", "autoload": { "psr-4": { @@ -3369,9 +3363,9 @@ ], "support": { "issues": "https://github.com/utopia-php/auth/issues", - "source": "https://github.com/utopia-php/auth/tree/0.5.1" + "source": "https://github.com/utopia-php/auth/tree/0.6.1" }, - "time": "2026-05-30T12:21:17+00:00" + "time": "2026-06-20T09:45:06+00:00" }, { "name": "utopia-php/cache", @@ -3682,16 +3676,16 @@ }, { "name": "utopia-php/database", - "version": "5.9.2", + "version": "6.0.0", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "698952455dd645ff41057621c90a4cea977fb1bf" + "reference": "fff9f0effbd40359ff925741ff9424856d8b4fde" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/698952455dd645ff41057621c90a4cea977fb1bf", - "reference": "698952455dd645ff41057621c90a4cea977fb1bf", + "url": "https://api.github.com/repos/utopia-php/database/zipball/fff9f0effbd40359ff925741ff9424856d8b4fde", + "reference": "fff9f0effbd40359ff925741ff9424856d8b4fde", "shasum": "" }, "require": { @@ -3736,9 +3730,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/5.9.2" + "source": "https://github.com/utopia-php/database/tree/6.0.0" }, - "time": "2026-06-12T08:33:14+00:00" + "time": "2026-06-18T10:37:40+00:00" }, { "name": "utopia-php/detector", @@ -4354,16 +4348,16 @@ }, { "name": "utopia-php/messaging", - "version": "1.0.0", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/messaging.git", - "reference": "1aca8968c3bf3c78c428a399dfe97cbe9b366ec4" + "reference": "2a8e82cda89b373833e10923ae959f56466300a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/messaging/zipball/1aca8968c3bf3c78c428a399dfe97cbe9b366ec4", - "reference": "1aca8968c3bf3c78c428a399dfe97cbe9b366ec4", + "url": "https://api.github.com/repos/utopia-php/messaging/zipball/2a8e82cda89b373833e10923ae959f56466300a3", + "reference": "2a8e82cda89b373833e10923ae959f56466300a3", "shasum": "" }, "require": { @@ -4371,7 +4365,8 @@ "ext-openssl": "*", "giggsey/libphonenumber-for-php-lite": "9.0.23", "php": ">=8.1.0", - "phpmailer/phpmailer": "6.9.1" + "phpmailer/phpmailer": "6.9.1", + "utopia-php/telemetry": "^0.4" }, "require-dev": { "laravel/pint": "1.*", @@ -4399,31 +4394,31 @@ ], "support": { "issues": "https://github.com/utopia-php/messaging/issues", - "source": "https://github.com/utopia-php/messaging/tree/1.0.0" + "source": "https://github.com/utopia-php/messaging/tree/1.1.0" }, - "time": "2026-06-02T14:54:22+00:00" + "time": "2026-06-16T03:44:58+00:00" }, { "name": "utopia-php/migration", - "version": "1.13.2", + "version": "1.14.0", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "50526e121efcf73e11309446f194623a431d7e32" + "reference": "f70dba326f1499d1ff4dd18b218b26a858aff1dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/50526e121efcf73e11309446f194623a431d7e32", - "reference": "50526e121efcf73e11309446f194623a431d7e32", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/f70dba326f1499d1ff4dd18b218b26a858aff1dd", + "reference": "f70dba326f1499d1ff4dd18b218b26a858aff1dd", "shasum": "" }, "require": { - "appwrite/appwrite": "24.*", + "appwrite/appwrite": "^26.0", "ext-curl": "*", "ext-openssl": "*", "halaxa/json-machine": "^1.2", "php": ">=8.2", - "utopia-php/database": "5.*", + "utopia-php/database": "^6.0.0", "utopia-php/dsn": "0.2.*", "utopia-php/storage": "2.*" }, @@ -4454,9 +4449,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.13.2" + "source": "https://github.com/utopia-php/migration/tree/1.14.0" }, - "time": "2026-06-04T05:09:07+00:00" + "time": "2026-06-18T11:19:06+00:00" }, { "name": "utopia-php/mongo", @@ -5129,16 +5124,16 @@ }, { "name": "utopia-php/vcs", - "version": "4.2.2", + "version": "4.2.3", "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "bb42584d3efb95ff4eb241605bb15165c56974de" + "reference": "598cbd2793a5a6394493f1046743e75ec6544a57" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/vcs/zipball/bb42584d3efb95ff4eb241605bb15165c56974de", - "reference": "bb42584d3efb95ff4eb241605bb15165c56974de", + "url": "https://api.github.com/repos/utopia-php/vcs/zipball/598cbd2793a5a6394493f1046743e75ec6544a57", + "reference": "598cbd2793a5a6394493f1046743e75ec6544a57", "shasum": "" }, "require": { @@ -5172,9 +5167,9 @@ ], "support": { "issues": "https://github.com/utopia-php/vcs/issues", - "source": "https://github.com/utopia-php/vcs/tree/4.2.2" + "source": "https://github.com/utopia-php/vcs/tree/4.2.3" }, - "time": "2026-06-10T08:08:48+00:00" + "time": "2026-06-16T12:14:08+00:00" }, { "name": "utopia-php/websocket", diff --git a/docker-compose.yml b/docker-compose.yml index d4b2aacd03..4341698653 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1249,7 +1249,7 @@ services: hostname: exc1 <<: *x-logging stop_signal: SIGINT - image: openruntimes/executor:0.24.1 + image: openruntimes/executor:0.25.1 restart: unless-stopped networks: - appwrite diff --git a/src/Appwrite/Bus/Listeners/Mails.php b/src/Appwrite/Bus/Listeners/Mails.php index eb36e0d394..948394d8b6 100644 --- a/src/Appwrite/Bus/Listeners/Mails.php +++ b/src/Appwrite/Bus/Listeners/Mails.php @@ -143,6 +143,7 @@ class Mails extends Listener project: $project, recipient: $event->user['email'], subject: $subject, + template: MAIL_TEMPLATE_SESSION_ALERT, bodyTemplate: __DIR__ . '/../../../../app/config/locale/templates/' . $smtpBaseTemplate . '.tpl', body: $body, preview: $preview, diff --git a/src/Appwrite/Event/Message/Executions.php b/src/Appwrite/Event/Message/Executions.php new file mode 100644 index 0000000000..b6fbf64b91 --- /dev/null +++ b/src/Appwrite/Event/Message/Executions.php @@ -0,0 +1,39 @@ + $executions + */ + public function __construct( + public readonly Document $project, + public readonly array $executions, + ) { + } + + public function toArray(): array + { + return [ + 'project' => $this->project->getArrayCopy(), + 'executions' => \array_map( + fn (Document $execution) => $execution->getArrayCopy(), + $this->executions + ), + ]; + } + + public static function fromArray(array $data): static + { + return new self( + project: new Document($data['project'] ?? []), + executions: \array_map( + fn (array $execution) => new Document($execution), + $data['executions'] ?? [] + ), + ); + } +} diff --git a/src/Appwrite/Event/Message/Mail.php b/src/Appwrite/Event/Message/Mail.php index aeeea8a616..b823f107da 100644 --- a/src/Appwrite/Event/Message/Mail.php +++ b/src/Appwrite/Event/Message/Mail.php @@ -12,6 +12,7 @@ final class Mail extends Base public readonly string $recipient = '', public readonly string $name = '', public readonly string $subject = '', + public readonly string $template = '', public readonly string $bodyTemplate = '', public readonly string $body = '', public readonly string $preview = '', @@ -33,6 +34,7 @@ final class Mail extends Base 'recipient' => $this->recipient, 'name' => $this->name, 'subject' => $this->subject, + 'template' => $this->template, 'bodyTemplate' => $this->bodyTemplate, 'body' => $this->body, 'preview' => $this->preview, @@ -52,6 +54,7 @@ final class Mail extends Base recipient: $data['recipient'] ?? '', name: $data['name'] ?? '', subject: $data['subject'] ?? '', + template: $data['template'] ?? '', bodyTemplate: $data['bodyTemplate'] ?? '', body: $data['body'] ?? '', preview: $data['preview'] ?? '', diff --git a/src/Appwrite/Event/Publisher/Execution.php b/src/Appwrite/Event/Publisher/Execution.php index 05ea28d540..60470fcb9d 100644 --- a/src/Appwrite/Event/Publisher/Execution.php +++ b/src/Appwrite/Event/Publisher/Execution.php @@ -3,6 +3,7 @@ namespace Appwrite\Event\Publisher; use Appwrite\Event\Message\Execution as ExecutionMessage; +use Appwrite\Event\Message\Executions as ExecutionsMessage; use Utopia\Queue\Publisher; use Utopia\Queue\Queue; @@ -15,7 +16,7 @@ readonly class Execution extends Base parent::__construct($publisher); } - public function enqueue(ExecutionMessage $message): string|bool + public function enqueue(ExecutionMessage|ExecutionsMessage $message): string|bool { return $this->publish($this->queue, $message); } diff --git a/src/Appwrite/Platform/Installer/Http/Installer/Install.php b/src/Appwrite/Platform/Installer/Http/Installer/Install.php index a3368a75b1..7cf81b5eb8 100644 --- a/src/Appwrite/Platform/Installer/Http/Installer/Install.php +++ b/src/Appwrite/Platform/Installer/Http/Installer/Install.php @@ -42,7 +42,14 @@ class Install extends Action ->param('accountPassword', '', new Password(allowEmpty: true), 'Account password', true) ->param('database', '', new WhiteList(['mongodb', 'mariadb', 'postgresql']), 'Database adapter', true) ->param('installId', '', new Text(64, 0), 'Installation ID', true) - ->param('retryStep', null, new Nullable(new WhiteList([Server::STEP_DOCKER_COMPOSE, Server::STEP_ENV_VARS, Server::STEP_DOCKER_CONTAINERS], true)), 'Retry from step', true) + ->param('retryStep', null, new Nullable(new WhiteList([ + Server::STEP_CONFIG_FILES, + Server::STEP_DOCKER_COMPOSE, + Server::STEP_ENV_VARS, + Server::STEP_DOCKER_CONTAINERS, + Server::STEP_ACCOUNT_SETUP, + Server::STEP_MIGRATION, + ], true)), 'Retry from step', true) ->param('migrate', false, new \Utopia\Validator\Boolean(true), 'Run database migration after upgrade', true) ->inject('request') ->inject('response') diff --git a/src/Appwrite/Platform/Installer/Http/Installer/Reset.php b/src/Appwrite/Platform/Installer/Http/Installer/Reset.php index 8e5b877473..0bd319019d 100644 --- a/src/Appwrite/Platform/Installer/Http/Installer/Reset.php +++ b/src/Appwrite/Platform/Installer/Http/Installer/Reset.php @@ -69,17 +69,33 @@ class Reset extends Action $isLocal = $config->isLocal(); $composeFileName = $isLocal ? 'docker-compose.web-installer.yml' : 'docker-compose.yml'; $envFileName = $isLocal ? '.env.web-installer' : '.env'; - $path = $isLocal ? '/usr/src/code' : '/usr/src/code/appwrite'; + $path = $isLocal ? $config->getHostPath() : '/usr/src/code/appwrite'; + + if ($path === null || $path === '') { + return 'Missing host path for local installer reset'; + } $composeFile = $path . '/' . $composeFileName; + $envFile = $path . '/' . $envFileName; if (file_exists($composeFile)) { - $command = array_map(escapeshellarg(...), [ + $command = [ 'docker', 'compose', - '-f', $composeFile, + ]; + if (file_exists($envFile)) { + $command[] = '--env-file'; + $command[] = $envFile; + } + $command = array_map(escapeshellarg(...), [ + ...$command, + '-f', + $composeFile, ...($isLocal ? ['--project-name', 'appwrite'] : []), - '--project-directory', $path, - 'down', '-v', '--remove-orphans', + '--project-directory', + $path, + 'down', + '-v', + '--remove-orphans', ]); $output = []; @@ -92,7 +108,6 @@ class Reset extends Action @unlink($composeFile); } - $envFile = $path . '/' . $envFileName; if (file_exists($envFile)) { @unlink($envFile); } diff --git a/src/Appwrite/Platform/Installer/Server.php b/src/Appwrite/Platform/Installer/Server.php index 26d82adf24..b86db4d93d 100644 --- a/src/Appwrite/Platform/Installer/Server.php +++ b/src/Appwrite/Platform/Installer/Server.php @@ -114,7 +114,6 @@ class Server } if (isset($opts['docker'])) { - $this->printInstallerUrl($host, $port); $this->startDockerInstaller($opts); } @@ -365,9 +364,13 @@ class Server '-i', '--rm', '--name', $container, + '--label', 'com.docker.compose.project=appwrite-installer', + '--label', 'com.docker.compose.service=appwrite-installer', + '--add-host', 'host.docker.internal:host-gateway', '-p', "127.0.0.1:$port:" . self::INSTALLER_WEB_PORT, '--volume', '/var/run/docker.sock:/var/run/docker.sock', '--volume', "$volumePath:/usr/src/code:rw", + '--volume', "$volumePath:$volumePath:rw", ]; $args[] = '-e'; $args[] = 'APPWRITE_INSTALLER_CONFIG=' . $configJson; diff --git a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php index 27d6f3e088..da6055fffd 100644 --- a/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php +++ b/src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php @@ -336,6 +336,7 @@ class Create extends Action project: $project, recipient: $user->getAttribute('email'), subject: $subject, + template: MAIL_TEMPLATE_MFA_CHALLENGE, bodyTemplate: $bodyTemplate, body: $body, preview: $preview, diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Action.php index 7893a70753..9ea4f11ccb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Action.php @@ -21,6 +21,41 @@ class Action extends AppwriteAction return $this->context; } + /** + * Database types this path may operate on. Single source of truth shared by + * the list filter ({@see getDatabaseTypeQueryFilters()}) and the by-id guard + * ({@see isDatabaseTypeMismatch()}) so they cannot diverge. + * + * TablesDB is the compatibility successor to the legacy databases API, so it + * also serves legacy-typed databases; the other product APIs are scoped to + * their own type. Every database carries a non-null `type` (set on create + * and backfilled to 'legacy' by migration V23), so null is not represented. + * + * @return string[] + */ + protected function getAllowedDatabaseTypes(): array + { + return match ($this->getDatabaseType()) { + DATABASE_TYPE_TABLESDB => [DATABASE_TYPE_TABLESDB, DATABASE_TYPE_LEGACY], + default => [$this->getDatabaseType()], + }; + } + + /** + * A database resolved by id on a product-DB path must be one of the path's + * allowed types; otherwise it is treated as not-found rather than proceeding + * to a type-mismatched backend operation that surfaces as an opaque 500. The + * legacy /v1/databases API is intentionally not type-guarded. + */ + protected function isDatabaseTypeMismatch(Document $database): bool + { + if ($this->getDatabaseType() === DATABASE_TYPE_LEGACY) { + return false; + } + + return !in_array($database->getAttribute('type', ''), $this->getAllowedDatabaseTypes(), true); + } + public function setHttpPath(string $path): self { if (\str_contains($path, '/tablesdb')) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index a07a4be561..292c613a5b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -6,6 +6,7 @@ use Appwrite\Event\Event; use Appwrite\Event\Message\Database as DatabaseMessage; use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; +use Appwrite\Platform\Modules\Databases\Http\Databases\Action as DatabasesAction; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response as UtopiaResponse; use Throwable; @@ -21,10 +22,9 @@ use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Structure; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; -use Utopia\Platform\Action as UtopiaAction; use Utopia\Validator\Range; -abstract class Action extends UtopiaAction +abstract class Action extends DatabasesAction { /** * @var string The current context (either 'column' or 'attribute') @@ -36,12 +36,14 @@ abstract class Action extends UtopiaAction */ abstract protected function getResponseModel(): string|array; - public function setHttpPath(string $path): UtopiaAction + public function setHttpPath(string $path): DatabasesAction { if (\str_contains($path, '/tablesdb')) { $this->context = COLUMNS; } - return parent::setHttpPath($path); + parent::setHttpPath($path); + + return $this; } /** @@ -333,7 +335,7 @@ abstract class Action extends UtopiaAction $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($db->isEmpty()) { + if ($db->isEmpty() || $this->isDatabaseTypeMismatch($db)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } @@ -495,7 +497,7 @@ abstract class Action extends UtopiaAction { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($db->isEmpty()) { + if ($db->isEmpty() || $this->isDatabaseTypeMismatch($db)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php index ff1636ae60..2808a14088 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php @@ -76,7 +76,7 @@ class Delete extends Action public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($db->isEmpty()) { + if ($db->isEmpty() || $this->isDatabaseTypeMismatch($db)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php index 3b9d665d70..4fc251fe51 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php @@ -75,7 +75,7 @@ class Get extends Action public function action(string $databaseId, string $collectionId, string $key, UtopiaResponse $response, Database $dbForProject, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php index 90591b43fb..6dd7492ce9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Create.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -57,6 +58,10 @@ class Create extends Action model: $this->getResponseModel() ) ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createLongtextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Update.php index 26e3f0ef8f..6af0578891 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Longtext/Update.php @@ -6,6 +6,7 @@ use Appwrite\Event\Event; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -55,6 +56,10 @@ class Update extends Action ) ], contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateLongtextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php index 0f7b386fd5..5e49243481 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Create.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -57,6 +58,10 @@ class Create extends Action model: $this->getResponseModel() ) ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createMediumtextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Update.php index 45feb7aa9a..1672131123 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Mediumtext/Update.php @@ -6,6 +6,7 @@ use Appwrite\Event\Event; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -55,6 +56,10 @@ class Update extends Action ) ], contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateMediumtextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php index f94a60b9de..c62b89a633 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php @@ -99,7 +99,7 @@ class Create extends Action $twoWayKey ??= $collectionId; $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php index 79968d0feb..8943c05339 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Create.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -57,6 +58,10 @@ class Create extends Action model: $this->getResponseModel() ) ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createTextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Update.php index ec9b2979f7..f86e47f36d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Text/Update.php @@ -6,6 +6,7 @@ use Appwrite\Event\Event; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -55,6 +56,10 @@ class Update extends Action ) ], contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateTextColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php index 89690de4e9..e45b3fed28 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Create.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Database as DatabasePublisher; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -59,6 +60,10 @@ class Create extends Action model: $this->getResponseModel() ) ], + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createVarcharColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Update.php index 0ce20abd2d..1aacd92fd5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Varchar/Update.php @@ -6,6 +6,7 @@ use Appwrite\Event\Event; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -57,6 +58,10 @@ class Update extends Action ) ], contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateVarcharColumn', + ), )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php index 5813690802..430117188f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php @@ -71,7 +71,7 @@ class XList extends Action public function action(string $databaseId, string $collectionId, array $queries, bool $includeTotal, UtopiaResponse $response, Database $dbForProject, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index b2e783bccd..35a6692b88 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -94,7 +94,7 @@ class Create extends Action { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php index 87171fb2fe..532ad23c67 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php @@ -73,7 +73,7 @@ class Delete extends Action public function action(string $databaseId, string $collectionId, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, DatabasePublisher $publisherForDatabase, Event $queueForEvents, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php index 9319cffc57..48c1802038 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php @@ -97,7 +97,7 @@ class Decrement extends Action $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php index ba74545342..4d4ecc6777 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php @@ -97,7 +97,7 @@ class Increment extends Action $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php index 2dc3100046..0959acf27c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php @@ -91,7 +91,7 @@ class Delete extends Action public function action(string $databaseId, string $collectionId, array $queries, ?string $transactionId, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Context $usage, Event $queueForEvents, Event $queueForRealtime, FunctionPublisher $publisherForFunctions, Event $queueForWebhooks, array $plan, EventProcessor $eventProcessor): void { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php index 393590d1e6..bc09c477d8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php @@ -103,7 +103,7 @@ class Update extends Action } $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php index d69298919b..231a2b3a4d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php @@ -93,7 +93,7 @@ class Upsert extends Action public function action(string $databaseId, string $collectionId, array $documents, ?string $transactionId, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Context $usage, Event $queueForEvents, Event $queueForRealtime, FunctionPublisher $publisherForFunctions, Event $queueForWebhooks, array $plan, EventProcessor $eventProcessor): void { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php index 2e861dfcce..676ff46a91 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php @@ -209,7 +209,7 @@ class Create extends Action } $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php index e0863b8ac7..55be2373a6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php @@ -110,7 +110,7 @@ class Delete extends Action $isAPIKey = $user->isKey($authorization->getRoles()); $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php index c40e70d667..1c51e38e2e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php @@ -82,7 +82,7 @@ class Get extends Action $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php index 8aaac5fcb4..976a76bba7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php @@ -81,7 +81,7 @@ class XList extends Action public function action(string $databaseId, string $collectionId, string $documentId, array $queries, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Locale $locale, Reader $geodb, Authorization $authorization, Audit $audit): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php index 4a675615da..7c80a578ff 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php @@ -106,7 +106,7 @@ class Update extends Action $isAPIKey = $user->isKey($authorization->getRoles()); $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php index ae940456f0..73fcf35b7b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php @@ -112,7 +112,7 @@ class Upsert extends Action $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php index afde3d0baa..fd1d5b53d4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php @@ -92,7 +92,7 @@ class XList extends Action $isPrivilegedUser = $user->isPrivileged($authorization->getRoles()); $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php index 61b9d515f4..43364413db 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php @@ -65,7 +65,7 @@ class Get extends Action { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php index 251e493cb6..4dad2429cc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php @@ -3,9 +3,9 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes; use Appwrite\Extend\Exception; -use Utopia\Platform\Action as UtopiaAction; +use Appwrite\Platform\Modules\Databases\Http\Databases\Action as DatabasesAction; -abstract class Action extends UtopiaAction +abstract class Action extends DatabasesAction { /** * The current API context (either 'columnIndex' or 'index'). @@ -17,12 +17,14 @@ abstract class Action extends UtopiaAction */ abstract protected function getResponseModel(): string; - public function setHttpPath(string $path): UtopiaAction + public function setHttpPath(string $path): DatabasesAction { if (\str_contains($path, '/tablesdb')) { $this->context = COLUMN_INDEX; } - return parent::setHttpPath($path); + parent::setHttpPath($path); + + return $this; } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php index 4e989621f1..2a2fffcc07 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php @@ -90,7 +90,7 @@ class Create extends Action { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($db->isEmpty()) { + if ($db->isEmpty() || $this->isDatabaseTypeMismatch($db)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php index 82cada6e0d..f88f833764 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php @@ -80,7 +80,7 @@ class Delete extends Action { $db = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($db->isEmpty()) { + if ($db->isEmpty() || $this->isDatabaseTypeMismatch($db)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php index 0ab022f777..763fd86f7b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php @@ -67,7 +67,7 @@ class Get extends Action { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } $collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php index a4f65d0fcc..c4d70c5fb6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php @@ -75,7 +75,7 @@ class XList extends Action /** @var Document $database */ $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php index cc082532f9..f2b4e1b4fa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php @@ -80,7 +80,7 @@ class XList extends Action { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php index 800df6d044..6ba8b67bd4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php @@ -80,7 +80,7 @@ class Update extends Action public function action(string $databaseId, string $collectionId, ?string $name, ?array $permissions, bool $documentSecurity, bool $enabled, bool $purge, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Event $queueForEvents, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php index f2f2947016..5d1ccbd45f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php @@ -75,7 +75,7 @@ class XList extends Action { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php index 058c48d68f..6394e2667e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php @@ -15,7 +15,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; -use Utopia\Platform\Action; class Delete extends Action { @@ -68,7 +67,7 @@ class Delete extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php index 90561364ab..5ee8e2f5e3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; -use Utopia\Platform\Action; class Get extends Action { @@ -60,7 +59,7 @@ class Get extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php index a13c6c4903..1474e602e3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Logs; use Appwrite\Detector\Detector; use Appwrite\Extend\Exception; +use Appwrite\Platform\Modules\Databases\Http\Databases\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; @@ -23,7 +24,6 @@ use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; use Utopia\Locale\Locale; -use Utopia\Platform\Action; class XList extends Action { @@ -75,7 +75,7 @@ class XList extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php index f2b351fa6a..1e0c7af49b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Create.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Transactions; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -49,7 +50,11 @@ class Create extends Action model: UtopiaResponse::MODEL_TRANSACTION, ) ], - contentType: ContentType::JSON + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createTransaction', + ) )) ->param('ttl', APP_DATABASE_TXN_TTL_DEFAULT, new Range(min: APP_DATABASE_TXN_TTL_MIN, max: APP_DATABASE_TXN_TTL_MAX), 'Seconds before the transaction expires.', true) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php index 072cb21bbc..9130929162 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Delete.php @@ -7,6 +7,7 @@ use Appwrite\Event\Publisher\Delete as DeletePublisher; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -48,7 +49,11 @@ class Delete extends Action model: UtopiaResponse::MODEL_NONE, ) ], - contentType: ContentType::NONE + contentType: ContentType::NONE, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.deleteTransaction', + ) )) ->param('transactionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Transaction ID.', false, ['dbForProject']) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php index af0f7cdc10..dc20349e7c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Get.php @@ -5,6 +5,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Transactions; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; @@ -45,7 +46,11 @@ class Get extends Action model: UtopiaResponse::MODEL_TRANSACTION, ) ], - contentType: ContentType::JSON + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.getTransaction', + ) )) ->param('transactionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Transaction ID.', false, ['dbForProject']) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php index 8e085a9481..3aca66cd6d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Operations/Create.php @@ -7,6 +7,7 @@ use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Transactions\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Documents\User; @@ -56,7 +57,11 @@ class Create extends Action model: UtopiaResponse::MODEL_TRANSACTION, ) ], - contentType: ContentType::JSON + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.createOperations', + ) )) ->param('transactionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Transaction ID.', false, ['dbForProject']) ->param('operations', [], new ArrayList(new Operation(type: 'legacy')), 'Array of staged operations.', true) @@ -117,7 +122,7 @@ class Create extends Action } $database = $databases[$operation['databaseId']] ??= $authorization->skip(fn () => $dbForProject->getDocument('databases', $operation['databaseId'])); - if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database) || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$operation['databaseId']]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php index de057ae15e..a757f0079e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/Update.php @@ -12,6 +12,7 @@ use Appwrite\Extend\Exception; use Appwrite\Functions\EventProcessor; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Usage\Context; @@ -65,7 +66,11 @@ class Update extends Action model: UtopiaResponse::MODEL_TRANSACTION, ) ], - contentType: ContentType::JSON + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.updateTransaction', + ) )) ->param('transactionId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Transaction ID.', false, ['dbForProject']) ->param('commit', false, new Boolean(), 'Commit transaction?', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/XList.php index b10972ad64..22a7da97aa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Transactions/XList.php @@ -5,6 +5,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Transactions; use Appwrite\Extend\Exception; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; +use Appwrite\SDK\Deprecated; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Transactions; @@ -48,7 +49,11 @@ class XList extends Action model: UtopiaResponse::MODEL_TRANSACTION_LIST, ) ], - contentType: ContentType::JSON + contentType: ContentType::JSON, + deprecated: new Deprecated( + since: '1.8.0', + replaceWith: 'tablesDB.listTransactions', + ) )) ->param('queries', [], new Transactions(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries).', true) ->inject('response') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php index c5d55c1b1b..c681d0b3f3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php @@ -13,7 +13,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; -use Utopia\Platform\Action; use Utopia\Validator\Boolean; use Utopia\Validator\Text; @@ -69,7 +68,7 @@ class Update extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php index 39e57a0aee..ee65cbd7ff 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php @@ -3,7 +3,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Usage; use Appwrite\Extend\Exception; -use Appwrite\Platform\Action; +use Appwrite\Platform\Modules\Databases\Http\Databases\Action as DatabasesAction; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Deprecated; @@ -20,7 +20,7 @@ use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; use Utopia\Platform\Enum; use Utopia\Validator\WhiteList; -class Get extends Action +class Get extends DatabasesAction { public static function getName(): string { @@ -29,7 +29,7 @@ class Get extends Action protected $databaseType = DATABASE_TYPE_LEGACY; - public function setHttpPath(string $path): Action + public function setHttpPath(string $path): DatabasesAction { $this->databaseType = match (true) { str_contains($path, '/documentsdb') => DATABASE_TYPE_DOCUMENTSDB, @@ -114,7 +114,7 @@ class Get extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php index 21dbc83edc..840672114c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php @@ -29,7 +29,7 @@ class XList extends Action protected function getDatabaseTypeQueryFilters(): array { - return [Query::equal('type', [$this->getDatabaseType()])]; + return [Query::equal('type', $this->getAllowedDatabaseTypes())]; } public function __construct() diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php index ccb421b36d..0df38fbf4b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/Logs/XList.php @@ -4,6 +4,7 @@ namespace Appwrite\Platform\Modules\Databases\Http\TablesDB\Logs; use Appwrite\Detector\Detector; use Appwrite\Extend\Exception; +use Appwrite\Platform\Modules\Databases\Http\Databases\Action; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; use Appwrite\SDK\Method; @@ -22,7 +23,6 @@ use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; use Utopia\Locale\Locale; -use Utopia\Platform\Action; class XList extends Action { @@ -70,7 +70,7 @@ class XList extends Action { $database = $dbForProject->getDocument('databases', $databaseId); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/XList.php index 8dc0f6521a..80a9bd3686 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/TablesDB/XList.php @@ -9,7 +9,6 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Databases; use Appwrite\Utopia\Response as UtopiaResponse; -use Utopia\Database\Query; use Utopia\Http\Adapter\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; @@ -21,16 +20,6 @@ class XList extends DatabaseXList return 'listTablesDatabases'; } - protected function getDatabaseTypeQueryFilters(): array - { - return [ - Query::or([ - Query::equal('type', [DATABASE_TYPE_TABLESDB, DATABASE_TYPE_LEGACY]), - Query::isNull('type'), - ]), - ]; - } - public function __construct() { $this diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php index 3b346bb7c0..49de7f7cc5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Create.php @@ -85,7 +85,7 @@ class Create extends CollectionAction { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Update.php index f8ba767e7e..12b680496a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/VectorsDB/Collections/Update.php @@ -76,7 +76,7 @@ class Update extends CollectionAction public function action(string $databaseId, string $collectionId, ?string $name, ?int $dimensions, ?array $permissions, bool $documentSecurity, ?bool $enabled, UtopiaResponse $response, Database $dbForProject, callable $getDatabasesDB, Event $queueForEvents, Authorization $authorization): void { $database = $authorization->skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - if ($database->isEmpty()) { + if ($database->isEmpty() || $this->isDatabaseTypeMismatch($database)) { throw new Exception(Exception::DATABASE_NOT_FOUND); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php index 601025c794..2692eaf630 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php @@ -218,6 +218,10 @@ class Create extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index fd89651800..e9e14a6e22 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -182,6 +182,10 @@ class Update extends Base $isConnected = !empty($function->getAttribute('providerRepositoryId', '')); + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + // Omitted providerRepositoryId (null) on a connected function — preserve existing VCS values if ($isConnected && $providerRepositoryId === null) { $providerRepositoryId = $function->getAttribute('providerRepositoryId', ''); diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php index df5b650d5d..689ebcb097 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/SMTP/Tests/Create.php @@ -152,6 +152,7 @@ class Create extends Action project: $project, recipient: $email, subject: $subject, + template: MAIL_TEMPLATE_SMTP_TEST, bodyTemplate: APP_CE_CONFIG_DIR . '/locale/templates/email-base-styled.tpl', body: $template->render(), smtp: [ diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php index 3662bb4d35..c5c7c82706 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Create.php @@ -151,6 +151,10 @@ class Create extends Base throw new Exception(Exception::INSTALLATION_NOT_FOUND); } + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + if (!empty($providerRepositoryId) && (empty($installationId) || empty($providerBranch))) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'When connecting to VCS (Version Control System), you need to provide "installationId" and "providerBranch".'); } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php index a9082b7436..474024fc76 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Update.php @@ -183,6 +183,10 @@ class Update extends Base $isConnected = !empty($site->getAttribute('providerRepositoryId', '')); + if (!empty($installationId) && $installation->getAttribute('projectId') !== $project->getId()) { + throw new Exception(Exception::INSTALLATION_NOT_FOUND); + } + // Omitted providerRepositoryId (null) on a connected site — preserve existing VCS values if ($isConnected && $providerRepositoryId === null) { $providerRepositoryId = $site->getAttribute('providerRepositoryId', ''); diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Create.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Create.php index ebe06d0ccf..8f288c45d1 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Create.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Create.php @@ -129,8 +129,8 @@ class Create extends Action '$id' => $index['$id'], 'type' => $index['type'], 'attributes' => $index['attributes'], - 'lengths' => $index['lengths'], - 'orders' => $index['orders'], + 'lengths' => $index['lengths'] ?? [], + 'orders' => $index['orders'] ?? [], ]); } diff --git a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php index 19d9237ff1..92db118c46 100644 --- a/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php +++ b/src/Appwrite/Platform/Modules/Teams/Http/Memberships/Create.php @@ -418,6 +418,7 @@ class Create extends Action recipient: $invitee->getAttribute('email'), name: $invitee->getAttribute('name', ''), subject: $subject, + template: MAIL_TEMPLATE_INVITATION, body: $body, preview: $preview, smtp: $smtpConfig, diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php index 3e11a4060c..75f3c5bf18 100644 --- a/src/Appwrite/Platform/Tasks/Install.php +++ b/src/Appwrite/Platform/Tasks/Install.php @@ -538,6 +538,19 @@ class Install extends Action $assistantKey = (string) ($input['_APP_ASSISTANT_OPENAI_API_KEY'] ?? ''); $enableAssistant = trim($assistantKey) !== ''; + $enabledRuntimes = \array_unique(\array_filter(\array_map( + 'trim', + \explode(',', ($input['_APP_FUNCTIONS_RUNTIMES'] ?? '') . ',' . ($input['_APP_SITES_RUNTIMES'] ?? '')) + ))); + $runtimes = Config::getParam('runtimes', []); + $runtimeImages = []; + foreach ($enabledRuntimes as $runtime) { + $imageName = $runtimes[$runtime]['image'] ?? ''; + if ($imageName !== '') { + $runtimeImages[] = $imageName; + } + } + $executorImages = \implode(',', \array_unique($runtimeImages)); $templateForCompose ->setParam('httpPort', $httpPort) @@ -547,17 +560,24 @@ class Install extends Action ->setParam('image', $image) ->setParam('database', $database) ->setParam('hostPath', $this->hostPath) - ->setParam('enableAssistant', $enableAssistant); + ->setParam('enableAssistant', $enableAssistant) + ->setParam('executorImages', $executorImages); $templateForEnv->setParam('vars', $input); $steps = [ InstallerServer::STEP_DOCKER_COMPOSE, InstallerServer::STEP_ENV_VARS, - InstallerServer::STEP_DOCKER_CONTAINERS + InstallerServer::STEP_DOCKER_CONTAINERS, + InstallerServer::STEP_ACCOUNT_SETUP, + InstallerServer::STEP_MIGRATION, ]; $startIndex = 0; + $resumeFromStep = match ($resumeFromStep) { + InstallerServer::STEP_CONFIG_FILES => InstallerServer::STEP_DOCKER_COMPOSE, + default => $resumeFromStep, + }; if ($resumeFromStep !== null) { $resumeIndex = array_search($resumeFromStep, $steps, true); if ($resumeIndex !== false) { @@ -597,37 +617,43 @@ class Install extends Action $this->updateProgress($progress, InstallerServer::STEP_CONFIG_FILES, InstallerServer::STATUS_COMPLETED, $messages); } - if ($database === 'mongodb' && !$useExistingConfig) { + if ($database === 'mongodb' && !$useExistingConfig && $startIndex <= 1) { $this->copyMongoEntrypointIfNeeded(); } if (!$noStart) { - $currentStep = InstallerServer::STEP_DOCKER_CONTAINERS; - $this->updateProgress($progress, InstallerServer::STEP_DOCKER_CONTAINERS, InstallerServer::STATUS_IN_PROGRESS, $messages); - $this->runDockerCompose($input, $isLocalInstall, $useExistingConfig, $isCLI, $progress, $isUpgrade); + $shouldStartContainers = $startIndex <= 2; + if ($shouldStartContainers) { + $currentStep = InstallerServer::STEP_DOCKER_CONTAINERS; + $this->updateProgress($progress, InstallerServer::STEP_DOCKER_CONTAINERS, InstallerServer::STATUS_IN_PROGRESS, $messages); + $this->runDockerCompose($input, $isLocalInstall, $useExistingConfig, $isCLI, $progress, $isUpgrade); - if (!$isUpgrade) { - $this->updateProgress($progress, InstallerServer::STEP_DOCKER_CONTAINERS, InstallerServer::STATUS_COMPLETED, $messages); - $this->updateProgress($progress, InstallerServer::STEP_ACCOUNT_SETUP, InstallerServer::STATUS_IN_PROGRESS, messageOverride: 'Creating Appwrite account...'); + if (!$isUpgrade) { + $this->updateProgress($progress, InstallerServer::STEP_DOCKER_CONTAINERS, InstallerServer::STATUS_COMPLETED, $messages); + $this->updateProgress($progress, InstallerServer::STEP_ACCOUNT_SETUP, InstallerServer::STATUS_IN_PROGRESS, messageOverride: 'Creating Appwrite account...'); + } } - if (!$isLocalInstall) { + if (!$isLocalInstall || file_exists('/.dockerenv') || file_exists('/run/.containerenv')) { $this->connectInstallerToAppwriteNetwork(); } $domain = $input['_APP_DOMAIN'] ?? 'localhost'; $healthStep = $isUpgrade ? InstallerServer::STEP_DOCKER_CONTAINERS : InstallerServer::STEP_ACCOUNT_SETUP; + if ($isUpgrade && $startIndex >= 4) { + $healthStep = InstallerServer::STEP_MIGRATION; + } if (!$isUpgrade) { $currentStep = InstallerServer::STEP_ACCOUNT_SETUP; } $apiUrl = $this->waitForApiReady($domain, $httpPort, $isLocalInstall, $progress, $healthStep); - if ($isUpgrade) { + if ($isUpgrade && $shouldStartContainers) { $this->updateProgress($progress, InstallerServer::STEP_DOCKER_CONTAINERS, InstallerServer::STATUS_COMPLETED, $messages); } - if (!$isUpgrade) { + if (!$isUpgrade && $startIndex <= 3) { $this->createInitialAdminAccount($account, $progress, $apiUrl, $domain); } @@ -762,13 +788,30 @@ class Install extends Action // Allow the SSE chunk to flush before the blocking exec usleep(100_000); - // Static command — no user input involved - $command = $isLocalInstall - ? 'docker compose exec appwrite migrate 2>&1' - : 'docker exec appwrite migrate 2>&1'; + if ($isLocalInstall) { + $composePath = $this->hostPath !== '' ? $this->hostPath : $this->path; + $command = [ + 'docker', + 'compose', + '--env-file', + $composePath . '/' . $this->getEnvFileName(), + '-f', + $composePath . '/' . $this->getComposeFileName(), + '--project-name', + 'appwrite', + '--project-directory', + $composePath, + 'exec', + 'appwrite', + 'migrate', + ]; + } else { + $command = ['docker', 'exec', 'appwrite', 'migrate']; + } + $commandLine = implode(' ', array_map(escapeshellarg(...), $command)); $output = []; - \exec($command, $output, $exit); + \exec($commandLine . ' 2>&1', $output, $exit); if ($exit !== 0) { $message = trim(implode("\n", $output)); @@ -856,9 +899,9 @@ class Install extends Action * the runtime context and returns whichever responds first. * * Candidates (in order of preference): - * - Docker internal DNS (http://appwrite) — only if on the appwrite network - * - host.docker.internal:{port} — reaches host-published ports from inside a container + * - Docker internal DNS (http://appwrite) — preferred when on the appwrite network * - localhost:{port} — works when running directly on the host (local dev) + * - host.docker.internal:{port} — non-local fallback for host-published ports */ private function waitForApiReady(string $domain, string $httpPort, bool $isLocalInstall, ?callable $progress, string $step = InstallerServer::STEP_ACCOUNT_SETUP): string { @@ -872,6 +915,7 @@ class Install extends Action if ($isLocalInstall) { $candidates = [ + self::APPWRITE_API_URL . $healthPath, 'http://localhost:' . $httpPort . $healthPath, ]; } else { @@ -1081,12 +1125,18 @@ class Install extends Action Console::log("Running \"docker compose up -d --remove-orphans --renew-anon-volumes\""); } - $composeFileName = $this->getComposeFileName(); - $composeFile = $this->path . '/' . $composeFileName; + $composePath = $this->path; + if ($isLocalInstall && $this->hostPath !== '') { + $composePath = $this->hostPath; + } + $composeFile = $composePath . '/' . $this->getComposeFileName(); + $envFile = $composePath . '/' . $this->getEnvFileName(); $command = [ 'docker', 'compose', + '--env-file', + $envFile, '-f', $composeFile, ]; @@ -1097,7 +1147,7 @@ class Install extends Action } $command[] = '--project-directory'; - $command[] = $this->path; + $command[] = $composePath; $command[] = 'up'; $command[] = '-d'; $command[] = '--remove-orphans'; diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index bd2a03ecf0..e7f5167611 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -180,20 +180,29 @@ class Specs extends Action 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', - 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by ID', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', - 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by email', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', - 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by phone', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], ], APP_SDK_PLATFORM_SERVER => [ @@ -258,20 +267,29 @@ class Specs extends Action 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', - 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by ID', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', - 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by email', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', - 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by phone', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], ], APP_SDK_PLATFORM_CONSOLE => [ @@ -336,20 +354,29 @@ class Specs extends Action 'ImpersonateUserId' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Id', - 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by ID', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', - 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by email', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', - 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', + 'description' => 'Impersonate a user by phone', 'in' => 'header', + 'x-appwrite' => [ + 'optional' => true, + ], ], ], ]; diff --git a/src/Appwrite/Platform/Workers/Audits.php b/src/Appwrite/Platform/Workers/Audits.php index e0f50756cb..6c45aa63f3 100644 --- a/src/Appwrite/Platform/Workers/Audits.php +++ b/src/Appwrite/Platform/Workers/Audits.php @@ -5,11 +5,11 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Message\Audit; use Exception; use Throwable; -use Utopia\Console; use Utopia\Database\Document; use Utopia\Database\Exception\Structure; use Utopia\Platform\Action; use Utopia\Queue\Message; +use Utopia\Span\Span; use Utopia\System\System; class Audits extends Action @@ -63,8 +63,6 @@ class Audits extends Action $auditMessage = Audit::fromArray($payload); - Console::info('Aggregating audit logs'); - $event = $auditMessage->event; $auditPayload = ''; @@ -123,10 +121,11 @@ class Audits extends Action ]; } - if (isset($this->logs[$auditMessage->project->getSequence()])) { - $this->logs[$auditMessage->project->getSequence()]['logs'][] = $eventData; + $projectSequence = (string) $auditMessage->project->getSequence(); + if (isset($this->logs[$projectSequence])) { + $this->logs[$projectSequence]['logs'][] = $eventData; } else { - $this->logs[$auditMessage->project->getSequence()] = [ + $this->logs[$projectSequence] = [ 'project' => new Document([ '$id' => $auditMessage->project->getId(), '$sequence' => $auditMessage->project->getSequence(), @@ -148,22 +147,25 @@ class Audits extends Action return; } + $projects = 0; + $events = 0; foreach ($this->logs as $sequence => $projectLogs) { try { - Console::log('Processing Project "' . $sequence . '" batch with ' . count($projectLogs['logs']) . ' events'); - - $projectDocument = $projectLogs['project']; - $audit = $getAudit($projectDocument); + $audit = $getAudit($projectLogs['project']); $audit->logBatch($projectLogs['logs']); - Console::success('Audit logs processed successfully'); + $projects++; + $events += count($projectLogs['logs']); } catch (Throwable $e) { - Console::error('Error processing audit logs for Project "' . $sequence . '": ' . $e->getMessage()); + Span::add('audits.error', $e->getMessage()); } finally { unset($this->logs[$sequence]); } } + Span::add('audits.projects', $projects); + Span::add('audits.count', $events); + $this->lastTriggeredTime = time(); } } diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 4a31216599..89da7d01de 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -572,6 +572,7 @@ class Certificates extends Action recipient: System::getEnv('_APP_EMAIL_CERTIFICATES', System::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS')), name: 'Appwrite Administrator', subject: $subject, + template: MAIL_TEMPLATE_CERTIFICATE_FAILED, bodyTemplate: __DIR__ . '/../../../../app/config/locale/templates/email-base-styled.tpl', body: $body, preview: $preview, diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 9eda3dbd52..1ac808c682 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -1106,7 +1106,7 @@ class Deletes extends Action // fast path, no need to list anything! $delete($dbForProject, $resourceInternalId, $resourceType); } else { - $processResource = function (string $type) use ($dbForProject, $delete) { + foreach ([RESOURCE_TYPE_SITES, RESOURCE_TYPE_FUNCTIONS] as $type) { $this->listByGroup( collection: $type, queries: [Query::select(['$id', '$sequence'])], @@ -1115,13 +1115,7 @@ class Deletes extends Action $delete($dbForProject, $resource->getSequence(), $type); } ); - }; - - /* perform processing in parallel */ - batch([ - fn () => $processResource(RESOURCE_TYPE_SITES), - fn () => $processResource(RESOURCE_TYPE_FUNCTIONS), - ]); + } } } diff --git a/src/Appwrite/Platform/Workers/Executions.php b/src/Appwrite/Platform/Workers/Executions.php index 8dbf10cae6..30b4a43a55 100644 --- a/src/Appwrite/Platform/Workers/Executions.php +++ b/src/Appwrite/Platform/Workers/Executions.php @@ -3,6 +3,7 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Message\Execution; +use Appwrite\Event\Message\Executions as ExecutionsMessage; use Exception; use Utopia\Database\Database; use Utopia\Platform\Action; @@ -11,6 +12,8 @@ use Utopia\Span\Span; class Executions extends Action { + private const int UPSERT_BATCH_SIZE = 100; + public static function getName(): string { return 'executions'; @@ -33,19 +36,36 @@ class Executions extends Action Message $message, Database $dbForProject, ): void { - $executionMessage = Execution::fromArray($message->getPayload()); - $execution = $executionMessage->execution; + $payload = $message->getPayload(); + $isBatch = isset($payload['executions']) && \is_array($payload['executions']); - if ($execution->isEmpty()) { - throw new Exception('Missing execution'); + if ($isBatch) { + $executionMessage = ExecutionsMessage::fromArray($payload); + $executions = \array_values(\array_filter( + $executionMessage->executions, + fn ($execution) => !$execution->isEmpty() + )); + } else { + $executionMessage = Execution::fromArray($payload); + $executions = [$executionMessage->execution]; + } + + if (empty($executions)) { + throw new Exception($isBatch ? 'Missing executions' : 'Missing execution'); } Span::add('project.id', $executionMessage->project->getId()); - Span::add('function.id', $execution->getAttribute('resourceId', '')); - Span::add('execution.id', $execution->getId()); - Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); - Span::add('resource.type', $execution->getAttribute('resourceType', '')); - $dbForProject->upsertDocument('executions', $execution); + if ($isBatch) { + Span::add('executions.count', \count($executions)); + $dbForProject->upsertDocuments('executions', $executions, self::UPSERT_BATCH_SIZE); + } else { + $execution = $executions[0]; + Span::add('function.id', $execution->getAttribute('resourceId', '')); + Span::add('execution.id', $execution->getId()); + Span::add('deployment.id', $execution->getAttribute('deploymentId', '')); + Span::add('resource.type', $execution->getAttribute('resourceType', '')); + $dbForProject->upsertDocument('executions', $execution); + } } } diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index 5cd4639988..48cb58722d 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -14,7 +14,9 @@ use Utopia\Messaging\Messages\Email\Attachment; use Utopia\Platform\Action; use Utopia\Queue\Message; use Utopia\Registry\Registry; +use Utopia\Span\Span; use Utopia\System\System; +use Utopia\Telemetry\Adapter as Telemetry; class Mails extends Action { @@ -39,6 +41,7 @@ class Mails extends Action ->inject('project') ->inject('register') ->inject('log') + ->inject('telemetry') ->callback($this->action(...)); } @@ -55,10 +58,11 @@ class Mails extends Action * @param Document $project * @param Registry $register * @param Log $log + * @param Telemetry $telemetry * @return void * @throws Exception */ - public function action(Message $message, Document $project, Registry $register, Log $log): void + public function action(Message $message, Document $project, Registry $register, Log $log, Telemetry $telemetry): void { Runtime::setHookFlags(SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP); $payload = $message->getPayload(); @@ -81,6 +85,12 @@ class Mails extends Action $recipient = $payload['recipient']; $subject = $payload['subject']; + $template = $payload['template'] ?? 'unknown'; + $recipientDomain = \strtolower(\substr(\strrchr($recipient, '@') ?: '', 1)); + + Span::add('mail.template', $template); + Span::add('mail.smtp_type', $type); + Span::add('mail.recipient_domain', $recipientDomain); $variables = $payload['variables']; $variables['host'] = $protocol . '://' . $hostname; $name = $payload['name']; @@ -150,6 +160,7 @@ class Mails extends Action keepAlive: true, timelimit: 30, ); + $adapter->setTelemetry($telemetry); // Resolve from/replyTo using fallback hierarchy: Custom options > SMTP config > Defaults $defaultFromEmail = System::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM); @@ -202,14 +213,19 @@ class Mails extends Action attachments: $attachments, html: true, ); + $emailMessage->setOrigin(MESSAGE_SEND_TYPE_INTERNAL); try { $adapter->send($emailMessage); } catch (\Throwable $error) { + Span::add('mail.status', 'failure'); + if ($type === 'smtp') { throw new Exception('Error sending mail: ' . $error->getMessage(), 401); } throw new Exception('Error sending mail: ' . $error->getMessage(), 500); } + + Span::add('mail.status', 'success'); } } diff --git a/src/Appwrite/Platform/Workers/Messaging.php b/src/Appwrite/Platform/Workers/Messaging.php index ddd7edf641..2a827f82cb 100644 --- a/src/Appwrite/Platform/Workers/Messaging.php +++ b/src/Appwrite/Platform/Workers/Messaging.php @@ -49,6 +49,7 @@ use Utopia\Storage\Device; use Utopia\Storage\Device\Local; use Utopia\Storage\Storage; use Utopia\System\System; +use Utopia\Telemetry\Adapter as Telemetry; use function Swoole\Coroutine\batch; @@ -56,6 +57,8 @@ class Messaging extends Action { private ?SMSAdapter $adapter = null; + private Telemetry $telemetry; + public static function getName(): string { return 'messaging'; @@ -74,6 +77,7 @@ class Messaging extends Action ->inject('dbForProject') ->inject('deviceForFiles') ->inject('publisherForUsage') + ->inject('telemetry') ->callback($this->action(...)); } @@ -84,6 +88,7 @@ class Messaging extends Action * @param Database $dbForProject * @param Device $deviceForFiles * @param UsagePublisher $publisherForUsage + * @param Telemetry $telemetry * @return void * @throws \Exception */ @@ -93,9 +98,12 @@ class Messaging extends Action Log $log, Database $dbForProject, Device $deviceForFiles, - UsagePublisher $publisherForUsage + UsagePublisher $publisherForUsage, + Telemetry $telemetry ): void { Runtime::setHookFlags(SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP); + + $this->telemetry = $telemetry; $payload = $message->getPayload(); if (empty($payload)) { @@ -143,6 +151,8 @@ class Messaging extends Action $userIds = $message->getAttribute('users', []); $providerType = $message->getAttribute('providerType'); + Span::add('message.provider_type', $providerType); + $default = $dbForProject->findOne('providers', [ Query::equal('enabled', [true]), Query::equal('type', [$providerType]), @@ -268,6 +278,11 @@ class Messaging extends Action $message->setAttribute('search', "{$message->getAttribute('search')} {$provider->getAttribute('name')} {$provider->getAttribute('provider')} {$provider->getAttribute('type')}"); } + Span::add('message.providers', \implode(',', \array_unique(\array_map( + fn (Document $provider) => $provider->getAttribute('provider'), + \array_values($providers) + )))); + $message->setAttribute('deliveredTotal', $deliveredTotal); $message->setAttribute('deliveredAt', DateTime::now()); @@ -533,6 +548,7 @@ class Messaging extends Action ] = $this->retrySend($batch, $message, $provider, $providerType, $adapter, $dbForProject, $deviceForFiles, $project); $failed = $recipients - $delivered; + $usage = new UsageContext(); $usage ->addMetric(METRIC_MESSAGES, $recipients) @@ -758,12 +774,16 @@ class Messaging extends Action $messageData = clone $message; $messageData->setAttribute('to', $to); - return match ($providerType) { + $data = match ($providerType) { MESSAGE_TYPE_SMS => $this->buildSmsMessage($messageData, $provider), MESSAGE_TYPE_PUSH => $this->buildPushMessage($messageData), MESSAGE_TYPE_EMAIL => $this->buildEmailMessage($dbForProject, $messageData, $provider, $deviceForFiles, $project), default => throw new \Exception('Provider with the requested ID is of the incorrect type') }; + + $data->setOrigin(MESSAGE_SEND_TYPE_EXTERNAL); + + return $data; } private function sendInternalSMSMessage(Document $message, Document $project, array $recipients, Log $log): void @@ -802,6 +822,7 @@ class Messaging extends Action $message->getAttribute('data')['content'], $from ); + $sms->setOrigin(MESSAGE_SEND_TYPE_INTERNAL); $this->adapter->send($sms); } @@ -811,7 +832,7 @@ class Messaging extends Action { $credentials = $provider->getAttribute('credentials'); - return match ($provider->getAttribute('provider')) { + $adapter = match ($provider->getAttribute('provider')) { 'mock' => (new Mock('username', 'password'))->setEndpoint('http://request-catcher-sms:5000/'), 'twilio' => new Twilio( $credentials['accountSid'] ?? '', @@ -848,6 +869,12 @@ class Messaging extends Action ), default => null }; + + if ($adapter !== null) { + $adapter->setTelemetry($this->telemetry); + } + + return $adapter; } protected function getPushAdapter(Document $provider): ?PushAdapter @@ -855,7 +882,7 @@ class Messaging extends Action $credentials = $provider->getAttribute('credentials'); $options = $provider->getAttribute('options'); - return match ($provider->getAttribute('provider')) { + $adapter = match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'apns' => new APNS( $credentials['authKey'] ?? '', @@ -867,6 +894,12 @@ class Messaging extends Action 'fcm' => new FCM(\json_encode($credentials['serviceAccountJSON'])), default => null }; + + if ($adapter !== null) { + $adapter->setTelemetry($this->telemetry); + } + + return $adapter; } protected function getEmailAdapter(Document $provider): ?EmailAdapter @@ -875,7 +908,7 @@ class Messaging extends Action $options = $provider->getAttribute('options', []); $apiKey = $credentials['apiKey'] ?? ''; - return match ($provider->getAttribute('provider')) { + $adapter = match ($provider->getAttribute('provider')) { 'mock' => new Mock('username', 'password'), 'smtp' => new SMTP( $credentials['host'] ?? '', @@ -901,6 +934,12 @@ class Messaging extends Action ), default => null }; + + if ($adapter !== null) { + $adapter->setTelemetry($this->telemetry); + } + + return $adapter; } private function buildEmailMessage( @@ -1117,6 +1156,7 @@ class Messaging extends Action $defaultProvider = $this->createProviderFromDSN($defaultDSN); $adapter = $this->getSmsAdapter($defaultProvider); $geosms = new GEOSMS($adapter); + $geosms->setTelemetry($this->telemetry); /** @var DSN $localDSN */ foreach ($localDSNs as $localDSN) { diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index a6f65fc742..825caf764d 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -947,6 +947,7 @@ class Migrations extends Action recipient: $user->getAttribute('email'), name: $user->getAttribute('name', $user->getAttribute('email')), subject: $subject, + template: MAIL_TEMPLATE_DATA_EXPORT, bodyTemplate: __DIR__ . '/../../../../app/config/locale/templates/email-base-styled.tpl', body: $emailBody, preview: $preview, diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index d91425d59b..593fd39767 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -272,6 +272,7 @@ class Webhooks extends Action recipient: $user->getAttribute('email'), name: $user->getAttribute('name', ''), subject: $subject, + template: MAIL_TEMPLATE_WEBHOOK_FAILED, body: $body->render(), preview: $preview, variables: ['user' => $user->getAttribute('name', '')], diff --git a/tests/e2e/Services/Project/VariablesBase.php b/tests/e2e/Services/Project/VariablesBase.php index b1f8ed61b9..c6cf4115f2 100644 --- a/tests/e2e/Services/Project/VariablesBase.php +++ b/tests/e2e/Services/Project/VariablesBase.php @@ -3,7 +3,6 @@ namespace Tests\E2E\Services\Project; use Appwrite\Tests\Async; -use Appwrite\Tests\Async\Exceptions\Critical; use CURLFile; use Tests\E2E\Client; use Utopia\Console; @@ -11,7 +10,6 @@ use Utopia\Database\Document; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; -use Utopia\System\System; trait VariablesBase { @@ -738,246 +736,6 @@ trait VariablesBase $this->assertSame('variable_not_found', $delete['body']['type']); } - // Integration tests - - /** - * Test that project variables are available in function build and runtime. - */ - public function testProjectVariableInFunction(): void - { - $projectId = $this->getProject()['$id']; - $apiKey = $this->getProject()['apiKey']; - - // 1. Create a project variable - $variable = $this->createVariable( - ID::unique(), - 'GLOBAL_VARIABLE', - 'Project Variable Value', - false - ); - - $this->assertSame(201, $variable['headers']['status-code']); - $variableId = $variable['body']['$id']; - - // 2. Create a function with build commands that echo the variable - $function = $this->client->call(Client::METHOD_POST, '/functions', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ], [ - 'functionId' => ID::unique(), - 'name' => 'Project Variable Test', - 'runtime' => 'node-22', - 'entrypoint' => 'index.js', - 'execute' => ['any'], - 'timeout' => 15, - 'commands' => 'echo $GLOBAL_VARIABLE', - ]); - - $this->assertSame(201, $function['headers']['status-code']); - $functionId = $function['body']['$id']; - - // 3. Deploy the function (basic function reads GLOBAL_VARIABLE from env) - $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', [ - 'content-type' => 'multipart/form-data', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ], [ - 'code' => $this->packageCode('functions', 'basic'), - 'activate' => true, - ]); - - $this->assertSame(202, $deployment['headers']['status-code']); - $deploymentId = $deployment['body']['$id'] ?? ''; - - // 4. Wait for deployment to be ready and activated - $this->assertEventually(function () use ($projectId, $apiKey, $functionId, $deploymentId) { - $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/deployments/' . $deploymentId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - - $status = $deployment['body']['status'] ?? ''; - if ($status === 'failed') { - throw new Critical('Deployment build failed: ' . ($deployment['body']['buildLogs'] ?? 'no logs')); - } - - $this->assertSame('ready', $status, 'Deployment status is not ready'); - }, 120000, 500); - - $this->assertEventually(function () use ($projectId, $apiKey, $functionId, $deploymentId) { - $function = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->assertSame($deploymentId, $function['body']['deploymentId'] ?? ''); - }, 120000, 500); - - // 5. Verify the project variable was available during build - $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/deployments/' . $deploymentId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->assertSame(200, $deployment['headers']['status-code']); - $this->assertStringContainsString('Project Variable Value', $deployment['body']['buildLogs']); - - // 6. Execute the function and verify the project variable is in runtime output - $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), [ - 'async' => false, - ]); - - $this->assertSame(201, $execution['headers']['status-code']); - $this->assertSame('completed', $execution['body']['status']); - $this->assertSame(200, $execution['body']['responseStatusCode']); - $output = json_decode($execution['body']['responseBody'], true); - $this->assertSame('Project Variable Value', $output['GLOBAL_VARIABLE']); - - // Cleanup - $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->deleteVariable($variableId); - } - - /** - * Test that project variables are available in site build and SSR runtime. - */ - public function testProjectVariableInSite(): void - { - $projectId = $this->getProject()['$id']; - $apiKey = $this->getProject()['apiKey']; - - // 1. Create a project variable - $variable = $this->createVariable( - ID::unique(), - 'name', - 'ProjectVarTest', - ); - - $this->assertSame(201, $variable['headers']['status-code']); - $variableId = $variable['body']['$id']; - - // 2. Create a site - $site = $this->client->call(Client::METHOD_POST, '/sites', [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ], [ - 'siteId' => ID::unique(), - 'name' => 'Project Variable Astro Site', - 'framework' => 'astro', - 'adapter' => 'ssr', - 'buildRuntime' => 'node-22', - 'outputDirectory' => './dist', - 'buildCommand' => 'echo $name && npm run build', - 'installCommand' => 'npm ci', - 'fallbackFile' => '', - ]); - - $this->assertSame(201, $site['headers']['status-code']); - $siteId = $site['body']['$id']; - - // 3. Setup domain for proxy access - $sitesDomain = \explode(',', System::getEnv('_APP_DOMAIN_SITES', ''))[0]; - $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/site', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), [ - 'domain' => ID::unique() . '.' . $sitesDomain, - 'siteId' => $siteId, - ]); - - $this->assertSame(201, $rule['headers']['status-code']); - - // 4. Deploy the site (astro site reads import.meta.env.name) - $deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', [ - 'content-type' => 'multipart/form-data', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ], [ - 'code' => $this->packageCode('sites', 'astro'), - 'activate' => 'true', - ]); - - $this->assertSame(202, $deployment['headers']['status-code']); - $deploymentId = $deployment['body']['$id'] ?? ''; - - // 5. Wait for deployment to be ready and activated - $this->assertEventually(function () use ($projectId, $apiKey, $siteId, $deploymentId) { - $deployment = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - - $status = $deployment['body']['status'] ?? ''; - if ($status === 'failed') { - throw new Critical('Site deployment failed: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); - } - - $this->assertSame('ready', $status, 'Deployment status is not ready'); - }, 120000, 500); - - $this->assertEventually(function () use ($projectId, $apiKey, $siteId, $deploymentId) { - $site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->assertSame($deploymentId, $site['body']['deploymentId'] ?? ''); - }, 120000, 500); - - // 6. Verify the project variable was available during build - $deployment = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->assertSame(200, $deployment['headers']['status-code']); - $this->assertStringContainsString('ProjectVarTest', $deployment['body']['buildLogs']); - - // 7. Get the domain and access the site - $rules = $this->client->call(Client::METHOD_GET, '/proxy/rules', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - ], $this->getHeaders()), [ - 'queries' => [ - Query::equal('deploymentResourceId', [$siteId])->toString(), - Query::equal('trigger', ['manual'])->toString(), - Query::equal('type', ['deployment'])->toString(), - ], - ]); - - $this->assertSame(200, $rules['headers']['status-code']); - $this->assertGreaterThanOrEqual(1, \count($rules['body']['rules'])); - $domain = $rules['body']['rules'][0]['domain']; - - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://' . $domain); - - $response = $proxyClient->call(Client::METHOD_GET, '/'); - - $this->assertSame(200, $response['headers']['status-code']); - $this->assertStringContainsString('Env variable is ProjectVarTest', $response['body']); - $this->assertStringNotContainsString('Variable not found', $response['body']); - - // Cleanup - $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $projectId, - 'x-appwrite-key' => $apiKey, - ]); - $this->deleteVariable($variableId); - } - // Helpers protected function createVariable(string $variableId, ?string $key, ?string $value, ?bool $secret = null, bool $authenticated = true): mixed diff --git a/tests/e2e/Services/Project/VariablesCustomServerTest.php b/tests/e2e/Services/Project/VariablesCustomServerTest.php index f4af7069cb..6c710fecf2 100644 --- a/tests/e2e/Services/Project/VariablesCustomServerTest.php +++ b/tests/e2e/Services/Project/VariablesCustomServerTest.php @@ -4,13 +4,256 @@ declare(strict_types=1); namespace Tests\E2E\Services\Project; +use Appwrite\Tests\Async\Exceptions\Critical; +use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\SideServer; +use Utopia\Database\Helpers\ID; +use Utopia\Database\Query; +use Utopia\System\System; final class VariablesCustomServerTest extends Scope { use VariablesBase; use ProjectCustom; use SideServer; + + /** + * Test that project variables are available in function build and runtime. + */ + public function testProjectVariableInFunction(): void + { + $projectId = $this->getProject()['$id']; + $apiKey = $this->getProject()['apiKey']; + + // 1. Create a project variable + $variable = $this->createVariable( + ID::unique(), + 'GLOBAL_VARIABLE', + 'Project Variable Value', + false + ); + + $this->assertSame(201, $variable['headers']['status-code']); + $variableId = $variable['body']['$id']; + + // 2. Create a function with build commands that echo the variable + $function = $this->client->call(Client::METHOD_POST, '/functions', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ], [ + 'functionId' => ID::unique(), + 'name' => 'Project Variable Test', + 'runtime' => 'node-22', + 'entrypoint' => 'index.js', + 'execute' => ['any'], + 'timeout' => 15, + 'commands' => 'echo $GLOBAL_VARIABLE', + ]); + + $this->assertSame(201, $function['headers']['status-code']); + $functionId = $function['body']['$id']; + + // 3. Deploy the function (basic function reads GLOBAL_VARIABLE from env) + $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', [ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ], [ + 'code' => $this->packageCode('functions', 'basic'), + 'activate' => true, + ]); + + $this->assertSame(202, $deployment['headers']['status-code']); + $deploymentId = $deployment['body']['$id'] ?? ''; + + // 4. Wait for deployment to be ready and activated + $this->assertEventually(function () use ($projectId, $apiKey, $functionId, $deploymentId) { + $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/deployments/' . $deploymentId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + + $status = $deployment['body']['status'] ?? ''; + if ($status === 'failed') { + throw new Critical('Deployment build failed: ' . ($deployment['body']['buildLogs'] ?? 'no logs')); + } + + $this->assertSame('ready', $status, 'Deployment status is not ready'); + }, 120000, 500); + + $this->assertEventually(function () use ($projectId, $apiKey, $functionId, $deploymentId) { + $function = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->assertSame($deploymentId, $function['body']['deploymentId'] ?? ''); + }, 120000, 500); + + // 5. Verify the project variable was available during build + $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/deployments/' . $deploymentId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->assertSame(200, $deployment['headers']['status-code']); + $this->assertStringContainsString('Project Variable Value', (string) $deployment['body']['buildLogs']); + + // 6. Execute the function and verify the project variable is in runtime output + $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), [ + 'async' => false, + ]); + + $this->assertSame(201, $execution['headers']['status-code']); + $this->assertSame('completed', $execution['body']['status']); + $this->assertSame(200, $execution['body']['responseStatusCode']); + $output = json_decode($execution['body']['responseBody'], true); + $this->assertSame('Project Variable Value', $output['GLOBAL_VARIABLE']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->deleteVariable($variableId); + } + + /** + * Test that project variables are available in site build and SSR runtime. + */ + public function testProjectVariableInSite(): void + { + $projectId = $this->getProject()['$id']; + $apiKey = $this->getProject()['apiKey']; + + // 1. Create a project variable + $variable = $this->createVariable( + ID::unique(), + 'name', + 'ProjectVarTest', + ); + + $this->assertSame(201, $variable['headers']['status-code']); + $variableId = $variable['body']['$id']; + + // 2. Create a site + $site = $this->client->call(Client::METHOD_POST, '/sites', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ], [ + 'siteId' => ID::unique(), + 'name' => 'Project Variable Astro Site', + 'framework' => 'astro', + 'adapter' => 'ssr', + 'buildRuntime' => 'node-22', + 'outputDirectory' => './dist', + 'buildCommand' => 'echo $name && npm run build', + 'installCommand' => 'npm ci', + 'fallbackFile' => '', + ]); + + $this->assertSame(201, $site['headers']['status-code']); + $siteId = $site['body']['$id']; + + // 3. Setup domain for proxy access + $sitesDomain = \explode(',', System::getEnv('_APP_DOMAIN_SITES', ''))[0]; + $rule = $this->client->call(Client::METHOD_POST, '/proxy/rules/site', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), [ + 'domain' => ID::unique() . '.' . $sitesDomain, + 'siteId' => $siteId, + ]); + + $this->assertSame(201, $rule['headers']['status-code']); + + // 4. Deploy the site (astro site reads import.meta.env.name) + $deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', [ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ], [ + 'code' => $this->packageCode('sites', 'astro'), + 'activate' => 'true', + ]); + + $this->assertSame(202, $deployment['headers']['status-code']); + $deploymentId = $deployment['body']['$id'] ?? ''; + + // 5. Wait for deployment to be ready and activated + $this->assertEventually(function () use ($projectId, $apiKey, $siteId, $deploymentId) { + $deployment = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + + $status = $deployment['body']['status'] ?? ''; + if ($status === 'failed') { + throw new Critical('Site deployment failed: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT)); + } + + $this->assertSame('ready', $status, 'Deployment status is not ready'); + }, 120000, 500); + + $this->assertEventually(function () use ($projectId, $apiKey, $siteId, $deploymentId) { + $site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->assertSame($deploymentId, $site['body']['deploymentId'] ?? ''); + }, 120000, 500); + + // 6. Verify the project variable was available during build + $deployment = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->assertSame(200, $deployment['headers']['status-code']); + $this->assertStringContainsString('ProjectVarTest', (string) $deployment['body']['buildLogs']); + + // 7. Get the domain and access the site + $rules = $this->client->call(Client::METHOD_GET, '/proxy/rules', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + ], $this->getHeaders()), [ + 'queries' => [ + Query::equal('deploymentResourceId', [$siteId])->toString(), + Query::equal('trigger', ['manual'])->toString(), + Query::equal('type', ['deployment'])->toString(), + ], + ]); + + $this->assertSame(200, $rules['headers']['status-code']); + $this->assertGreaterThanOrEqual(1, \count($rules['body']['rules'])); + $domain = $rules['body']['rules'][0]['domain']; + + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + + $this->assertSame(200, $response['headers']['status-code']); + $this->assertStringContainsString('Env variable is ProjectVarTest', (string) $response['body']); + $this->assertStringNotContainsString('Variable not found', (string) $response['body']); + + // Cleanup + $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $projectId, + 'x-appwrite-key' => $apiKey, + ]); + $this->deleteVariable($variableId); + } } diff --git a/tests/e2e/Services/VCS/VCSConsoleClientTest.php b/tests/e2e/Services/VCS/VCSConsoleClientTest.php index 041f825cee..e936013a90 100644 --- a/tests/e2e/Services/VCS/VCSConsoleClientTest.php +++ b/tests/e2e/Services/VCS/VCSConsoleClientTest.php @@ -715,6 +715,112 @@ final class VCSConsoleClientTest extends Scope ], $this->getHeaders())); } + public function testCrossProjectInstallationRejected(): void + { + $installationId = $this->setupInstallation(); + $consoleHeaders = [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ]; + + $team = $this->client->call(Client::METHOD_POST, '/teams', $consoleHeaders, [ + 'teamId' => ID::unique(), + 'name' => 'Cross Project Team', + ]); + $this->assertEquals(201, $team['headers']['status-code']); + + $project2 = $this->client->call(Client::METHOD_POST, '/projects', $consoleHeaders, [ + 'projectId' => ID::unique(), + 'name' => 'Cross Project Test', + 'teamId' => $team['body']['$id'], + 'region' => System::getEnv('_APP_REGION', 'default'), + ]); + $this->assertEquals(201, $project2['headers']['status-code']); + $project2Id = $project2['body']['$id']; + + $key = $this->client->call(Client::METHOD_POST, '/projects/' . $project2Id . '/keys', $consoleHeaders, [ + 'keyId' => ID::unique(), + 'name' => 'Test Key', + 'scopes' => ['functions.write', 'sites.write'], + ]); + $this->assertEquals(201, $key['headers']['status-code']); + + $headers2 = [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $project2Id, + 'x-appwrite-key' => $key['body']['secret'], + ]; + + try { + // createFunction with installation from project 1 → should fail + $function = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ + 'functionId' => ID::unique(), + 'name' => 'Test Cross', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $function['headers']['status-code']); + + // createSite with installation from project 1 → should fail + $site = $this->client->call(Client::METHOD_POST, '/sites', $headers2, [ + 'siteId' => ID::unique(), + 'name' => 'Test Cross Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId3, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $site['headers']['status-code']); + + // updateFunction with cross-project installation → should fail + $fn = $this->client->call(Client::METHOD_POST, '/functions', $headers2, [ + 'functionId' => ID::unique(), + 'name' => 'Test No VCS', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + ]); + $this->assertEquals(201, $fn['headers']['status-code']); + + $updated = $this->client->call(Client::METHOD_PUT, '/functions/' . $fn['body']['$id'], $headers2, [ + 'name' => 'Test No VCS', + 'runtime' => 'php-8.0', + 'entrypoint' => 'index.php', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $updated['headers']['status-code']); + + // updateSite with cross-project installation → should fail + $siteNoVcs = $this->client->call(Client::METHOD_POST, '/sites', $headers2, [ + 'siteId' => ID::unique(), + 'name' => 'Test No VCS Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + ]); + $this->assertEquals(201, $siteNoVcs['headers']['status-code']); + + $updatedSite = $this->client->call(Client::METHOD_PUT, '/sites/' . $siteNoVcs['body']['$id'], $headers2, [ + 'name' => 'Test No VCS Site', + 'framework' => 'other', + 'buildRuntime' => 'node-22', + 'installationId' => $installationId, + 'providerRepositoryId' => $this->providerRepositoryId3, + 'providerBranch' => 'main', + ]); + $this->assertEquals(404, $updatedSite['headers']['status-code']); + } finally { + $this->client->call(Client::METHOD_DELETE, '/projects/' . $project2Id, $consoleHeaders); + $this->client->call(Client::METHOD_DELETE, '/teams/' . $team['body']['$id'], $consoleHeaders); + } + } + public function testCreateRepository(): void { $installationId = $this->setupInstallation(); diff --git a/tests/extensions/TestFinishedSubscriber.php b/tests/extensions/TestFinishedSubscriber.php index e07a9b67ed..fd58ad1f88 100644 --- a/tests/extensions/TestFinishedSubscriber.php +++ b/tests/extensions/TestFinishedSubscriber.php @@ -15,16 +15,22 @@ class TestFinishedSubscriber implements FinishedSubscriber public function notify(Finished $event): void { $test = $event->test()->name(); - $time = $event->telemetryInfo()->durationSinceStart()->seconds(); + $testId = $event->test()->id(); + + $elapsed = $event->telemetryInfo()->durationSinceStart()->asFloat(); + $start = TestPreparationStartedSubscriber::$startSeconds[$testId] ?? null; + $time = $start === null ? $elapsed : $elapsed - $start; + + unset(TestPreparationStartedSubscriber::$startSeconds[$testId]); printf( - "%s ended in %s milliseconds\n", + "%s ended in %d milliseconds\n", $test, - $time * 1000 + (int) round($time * 1000) ); if ($time > $this->maxSecondsAllowed) { - fwrite(STDOUT, sprintf("\e[31mThe %s test is slow, it took %s seconds!\n\e[0m", $test, $time)); + fwrite(STDOUT, sprintf("\e[31mThe %s test is slow, it took %.2f seconds!\n\e[0m", $test, $time)); } } } diff --git a/tests/extensions/TestHook.php b/tests/extensions/TestHook.php index 6ac1ec4afe..00cdfda33c 100644 --- a/tests/extensions/TestHook.php +++ b/tests/extensions/TestHook.php @@ -13,6 +13,7 @@ class TestHook implements Extension public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void { + $facade->registerSubscriber(new TestPreparationStartedSubscriber()); $facade->registerSubscriber(new TestFinishedSubscriber(self::MAX_SECONDS_ALLOWED)); $facade->registerSubscriber(new RetrySubscriber()); } diff --git a/tests/extensions/TestPreparationStartedSubscriber.php b/tests/extensions/TestPreparationStartedSubscriber.php new file mode 100644 index 0000000000..3bb59e52a8 --- /dev/null +++ b/tests/extensions/TestPreparationStartedSubscriber.php @@ -0,0 +1,26 @@ + + */ + public static array $startSeconds = []; + + public function notify(PreparationStarted $event): void + { + self::$startSeconds[$event->test()->id()] = $event->telemetryInfo()->durationSinceStart()->asFloat(); + } +} diff --git a/tests/unit/Messaging/MessagingFanoutTest.php b/tests/unit/Messaging/MessagingFanoutTest.php index 78172a5a0e..75f01b902b 100644 --- a/tests/unit/Messaging/MessagingFanoutTest.php +++ b/tests/unit/Messaging/MessagingFanoutTest.php @@ -558,6 +558,7 @@ class ScriptedEmailAdapter extends EmailAdapter */ public function __construct(private readonly array $script = []) { + parent::__construct(); } public function getName(): string diff --git a/tests/unit/Platform/Modules/Databases/DatabaseTypeMismatchTest.php b/tests/unit/Platform/Modules/Databases/DatabaseTypeMismatchTest.php new file mode 100644 index 0000000000..68da1db3fa --- /dev/null +++ b/tests/unit/Platform/Modules/Databases/DatabaseTypeMismatchTest.php @@ -0,0 +1,102 @@ +isDatabaseTypeMismatch($database); + } + + /** @return string[] */ + public function exposeAllowedTypes(): array + { + return $this->getAllowedDatabaseTypes(); + } + }; + $action->setHttpPath('/v1/tablesdb/:databaseId/tables'); + + // TablesDB is the compatibility successor to the legacy databases API: + // the allowed set must equal what listTablesDatabases advertises. + $this->assertSame([DATABASE_TYPE_TABLESDB, DATABASE_TYPE_LEGACY], $action->exposeAllowedTypes()); + + $this->assertFalse($action->exposeMismatch(new Document(['type' => DATABASE_TYPE_TABLESDB]))); + $this->assertFalse($action->exposeMismatch(new Document(['type' => DATABASE_TYPE_LEGACY]))); + $this->assertTrue($action->exposeMismatch(new Document(['type' => DATABASE_TYPE_DOCUMENTSDB]))); + $this->assertTrue($action->exposeMismatch(new Document(['type' => DATABASE_TYPE_VECTORSDB]))); + // Databases always carry a non-null type (V23 backfilled old rows to + // legacy); an unexpected empty type is excluded by both the list and guard. + $this->assertTrue($action->exposeMismatch(new Document([]))); + } + + public function testDocumentsAndVectorsPathsScopeStrictlyToTheirOwnType(): void + { + $documents = new class () extends Action { + public static function getName(): string + { + return 'testDocumentsdbTypeGuard'; + } + + public function exposeMismatch(Document $database): bool + { + return $this->isDatabaseTypeMismatch($database); + } + }; + $documents->setHttpPath('/v1/documentsdb/:databaseId/collections'); + $this->assertFalse($documents->exposeMismatch(new Document(['type' => DATABASE_TYPE_DOCUMENTSDB]))); + $this->assertTrue($documents->exposeMismatch(new Document(['type' => DATABASE_TYPE_VECTORSDB]))); + $this->assertTrue($documents->exposeMismatch(new Document(['type' => DATABASE_TYPE_LEGACY]))); + $this->assertTrue($documents->exposeMismatch(new Document([]))); + + $vectors = new class () extends Action { + public static function getName(): string + { + return 'testVectorsdbTypeGuard'; + } + + public function exposeMismatch(Document $database): bool + { + return $this->isDatabaseTypeMismatch($database); + } + }; + $vectors->setHttpPath('/v1/vectorsdb/:databaseId/collections'); + $this->assertFalse($vectors->exposeMismatch(new Document(['type' => DATABASE_TYPE_VECTORSDB]))); + $this->assertTrue($vectors->exposeMismatch(new Document(['type' => DATABASE_TYPE_DOCUMENTSDB]))); + $this->assertTrue($vectors->exposeMismatch(new Document(['type' => DATABASE_TYPE_LEGACY]))); + } + + public function testLegacyDatabasesPathIsNeverTypeGuarded(): void + { + $legacy = new class () extends Action { + public static function getName(): string + { + return 'testLegacyTypeGuard'; + } + + public function exposeMismatch(Document $database): bool + { + return $this->isDatabaseTypeMismatch($database); + } + }; + $legacy->setHttpPath('/v1/databases/:databaseId/collections'); + $this->assertFalse($legacy->exposeMismatch(new Document(['type' => DATABASE_TYPE_LEGACY]))); + $this->assertFalse($legacy->exposeMismatch(new Document([]))); + $this->assertFalse($legacy->exposeMismatch(new Document(['type' => DATABASE_TYPE_TABLESDB]))); + $this->assertFalse($legacy->exposeMismatch(new Document(['type' => DATABASE_TYPE_DOCUMENTSDB]))); + } +} diff --git a/tests/unit/Utopia/ResponseTest.php b/tests/unit/Utopia/ResponseTest.php index 80c59ee2f8..e00809ce26 100644 --- a/tests/unit/Utopia/ResponseTest.php +++ b/tests/unit/Utopia/ResponseTest.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace Tests\Unit\Utopia; +use Appwrite\Models\Project as GeneratedProject; use Appwrite\Utopia\Response; +use Appwrite\Utopia\Response\Model\Project as ProjectModel; use Exception; use PHPUnit\Framework\TestCase; use ReflectionProperty; @@ -110,6 +112,56 @@ final class ResponseTest extends TestCase ]), 'single'); } + public function testProjectResponseCanHydrateGeneratedSdkProjectWithoutOAuth2Fields(): void + { + $this->response->setModel(new ProjectModel()); + + $project = $this->response->output(new Document([ + '$id' => 'project', + '$createdAt' => '2026-06-19T00:00:00.000+00:00', + '$updatedAt' => '2026-06-19T00:00:00.000+00:00', + 'name' => 'Project', + 'teamId' => 'team', + 'region' => 'default', + ]), Response::MODEL_PROJECT); + + $generated = GeneratedProject::from($project); + + foreach ([ + 'oAuth2ServerEnabled', + 'oAuth2ServerAuthorizationUrl', + 'oAuth2ServerScopes', + 'oAuth2ServerAuthorizationDetailsTypes', + 'oAuth2ServerAccessTokenDuration', + 'oAuth2ServerRefreshTokenDuration', + 'oAuth2ServerPublicAccessTokenDuration', + 'oAuth2ServerPublicRefreshTokenDuration', + 'oAuth2ServerConfidentialPkce', + 'oAuth2ServerVerificationUrl', + 'oAuth2ServerUserCodeLength', + 'oAuth2ServerUserCodeFormat', + 'oAuth2ServerDeviceCodeDuration', + 'oAuth2ServerDiscoveryUrl', + ] as $key) { + $this->assertArrayNotHasKey($key, $project); + } + + $this->assertNull($generated->oAuth2ServerEnabled); + $this->assertNull($generated->oAuth2ServerAuthorizationUrl); + $this->assertNull($generated->oAuth2ServerScopes); + $this->assertNull($generated->oAuth2ServerAuthorizationDetailsTypes); + $this->assertNull($generated->oAuth2ServerAccessTokenDuration); + $this->assertNull($generated->oAuth2ServerRefreshTokenDuration); + $this->assertNull($generated->oAuth2ServerPublicAccessTokenDuration); + $this->assertNull($generated->oAuth2ServerPublicRefreshTokenDuration); + $this->assertNull($generated->oAuth2ServerConfidentialPkce); + $this->assertNull($generated->oAuth2ServerVerificationUrl); + $this->assertNull($generated->oAuth2ServerUserCodeLength); + $this->assertNull($generated->oAuth2ServerUserCodeFormat); + $this->assertNull($generated->oAuth2ServerDeviceCodeDuration); + $this->assertNull($generated->oAuth2ServerDiscoveryUrl); + } + public function testResponseModelLists(): void { $output = $this->response->output(new Document([