-
Notifications
You must be signed in to change notification settings - Fork 36
#1424: Add Tables to user_migration #2292
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
4e3e6ab
89dd08b
a739c36
5fceb33
07f1953
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Tables\Db; | ||
|
|
||
| use OCP\DB\QueryBuilder\IQueryBuilder; | ||
|
|
||
| trait RowCellBulkFetchTrait { | ||
| /** | ||
| * @param int[] $rowIds | ||
| * @param int[] $columnIds | ||
| * | ||
| * @return array | ||
| */ | ||
| public function findAllByRowIdsAndColumnIds(array $rowIds, array $columnIds): array { | ||
| if (empty($rowIds) || empty($columnIds)) { | ||
| return []; | ||
| } | ||
| $qb = $this->db->getQueryBuilder(); | ||
| $qb->select('*') | ||
| ->from($this->table) | ||
| ->where($qb->expr()->in('row_id', $qb->createNamedParameter($rowIds, IQueryBuilder::PARAM_INT_ARRAY))) | ||
| ->andWhere($qb->expr()->in('column_id', $qb->createNamedParameter($columnIds, IQueryBuilder::PARAM_INT_ARRAY))); | ||
|
|
||
| return $this->findEntities($qb); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| use OCA\Tables\Db\PageContent; | ||
| use OCA\Tables\Db\PageContentMapper; | ||
| use OCA\Tables\Db\PageMapper; | ||
| use OCA\Tables\Db\Table; | ||
| use OCA\Tables\Errors\BadRequestError; | ||
| use OCA\Tables\Errors\InternalError; | ||
| use OCA\Tables\Errors\NotFoundError; | ||
|
|
@@ -508,4 +509,79 @@ protected function insertNodesFromArray(Context $context, array $nodes): void { | |
| } | ||
| $context->setNodes($addedNodes); | ||
| } | ||
|
|
||
| /** | ||
| * @param Table $table | ||
| * @param array $context | ||
| * @param int $tableOldId | ||
| * | ||
| * @return Context|null | ||
| * | ||
| * @throws \Exception | ||
| */ | ||
| public function importContext(Table $table, array $context, int $tableOldId): ?Context { | ||
| // checking if any node in $context['nodes'] matches the old table id | ||
| $hasMatchingNode = false; | ||
| if (!empty($context['nodes'])) { | ||
| foreach ($context['nodes'] as $nodeArr) { | ||
| if (($nodeArr['node_id'] ?? null) == $tableOldId) { | ||
| $hasMatchingNode = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!$hasMatchingNode) { | ||
| return null; | ||
| } | ||
|
|
||
| $newContext = new Context(); | ||
| $newContext->setName($context['name'] ?? ''); | ||
| $newContext->setIcon($context['iconName'] ?? ''); | ||
| $newContext->setDescription($context['description'] ?? ''); | ||
| $newContext->setOwnerId($context['owner'] ?? ''); | ||
|
||
| $newContext->setOwnerType($context['ownerType'] ?? 0); | ||
| $this->contextMapper->insert($newContext); | ||
|
|
||
| // insert nodes | ||
| $nodeRelMap = []; | ||
| if (!empty($context['nodes'])) { | ||
| foreach ($context['nodes'] as $nodeArr) { | ||
| $contextNodeRel = new ContextNodeRelation(); | ||
| $contextNodeRel->setContextId($newContext->getId()); | ||
| $contextNodeRel->setNodeId($table->getId()); | ||
| $contextNodeRel->setNodeType($nodeArr['node_type'] ?? $nodeArr['nodeType'] ?? 0); | ||
| $contextNodeRel->setPermissions($nodeArr['permissions'] ?? 0); | ||
| $contextNodeRel = $this->contextNodeRelMapper->insert($contextNodeRel); | ||
| $nodeRelMap[$nodeArr['id'] ?? null] = $contextNodeRel; | ||
| } | ||
| } | ||
|
|
||
| // insert pages | ||
| $pageMap = []; | ||
| if (!empty($context['pages'])) { | ||
| foreach ($context['pages'] as $pageArr) { | ||
| $page = new Page(); | ||
| $page->setContextId($newContext->getId()); | ||
| $page->setPageType($pageArr['page_type'] ?? $pageArr['pageType'] ?? ''); | ||
| $page = $this->pageMapper->insert($page); | ||
| $pageMap[$pageArr['id'] ?? null] = $page; | ||
|
|
||
| // insert page conten | ||
| if (!empty($pageArr['content'])) { | ||
| foreach ($pageArr['content'] as $contentArr) { | ||
| $pageContent = new PageContent(); | ||
| $pageContent->setPageId($page->getId()); | ||
| $oldNodeRelId = $contentArr['node_rel_id'] ?? $contentArr['nodeRelId'] ?? null; | ||
| $newNodeRel = $nodeRelMap[$oldNodeRelId] ?? null; | ||
| $pageContent->setNodeRelId($newNodeRel ? $newNodeRel->getId() : null); | ||
| $pageContent->setOrder($contentArr['order'] ?? 100); | ||
| $this->pageContentMapper->insert($pageContent); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return $newContext; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure with the abstraction layers in the tables app but you could probably shorten this by using https://github.com/nextcloud/server/blob/master/lib/public/AppFramework/Db/Entity.php#L51-L62
Please verify though, setTableId may need separate handling still.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juliusknorr will do.