FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ConfController.php
Go to the documentation of this file.
1 <?php
2 /*
3  Author: Soham Banerjee <sohambanerjee4abc@hotmail.com>
4  SPDX-FileCopyrightText: © 2023 Soham Banerjee <sohambanerjee4abc@hotmail.com>
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
13 namespace Fossology\UI\Api\Controllers;
14 
22 use Psr\Http\Message\ServerRequestInterface;
23 
25 {
35  public function getConfInfo($request, $response, $args)
36  {
37  $uploadPk = $args["id"];
38  $this->uploadAccessible($uploadPk);
39 
40  $response_view = $this->restHelper->getUploadDao()->getReportInfo($uploadPk);
41  $returnVal = new Conf($response_view);
42  return $response->withJson($returnVal->getArray(), 200);
43  }
44 
54  public function updateConfData($request, $response, $args)
55  {
56  $uploadPk = $args["id"];
57  $body = $this->getParsedBody($request);
58  $confObj = new Conf();
59 
60  $this->uploadAccessible($uploadPk);
61 
62  if (empty($body) || !array_key_exists("key", $body) ||
63  !array_key_exists("value", $body)) {
64  throw new HttpBadRequestException("Invalid request.");
65  } elseif (!$confObj->doesKeyExist($body['key'])) {
66  throw new HttpBadRequestException("Invalid key " . $body["key"] .
67  " sent.");
68  }
69 
70  $key = $body['key'];
71  $value = $body['value'];
72  $result = $this->restHelper->getUploadDao()->updateReportInfo($uploadPk,
73  $confObj->getKeyColumnName($key), $value);
74 
75  if ($result) {
76  $info = new Info(200, "Successfully updated " . $key, InfoType::INFO);
77  } else {
78  throw new HttpInternalServerErrorException("Failed to update " . $key);
79  }
80  return $response->withJson($info->getarray(), $info->getCode());
81  }
82 }
updateConfData($request, $response, $args)
getConfInfo($request, $response, $args)
Base controller for REST calls.
getParsedBody(ServerRequestInterface $request)
Parse request body as JSON and return associative PHP array.
Override Slim response for withJson function.
Conf model to contain general error and return values.
Definition: Conf.php:23
Different type of infos provided by REST.
Definition: InfoType.php:16
Info model to contain general error and return values.
Definition: Info.php:19