Skip to content

Commit

Permalink
fix: Avoid undefined variable
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliushaertl committed Dec 5, 2023
1 parent 216f3d9 commit 4cdd771
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 44 deletions.
55 changes: 20 additions & 35 deletions lib/Db/BoardMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

namespace OCA\Deck\Db;

use OC\Cache\CappedMemoryCache;
use OCA\Deck\Service\CirclesService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\Cache\CappedMemoryCache;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IGroupManager;
Expand All @@ -35,37 +35,22 @@

/** @template-extends QBMapper<Board> */
class BoardMapper extends QBMapper implements IPermissionMapper {
private $labelMapper;
private $aclMapper;
private $stackMapper;
private $userManager;
private $groupManager;
private $circlesService;
private $logger;

/** @var CappedMemoryCache<Board[]> */
private $userBoardCache;
private CappedMemoryCache $userBoardCache;
/** @var CappedMemoryCache<Board> */
private $boardCache;
private CappedMemoryCache $boardCache;

public function __construct(
IDBConnection $db,
LabelMapper $labelMapper,
AclMapper $aclMapper,
StackMapper $stackMapper,
IUserManager $userManager,
IGroupManager $groupManager,
CirclesService $circlesService,
LoggerInterface $logger
private LabelMapper $labelMapper,
private AclMapper $aclMapper,
private StackMapper $stackMapper,
private IUserManager $userManager,
private IGroupManager $groupManager,
private CirclesService $circlesService,
private LoggerInterface $logger
) {
parent::__construct($db, 'deck_boards', Board::class);
$this->labelMapper = $labelMapper;
$this->aclMapper = $aclMapper;
$this->stackMapper = $stackMapper;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->circlesService = $circlesService;
$this->logger = $logger;

$this->userBoardCache = new CappedMemoryCache();
$this->boardCache = new CappedMemoryCache();
Expand All @@ -81,30 +66,31 @@ public function __construct(
* @throws DoesNotExistException
*/
public function find(int $id, bool $withLabels = false, bool $withAcl = false, bool $allowDeleted = false): Board {
if (!isset($this->boardCache[$id])) {
$cacheKey = (string)$id;
if (!isset($this->boardCache[$cacheKey])) {
$qb = $this->db->getQueryBuilder();
$deletedWhere = $allowDeleted ? $qb->expr()->gte('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)) : $qb->expr()->eq('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT));
$qb->select('*')
->from('deck_boards')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
->andWhere($deletedWhere)
->orderBy('id');
$this->boardCache[$id] = $this->findEntity($qb);
$this->boardCache[(string)$id] = $this->findEntity($qb);
}

// Add labels
if ($withLabels && $this->boardCache[$id]->getLabels() === null) {
if ($withLabels && $this->boardCache[$cacheKey]->getLabels() === null) {
$labels = $this->labelMapper->findAll($id);
$this->boardCache[$id]->setLabels($labels);
$this->boardCache[$cacheKey]->setLabels($labels);
}

// Add acl
if ($withAcl && $this->boardCache[$id]->getAcl() === null) {
if ($withAcl && $this->boardCache[$cacheKey]->getAcl() === null) {
$acl = $this->aclMapper->findAll($id);
$this->boardCache[$id]->setAcl($acl);
$this->boardCache[$cacheKey]->setAcl($acl);
}

return $this->boardCache[$id];
return $this->boardCache[$cacheKey];
}

public function findBoardIds(string $userId): array {
Expand Down Expand Up @@ -464,8 +450,7 @@ public function findBoardId($id): ?int {
}

public function mapAcl(Acl &$acl) {
$groupManager = $this->groupManager;
$acl->resolveRelation('participant', function ($participant) use (&$acl, &$userManager, &$groupManager) {
$acl->resolveRelation('participant', function ($participant) use (&$acl) {
if ($acl->getType() === Acl::PERMISSION_TYPE_USER) {
if ($this->userManager->userExists($acl->getParticipant())) {
return new User($acl->getParticipant(), $this->userManager);
Expand All @@ -474,7 +459,7 @@ public function mapAcl(Acl &$acl) {
return null;
}
if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
$group = $groupManager->get($participant);
$group = $this->groupManager->get($participant);
if ($group !== null) {
return new Group($group);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/database/AssignmentMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class AssignmentMapperTest extends \Test\TestCase {
/** @var AssignmentService */
private $assignmentService;

/** @var Board */
private $board;
/** @var Card[] */
private $cards;
/** @var Stack[] */
private $stacks;

public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();

Expand Down
14 changes: 5 additions & 9 deletions tests/integration/features/bootstrap/SessionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
class SessionContext implements Context {
use RequestTrait;

/** @var ServerContext */
private $serverContext;

/** @var BoardContext */
private $boardContext;

private $tokens = [];
private ServerContext $serverContext;
private BoardContext $boardContext;
private array $tokens = [];

/** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope) {
Expand All @@ -40,7 +36,7 @@ public function opensTheBoardNamed($name) {

// store token
$user = $this->serverContext->getCurrentUser();
$this->token[$user] = $res['ocs']['data']['token'];
$this->tokens[$user] = $res['ocs']['data']['token'];
}

/**
Expand Down Expand Up @@ -70,7 +66,7 @@ public function closingTheBoardNamed($name) {
}

$user = $this->serverContext->getCurrentUser();
$token = $this->token[$user];
$token = $this->tokens[$user];
Assert::assertNotEmpty($token, "no token for the user found");
$this->requestContext->sendOCSRequest('POST', '/apps/deck/api/v1.0/session/close', [
'boardId' => $board['id'],
Expand Down

0 comments on commit 4cdd771

Please sign in to comment.