diff --git a/actions/class.RestQtiTests.php b/actions/class.RestQtiTests.php index 45d1d7921..88ce5d53f 100644 --- a/actions/class.RestQtiTests.php +++ b/actions/class.RestQtiTests.php @@ -46,7 +46,6 @@ class taoQtiTest_actions_RestQtiTests extends AbstractRestQti */ private const OVERWRITE_TEST = 'overwriteTest'; - private const SUBCLASS_LABEL = 'subclassLabel'; private const OVERWRITE_TEST_URI = 'overwriteTestUri'; private const PACKAGE_LABEL = 'packageLabel'; @@ -136,17 +135,16 @@ public function import() } } - protected function getItemClassUri(): ?string + /** + * @throws common_exception_RestApi + */ + protected function getItemClassUri(): string { - $itemClassUri = $this->getPostParameter(self::ITEM_CLASS_URI); - $subclassLabel = $this->getSubclassLabel(); + $itemClassUri = $this->getPostParameter(self::ITEM_CLASS_URI, TaoOntology::CLASS_URI_ITEM); + $itemClass = $this->getClass($itemClassUri); - if ($subclassLabel) { - foreach ($this->getClass($itemClassUri)->getSubClasses() as $subclass) { - if ($subclass->getLabel() === $subclassLabel) { - $itemClassUri = $subclass->getUri(); - } - } + if (!$itemClass->exists()) { + throw new common_exception_RestApi('Class does not exist. Please use valid ' . self::ITEM_CLASS_URI); } return $itemClassUri; @@ -164,7 +162,7 @@ protected function isOverwriteTest(): bool } if (!in_array($isOverwriteTest, ['true', 'false'])) { - throw new \common_exception_RestApi( + throw new common_exception_RestApi( 'isOverwriteTest parameter should be boolean (true or false).' ); } @@ -321,23 +319,6 @@ private function getUploadedPackageData() return $fileData; } - /** - * @return string|null - * @throws common_exception_RestApi - */ - private function getSubclassLabel(): ?string - { - $subclassLabel = $this->getPostParameter(self::SUBCLASS_LABEL); - - if ($subclassLabel !== null && !is_string($subclassLabel)) { - throw new common_exception_RestApi( - sprintf('%s parameter should be string', self::SUBCLASS_LABEL) - ); - } - - return $subclassLabel; - } - /** * @return string|null * @throws common_exception_RestApi @@ -379,18 +360,7 @@ private function getPackageLabel(): ?string */ private function getTestClass(): core_kernel_classes_Class { - $testClass = $this->getClassFromRequest(new core_kernel_classes_Class(TaoOntology::CLASS_URI_TEST)); - $subclassLabel = $this->getSubclassLabel(); - - if ($subclassLabel) { - foreach ($testClass->getSubClasses() as $subClass) { - if ($subClass->getLabel() === $subclassLabel) { - $testClass = $subClass; - } - } - } - - return $testClass; + return $this->getClassFromRequest(new core_kernel_classes_Class(TaoOntology::CLASS_URI_TEST)); } /** diff --git a/models/classes/tasks/ImportQtiTest.php b/models/classes/tasks/ImportQtiTest.php index a826c988f..3e9fd09ac 100644 --- a/models/classes/tasks/ImportQtiTest.php +++ b/models/classes/tasks/ImportQtiTest.php @@ -94,7 +94,7 @@ public function __invoke($params) $params[self::PARAM_ITEM_MUST_EXIST] ?? false, $params[self::PARAM_ITEM_MUST_BE_OVERWRITTEN] ?? false, $params[self::PARAM_OVERWRITE_TEST] ?? false, - $params[self::PARAM_ITEM_CLASS_URI] ?? false, + $params[self::PARAM_ITEM_CLASS_URI] ?? null, $params[self::PARAM_OVERWRITE_TEST_URI] ?? null, $params[self::PARAM_PACKAGE_LABEL] ?? null, );