added DiffTaskResult Entity and Mapper

This commit is contained in:
Jonathan Treffler 2023-09-02 02:41:53 +02:00 committed by root
parent d8651c7780
commit 29aa0d24fa
2 changed files with 84 additions and 0 deletions

48
lib/Db/DiffTaskResult.php Normal file
View file

@ -0,0 +1,48 @@
<?php
namespace OCA\GroupfolderFilesystemSnapshots\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class DiffTaskResult extends Entity implements JsonSerializable {
protected $taskId;
protected $timestamp;
protected $type;
protected $beforeFileExists;
protected $beforePath;
protected $beforeSize;
protected $currentFileExists;
protected $currentPath;
protected $currentSize;
public function __construct() {
$this->addType('id','integer');
$this->addType('taskId','integer');
$this->addType('beforeFileExists','boolean');
$this->addType('beforeSize','integer');
$this->addType('currentFileExists','boolean');
$this->addType('currentSize','integer');
}
public function jsonSerialize() {
return [
'id' => $this->id,
'taskId' => $this->taskId,
'type' => $this->type,
'before' => [
'fileExists' => $this->beforeFileExists,
'path' => $this->beforePath,
'size' => $this->beforeSize,
],
'current' => [
'fileExists' => $this->currentFileExists,
'path' => $this->currentPath,
'size' => $this->currentSize,
]
];
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace OCA\GroupfolderFilesystemSnapshots\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;
/**
* @extends QBMapper<DiffTaskResult>
*/
class DiffTaskResultMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'groupfolder_snapshots_task_results', DiffTaskResult::class);
}
public function find(int $id) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
return $this->findEntity($qb);
}
public function findAll(int $taskId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->eq('task_id', $qb->createNamedParameter($taskId)));
return $this->findEntities($qb);
}
}