From aa751781cec7d86b277c374da121fe3fbb8a53e6 Mon Sep 17 00:00:00 2001 From: Andrei Shapiro Date: Thu, 15 Aug 2024 02:54:42 +0300 Subject: [PATCH 1/3] chore: remove unnecessary parameter --- actions/class.RestQtiTests.php | 43 ++-------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/actions/class.RestQtiTests.php b/actions/class.RestQtiTests.php index 45d1d7921..d3482a70c 100644 --- a/actions/class.RestQtiTests.php +++ b/actions/class.RestQtiTests.php @@ -138,18 +138,7 @@ public function import() protected function getItemClassUri(): ?string { - $itemClassUri = $this->getPostParameter(self::ITEM_CLASS_URI); - $subclassLabel = $this->getSubclassLabel(); - - if ($subclassLabel) { - foreach ($this->getClass($itemClassUri)->getSubClasses() as $subclass) { - if ($subclass->getLabel() === $subclassLabel) { - $itemClassUri = $subclass->getUri(); - } - } - } - - return $itemClassUri; + return $this->getPostParameter(self::ITEM_CLASS_URI); } /** @@ -321,23 +310,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 +351,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)); } /** From 817967ca57f8e02e11965fd395bc0696231f12a1 Mon Sep 17 00:00:00 2001 From: Andrei Shapiro Date: Thu, 15 Aug 2024 10:20:05 +0300 Subject: [PATCH 2/3] chore: throw an exception if item calss does not exists --- actions/class.RestQtiTests.php | 16 +++++++++++++--- models/classes/tasks/ImportQtiTest.php | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) 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, ); From f6b1a01a931b613e5096c9b7e21bcbda8c580b8f Mon Sep 17 00:00:00 2001 From: Andrei Shapiro Date: Thu, 15 Aug 2024 11:07:54 +0300 Subject: [PATCH 3/3] chore: remove unnecessary constant --- actions/class.RestQtiTests.php | 1 - 1 file changed, 1 deletion(-) diff --git a/actions/class.RestQtiTests.php b/actions/class.RestQtiTests.php index c6ccdacb9..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';