Skip to content

Commit

Permalink
Merge branch 'v2.x' into ignore-disableMD5
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored Nov 7, 2024
2 parents f8b4e79 + 0c8b2d9 commit 0d26c28
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 62 deletions.
18 changes: 9 additions & 9 deletions .evergreen/config/build-variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ buildvariants:
run_on: rhel90-small
tasks:
- name: "build-all-php"
- name: build-rhel83-zseries
display_name: "Build: RHEL 8.3 Zseries"
- name: build-rhel9-zseries
display_name: "Build: RHEL 9 Zseries"
tags: ["build", "rhel", "zseries", "tag"]
run_on: rhel83-zseries-small
run_on: rhel9-zseries-small
tasks:
- name: "build-all-php"
- name: build-rhel9-power
display_name: "Build: RHEL 9 PPC"
tags: ["build", "rhel", "power", "tag"]
run_on: rhel9-power-small
tasks:
- name: "build-all-php"
- name: build-rhel82-arm64
Expand All @@ -35,12 +41,6 @@ buildvariants:
run_on: rhel82-arm64
tasks:
- name: "build-all-php"
- name: build-rhel81-power8
display_name: "Build: RHEL 8.1 Power8"
tags: ["build", "rhel", "power8", "tag"]
run_on: rhel81-power8-large
tasks:
- name: "build-all-php"
- name: build-rhel80
display_name: "Build: RHEL 8.0"
tags: ["build", "rhel", "x64", "pr", "tag"]
Expand Down
62 changes: 33 additions & 29 deletions .evergreen/config/generated/build/build-extension.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ updates:
- package-ecosystem: "gitsubmodule"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
41 changes: 34 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function __debugInfo(): array
*/
public function __get(string $databaseName): Database
{
return $this->selectDatabase($databaseName);
return $this->getDatabase($databaseName);
}

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

/**
* Returns a collection instance.
*
* If the collection does not exist in the database, it is not created when
* invoking this method.
*
* @see Collection::__construct() for supported options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
public function getCollection(string $databaseName, string $collectionName, array $options = []): Collection
{
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];

return new Collection($this->manager, $databaseName, $collectionName, $options);
}

/**
* Returns a database instance.
*
* If the database does not exist on the server, it is not created when
* invoking this method.
*
* @see Database::__construct() for supported options
*/
public function getDatabase(string $databaseName, array $options = []): Database
{
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];

return new Database($this->manager, $databaseName, $options);
}

/**
* Return the Manager.
*/
Expand Down Expand Up @@ -329,9 +360,7 @@ final public function removeSubscriber(Subscriber $subscriber): void
*/
public function selectCollection(string $databaseName, string $collectionName, array $options = []): Collection
{
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];

return new Collection($this->manager, $databaseName, $collectionName, $options);
return $this->getCollection($databaseName, $collectionName, $options);
}

/**
Expand All @@ -344,9 +373,7 @@ public function selectCollection(string $databaseName, string $collectionName, a
*/
public function selectDatabase(string $databaseName, array $options = []): Database
{
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];

return new Database($this->manager, $databaseName, $options);
return $this->getDatabase($databaseName, $options);
}

/**
Expand Down
34 changes: 24 additions & 10 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function __debugInfo(): array
*/
public function __get(string $collectionName): Collection
{
return $this->selectCollection($collectionName);
return $this->getCollection($collectionName);
}

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

/**
* Returns a collection instance.
*
* If the collection does not exist in the database, it is not created when
* invoking this method.
*
* @see Collection::__construct() for supported options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
public function getCollection(string $collectionName, array $options = []): Collection
{
$options += [
'builderEncoder' => $this->builderEncoder,
'readConcern' => $this->readConcern,
'readPreference' => $this->readPreference,
'typeMap' => $this->typeMap,
'writeConcern' => $this->writeConcern,
];

return new Collection($this->manager, $this->databaseName, $collectionName, $options);
}

/**
* Returns the database name.
*/
Expand Down Expand Up @@ -534,15 +556,7 @@ public function renameCollection(string $fromCollectionName, string $toCollectio
*/
public function selectCollection(string $collectionName, array $options = []): Collection
{
$options += [
'builderEncoder' => $this->builderEncoder,
'readConcern' => $this->readConcern,
'readPreference' => $this->readPreference,
'typeMap' => $this->typeMap,
'writeConcern' => $this->writeConcern,
];

return new Collection($this->manager, $this->databaseName, $collectionName, $options);
return $this->getCollection($collectionName, $options);
}

/**
Expand Down
35 changes: 35 additions & 0 deletions src/GridFS/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ public function delete(mixed $id): void
}
}

/**
* Delete all the revisions of a file name from the GridFS bucket.
*
* @param string $filename Filename
*
* @throws FileNotFoundException if no file could be selected
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function deleteByName(string $filename): void
{
$count = $this->collectionWrapper->deleteFileAndChunksByFilename($filename);

if ($count === 0) {
throw FileNotFoundException::byFilename($filename);
}
}

/**
* Writes the contents of a GridFS file to a writable stream.
*
Expand Down Expand Up @@ -590,6 +607,24 @@ public function rename(mixed $id, string $newFilename): void
}
}

/**
* Renames all the revisions of a file name in the GridFS bucket.
*
* @param string $filename Filename
* @param string $newFilename New filename
*
* @throws FileNotFoundException if no file could be selected
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function renameByName(string $filename, string $newFilename): void
{
$count = $this->collectionWrapper->updateFilenameForFilename($filename, $newFilename);

if ($count === 0) {
throw FileNotFoundException::byFilename($filename);
}
}

/**
* Writes the contents of a readable stream to a GridFS file.
*
Expand Down
3 changes: 0 additions & 3 deletions src/GridFS/CollectionWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ public function findChunksByFileId(mixed $id, int $fromChunk = 0): CursorInterfa
*/
public function findFileByFilenameAndRevision(string $filename, int $revision): ?object
{
$filename = $filename;
$revision = $revision;

if ($revision < 0) {
$skip = abs($revision) - 1;
$sortOrder = -1;
Expand Down
46 changes: 46 additions & 0 deletions tests/GridFS/BucketFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,34 @@ public function testDeleteStillRemovesChunksIfFileDoesNotExist($input, $expected
$this->assertCollectionCount($this->chunksCollection, 0);
}

public function testDeleteByName(): void
{
$this->bucket->uploadFromStream('filename', self::createStream('foobar1'));
$this->bucket->uploadFromStream('filename', self::createStream('foobar2'));
$this->bucket->uploadFromStream('filename', self::createStream('foobar3'));

$this->bucket->uploadFromStream('other', self::createStream('foobar'));

$this->assertCollectionCount($this->filesCollection, 4);
$this->assertCollectionCount($this->chunksCollection, 4);

$this->bucket->deleteByName('filename');

$this->assertCollectionCount($this->filesCollection, 1);
$this->assertCollectionCount($this->chunksCollection, 1);

$this->bucket->deleteByName('other');

$this->assertCollectionCount($this->filesCollection, 0);
$this->assertCollectionCount($this->chunksCollection, 0);
}

public function testDeleteByNameShouldRequireFileToExist(): void
{
$this->expectException(FileNotFoundException::class);
$this->bucket->deleteByName('nonexistent-name');
}

public function testDownloadingFileWithMissingChunk(): void
{
$id = $this->bucket->uploadFromStream('filename', self::createStream('foobar'));
Expand Down Expand Up @@ -721,6 +749,24 @@ public function testRenameShouldRequireFileToExist(): void
$this->bucket->rename('nonexistent-id', 'b');
}

public function testRenameByName(): void
{
$this->bucket->uploadFromStream('filename', self::createStream('foo'));
$this->bucket->uploadFromStream('filename', self::createStream('foo'));
$this->bucket->uploadFromStream('filename', self::createStream('foo'));

$this->bucket->renameByName('filename', 'newname');

$this->assertNull($this->bucket->findOne(['filename' => 'filename']), 'No file has the old name');
$this->assertStreamContents('foo', $this->bucket->openDownloadStreamByName('newname'));
}

public function testRenameByNameShouldRequireFileToExist(): void
{
$this->expectException(FileNotFoundException::class);
$this->bucket->renameByName('nonexistent-name', 'b');
}

public function testUploadFromStream(): void
{
$options = [
Expand Down
Loading

0 comments on commit 0d26c28

Please sign in to comment.