Skip to content

Commit 5d7efbe

Browse files
authored
Merge pull request #111 from utopia-php/feat/sdk-23
feat: bump appwrite/appwrite to 23.*
2 parents 53f4274 + c20ded6 commit 5d7efbe

11 files changed

Lines changed: 320 additions & 361 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
php-versions: ['8.1', '8.2', '8.3']
10+
php-versions: ['8.2', '8.3', '8.4']
1111

1212
steps:
1313
- name: Checkout repository

Dockerfile.php-8.2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ COPY composer.json /src/
88
RUN composer install --ignore-platform-reqs --optimize-autoloader \
99
--no-plugins --no-scripts --prefer-dist
1010

11-
FROM appwrite/utopia-base:php-8.2-0.1.0 as final
11+
FROM appwrite/utopia-base:php-8.2-1.0.0 as final
1212

1313
LABEL maintainer="team@appwrite.io"
1414

Dockerfile.php-8.3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ COPY composer.json /src/
88
RUN composer install --ignore-platform-reqs --optimize-autoloader \
99
--no-plugins --no-scripts --prefer-dist
1010

11-
FROM appwrite/utopia-base:php-8.3-0.1.0 as final
11+
FROM appwrite/utopia-base:php-8.3-1.0.0 as final
1212

1313
LABEL maintainer="team@appwrite.io"
1414

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ COPY composer.json /src/
88
RUN composer install --ignore-platform-reqs --optimize-autoloader \
99
--no-plugins --no-scripts --prefer-dist
1010

11-
FROM appwrite/utopia-base:php-8.1-0.1.0 as final
11+
FROM appwrite/utopia-base:php-8.4-1.0.0 as final
1212

1313
LABEL maintainer="team@appwrite.io"
1414

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
"bench": "vendor/bin/phpbench run --report=aggregate"
1919
},
2020
"require": {
21-
"php": ">=8.0",
21+
"php": ">=8.2",
2222
"ext-pdo": "*",
2323
"ext-curl": "*",
2424
"ext-redis": "*",
2525
"utopia-php/database": "5.*",
26-
"appwrite/appwrite": "19.*"
26+
"appwrite/appwrite": "23.*"
2727
},
2828
"require-dev": {
2929
"phpunit/phpunit": "9.*",

composer.lock

Lines changed: 275 additions & 304 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Abuse/Adapters/TimeLimit/Appwrite/TablesDB.php

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
use Appwrite\AppwriteException;
66
use Appwrite\Client;
7-
use Appwrite\Enums\IndexType;
7+
use Appwrite\Enums\TablesDBIndexType;
88
use Appwrite\ID;
9+
use Appwrite\Models\Row;
910
use Appwrite\Query;
1011
use Appwrite\Services\TablesDB as TablesDBService;
1112
use Utopia\Abuse\Adapters\TimeLimit;
1213
use Utopia\Database\Document;
13-
use Utopia\Exception;
1414

1515
class TablesDB extends TimeLimit
1616
{
@@ -35,7 +35,7 @@ public function __construct(string $key, int $limit, int $seconds, Client $clien
3535
}
3636

3737
/**
38-
* @throws Exception|\Exception
38+
* @throws \Exception
3939
*/
4040
public function setup(): void
4141
{
@@ -94,8 +94,8 @@ protected function createColumns(): void
9494
protected function createIndexes(): void
9595
{
9696
$indexes = [
97-
fn () => $this->tablesDB->createIndex($this->databaseId, self::TABLE_ID, 'unique1', IndexType::UNIQUE(), ['key', 'time']),
98-
fn () => $this->tablesDB->createIndex($this->databaseId, self::TABLE_ID, 'index2', IndexType::KEY(), ['time'])
97+
fn () => $this->tablesDB->createIndex($this->databaseId, self::TABLE_ID, 'unique1', TablesDBIndexType::UNIQUE(), ['key', 'time']),
98+
fn () => $this->tablesDB->createIndex($this->databaseId, self::TABLE_ID, 'index2', TablesDBIndexType::KEY(), ['time'])
9999
];
100100

101101
foreach ($indexes as $createIndexFunction) {
@@ -111,12 +111,12 @@ protected function waitForResourcesReady(string $resourceType): void
111111
while ($attempts < $maxAttempts) {
112112
$attempts++;
113113

114-
$response = $resourceType === 'columns'
115-
? $this->tablesDB->listColumns($this->databaseId, self::TABLE_ID, [Query::notEqual('status', 'available'), Query::limit(1)])
116-
: $this->tablesDB->listIndexes($this->databaseId, self::TABLE_ID, [Query::notEqual('status', 'available'), Query::limit(1)]);
114+
$resources = $resourceType === 'columns'
115+
? $this->tablesDB->listColumns($this->databaseId, self::TABLE_ID, [Query::notEqual('status', 'available'), Query::limit(1)])->columns
116+
: $this->tablesDB->listIndexes($this->databaseId, self::TABLE_ID, [Query::notEqual('status', 'available'), Query::limit(1)])->indexes;
117117

118-
$resources = $response[$resourceType];
119-
$resources = \array_filter($resources, fn ($resource) => $resource['status'] !== 'available');
118+
// Column models expose status as a ColumnStatus enum; index models as a plain string. Cast for both.
119+
$resources = \array_filter($resources, fn ($resource) => (string) $resource->status !== 'available');
120120

121121
if (\count($resources) === 0) {
122122
return;
@@ -170,16 +170,15 @@ protected function count(string $key, int $timestamp): int
170170

171171
$timestamp = $this->toDateTime($timestamp);
172172

173-
$response = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
173+
$rows = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
174174
Query::equal('key', [$key]),
175175
Query::equal('time', [$timestamp]),
176-
]);
177-
$rows = $response['rows'];
176+
])->rows;
178177

179178
$this->count = 0;
180179

181180
if (\count($rows) === 1) { // Unique Index
182-
$count = $rows[0]['count'] ?? 0;
181+
$count = $rows[0]->data['count'] ?? 0;
183182
if (\is_numeric($count)) {
184183
$this->count = intval($count);
185184
}
@@ -203,14 +202,13 @@ protected function hit(string $key, int $timestamp): void
203202

204203
$timestamp = $this->toDateTime($timestamp);
205204

206-
$response = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
205+
$rows = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
207206
Query::equal('key', [$key]),
208207
Query::equal('time', [$timestamp]),
209-
]);
210-
$rows = $response['rows'];
211-
$data = $rows[0] ?? null;
208+
])->rows;
209+
$row = $rows[0] ?? null;
212210

213-
if (\is_null($data)) {
211+
if (\is_null($row)) {
214212
$data = [
215213
'key' => $key,
216214
'time' => $timestamp,
@@ -224,27 +222,26 @@ protected function hit(string $key, int $timestamp): void
224222
throw $err;
225223
}
226224

227-
$response = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
225+
$rows = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
228226
Query::equal('key', [$key]),
229227
Query::equal('time', [$timestamp]),
230-
]);
231-
$rows = $response['rows'];
228+
])->rows;
232229

233-
$data = $rows[0] ?? null;
230+
$row = $rows[0] ?? null;
234231

235-
if (!is_null($data)) {
236-
$count = $data['count'] ?? 0;
232+
if (!is_null($row)) {
233+
$count = $row->data['count'] ?? 0;
237234
if (\is_numeric($count)) {
238235
$this->count = intval($count);
239236
}
240237

241-
$this->tablesDB->incrementRowColumn($this->databaseId, self::TABLE_ID, $data['$id'], 'count', 1);
238+
$this->tablesDB->incrementRowColumn($this->databaseId, self::TABLE_ID, $row->id, 'count', 1);
242239
} else {
243240
throw new \Exception('Document Not Found');
244241
}
245242
}
246243
} else {
247-
$this->tablesDB->incrementRowColumn($this->databaseId, self::TABLE_ID, $data['$id'], 'count', 1);
244+
$this->tablesDB->incrementRowColumn($this->databaseId, self::TABLE_ID, $row->id, 'count', 1);
248245
}
249246

250247
$this->count++;
@@ -262,14 +259,13 @@ protected function set(string $key, int $timestamp, int $value): void
262259
{
263260
$timestamp = $this->toDateTime($timestamp);
264261

265-
$response = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
262+
$rows = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
266263
Query::equal('key', [$key]),
267264
Query::equal('time', [$timestamp]),
268-
]);
269-
$rows = $response['rows'];
270-
$data = $rows[0] ?? null;
265+
])->rows;
266+
$row = $rows[0] ?? null;
271267

272-
if (\is_null($data)) {
268+
if (\is_null($row)) {
273269
$data = [
274270
'key' => $key,
275271
'time' => $timestamp,
@@ -283,22 +279,21 @@ protected function set(string $key, int $timestamp, int $value): void
283279
throw $err;
284280
}
285281

286-
$response = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
282+
$rows = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [
287283
Query::equal('key', [$key]),
288284
Query::equal('time', [$timestamp]),
289-
]);
290-
$rows = $response['rows'];
285+
])->rows;
291286

292-
$data = $rows[0] ?? null;
287+
$row = $rows[0] ?? null;
293288

294-
if (!is_null($data)) {
295-
$this->tablesDB->updateRow($this->databaseId, self::TABLE_ID, $data['$id'], ['count' => $value]);
289+
if (!is_null($row)) {
290+
$this->tablesDB->updateRow($this->databaseId, self::TABLE_ID, $row->id, ['count' => $value]);
296291
} else {
297292
throw new \Exception('Unable to find abuse tracking row after race condition handling');
298293
}
299294
}
300295
} else {
301-
$this->tablesDB->updateRow($this->databaseId, self::TABLE_ID, $data['$id'], ['count' => $value]);
296+
$this->tablesDB->updateRow($this->databaseId, self::TABLE_ID, $row->id, ['count' => $value]);
302297
}
303298

304299
$this->count = $value;
@@ -328,9 +323,9 @@ public function getLogs(?int $offset = null, ?int $limit = 25): array
328323
$queries[] = Query::limit($limit);
329324
}
330325

331-
$response = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, $queries);
326+
$rows = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, $queries)->rows;
332327

333-
return \array_map(fn ($document) => new Document($document), $response['documents']);
328+
return \array_map(fn (Row $row) => new Document($row->toArray()), $rows);
334329
}
335330

336331
/**
@@ -349,7 +344,7 @@ public function cleanup(int $timestamp): bool
349344
$response = $this->tablesDB->deleteRows($this->databaseId, self::TABLE_ID, [
350345
Query::lessThan('time', $timestamp),
351346
]);
352-
} while ($response['total'] > 0);
347+
} while ($response->total > 0);
353348

354349
return true;
355350
}

src/Abuse/Adapters/TimeLimit/Database.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Utopia\Database\Exception\Duplicate;
1111
use Utopia\Database\Exception\Structure;
1212
use Utopia\Database\Query;
13-
use Utopia\Exception;
1413

1514
class Database extends TimeLimit
1615
{
@@ -87,12 +86,12 @@ public function __construct(string $key, int $limit, int $seconds, UtopiaDB $db)
8786

8887
/**
8988
* @throws Duplicate
90-
* @throws Exception|\Exception
89+
* @throws \Exception
9190
*/
9291
public function setup(): void
9392
{
9493
if (! $this->db->exists($this->db->getDatabase())) {
95-
throw new Exception('You need to create database before running timelimit setup');
94+
throw new \Exception('You need to create database before running timelimit setup');
9695
}
9796

9897
$attributes = \array_map(function ($attribute) {

tests/Abuse/Bench/Database.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@
1010
use Utopia\Database\Adapter\MySQL;
1111
use Utopia\Database\Adapter\SQL;
1212
use Utopia\Database\Database as UtopiaDatabase;
13-
use Utopia\Exception;
1413

1514
final class Database extends Base
1615
{
1716
protected UtopiaDatabase $db;
1817

1918
/**
20-
* @throws Exception
2119
* @throws \Exception
2220
*/
2321
public function setUp(): void

tests/Abuse/RedisClusterTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
use Utopia\Abuse\Adapters\TimeLimit;
66
use Utopia\Abuse\Adapters\TimeLimit\RedisCluster as AdapterRedisCluster;
7-
use Utopia\Exception;
87

98
class RedisClusterTest extends Base
109
{
1110
protected static \RedisCluster $redis;
1211

1312
/**
14-
* @throws Exception
1513
* @throws \Exception
1614
*/
1715
public static function setUpBeforeClass(): void

0 commit comments

Comments
 (0)