@@ -4464,15 +4464,17 @@ public function createDocument(string $collection, Document $document): Document
44644464 }
44654465 }
44664466
4467- $ structure = new Structure (
4468- $ collection ,
4469- $ this ->adapter ->getIdAttributeType (),
4470- $ this ->adapter ->getMinDateTime (),
4471- $ this ->adapter ->getMaxDateTime (),
4472- $ this ->adapter ->getSupportForAttributes ()
4473- );
4474- if (!$ structure ->isValid ($ document )) {
4475- throw new StructureException ($ structure ->getDescription ());
4467+ if ($ this ->validate ) {
4468+ $ structure = new Structure (
4469+ $ collection ,
4470+ $ this ->adapter ->getIdAttributeType (),
4471+ $ this ->adapter ->getMinDateTime (),
4472+ $ this ->adapter ->getMaxDateTime (),
4473+ $ this ->adapter ->getSupportForAttributes ()
4474+ );
4475+ if (!$ structure ->isValid ($ document )) {
4476+ throw new StructureException ($ structure ->getDescription ());
4477+ }
44764478 }
44774479
44784480 $ document = $ this ->adapter ->castingBefore ($ collection , $ document );
@@ -4565,15 +4567,17 @@ public function createDocuments(
45654567
45664568 $ document = $ this ->encode ($ collection , $ document );
45674569
4568- $ validator = new Structure (
4569- $ collection ,
4570- $ this ->adapter ->getIdAttributeType (),
4571- $ this ->adapter ->getMinDateTime (),
4572- $ this ->adapter ->getMaxDateTime (),
4573- $ this ->adapter ->getSupportForAttributes ()
4574- );
4575- if (!$ validator ->isValid ($ document )) {
4576- throw new StructureException ($ validator ->getDescription ());
4570+ if ($ this ->validate ) {
4571+ $ validator = new Structure (
4572+ $ collection ,
4573+ $ this ->adapter ->getIdAttributeType (),
4574+ $ this ->adapter ->getMinDateTime (),
4575+ $ this ->adapter ->getMaxDateTime (),
4576+ $ this ->adapter ->getSupportForAttributes ()
4577+ );
4578+ if (!$ validator ->isValid ($ document )) {
4579+ throw new StructureException ($ validator ->getDescription ());
4580+ }
45774581 }
45784582
45794583 if ($ this ->resolveRelationships ) {
@@ -5127,16 +5131,18 @@ public function updateDocument(string $collection, string $id, Document $documen
51275131
51285132 $ document = $ this ->encode ($ collection , $ document );
51295133
5130- $ structureValidator = new Structure (
5131- $ collection ,
5132- $ this ->adapter ->getIdAttributeType (),
5133- $ this ->adapter ->getMinDateTime (),
5134- $ this ->adapter ->getMaxDateTime (),
5135- $ this ->adapter ->getSupportForAttributes (),
5136- $ old
5137- );
5138- if (!$ structureValidator ->isValid ($ document )) { // Make sure updated structure still apply collection rules (if any)
5139- throw new StructureException ($ structureValidator ->getDescription ());
5134+ if ($ this ->validate ) {
5135+ $ structureValidator = new Structure (
5136+ $ collection ,
5137+ $ this ->adapter ->getIdAttributeType (),
5138+ $ this ->adapter ->getMinDateTime (),
5139+ $ this ->adapter ->getMaxDateTime (),
5140+ $ this ->adapter ->getSupportForAttributes (),
5141+ $ old
5142+ );
5143+ if (!$ structureValidator ->isValid ($ document )) { // Make sure updated structure still apply collection rules (if any)
5144+ throw new StructureException ($ structureValidator ->getDescription ());
5145+ }
51405146 }
51415147
51425148 if ($ this ->resolveRelationships ) {
@@ -5282,17 +5288,19 @@ public function updateDocuments(
52825288 applyDefaults: false
52835289 );
52845290
5285- $ validator = new PartialStructure (
5286- $ collection ,
5287- $ this ->adapter ->getIdAttributeType (),
5288- $ this ->adapter ->getMinDateTime (),
5289- $ this ->adapter ->getMaxDateTime (),
5290- $ this ->adapter ->getSupportForAttributes (),
5291- null // No old document available in bulk updates
5292- );
5291+ if ($ this ->validate ) {
5292+ $ validator = new PartialStructure (
5293+ $ collection ,
5294+ $ this ->adapter ->getIdAttributeType (),
5295+ $ this ->adapter ->getMinDateTime (),
5296+ $ this ->adapter ->getMaxDateTime (),
5297+ $ this ->adapter ->getSupportForAttributes (),
5298+ null // No old document available in bulk updates
5299+ );
52935300
5294- if (!$ validator ->isValid ($ updates )) {
5295- throw new StructureException ($ validator ->getDescription ());
5301+ if (!$ validator ->isValid ($ updates )) {
5302+ throw new StructureException ($ validator ->getDescription ());
5303+ }
52965304 }
52975305
52985306 $ originalLimit = $ limit ;
@@ -6046,17 +6054,19 @@ public function upsertDocumentsWithIncrease(
60466054 }
60476055 }
60486056
6049- $ validator = new Structure (
6050- $ collection ,
6051- $ this ->adapter ->getIdAttributeType (),
6052- $ this ->adapter ->getMinDateTime (),
6053- $ this ->adapter ->getMaxDateTime (),
6054- $ this ->adapter ->getSupportForAttributes (),
6055- $ old ->isEmpty () ? null : $ old
6056- );
6057+ if ($ this ->validate ) {
6058+ $ validator = new Structure (
6059+ $ collection ,
6060+ $ this ->adapter ->getIdAttributeType (),
6061+ $ this ->adapter ->getMinDateTime (),
6062+ $ this ->adapter ->getMaxDateTime (),
6063+ $ this ->adapter ->getSupportForAttributes (),
6064+ $ old ->isEmpty () ? null : $ old
6065+ );
60576066
6058- if (!$ validator ->isValid ($ document )) {
6059- throw new StructureException ($ validator ->getDescription ());
6067+ if (!$ validator ->isValid ($ document )) {
6068+ throw new StructureException ($ validator ->getDescription ());
6069+ }
60606070 }
60616071
60626072 $ document = $ this ->encode ($ collection , $ document );
0 commit comments