Skip to content

Commit 0d26c28

Browse files
authored
Merge branch 'v2.x' into ignore-disableMD5
2 parents f8b4e79 + 0c8b2d9 commit 0d26c28

File tree

15 files changed

+288
-62
lines changed

15 files changed

+288
-62
lines changed

.evergreen/config/build-variants.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ buildvariants:
2323
run_on: rhel90-small
2424
tasks:
2525
- name: "build-all-php"
26-
- name: build-rhel83-zseries
27-
display_name: "Build: RHEL 8.3 Zseries"
26+
- name: build-rhel9-zseries
27+
display_name: "Build: RHEL 9 Zseries"
2828
tags: ["build", "rhel", "zseries", "tag"]
29-
run_on: rhel83-zseries-small
29+
run_on: rhel9-zseries-small
30+
tasks:
31+
- name: "build-all-php"
32+
- name: build-rhel9-power
33+
display_name: "Build: RHEL 9 PPC"
34+
tags: ["build", "rhel", "power", "tag"]
35+
run_on: rhel9-power-small
3036
tasks:
3137
- name: "build-all-php"
3238
- name: build-rhel82-arm64
@@ -35,12 +41,6 @@ buildvariants:
3541
run_on: rhel82-arm64
3642
tasks:
3743
- name: "build-all-php"
38-
- name: build-rhel81-power8
39-
display_name: "Build: RHEL 8.1 Power8"
40-
tags: ["build", "rhel", "power8", "tag"]
41-
run_on: rhel81-power8-large
42-
tasks:
43-
- name: "build-all-php"
4444
- name: build-rhel80
4545
display_name: "Build: RHEL 8.0"
4646
tags: ["build", "rhel", "x64", "pr", "tag"]

.evergreen/config/generated/build/build-extension.yml

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

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ updates:
77
- package-ecosystem: "gitsubmodule"
88
directory: "/"
99
schedule:
10-
interval: "daily"
10+
interval: "weekly"

src/Client.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function __debugInfo(): array
168168
*/
169169
public function __get(string $databaseName): Database
170170
{
171-
return $this->selectDatabase($databaseName);
171+
return $this->getDatabase($databaseName);
172172
}
173173

174174
/**
@@ -230,6 +230,37 @@ public function dropDatabase(string $databaseName, array $options = []): void
230230
$operation->execute($server);
231231
}
232232

233+
/**
234+
* Returns a collection instance.
235+
*
236+
* If the collection does not exist in the database, it is not created when
237+
* invoking this method.
238+
*
239+
* @see Collection::__construct() for supported options
240+
* @throws InvalidArgumentException for parameter/option parsing errors
241+
*/
242+
public function getCollection(string $databaseName, string $collectionName, array $options = []): Collection
243+
{
244+
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];
245+
246+
return new Collection($this->manager, $databaseName, $collectionName, $options);
247+
}
248+
249+
/**
250+
* Returns a database instance.
251+
*
252+
* If the database does not exist on the server, it is not created when
253+
* invoking this method.
254+
*
255+
* @see Database::__construct() for supported options
256+
*/
257+
public function getDatabase(string $databaseName, array $options = []): Database
258+
{
259+
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];
260+
261+
return new Database($this->manager, $databaseName, $options);
262+
}
263+
233264
/**
234265
* Return the Manager.
235266
*/
@@ -329,9 +360,7 @@ final public function removeSubscriber(Subscriber $subscriber): void
329360
*/
330361
public function selectCollection(string $databaseName, string $collectionName, array $options = []): Collection
331362
{
332-
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];
333-
334-
return new Collection($this->manager, $databaseName, $collectionName, $options);
363+
return $this->getCollection($databaseName, $collectionName, $options);
335364
}
336365

337366
/**
@@ -344,9 +373,7 @@ public function selectCollection(string $databaseName, string $collectionName, a
344373
*/
345374
public function selectDatabase(string $databaseName, array $options = []): Database
346375
{
347-
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];
348-
349-
return new Database($this->manager, $databaseName, $options);
376+
return $this->getDatabase($databaseName, $options);
350377
}
351378

352379
/**

src/Database.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function __debugInfo(): array
171171
*/
172172
public function __get(string $collectionName): Collection
173173
{
174-
return $this->selectCollection($collectionName);
174+
return $this->getCollection($collectionName);
175175
}
176176

177177
/**
@@ -384,6 +384,28 @@ public function dropCollection(string $collectionName, array $options = []): voi
384384
$operation->execute($server);
385385
}
386386

387+
/**
388+
* Returns a collection instance.
389+
*
390+
* If the collection does not exist in the database, it is not created when
391+
* invoking this method.
392+
*
393+
* @see Collection::__construct() for supported options
394+
* @throws InvalidArgumentException for parameter/option parsing errors
395+
*/
396+
public function getCollection(string $collectionName, array $options = []): Collection
397+
{
398+
$options += [
399+
'builderEncoder' => $this->builderEncoder,
400+
'readConcern' => $this->readConcern,
401+
'readPreference' => $this->readPreference,
402+
'typeMap' => $this->typeMap,
403+
'writeConcern' => $this->writeConcern,
404+
];
405+
406+
return new Collection($this->manager, $this->databaseName, $collectionName, $options);
407+
}
408+
387409
/**
388410
* Returns the database name.
389411
*/
@@ -534,15 +556,7 @@ public function renameCollection(string $fromCollectionName, string $toCollectio
534556
*/
535557
public function selectCollection(string $collectionName, array $options = []): Collection
536558
{
537-
$options += [
538-
'builderEncoder' => $this->builderEncoder,
539-
'readConcern' => $this->readConcern,
540-
'readPreference' => $this->readPreference,
541-
'typeMap' => $this->typeMap,
542-
'writeConcern' => $this->writeConcern,
543-
];
544-
545-
return new Collection($this->manager, $this->databaseName, $collectionName, $options);
559+
return $this->getCollection($collectionName, $options);
546560
}
547561

548562
/**

src/GridFS/Bucket.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,23 @@ public function delete(mixed $id): void
219219
}
220220
}
221221

222+
/**
223+
* Delete all the revisions of a file name from the GridFS bucket.
224+
*
225+
* @param string $filename Filename
226+
*
227+
* @throws FileNotFoundException if no file could be selected
228+
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
229+
*/
230+
public function deleteByName(string $filename): void
231+
{
232+
$count = $this->collectionWrapper->deleteFileAndChunksByFilename($filename);
233+
234+
if ($count === 0) {
235+
throw FileNotFoundException::byFilename($filename);
236+
}
237+
}
238+
222239
/**
223240
* Writes the contents of a GridFS file to a writable stream.
224241
*
@@ -590,6 +607,24 @@ public function rename(mixed $id, string $newFilename): void
590607
}
591608
}
592609

610+
/**
611+
* Renames all the revisions of a file name in the GridFS bucket.
612+
*
613+
* @param string $filename Filename
614+
* @param string $newFilename New filename
615+
*
616+
* @throws FileNotFoundException if no file could be selected
617+
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
618+
*/
619+
public function renameByName(string $filename, string $newFilename): void
620+
{
621+
$count = $this->collectionWrapper->updateFilenameForFilename($filename, $newFilename);
622+
623+
if ($count === 0) {
624+
throw FileNotFoundException::byFilename($filename);
625+
}
626+
}
627+
593628
/**
594629
* Writes the contents of a readable stream to a GridFS file.
595630
*

src/GridFS/CollectionWrapper.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ public function findChunksByFileId(mixed $id, int $fromChunk = 0): CursorInterfa
148148
*/
149149
public function findFileByFilenameAndRevision(string $filename, int $revision): ?object
150150
{
151-
$filename = $filename;
152-
$revision = $revision;
153-
154151
if ($revision < 0) {
155152
$skip = abs($revision) - 1;
156153
$sortOrder = -1;

tests/GridFS/BucketFunctionalTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,34 @@ public function testDeleteStillRemovesChunksIfFileDoesNotExist($input, $expected
158158
$this->assertCollectionCount($this->chunksCollection, 0);
159159
}
160160

161+
public function testDeleteByName(): void
162+
{
163+
$this->bucket->uploadFromStream('filename', self::createStream('foobar1'));
164+
$this->bucket->uploadFromStream('filename', self::createStream('foobar2'));
165+
$this->bucket->uploadFromStream('filename', self::createStream('foobar3'));
166+
167+
$this->bucket->uploadFromStream('other', self::createStream('foobar'));
168+
169+
$this->assertCollectionCount($this->filesCollection, 4);
170+
$this->assertCollectionCount($this->chunksCollection, 4);
171+
172+
$this->bucket->deleteByName('filename');
173+
174+
$this->assertCollectionCount($this->filesCollection, 1);
175+
$this->assertCollectionCount($this->chunksCollection, 1);
176+
177+
$this->bucket->deleteByName('other');
178+
179+
$this->assertCollectionCount($this->filesCollection, 0);
180+
$this->assertCollectionCount($this->chunksCollection, 0);
181+
}
182+
183+
public function testDeleteByNameShouldRequireFileToExist(): void
184+
{
185+
$this->expectException(FileNotFoundException::class);
186+
$this->bucket->deleteByName('nonexistent-name');
187+
}
188+
161189
public function testDownloadingFileWithMissingChunk(): void
162190
{
163191
$id = $this->bucket->uploadFromStream('filename', self::createStream('foobar'));
@@ -721,6 +749,24 @@ public function testRenameShouldRequireFileToExist(): void
721749
$this->bucket->rename('nonexistent-id', 'b');
722750
}
723751

752+
public function testRenameByName(): void
753+
{
754+
$this->bucket->uploadFromStream('filename', self::createStream('foo'));
755+
$this->bucket->uploadFromStream('filename', self::createStream('foo'));
756+
$this->bucket->uploadFromStream('filename', self::createStream('foo'));
757+
758+
$this->bucket->renameByName('filename', 'newname');
759+
760+
$this->assertNull($this->bucket->findOne(['filename' => 'filename']), 'No file has the old name');
761+
$this->assertStreamContents('foo', $this->bucket->openDownloadStreamByName('newname'));
762+
}
763+
764+
public function testRenameByNameShouldRequireFileToExist(): void
765+
{
766+
$this->expectException(FileNotFoundException::class);
767+
$this->bucket->renameByName('nonexistent-name', 'b');
768+
}
769+
724770
public function testUploadFromStream(): void
725771
{
726772
$options = [

0 commit comments

Comments
 (0)