Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove deleted resource from associated applications #1156

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/Db/ContextNodeRelationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 deleteByNodeRelIds(array $nodeRelIds): void {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->table)
->where($qb->expr()->in('id', $qb->createNamedParameter($nodeRelIds, IQueryBuilder::PARAM_INT_ARRAY), ':nodeRelIds'));
$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 @@ -72,4 +72,11 @@ public function deleteByPageId(int $pageId): int {

return $qb->executeStatement();
}

public function deleteByNodeRelIds(array $nodeRelIds): void {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->table)
->where($qb->expr()->in('node_rel_id', $qb->createNamedParameter($nodeRelIds, IQueryBuilder::PARAM_INT_ARRAY), ':nodeRelIds'));
$qb->executeStatement();
}
}
12 changes: 12 additions & 0 deletions lib/Service/ContextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,18 @@ 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);
$this->atomic(function () use ($nodeRelIds) {
$this->pageContentMapper->deleteByNodeRelIds($nodeRelIds);
$this->contextNodeRelMapper->deleteByNodeRelIds($nodeRelIds);
}, $this->dbc);
} catch (Exception $e) {
$this->logger->error('Something went wrong while deleting node relation for node id: ' . (string)$nodeId . ' and node type ' . (string)$nodeType, ['exception' => $e]);
}
}

/**
* @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 @@ -453,6 +453,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 @@ -308,6 +308,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 @@ -341,6 +344,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 @@ -9,7 +9,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 }}
enjeck marked this conversation as resolved.
Show resolved Hide resolved
</h1>
</div>
<div class="row space-L context__description">
Expand Down Expand Up @@ -153,29 +154,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
Loading