Skip to content

Commit 9e9d48a

Browse files
committed
pass hash to lifecycle
1 parent 5d539ea commit 9e9d48a

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

src/Service/Action.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ public function create(ActionCreate $action, UserContext $context): int
6969
$parameters = new Parameters($config);
7070
$handler = $this->newAction($class);
7171

72-
// call lifecycle
73-
if ($handler instanceof LifecycleInterface) {
74-
$handler->onCreate($name, $parameters);
75-
}
76-
7772
// create action
7873
try {
7974
$this->actionTable->beginTransaction();
@@ -93,7 +88,12 @@ public function create(ActionCreate $action, UserContext $context): int
9388
$actionId = $this->actionTable->getLastInsertId();
9489
$action->setId($actionId);
9590

96-
$this->actionCommitter->commit($actionId, $row->getConfig(), $context);
91+
$hash = $this->actionCommitter->commit($actionId, $row->getConfig(), $context);
92+
93+
// call lifecycle
94+
if ($handler instanceof LifecycleInterface) {
95+
$handler->onCreate($name, $parameters, $hash);
96+
}
9797

9898
$this->actionTable->commit();
9999
} catch (Throwable $e) {
@@ -128,11 +128,6 @@ public function update(string $actionId, ActionUpdate $action, UserContext $cont
128128
$parameters = new Parameters($config ?? []);
129129
$handler = $this->newAction($class);
130130

131-
// call lifecycle
132-
if ($handler instanceof LifecycleInterface) {
133-
$handler->onUpdate($name, $parameters);
134-
}
135-
136131
// update action
137132
try {
138133
$this->actionTable->beginTransaction();
@@ -145,7 +140,12 @@ public function update(string $actionId, ActionUpdate $action, UserContext $cont
145140
$existing->setDate(LocalDateTime::now());
146141
$this->actionTable->update($existing);
147142

148-
$this->actionCommitter->commit($existing->getId(), $existing->getConfig(), $context);
143+
$hash = $this->actionCommitter->commit($existing->getId(), $existing->getConfig(), $context);
144+
145+
// call lifecycle
146+
if ($handler instanceof LifecycleInterface) {
147+
$handler->onUpdate($name, $parameters, $hash);
148+
}
149149

150150
$this->actionTable->commit();
151151
} catch (Throwable $e) {

src/Service/Action/Committer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public function __construct(
3838
) {
3939
}
4040

41-
public function commit(int $actionId, ?string $config, UserContext $context): void
41+
public function commit(int $actionId, ?string $config, UserContext $context): ?string
4242
{
4343
if (empty($config)) {
44-
return;
44+
return null;
4545
}
4646

4747
$previousHash = $this->actionCommitTable->findCurrentHash($actionId);
@@ -50,7 +50,7 @@ public function commit(int $actionId, ?string $config, UserContext $context): vo
5050

5151
$existing = $this->actionCommitTable->findOneByCommitHash($hash);
5252
if ($existing instanceof Table\Generated\ActionCommitRow) {
53-
return;
53+
return null;
5454
}
5555

5656
$row = new Table\Generated\ActionCommitRow();
@@ -61,5 +61,7 @@ public function commit(int $actionId, ?string $config, UserContext $context): vo
6161
$row->setConfig($config);
6262
$row->setInsertDate(LocalDateTime::now());
6363
$this->actionCommitTable->create($row);
64+
65+
return $hash;
6466
}
6567
}

src/Service/Schema/Committer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public function __construct(
3838
) {
3939
}
4040

41-
public function commit(int $schemaId, string $source, UserContext $context): void
41+
public function commit(int $schemaId, string $source, UserContext $context): ?string
4242
{
4343
$previousHash = $this->schemaCommitTable->findCurrentHash($schemaId);
4444

4545
$hash = sha1($context->getTenantId() . $context->getUserId() . $schemaId . $previousHash . $source);
4646

4747
$existing = $this->schemaCommitTable->findOneByCommitHash($hash);
4848
if ($existing instanceof Table\Generated\SchemaCommitRow) {
49-
return;
49+
return null;
5050
}
5151

5252
$row = new Table\Generated\SchemaCommitRow();
@@ -57,5 +57,7 @@ public function commit(int $schemaId, string $source, UserContext $context): voi
5757
$row->setSource($source);
5858
$row->setInsertDate(LocalDateTime::now());
5959
$this->schemaCommitTable->create($row);
60+
61+
return $hash;
6062
}
6163
}

0 commit comments

Comments
 (0)