-
-
Notifications
You must be signed in to change notification settings - Fork 505
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
Deprecate legacy commit options #2578
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
use Psr\Cache\CacheItemPoolInterface; | ||
use ReflectionClass; | ||
|
||
use function array_key_exists; | ||
use function interface_exists; | ||
use function trigger_deprecation; | ||
use function trim; | ||
|
@@ -449,6 +450,19 @@ public function getDefaultCommitOptions(): array | |
/** @psalm-param CommitOptions $defaultCommitOptions */ | ||
public function setDefaultCommitOptions(array $defaultCommitOptions): void | ||
{ | ||
foreach (UnitOfWork::DEPRECATED_WRITE_OPTIONS as $deprecatedOption) { | ||
if (! array_key_exists($deprecatedOption, $defaultCommitOptions)) { | ||
continue; | ||
} | ||
|
||
trigger_deprecation( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL symfony/deprecation-contracts exists. Is this something we might want to use in PHPLIB down the line? Or do you think we should stick with the forthcoming logging API? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW there's also https://github.com/doctrine/deprecations but we never changed ODM (we were using Symfony's stuff before Doctrine's was introduced) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see no benefits either so no worries ;) |
||
'doctrine/mongodb-odm', | ||
'2.6', | ||
'The "%s" commit option used in the configuration is deprecated.', | ||
$deprecatedOption, | ||
); | ||
} | ||
|
||
$this->attributes['defaultCommitOptions'] = $defaultCommitOptions; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
use UnexpectedValueException; | ||
|
||
use function array_filter; | ||
use function array_key_exists; | ||
use function assert; | ||
use function count; | ||
use function get_class; | ||
|
@@ -42,6 +43,7 @@ | |
use function serialize; | ||
use function spl_object_hash; | ||
use function sprintf; | ||
use function trigger_deprecation; | ||
|
||
/** | ||
* The UnitOfWork is responsible for tracking changes to objects during an | ||
|
@@ -88,6 +90,9 @@ final class UnitOfWork implements PropertyChangedListener | |
*/ | ||
public const STATE_REMOVED = 4; | ||
|
||
/** @internal */ | ||
public const DEPRECATED_WRITE_OPTIONS = ['fsync', 'safe', 'w']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes me wonder how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😅 |
||
|
||
/** | ||
* The identity map holds references to all managed documents. | ||
* | ||
|
@@ -393,6 +398,19 @@ public function setDocumentPersister(string $documentName, Persisters\DocumentPe | |
*/ | ||
public function commit(array $options = []): void | ||
{ | ||
foreach (self::DEPRECATED_WRITE_OPTIONS as $deprecatedOption) { | ||
if (! array_key_exists($deprecatedOption, $options)) { | ||
continue; | ||
} | ||
|
||
trigger_deprecation( | ||
'doctrine/mongodb-odm', | ||
'2.6', | ||
'The "%s" commit option is deprecated.', | ||
$deprecatedOption, | ||
); | ||
} | ||
|
||
// Raise preFlush | ||
$this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->dm)); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to flip this logic and avoid the
continue
? This isn't a matter of nesting conditionals, so I think we could go either way here.Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible with a small change to the phpcs configuration. The early exit is now no longer required if there's only a single if in the scope. Good judgment should still be applied :)