Skip to content

Commit 53f7a9f

Browse files
committed
add schemas to taxonomy and return id on move
1 parent 911b1c1 commit 53f7a9f

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/Backend/Action/Taxonomy/Move.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function handle(RequestInterface $request, ParametersInterface $configura
4747

4848
assert($body instanceof TaxonomyMove);
4949

50-
$this->taxonomyService->move(
50+
$taxonomyId = $this->taxonomyService->move(
5151
$request->get('taxonomy_id'),
5252
$body,
5353
$this->contextFactory->newActionContext($context)
@@ -56,6 +56,7 @@ public function handle(RequestInterface $request, ParametersInterface $configura
5656
return [
5757
'success' => true,
5858
'message' => 'Moved objects to taxonomy successfully',
59+
'id' => '' . $taxonomyId,
5960
];
6061
}
6162
}

src/Service/Taxonomy.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function delete(string $taxonomyId, UserContext $context): int
133133
return $existing->getId();
134134
}
135135

136-
public function move(string $taxonomyId, TaxonomyMove $move, UserContext $context): void
136+
public function move(string $taxonomyId, TaxonomyMove $move, UserContext $context): int
137137
{
138138
$existing = $this->taxonomyTable->findOneByIdentifier($context->getTenantId(), $taxonomyId);
139139
if (empty($existing)) {
@@ -157,6 +157,11 @@ public function move(string $taxonomyId, TaxonomyMove $move, UserContext $contex
157157
$this->mover->moveAction($context->getTenantId(), $context->getCategoryId(), $actionId, $existing);
158158
}
159159

160+
$schemaIds = $move->getSchemas() ?? [];
161+
foreach ($schemaIds as $schemaId) {
162+
$this->mover->moveSchema($context->getTenantId(), $context->getCategoryId(), $schemaId, $existing);
163+
}
164+
160165
$eventIds = $move->getEvents() ?? [];
161166
foreach ($eventIds as $eventId) {
162167
$this->mover->moveEvent($context->getTenantId(), $context->getCategoryId(), $eventId, $existing);
@@ -173,6 +178,8 @@ public function move(string $taxonomyId, TaxonomyMove $move, UserContext $contex
173178
}
174179

175180
$this->taxonomyTable->commit();
181+
182+
return $existing->getId();
176183
} catch (Throwable $e) {
177184
$this->taxonomyTable->rollBack();
178185

src/Service/Taxonomy/Mover.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
public function __construct(
3939
private Table\Operation $operationTable,
4040
private Table\Action $actionTable,
41+
private Table\Schema $schemaTable,
4142
private Table\Event $eventTable,
4243
private Table\Cronjob $cronjobTable,
4344
private Table\Trigger $triggerTable,
@@ -66,6 +67,17 @@ public function moveAction(?string $tenantId, int $categoryId, int $actionId, Ta
6667
$this->actionTable->update($actionRow);
6768
}
6869

70+
public function moveSchema(?string $tenantId, int $categoryId, int $schemaId, TaxonomyRow $taxonomyRow): void
71+
{
72+
$schemaRow = $this->schemaTable->findOneByTenantAndId($tenantId, $categoryId, $schemaId);
73+
if (!$schemaRow instanceof Table\Generated\SchemaRow) {
74+
throw new StatusCode\BadRequestException('Provided an invalid schema id: ' . $schemaId);
75+
}
76+
77+
$schemaRow->setTaxonomyId($taxonomyRow->getId());
78+
$this->schemaTable->update($schemaRow);
79+
}
80+
6981
public function moveEvent(?string $tenantId, int $categoryId, int $eventId, TaxonomyRow $taxonomyRow): void
7082
{
7183
$eventRow = $this->eventTable->findOneByTenantAndId($tenantId, $categoryId, $eventId);

0 commit comments

Comments
 (0)