Skip to content

Commit

Permalink
appendToCommandLog, ref #140
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Aug 24, 2022
1 parent b94c970 commit 4e3a534
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/run-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,33 @@ function toCamel($str)
}, $parts));
}

function appendToCommandLog($context, $command) {
// $context is e.g.:
// [
// "user" => [
// "id" => 1,
// "username" => "admin"
// ],
// "adminParty" => false,
// "openMode" => false,
// "employer" => "stichting"
// ]
//
// $command is e.g. [ "worked-hours", "20 September 2021", "stichting", "Peppol for the Masses", 4]
$conn = getDbConn();
$conn->executeStatement("INSERT INTO commandLog (contextJson, commandJson) VALUES (:contextJson, :commandJson)", [
"contextJson" => json_encode($context),
"commandJson" => json_encode($command)
]);
}

function runCommandWithInlineData($context, $command)
{
// TODO: support this for more commands - maybe in some more generic way to pass the data?
// Maybe command implementations shouldn't be doing their own file_get_contents
// to make them reusable across both runCommand and runCommandWithInlineData
error_log(var_export($command, true));
appendToCommandLog($context, $command);
if ($command[0] == "import-hours") {
return importHoursInline($context, $command[1], $command[2], "2022-03-31 12:00:00");
}
Expand All @@ -58,6 +79,7 @@ function runCommandWithInlineData($context, $command)

function runCommand($context, $command)
{
appendToCommandLog($context, $command);
// print("running " . json_encode($command));
$commands = [
"register" => 3,
Expand Down

0 comments on commit 4e3a534

Please sign in to comment.