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

Merge release 2.2.3 into 2.3.x #2393

Merged
merged 15 commits into from
Nov 30, 2021
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
use Doctrine\ODM\MongoDB\UnitOfWork;
use Doctrine\ODM\MongoDB\Utility\CollectionHelper;

use function array_udiff;
use function array_combine;
use function array_diff_key;
use function array_map;
use function array_udiff_assoc;
use function array_values;
use function count;
use function get_class;
use function is_object;
use function spl_object_hash;

/**
* Trait with methods needed to implement PersistentCollectionInterface.
Expand Down Expand Up @@ -255,18 +256,11 @@ static function ($a, $b) {
/** {@inheritdoc} */
public function getDeletedDocuments()
{
$compare = static function ($a, $b) {
$compareA = is_object($a) ? spl_object_hash($a) : $a;
$compareb = is_object($b) ? spl_object_hash($b) : $b;
$coll = $this->coll->toArray();
$loadedObjectsByOid = array_combine(array_map('spl_object_id', $this->snapshot), $this->snapshot);
$newObjectsByOid = array_combine(array_map('spl_object_id', $coll), $coll);

return $compareA === $compareb ? 0 : ($compareA > $compareb ? 1 : -1);
};

return array_values(array_udiff(
$this->snapshot,
$this->coll->toArray(),
$compare
));
return array_values(array_diff_key($loadedObjectsByOid, $newObjectsByOid));
}

/** {@inheritdoc} */
Expand All @@ -284,18 +278,11 @@ static function ($a, $b) {
/** {@inheritdoc} */
public function getInsertedDocuments()
{
$compare = static function ($a, $b) {
$compareA = is_object($a) ? spl_object_hash($a) : $a;
$compareb = is_object($b) ? spl_object_hash($b) : $b;
$coll = $this->coll->toArray();
$newObjectsByOid = array_combine(array_map('spl_object_id', $coll), $coll);
$loadedObjectsByOid = array_combine(array_map('spl_object_id', $this->snapshot), $this->snapshot);

return $compareA === $compareb ? 0 : ($compareA > $compareb ? 1 : -1);
};

return array_values(array_udiff(
$this->coll->toArray(),
$this->snapshot,
$compare
));
return array_values(array_diff_key($newObjectsByOid, $loadedObjectsByOid));
}

/** {@inheritdoc} */
Expand Down