Skip to content
Snippets Groups Projects
Commit c581538c authored by Robert Lange's avatar Robert Lange Committed by Dorian Merz
Browse files

refs #16388 [fid] fix caching of libraries in fid client

* set library list in session correctly in method requestLibraryList
* add method 'requestLibraryById' for getting single library from api
parent 9e1cfaae
No related merge requests found
......@@ -488,7 +488,7 @@ class Client
*/
public function requestLibraryList(): array
{
if ($list = $this->session['libraries'][$this->locale] ?? null) {
if ($list = $this->session->libraries[$this->locale] ?? null) {
return $list;
}
......@@ -506,10 +506,47 @@ class Client
return $libary->getId();
}, $list);
return $this->session['libraries'][$this->locale] = array_combine($keys,
if (empty($this->session->libraries)) {
$this->session->libraries = [];
}
return $this->session->libraries[$this->locale] = array_combine($keys,
$list);
}
/**
* @param $id
* @return Library
* @throws ClientException
*/
public function requestLibraryById($id): Library
{
if ($library = $this->session->homeLibrary[$this->locale] ?? null) {
return $library;
}
$request = $this->buildRequest('get', "libraries/$id");
$response = $this->sendAuthenticatedRequest($request);
if ($response->getStatusCode() !== 200) {
$this->throwException($response);
}
/** @var Library $list */
$library = $this->serializer->deserialize(
(string)$response->getBody(), Library::class, 'json');
$phpTypeCasting = array_map(function (Library $library) {
return $library->getId();
}, [$library]);
if (empty($this->session->homeLibrary)) {
$this->session->homeLibrary = [];
}
return $this->session->homeLibrary[$this->locale] = array_combine($phpTypeCasting, [$library])[$id];
}
/**
* @param User $user
* @param array $groups
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment