Skip to content

Commit f3fd94d

Browse files
committed
add action and schema commit table
1 parent 94ec16f commit f3fd94d

File tree

5 files changed

+101
-31
lines changed

5 files changed

+101
-31
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Auto-generated Migration: Please modify to your needs!
1212
*/
13-
final class Version20260103120756 extends AbstractMigration
13+
final class Version20260204195815 extends AbstractMigration
1414
{
1515
public function getDescription(): string
1616
{
@@ -54,8 +54,6 @@ public function up(Schema $schema): void
5454

5555
public function down(Schema $schema): void
5656
{
57-
// this down() migration is auto-generated, please modify it to your needs
58-
5957
}
6058

6159
public function isTransactional(): bool

src/Service/Action/Committer.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
namespace Fusio\Impl\Service\Action;
2222

23-
use Doctrine\DBAL\Connection;
2423
use Fusio\Impl\Authorization\UserContext;
24+
use Fusio\Impl\Table;
2525
use PSX\DateTime\LocalDateTime;
2626

2727
/**
@@ -34,26 +34,24 @@
3434
readonly class Committer
3535
{
3636
public function __construct(
37-
private Connection $connection,
37+
private Table\ActionCommit $actionCommitTable,
3838
) {
3939
}
4040

4141
public function commit(int $actionId, string $config, UserContext $context): void
4242
{
43-
$prevHash = (string) $this->connection->fetchOne('SELECT commit_hash FROM fusio_action_commit WHERE action_id = :action_id ORDER BY id DESC', [
44-
'action_id' => $actionId,
45-
]);
43+
$previousHash = $this->actionCommitTable->findPreviousHash($actionId);
4644

4745
$now = LocalDateTime::now();
48-
$hash = sha1($actionId . $context->getUserId() . $prevHash . $config . $now->toString());
46+
$hash = sha1($actionId . $context->getUserId() . $previousHash . $config . $now->toString());
4947

50-
$this->connection->insert('fusio_action_commit', [
51-
'action_id' => $actionId,
52-
'user_id' => $context->getUserId(),
53-
'prev_hash' => $prevHash,
54-
'commit_hash' => $hash,
55-
'config' => $config,
56-
'insert_date' => $now,
57-
]);
48+
$row = new Table\Generated\ActionCommitRow();
49+
$row->setActionId($actionId);
50+
$row->setUserId($context->getUserId());
51+
$row->setPrevHash($previousHash);
52+
$row->setCommitHash($hash);
53+
$row->setConfig($config);
54+
$row->setInsertDate($now);
55+
$this->actionCommitTable->create($row);
5856
}
5957
}

src/Service/Schema/Committer.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
namespace Fusio\Impl\Service\Schema;
2222

23-
use Doctrine\DBAL\Connection;
2423
use Fusio\Impl\Authorization\UserContext;
24+
use Fusio\Impl\Table;
2525
use PSX\DateTime\LocalDateTime;
2626

2727
/**
@@ -34,26 +34,24 @@
3434
readonly class Committer
3535
{
3636
public function __construct(
37-
private Connection $connection,
37+
private Table\SchemaCommit $schemaCommitTable,
3838
) {
3939
}
4040

4141
public function commit(int $schemaId, string $source, UserContext $context): void
4242
{
43-
$prevHash = (string) $this->connection->fetchOne('SELECT commit_hash FROM fusio_schema_commit WHERE schema_id = :schema_id ORDER BY id DESC', [
44-
'schema_id' => $schemaId,
45-
]);
43+
$previousHash = $this->schemaCommitTable->findPreviousHash($schemaId);
4644

4745
$now = LocalDateTime::now();
48-
$hash = sha1($schemaId . $context->getUserId() . $prevHash . $source . $now->toString());
46+
$hash = sha1($schemaId . $context->getUserId() . $previousHash . $source . $now->toString());
4947

50-
$this->connection->insert('fusio_schema_commit', [
51-
'schema_id' => $schemaId,
52-
'user_id' => $context->getUserId(),
53-
'prev_hash' => $prevHash,
54-
'commit_hash' => $hash,
55-
'source' => $source,
56-
'insert_date' => $now,
57-
]);
48+
$row = new Table\Generated\SchemaCommitRow();
49+
$row->setSchemaId($schemaId);
50+
$row->setUserId($context->getUserId());
51+
$row->setPrevHash($previousHash);
52+
$row->setCommitHash($hash);
53+
$row->setSource($source);
54+
$row->setInsertDate($now);
55+
$this->schemaCommitTable->create($row);
5856
}
5957
}

src/Table/ActionCommit.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/*
3+
* Fusio - Self-Hosted API Management for Builders.
4+
* For the current version and information visit <https://www.fusio-project.org/>
5+
*
6+
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
namespace Fusio\Impl\Table;
22+
23+
/**
24+
* ActionCommit
25+
*
26+
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
27+
* @license http://www.apache.org/licenses/LICENSE-2.0
28+
* @link https://www.fusio-project.org
29+
*/
30+
class ActionCommit extends Generated\ActionCommitTable
31+
{
32+
public function findPreviousHash(int $actionId): ?string
33+
{
34+
return (string) $this->connection->fetchOne('SELECT commit_hash FROM fusio_action_commit WHERE action_id = :action_id ORDER BY id DESC', [
35+
'action_id' => $actionId,
36+
]);
37+
}
38+
}

src/Table/SchemaCommit.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/*
3+
* Fusio - Self-Hosted API Management for Builders.
4+
* For the current version and information visit <https://www.fusio-project.org/>
5+
*
6+
* Copyright (c) Christoph Kappestein <christoph.kappestein@gmail.com>
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
namespace Fusio\Impl\Table;
22+
23+
/**
24+
* SchemaCommit
25+
*
26+
* @author Christoph Kappestein <christoph.kappestein@gmail.com>
27+
* @license http://www.apache.org/licenses/LICENSE-2.0
28+
* @link https://www.fusio-project.org
29+
*/
30+
class SchemaCommit extends Generated\SchemaCommitTable
31+
{
32+
public function findPreviousHash(int $schemaId): ?string
33+
{
34+
return (string) $this->connection->fetchOne('SELECT commit_hash FROM fusio_schema_commit WHERE schema_id = :schema_id ORDER BY id DESC', [
35+
'schema_id' => $schemaId,
36+
]);
37+
}
38+
}

0 commit comments

Comments
 (0)