@@ -4482,15 +4482,17 @@ public function createDocument(string $collection, Document $document): Document
44824482 }
44834483 }
44844484
4485- $ structure = new Structure (
4486- $ collection ,
4487- $ this ->adapter ->getIdAttributeType (),
4488- $ this ->adapter ->getMinDateTime (),
4489- $ this ->adapter ->getMaxDateTime (),
4490- $ this ->adapter ->getSupportForAttributes ()
4491- );
4492- if (!$ structure ->isValid ($ document )) {
4493- throw new StructureException ($ structure ->getDescription ());
4485+ if ($ this ->validate ) {
4486+ $ structure = new Structure (
4487+ $ collection ,
4488+ $ this ->adapter ->getIdAttributeType (),
4489+ $ this ->adapter ->getMinDateTime (),
4490+ $ this ->adapter ->getMaxDateTime (),
4491+ $ this ->adapter ->getSupportForAttributes ()
4492+ );
4493+ if (!$ structure ->isValid ($ document )) {
4494+ throw new StructureException ($ structure ->getDescription ());
4495+ }
44944496 }
44954497
44964498 $ document = $ this ->adapter ->castingBefore ($ collection , $ document );
@@ -4583,15 +4585,17 @@ public function createDocuments(
45834585
45844586 $ document = $ this ->encode ($ collection , $ document );
45854587
4586- $ validator = new Structure (
4587- $ collection ,
4588- $ this ->adapter ->getIdAttributeType (),
4589- $ this ->adapter ->getMinDateTime (),
4590- $ this ->adapter ->getMaxDateTime (),
4591- $ this ->adapter ->getSupportForAttributes ()
4592- );
4593- if (!$ validator ->isValid ($ document )) {
4594- throw new StructureException ($ validator ->getDescription ());
4588+ if ($ this ->validate ) {
4589+ $ validator = new Structure (
4590+ $ collection ,
4591+ $ this ->adapter ->getIdAttributeType (),
4592+ $ this ->adapter ->getMinDateTime (),
4593+ $ this ->adapter ->getMaxDateTime (),
4594+ $ this ->adapter ->getSupportForAttributes ()
4595+ );
4596+ if (!$ validator ->isValid ($ document )) {
4597+ throw new StructureException ($ validator ->getDescription ());
4598+ }
45954599 }
45964600
45974601 if ($ this ->resolveRelationships ) {
@@ -5145,16 +5149,18 @@ public function updateDocument(string $collection, string $id, Document $documen
51455149
51465150 $ document = $ this ->encode ($ collection , $ document );
51475151
5148- $ structureValidator = new Structure (
5149- $ collection ,
5150- $ this ->adapter ->getIdAttributeType (),
5151- $ this ->adapter ->getMinDateTime (),
5152- $ this ->adapter ->getMaxDateTime (),
5153- $ this ->adapter ->getSupportForAttributes (),
5154- $ old
5155- );
5156- if (!$ structureValidator ->isValid ($ document )) { // Make sure updated structure still apply collection rules (if any)
5157- throw new StructureException ($ structureValidator ->getDescription ());
5152+ if ($ this ->validate ) {
5153+ $ structureValidator = new Structure (
5154+ $ collection ,
5155+ $ this ->adapter ->getIdAttributeType (),
5156+ $ this ->adapter ->getMinDateTime (),
5157+ $ this ->adapter ->getMaxDateTime (),
5158+ $ this ->adapter ->getSupportForAttributes (),
5159+ $ old
5160+ );
5161+ if (!$ structureValidator ->isValid ($ document )) { // Make sure updated structure still apply collection rules (if any)
5162+ throw new StructureException ($ structureValidator ->getDescription ());
5163+ }
51585164 }
51595165
51605166 if ($ this ->resolveRelationships ) {
@@ -5300,17 +5306,19 @@ public function updateDocuments(
53005306 applyDefaults: false
53015307 );
53025308
5303- $ validator = new PartialStructure (
5304- $ collection ,
5305- $ this ->adapter ->getIdAttributeType (),
5306- $ this ->adapter ->getMinDateTime (),
5307- $ this ->adapter ->getMaxDateTime (),
5308- $ this ->adapter ->getSupportForAttributes (),
5309- null // No old document available in bulk updates
5310- );
5309+ if ($ this ->validate ) {
5310+ $ validator = new PartialStructure (
5311+ $ collection ,
5312+ $ this ->adapter ->getIdAttributeType (),
5313+ $ this ->adapter ->getMinDateTime (),
5314+ $ this ->adapter ->getMaxDateTime (),
5315+ $ this ->adapter ->getSupportForAttributes (),
5316+ null // No old document available in bulk updates
5317+ );
53115318
5312- if (!$ validator ->isValid ($ updates )) {
5313- throw new StructureException ($ validator ->getDescription ());
5319+ if (!$ validator ->isValid ($ updates )) {
5320+ throw new StructureException ($ validator ->getDescription ());
5321+ }
53145322 }
53155323
53165324 $ originalLimit = $ limit ;
@@ -6064,17 +6072,19 @@ public function upsertDocumentsWithIncrease(
60646072 }
60656073 }
60666074
6067- $ validator = new Structure (
6068- $ collection ,
6069- $ this ->adapter ->getIdAttributeType (),
6070- $ this ->adapter ->getMinDateTime (),
6071- $ this ->adapter ->getMaxDateTime (),
6072- $ this ->adapter ->getSupportForAttributes (),
6073- $ old ->isEmpty () ? null : $ old
6074- );
6075+ if ($ this ->validate ) {
6076+ $ validator = new Structure (
6077+ $ collection ,
6078+ $ this ->adapter ->getIdAttributeType (),
6079+ $ this ->adapter ->getMinDateTime (),
6080+ $ this ->adapter ->getMaxDateTime (),
6081+ $ this ->adapter ->getSupportForAttributes (),
6082+ $ old ->isEmpty () ? null : $ old
6083+ );
60756084
6076- if (!$ validator ->isValid ($ document )) {
6077- throw new StructureException ($ validator ->getDescription ());
6085+ if (!$ validator ->isValid ($ document )) {
6086+ throw new StructureException ($ validator ->getDescription ());
6087+ }
60786088 }
60796089
60806090 $ document = $ this ->encode ($ collection , $ document );
0 commit comments