Merge pull request #1156 from nextcloud/fix/1027

fix: Remove deleted resource from associated applications
This commit is contained in:
Cleopatra
2024-09-11 12:23:10 +01:00
committed by GitHub
6 changed files with 76 additions and 22 deletions

View File

@ -31,6 +31,26 @@ class ContextNodeRelationMapper extends QBMapper {
$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

View File

@ -72,4 +72,11 @@ class PageContentMapper extends QBMapper {
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();
}
}

View File

@ -261,6 +261,18 @@ class ContextService {
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

View File

@ -453,6 +453,9 @@ class TableService extends SuperService {
// 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);

View File

@ -308,6 +308,9 @@ class ViewService extends SuperService {
}
$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);
@ -341,6 +344,9 @@ class ViewService extends SuperService {
// 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);

View File

@ -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 }}
</h1>
</div>
<div class="row space-L context__description">
@ -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)
}
}
}
}