Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom _id for GridFS documents (#2487) #2489

Merged
merged 11 commits into from
Feb 24, 2023
Merged

Conversation

andrey-tech
Copy link
Contributor

@andrey-tech andrey-tech commented Dec 12, 2022

Q A
Type feature
BC Break no
Fixed issues #2487
Version 2.5.x

Summary

Added two missing options to UploadOptions:

  • id (mixed): File document identifier. Defaults to a new ObjectId.
    - disableMD5 (boolean): When true, no MD5 sum will be generated for the stored file. Defaults to false.

The mongodb/mongodb ^1.4.0 is required for option disableMD5.

@andrey-tech
Copy link
Contributor Author

It might make sense to change the property name from _id to id in UploadOptions for PHP CodeSniffer with Slevomat coding standard rules.

@andrey-tech
Copy link
Contributor Author

  1. Renamed _id to id in UploadOptions for PHP CodeSniffer with SlevomatCodingStandard rules.
  2. Added tests for new options id and disableMD5.

@franmomu
Copy link
Contributor

Hi @andrey-tech, thanks for the PR! since this is a feature, can you please target to 2.5.x instead?

@andrey-tech andrey-tech changed the base branch from 2.4.x to 2.5.x December 13, 2022 07:49
@andrey-tech
Copy link
Contributor Author

@franmomu Done.

Copy link
Member

@malarzm malarzm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Mind adding one more test please? :)

@@ -108,6 +110,14 @@ private function prepareOptions(?UploadOptions $uploadOptions = null): array
$chunkSizeBytes = $uploadOptions->chunkSizeBytes ?: $this->class->getChunkSizeBytes();
$options = [];

if ($uploadOptions->id !== null) {
$options['_id'] = $this->class->getDatabaseIdentifierValue($uploadOptions->id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to have a test that covers type transformation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MongoDB documentation lists ObjectId as just one of the common variants for the _id field. So I removed type transformation from method prepareOptions() of class DefaultGridFSRepository for more flexibility. Test that covers this type transformation not needed anymore.

@malarzm malarzm added this to the 2.5.0 milestone Dec 14, 2022
public $id;

/** @var bool|null */
public $disableMD5;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a specific use-case for the disableMD5 option? The reason I omitted this was that the specification marks the option as deprecated and it will be removed from the PHP driver in the next major release. I would prefer not adding it in now, as we'd have to do another BC break for 3.x then (as opposed to breaking it once for people migrating to ODM 2.0).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's on me (#2487 (comment)) I didn't know it's deprecated :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, yes. We deprecated it since using MD5 is forbidden when being compliant with FIPS, and personally I wouldn't rely on MD5 for checksums anymore. @andrey-tech do you mind dropping it? I don't think we should introduce the option at this point, especially since we haven't had anyone ask for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alcaeus I don't mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malarzm Do you mind dropping it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrey-tech since it's deprecated and it was not added on purpose, we should not add it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecated option disableMD5 has been removed from this PR.

composer.json Outdated
@@ -32,7 +32,7 @@
"doctrine/persistence": "^2.4 || ^3.0",
"friendsofphp/proxy-manager-lts": "^1.0",
"jean85/pretty-package-versions": "^1.3.0 || ^2.0.1",
"mongodb/mongodb": "^1.2.0",
"mongodb/mongodb": "^1.4.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well bump this to 1.15 while you're at it. 1.4 is ancient and no longer supported, we should encourage people to upgrade :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@malarzm Do you mind to set ^1.15.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set mongodb/mongodb to ^1.15.0.

@IonBazan IonBazan requested a review from alcaeus February 21, 2023 08:52
Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

We should add a test for using an identifier with a custom type, but I'm fine deferring that to a separate pull request.

@IonBazan
Copy link
Member

IonBazan commented Feb 21, 2023

@alcaeus I think many people are still stuck on older versions and I wouldn't force them to update to v1.15 yet, especially that it requires updating the PHP extension via pecl which may not be an easy option, depending on their infrastructure.
There are still number of installs of older version. Would you consider relaxing the requirement to ^1.8.0 or ^1.10.0 instead?
image

https://packagist.org/packages/mongodb/mongodb/stats#major/1

@alcaeus
Copy link
Member

alcaeus commented Feb 21, 2023

Bumping to ^1.10 seems sensible in that case. I'm aware that this will require folks to upgrade their extension, but considering that we don't support anything older than 1.15, they should've upgraded already :)

@@ -37,7 +37,7 @@ jobs:
- dependencies: "lowest"
php-version: "7.2"
mongodb-version: "3.6"
driver-version: "1.5.0"
driver-version: "1.10.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mongodb/mongodb 1.10 requires ext-mongodb 1.11 - we've corrected this with 1.15 to restore version number parity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, thanks! Some builds are canceled because of ubuntu-18.04 being deprecated but 20.04 doesn't play well with the mongodb-labs/drivers-evergreen-tools action. Let's look into that in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look 👍

@IonBazan IonBazan force-pushed the issue-2487 branch 2 times, most recently from 9a25306 to ee120a2 Compare February 21, 2023 10:06
@alcaeus alcaeus merged commit 36ba53f into doctrine:2.5.x Feb 24, 2023
@alcaeus
Copy link
Member

alcaeus commented Feb 24, 2023

Thanks @andrey-tech!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants