Skip to content

Commit

Permalink
Fixed small issue with storage view / edit (#30)
Browse files Browse the repository at this point in the history
* Fixed remaining storageclass issue and rewrote storage settings for use with tags

* Fixed missed variable
  • Loading branch information
Anuril authored Oct 13, 2023
1 parent 2cc7995 commit ed89eab
Showing 1 changed file with 6 additions and 40 deletions.
46 changes: 6 additions & 40 deletions src/Api/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,6 @@ public function storage_get_list()
return $storages_grouped;
}

/**
* Get list of storageclasses
*
* @return array
*/
public function storageclass_get_list()
{
$storageclasses = $this->di['db']->find('service_proxmox_storageclass');
return $storageclasses;
}

/**
* Get list of storage controllers
Expand Down Expand Up @@ -224,29 +214,6 @@ public function service_proxmox_get_list()
return $services;
}

/**
* Create a new storageclass
*
* @return array<mixed>
*/
public function storageclass_create($data)
{
$storageclass = $this->di['db']->dispense('service_proxmox_storageclass');
$storageclass->storageclass = $data['storageClassName'];
$this->di['db']->store($storageclass);
return $storageclass;
}

/**
* Retrieve a single storageclass
*
* @return array<mixed>
*/
public function storageclass_get($data)
{
$storageclass = $this->di['db']->getExistingModelById('service_proxmox_storageclass', $data['id'], 'Storageclass not found');
return $storageclass;
}

/**
* Get list of server groups
Expand Down Expand Up @@ -820,8 +787,6 @@ public function storage_get($data)
'used' => $storage->used,
'free' => $storage->free,
'percent_used' => ($storage->size == 0 || $storage->used == 0 || $storage->free == 0) ? 0 : round($storage->used / $storage->size * 100, 2),
// add list of storage classes
'storageclasses' => $this->storageclass_get_list(),
'server_name' => $server->name,
);

Expand All @@ -842,6 +807,7 @@ public function storage_update($data)
$required = array(
'storageid' => 'Storage id is missing',
'storageTypeTags' => 'Storage tags are missing',
'storagetype' => 'Storage type is missing',
);
$this->di['validator']->checkRequiredParamsForArray($required, $data);

Expand All @@ -852,14 +818,14 @@ public function storage_update($data)
$tagArray = [];
foreach ($data['storageTypeTags'] as $tag) {
$splitTags = explode(',', $tag);
$tagArray = array_merge($tagArray, $splitTags);
$tagArray = array_merge($tagArray, $splitTags);
}

$jsonArray = [];
foreach ($tagArray as $tagId) {
foreach ($tagArray as $tagName) {
// Fetch the tag details from DB
$tag_from_db = $this->di['db']->findOne('service_proxmox_tag', 'id=:id AND type=:type', [
':id' => $tagId,
$tag_from_db = $this->di['db']->findOne('service_proxmox_tag', 'name=:name AND type=:type', [
':name' => $tagName,
':type' => $storageType
]);

Expand All @@ -869,7 +835,7 @@ public function storage_update($data)
'name' => $tag_from_db->name
];
} else {
error_log("No DB entry found for tagId: $tagId and type: $storageType");
error_log("No DB entry found for tagId: $tagName and type: $storageType");
}
}

Expand Down

0 comments on commit ed89eab

Please sign in to comment.