feat: improve module management
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -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)]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user