mirror of
https://github.com/nextcloud/server.git
synced 2024-07-25 13:54:59 +02:00
Deduplicate code
This commit is contained in:
parent
8e1a51731a
commit
a2182cde90
@ -80,6 +80,29 @@ class OCSClient {
|
||||
return $this->config->getSystemValue('appstoreurl', 'https://api.owncloud.com/v1');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $body
|
||||
* @param string $action
|
||||
* @return null|\SimpleXMLElement
|
||||
*/
|
||||
private function loadData($body, $action) {
|
||||
$loadEntities = libxml_disable_entity_loader(true);
|
||||
$data = @simplexml_load_string($body);
|
||||
libxml_disable_entity_loader($loadEntities);
|
||||
|
||||
if($data === false) {
|
||||
$this->logger->error(
|
||||
sprintf('Could not get %s, content was no valid XML', $action),
|
||||
[
|
||||
'app' => 'core',
|
||||
]
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the categories from the OCS server
|
||||
*
|
||||
@ -110,17 +133,8 @@ class OCSClient {
|
||||
return null;
|
||||
}
|
||||
|
||||
$loadEntities = libxml_disable_entity_loader(true);
|
||||
$data = @simplexml_load_string($response->getBody());
|
||||
libxml_disable_entity_loader($loadEntities);
|
||||
|
||||
if($data === false) {
|
||||
$this->logger->error(
|
||||
'Could not get categories, content was no valid XML',
|
||||
[
|
||||
'app' => 'core',
|
||||
]
|
||||
);
|
||||
$data = $this->loadData($response->getBody(), 'categories');
|
||||
if($data === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -175,17 +189,8 @@ class OCSClient {
|
||||
return [];
|
||||
}
|
||||
|
||||
$loadEntities = libxml_disable_entity_loader(true);
|
||||
$data = @simplexml_load_string($response->getBody());
|
||||
libxml_disable_entity_loader($loadEntities);
|
||||
|
||||
if($data === false) {
|
||||
$this->logger->error(
|
||||
'Could not get applications, content was no valid XML',
|
||||
[
|
||||
'app' => 'core',
|
||||
]
|
||||
);
|
||||
$data = $this->loadData($response->getBody(), 'applications');
|
||||
if($data === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -251,17 +256,8 @@ class OCSClient {
|
||||
return null;
|
||||
}
|
||||
|
||||
$loadEntities = libxml_disable_entity_loader(true);
|
||||
$data = @simplexml_load_string($response->getBody());
|
||||
libxml_disable_entity_loader($loadEntities);
|
||||
|
||||
if($data === false) {
|
||||
$this->logger->error(
|
||||
'Could not get application, content was no valid XML',
|
||||
[
|
||||
'app' => 'core',
|
||||
]
|
||||
);
|
||||
$data = $this->loadData($response->getBody(), 'application');
|
||||
if($data === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -316,17 +312,8 @@ class OCSClient {
|
||||
return null;
|
||||
}
|
||||
|
||||
$loadEntities = libxml_disable_entity_loader(true);
|
||||
$data = @simplexml_load_string($response->getBody());
|
||||
libxml_disable_entity_loader($loadEntities);
|
||||
|
||||
if($data === false) {
|
||||
$this->logger->error(
|
||||
'Could not get application download URL, content was no valid XML',
|
||||
[
|
||||
'app' => 'core',
|
||||
]
|
||||
);
|
||||
$data = $this->loadData($response->getBody(), 'application download URL');
|
||||
if($data === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user