Skip to content

Commit

Permalink
fix: Remove deleted resource from associated applications
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
  • Loading branch information
enjeck committed Jun 28, 2024
1 parent 588a259 commit 2a985b0
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 22 deletions.
20 changes: 20 additions & 0 deletions lib/Db/ContextNodeRelationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ public function deleteAllByContextId(int $contextId): void {
$qb->executeStatement();
}

public function getRelIdsForNode(int $nodeId, int $nodeType): array {
$qb = $this->db->getQueryBuilder();
$qb->select('id')->from($this->table)->where($qb->expr()->eq('node_id', $qb->createNamedParameter($nodeId)))
->andWhere($qb->expr()->eq('node_type', $qb->createNamedParameter($nodeType)));
$result = $qb->executeQuery();
$nodeRelIds = [];
while ($row = $result->fetch()) {
$nodeRelIds[] = (int)$row['id'];
}
return $nodeRelIds;
}

public function deleteByNodeRelId(int $nodeRelId): int {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->table)
->where($qb->expr()->eq('id', $qb->createNamedParameter($nodeRelId, IQueryBuilder::PARAM_INT)));
return $qb->executeStatement();
}


/**
* @throws MultipleObjectsReturnedException
* @throws DoesNotExistException
Expand Down
7 changes: 7 additions & 0 deletions lib/Db/PageContentMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,11 @@ public function deleteByPageId(int $pageId): int {

return $qb->executeStatement();
}

public function deleteByNodeRelId(int $nodeRelId): int {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->table)
->where($qb->expr()->eq('node_rel_id', $qb->createNamedParameter($nodeRelId, IQueryBuilder::PARAM_INT)));
return $qb->executeStatement();
}
}
13 changes: 13 additions & 0 deletions lib/Service/ContextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,19 @@ public function delete(int $contextId, string $userId): Context {
return $context;
}

public function deleteNodeRel(int $nodeId, int $nodeType): void {
try {
$nodeRelIds = $this->contextNodeRelMapper->getRelIdsForNode($nodeId, $nodeType);
foreach ($nodeRelIds as $nodeRelId) {
$this->pageContentMapper->deleteByNodeRelId($nodeRelId);
$this->contextNodeRelMapper->deleteByNodeRelId($nodeRelId);
}

} catch (Exception $e) {
$this->logger->error('something went wrong while deleting node relation for node id: '.(string)$nodeId. ' and node type '.(string)$nodeType);
}
}

/**
* @throws MultipleObjectsReturnedException
* @throws DoesNotExistException
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/TableService.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ public function delete(int $id, ?string $userId = null): Table {
// delete all shares for that table
$this->shareService->deleteAllForTable($item);

// delete node relations if view is in any context
$this->contextService->deleteNodeRel($id, Application::NODE_TYPE_TABLE);

// delete table
try {
$this->mapper->delete($item);
Expand Down
6 changes: 6 additions & 0 deletions lib/Service/ViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ public function delete(int $id, ?string $userId = null): View {
}
$this->shareService->deleteAllForView($view);

// delete node relations if view is in any context
$this->contextService->deleteNodeRel($id, Application::NODE_TYPE_VIEW);

try {
$deletedView = $this->mapper->delete($view);

Expand Down Expand Up @@ -335,6 +338,9 @@ public function deleteByObject(View $view, ?string $userId = null): View {
// delete all shares for that table
$this->shareService->deleteAllForView($view);

// delete node relations if view is in any context
$this->contextService->deleteNodeRel($view->getId(), Application::NODE_TYPE_VIEW);

$this->mapper->delete($view);

$event = new ViewDeletedEvent(view: $view);
Expand Down
50 changes: 28 additions & 22 deletions src/pages/Context.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<div class="content context">
<div class="row first-row">
<h1 class="context__title">
<NcIconSvgWrapper :svg="icon" :size="32" style="display: inline-block;" />&nbsp; {{ activeContext.name }}
<NcIconSvgWrapper :svg="icon" :size="32" style="display: inline-block;" />&nbsp; {{
activeContext.name }}
</h1>
</div>
<div class="row space-L context__description">
Expand Down Expand Up @@ -149,29 +150,34 @@ export default {
const nodeType = parseInt(node.node_type)
if (nodeType === NODE_TYPE_TABLE) {
const table = this.tables.find(table => table.id === node.node_id)
await this.$store.dispatch('loadColumnsFromBE', {
view: null,
tableId: table.id,
})
await this.$store.dispatch('loadRowsFromBE', {
viewId: null,
tableId: table.id,
})
table.key = (table.id).toString()
table.isView = false
this.contextResources.push(table)
if (table) {
await this.$store.dispatch('loadColumnsFromBE', {
view: null,
tableId: table.id,
})
await this.$store.dispatch('loadRowsFromBE', {
viewId: null,
tableId: table.id,
})
table.key = (table.id).toString()
table.isView = false
this.contextResources.push(table)
}
} else if (nodeType === NODE_TYPE_VIEW) {
const view = this.views.find(view => view.id === node.node_id)
await this.$store.dispatch('loadColumnsFromBE', {
view,
})
await this.$store.dispatch('loadRowsFromBE', {
viewId: view.id,
tableId: view.tableId,
})
view.key = 'view-' + (view.id).toString()
view.isView = true
this.contextResources.push(view)
if (view) {
await this.$store.dispatch('loadColumnsFromBE', {
view,
})
await this.$store.dispatch('loadRowsFromBE', {
viewId: view.id,
tableId: view.tableId,
})
view.key = 'view-' + (view.id).toString()
view.isView = true
this.contextResources.push(view)
}
}
}
}
Expand Down

0 comments on commit 2a985b0

Please sign in to comment.