807353cbe4
RepositoryImportSource::copyToFolder() called putContent() on the generic return type of Node::get(), which doesn't declare that method -- only File does. Existing-file overwrite during a per-user restore would have fatally errored at runtime; added an instanceof check and a resource leak fix (finally-close) while there. Also guarded getFileAsStream() against fopen() returning false. Everything else Psalm (strict level) currently flags is mechanical (missing `final` on leaf classes -- applied everywhere safe) or pre-existing array-shape/type gaps, captured in psalm-baseline.xml so CI fails only on new issues from here on, not the whole backlog at once.
46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
// SPDX-FileCopyrightText: 2026 Dillard Blom
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
namespace OCA\NgBackup\Db;
|
|
|
|
use OCP\AppFramework\Db\QBMapper;
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
use OCP\IDBConnection;
|
|
|
|
/** @template-extends QBMapper<Snapshot> */
|
|
final class SnapshotMapper extends QBMapper {
|
|
public function __construct(IDBConnection $db) {
|
|
parent::__construct($db, 'ngb_snapshots', Snapshot::class);
|
|
}
|
|
|
|
/** @return list<Snapshot> newest first */
|
|
public function findForTarget(int $targetId): array {
|
|
$qb = $this->db->getQueryBuilder();
|
|
$qb->select('*')->from($this->getTableName())
|
|
->where($qb->expr()->eq('target_id', $qb->createNamedParameter($targetId, IQueryBuilder::PARAM_INT)))
|
|
->orderBy('created_at', 'DESC');
|
|
return $this->findEntities($qb);
|
|
}
|
|
|
|
public function findOne(int $targetId, string $snapshotId): Snapshot {
|
|
$qb = $this->db->getQueryBuilder();
|
|
$qb->select('*')->from($this->getTableName())
|
|
->where($qb->expr()->eq('target_id', $qb->createNamedParameter($targetId, IQueryBuilder::PARAM_INT)))
|
|
->andWhere($qb->expr()->eq('snapshot_id', $qb->createNamedParameter($snapshotId)));
|
|
return $this->findEntity($qb);
|
|
}
|
|
|
|
public function latest(int $targetId, string $kind): ?Snapshot {
|
|
foreach ($this->findForTarget($targetId) as $s) {
|
|
if ($s->getKind() === $kind) {
|
|
return $s;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|