feat: improve module management
All checks were successful
JS Unit Tests / test (pull_request) Successful in 39s
Build Test / build (pull_request) Successful in 44s
PHP Unit Tests / test (pull_request) Successful in 53s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-02-22 00:40:38 -05:00
parent f44fd85dcc
commit c687bd0795
12 changed files with 391 additions and 28 deletions

View File

@@ -3,6 +3,7 @@
namespace KTXC\Module\Store;
use KTXC\Db\DataStore;
use KTXC\Db\ObjectId;
class ModuleStore
{
@@ -13,9 +14,18 @@ class ModuleStore
protected readonly DataStore $dataStore
) { }
public function list(): array
public function list(bool|null $installed = null, bool|null $enabled = null): array
{
$cursor = $this->dataStore->selectCollection(self::COLLECTION_NAME)->find(['enabled' => true, 'installed' => true]);
$filter = [];
if ($installed !== null) {
$filter['installed'] = $installed;
}
if ($enabled !== null) {
$filter['enabled'] = $enabled;
}
$cursor = $this->dataStore->selectCollection(self::COLLECTION_NAME)->find($filter);
$modules = [];
foreach ($cursor as $entry) {
$entity = new ModuleEntry();
@@ -52,7 +62,11 @@ class ModuleStore
{
$id = $entry->getId();
if (!$id) { return null; }
$this->dataStore->selectCollection(self::COLLECTION_NAME)->updateOne(['_id' => $id], ['$set' => $entry->jsonSerialize()]);
$data = $entry->jsonSerialize();
unset($data['id']);
$result = $this->dataStore->selectCollection(self::COLLECTION_NAME)->updateOne(['_id' => new ObjectId($id)], ['$set' => $data]);
return $entry;
}
@@ -60,7 +74,7 @@ class ModuleStore
{
$id = $entry->getId();
if (!$id) { return; }
$this->dataStore->selectCollection(self::COLLECTION_NAME)->deleteOne([ '_id' => $id]);
$result = $this->dataStore->selectCollection(self::COLLECTION_NAME)->deleteOne(['_id' => new ObjectId($id)]);
}
}