diff options
author | Joas Schilling <coding@schilljs.com> | 2019-01-30 18:59:03 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-02-20 14:17:35 +0300 |
commit | 835e6bdc77881eba0979b396e975053786b98e82 (patch) | |
tree | ccb9497ce25a492965f0bc47a92d4410a2d5c6fb /lib/Model | |
parent | 18aa82dabf3a00d34ce4e17010fd9bd67e0792d3 (diff) |
Add console commands to manage commands
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Model')
-rw-r--r-- | lib/Model/Command.php | 15 | ||||
-rw-r--r-- | lib/Model/CommandMapper.php | 20 |
2 files changed, 32 insertions, 3 deletions
diff --git a/lib/Model/Command.php b/lib/Model/Command.php index be8329f09..c6a949b11 100644 --- a/lib/Model/Command.php +++ b/lib/Model/Command.php @@ -75,4 +75,19 @@ class Command extends Entity { $this->addType('response', 'int'); $this->addType('enabled', 'int'); } + + /** + * @return array + */ + public function asArray(): array { + return [ + 'id' => $this->getId(), + 'app' => $this->getApp(), + 'name' => $this->getName(), + 'command' => $this->getCommand(), + 'script' => $this->getScript(), + 'response' => $this->getResponse(), + 'enabled' => $this->getEnabled(), + ]; + } } diff --git a/lib/Model/CommandMapper.php b/lib/Model/CommandMapper.php index 226e673fc..e3b842417 100644 --- a/lib/Model/CommandMapper.php +++ b/lib/Model/CommandMapper.php @@ -38,12 +38,12 @@ class CommandMapper extends QBMapper { * @return Command[] */ public function findAll(): array { - $qb = $this->db->getQueryBuilder(); - $qb->select('*') + $query = $this->db->getQueryBuilder(); + $query->select('*') ->from($this->getTableName()) ->orderBy('id', 'ASC'); - return $this->findEntities($qb); + return $this->findEntities($query); } /** @@ -62,6 +62,20 @@ class CommandMapper extends QBMapper { /** * @param string $app + * @return Command[] + */ + public function findByApp(string $app): array { + $query = $this->db->getQueryBuilder(); + $query->select('*') + ->from($this->getTableName()) + ->where($query->expr()->eq('app', $query->createNamedParameter($app))) + ->orderBy('id', 'ASC'); + + return $this->findEntities($query); + } + + /** + * @param string $app * @param string $cmd * @return Command * @throws \OCP\AppFramework\Db\DoesNotExistException |