@@ -450,22 +450,30 @@ private function getClassesForCommitAction(array $documents, bool $includeEmbedd
450
450
if (empty ($ documents )) {
451
451
return [];
452
452
}
453
+
453
454
$ divided = [];
454
455
$ embeds = [];
455
456
foreach ($ documents as $ oid => $ d ) {
456
457
$ className = get_class ($ d );
457
458
if (isset ($ embeds [$ className ])) {
458
459
continue ;
459
460
}
461
+
460
462
if (isset ($ divided [$ className ])) {
461
463
$ divided [$ className ][1 ][$ oid ] = $ d ;
462
464
continue ;
463
465
}
466
+
464
467
$ class = $ this ->dm ->getClassMetadata ($ className );
465
468
if ($ class ->isEmbeddedDocument && ! $ includeEmbedded ) {
466
469
$ embeds [$ className ] = true ;
467
470
continue ;
468
471
}
472
+
473
+ if ($ class ->isView ()) {
474
+ continue ;
475
+ }
476
+
469
477
if (empty ($ divided [$ class ->name ])) {
470
478
$ divided [$ class ->name ] = [$ class , [$ oid => $ d ]];
471
479
} else {
@@ -485,7 +493,7 @@ private function computeScheduleInsertsChangeSets() : void
485
493
{
486
494
foreach ($ this ->documentInsertions as $ document ) {
487
495
$ class = $ this ->dm ->getClassMetadata (get_class ($ document ));
488
- if ($ class ->isEmbeddedDocument ) {
496
+ if ($ class ->isEmbeddedDocument || $ class -> isView () ) {
489
497
continue ;
490
498
}
491
499
@@ -502,7 +510,7 @@ private function computeScheduleUpsertsChangeSets() : void
502
510
{
503
511
foreach ($ this ->documentUpserts as $ document ) {
504
512
$ class = $ this ->dm ->getClassMetadata (get_class ($ document ));
505
- if ($ class ->isEmbeddedDocument ) {
513
+ if ($ class ->isEmbeddedDocument || $ class -> isView () ) {
506
514
continue ;
507
515
}
508
516
@@ -611,6 +619,10 @@ public function computeChangeSet(ClassMetadata $class, object $document) : void
611
619
*/
612
620
private function computeOrRecomputeChangeSet (ClassMetadata $ class , object $ document , bool $ recompute = false ) : void
613
621
{
622
+ if ($ class ->isView ()) {
623
+ return ;
624
+ }
625
+
614
626
$ oid = spl_object_hash ($ document );
615
627
$ actualData = $ this ->getDocumentActualData ($ document );
616
628
$ isNewDocument = ! isset ($ this ->originalDocumentData [$ oid ]);
@@ -813,7 +825,7 @@ public function computeChangeSets() : void
813
825
// Compute changes for other MANAGED documents. Change tracking policies take effect here.
814
826
foreach ($ this ->identityMap as $ className => $ documents ) {
815
827
$ class = $ this ->dm ->getClassMetadata ($ className );
816
- if ($ class ->isEmbeddedDocument ) {
828
+ if ($ class ->isEmbeddedDocument || $ class -> isView () ) {
817
829
/* we do not want to compute changes to embedded documents up front
818
830
* in case embedded document was replaced and its changeset
819
831
* would corrupt data. Embedded documents' change set will
@@ -1280,7 +1292,7 @@ public function isScheduledForSynchronization(object $document) : bool
1280
1292
*
1281
1293
* @internal
1282
1294
*/
1283
- public function scheduleForDelete (object $ document ) : void
1295
+ public function scheduleForDelete (object $ document, bool $ isView = false ) : void
1284
1296
{
1285
1297
$ oid = spl_object_hash ($ document );
1286
1298
@@ -1307,6 +1319,10 @@ public function scheduleForDelete(object $document) : void
1307
1319
return ;
1308
1320
}
1309
1321
1322
+ if ($ isView ) {
1323
+ return ;
1324
+ }
1325
+
1310
1326
$ this ->documentDeletions [$ oid ] = $ document ;
1311
1327
}
1312
1328
@@ -1559,7 +1575,7 @@ public function containsId($id, string $rootClassName) : bool
1559
1575
public function persist (object $ document ) : void
1560
1576
{
1561
1577
$ class = $ this ->dm ->getClassMetadata (get_class ($ document ));
1562
- if ($ class ->isMappedSuperclass || $ class ->isQueryResultDocument || $ class -> isView () ) {
1578
+ if ($ class ->isMappedSuperclass || $ class ->isQueryResultDocument ) {
1563
1579
throw MongoDBException::cannotPersistMappedSuperclass ($ class ->name );
1564
1580
}
1565
1581
$ visited = [];
@@ -1592,7 +1608,7 @@ private function doPersist(object $document, array &$visited) : void
1592
1608
switch ($ documentState ) {
1593
1609
case self ::STATE_MANAGED :
1594
1610
// Nothing to do, except if policy is "deferred explicit"
1595
- if ($ class ->isChangeTrackingDeferredExplicit ()) {
1611
+ if ($ class ->isChangeTrackingDeferredExplicit () && ! $ class -> isView () ) {
1596
1612
$ this ->scheduleForSynchronization ($ document );
1597
1613
}
1598
1614
break ;
@@ -1601,6 +1617,10 @@ private function doPersist(object $document, array &$visited) : void
1601
1617
throw MongoDBException::cannotPersistGridFSFile ($ class ->name );
1602
1618
}
1603
1619
1620
+ if ($ class ->isView ()) {
1621
+ return ;
1622
+ }
1623
+
1604
1624
$ this ->persistNew ($ class , $ document );
1605
1625
break ;
1606
1626
@@ -1666,7 +1686,7 @@ private function doRemove(object $document, array &$visited) : void
1666
1686
break ;
1667
1687
case self ::STATE_MANAGED :
1668
1688
$ this ->lifecycleEventManager ->preRemove ($ class , $ document );
1669
- $ this ->scheduleForDelete ($ document );
1689
+ $ this ->scheduleForDelete ($ document, $ class -> isView () );
1670
1690
break ;
1671
1691
case self ::STATE_DETACHED :
1672
1692
throw MongoDBException::detachedDocumentCannotBeRemoved ();
@@ -2560,7 +2580,7 @@ public function getOrCreateDocument(string $className, array $data, array &$hint
2560
2580
$ isManagedObject = false ;
2561
2581
$ serializedId = null ;
2562
2582
$ id = null ;
2563
- if (! $ class ->isQueryResultDocument && ! $ class -> isView () ) {
2583
+ if (! $ class ->isQueryResultDocument ) {
2564
2584
$ id = $ class ->getDatabaseIdentifierValue ($ data ['_id ' ]);
2565
2585
$ serializedId = serialize ($ id );
2566
2586
$ isManagedObject = isset ($ this ->identityMap [$ class ->name ][$ serializedId ]);
@@ -2588,7 +2608,7 @@ public function getOrCreateDocument(string $className, array $data, array &$hint
2588
2608
$ document = $ class ->newInstance ();
2589
2609
}
2590
2610
2591
- if (! $ class ->isQueryResultDocument && ! $ class -> isView () ) {
2611
+ if (! $ class ->isQueryResultDocument ) {
2592
2612
$ this ->registerManaged ($ document , $ id , $ data );
2593
2613
$ oid = spl_object_hash ($ document );
2594
2614
$ this ->documentStates [$ oid ] = self ::STATE_MANAGED ;
0 commit comments