Skip to content

Commit

Permalink
Merge branch 'release-54.16.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jul 4, 2024
2 parents f680fd7 + 2744ceb commit 45f695f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
42 changes: 31 additions & 11 deletions actions/class.RdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,7 @@ public function moveResource()
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature($data['signature'], $id);
$this->validateMoveRequest();
$this->validateDestinationClass($destinationClassUri, $this->getResourceParentClass($id));

$result = $this->getResourceTransfer()->transfer(
new ResourceTransferCommand(
Expand All @@ -1010,17 +1011,19 @@ public function moveResource()
],
]
);
} catch (InvalidArgumentException $exception) {
$this->logError(
sprintf(
'Error moving instance %s to %s: %s',
$id ?? '',
$destinationClassUri ?? '',
$exception->getMessage() . ' - ' . $exception->getTraceAsString()
)
} catch (InvalidArgumentException $e) {
$this->returnJson(
[
'success' => true,
'data' => [
'failed' => [
'success' => false,
'message' => $e->getMessage(),
],
],
],
204
);

$this->returnJsonError($e->getMessage());
}
}

Expand Down Expand Up @@ -1686,7 +1689,7 @@ private function validateDestinationClass($destinationUri, $currentClassUri)
{
$destinationClass = $this->getClass($destinationUri);
if (empty($destinationUri) || $destinationUri === $currentClassUri || !$destinationClass->exists()) {
throw new InvalidArgumentException('Wrong destination class uri');
throw new InvalidArgumentException('The selected class already contains the resource');
}
}

Expand Down Expand Up @@ -1714,4 +1717,21 @@ private function getResourceTransfer(): ResourceTransferInterface
{
return $this->getPsrContainer()->get(ResourceTransferProxy::class);
}

private function getResourceParentClass(string $id): string
{
$types = $this->getResource($id)->getTypes();
if (count($types) !== 1) {
throw new InvalidArgumentException('Resource has no class or resource types are ambiguous');
}

/** @var core_kernel_classes_Class $type */
$type = reset($types);

if (!($type instanceof core_kernel_classes_Class) && !$type->isClass()) {
throw new InvalidArgumentException('Type is not a class');
}

return $type->getUri();
}
}
2 changes: 1 addition & 1 deletion models/classes/http/LegacyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getRequestParameter($name)
*
* @param string $paramName
* @throws \common_exception_MissingParameter
* @return string
* @return string|array
*/
protected function getRawParameter($paramName)
{
Expand Down
2 changes: 1 addition & 1 deletion views/js/layout/actions/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ define([
});

if (!success.length) {
feedback().error(__('Unable to move the resources'));
feedback().warning(__(failed.join(', ')));
} else if (failed.length) {
feedback().warning(
__('Some resources have not been moved: %s', failed.join(', '))
Expand Down
2 changes: 1 addition & 1 deletion views/js/loader/tao.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/loader/tao.min.js.map

Large diffs are not rendered by default.

0 comments on commit 45f695f

Please sign in to comment.