diff --git a/actions/class.RestQtiTests.php b/actions/class.RestQtiTests.php index d3482a70c..c6ccdacb9 100644 --- a/actions/class.RestQtiTests.php +++ b/actions/class.RestQtiTests.php @@ -136,9 +136,19 @@ public function import() } } - protected function getItemClassUri(): ?string + /** + * @throws common_exception_RestApi + */ + protected function getItemClassUri(): string { - return $this->getPostParameter(self::ITEM_CLASS_URI); + $itemClassUri = $this->getPostParameter(self::ITEM_CLASS_URI, TaoOntology::CLASS_URI_ITEM); + $itemClass = $this->getClass($itemClassUri); + + if (!$itemClass->exists()) { + throw new common_exception_RestApi('Class does not exist. Please use valid ' . self::ITEM_CLASS_URI); + } + + return $itemClassUri; } /** @@ -153,7 +163,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).' ); } 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, );