From 5af5d5279cf11673f9b673a02684675e7b703d9b Mon Sep 17 00:00:00 2001 From: iszmais <45942348+iszmais@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:32:14 +0100 Subject: [PATCH] secure broken dc ref fields against copy and sort calls (#8600) --- .../Fields/Reference/class.ilDclReferenceFieldModel.php | 6 +++++- Modules/DataCollection/classes/Table/class.ilDclTable.php | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Modules/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldModel.php b/Modules/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldModel.php index 4760d68264cd..40ea498ac1bd 100644 --- a/Modules/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldModel.php +++ b/Modules/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldModel.php @@ -31,7 +31,11 @@ public function getRecordQuerySortObject( global $DIC; $ilDB = $DIC['ilDB']; - if ($this->hasProperty(self::PROP_N_REFERENCE)) { + if ( + $this->hasProperty(self::PROP_N_REFERENCE) || + $this->getProperty(self::PROP_REFERENCE) === null || + ilDclCache::getFieldCache($this->getProperty(self::PROP_REFERENCE))->getTableId() === 0 + ) { return null; } diff --git a/Modules/DataCollection/classes/Table/class.ilDclTable.php b/Modules/DataCollection/classes/Table/class.ilDclTable.php index dbd4ca2589f8..0dcd91b2ac37 100644 --- a/Modules/DataCollection/classes/Table/class.ilDclTable.php +++ b/Modules/DataCollection/classes/Table/class.ilDclTable.php @@ -1060,6 +1060,9 @@ public function cloneStructure(ilDclTable $original): void if (!$orig_field->isStandardField()) { $class_name = get_class($orig_field); $new_field = new $class_name(); + if ($new_field instanceof ilDclReferenceFieldModel && $new_field->getFieldRef()->getTableId() === 0) { + continue; + } $new_field->setTableId($this->getId()); $new_field->cloneStructure((int) $orig_field->getId()); $new_fields[$orig_field->getId()] = $new_field;