Skip to content

Commit

Permalink
chore: throw an exception if item calss does not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
shpran committed Aug 15, 2024
1 parent d92b93f commit 559515c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions actions/class.RestQtiTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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).'
);
}
Expand Down
2 changes: 1 addition & 1 deletion models/classes/tasks/ImportQtiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down

0 comments on commit 559515c

Please sign in to comment.