Skip to content

Commit

Permalink
Merge pull request #77 from jeyroik/v6
Browse files Browse the repository at this point in the history
fixed work with parallel tables modifications + rm outdated bin cmd
  • Loading branch information
jeyroik authored Jul 16, 2023
2 parents 1c3c280 + 22be429 commit ef1a71e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 6.22.1

- Fixed `DriverFileJson` work with parallel tables modifications.

# 6.22.0

- Added method `IHaveParams::setParamValue(string $paramName, mixed $value): static`.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"test": "vendor/bin/phpunit --testdox --coverage-clover=coverage.xml --whitelist=src tests"
},
"bin": [
"src/bin/extas", "src/bin/extas-extra", "src/bin/extas-cfg-php"
"src/bin/extas", "src/bin/extas-extra"
]
}
25 changes: 24 additions & 1 deletion src/components/repositories/drivers/DriverFileJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,27 @@ protected function getTableData(): array

protected function saveData(): void
{
if (!$this->isTheSameDb()) {
$this->reloadDb();
}
file_put_contents($this->path . $this->db, json_encode($this->data));
}

protected function reloadDb(): bool
{
$db = $this->getDbData();
$db[$this->getTableName()] = $this->data[$this->getTableName()];

$this->data = $db;

return true;
}

protected function isTheSameDb(): bool
{
return $this->data == $this->getDbData();
}

protected function initData(): void
{
$path = $this->path . $this->db;
Expand All @@ -251,8 +269,13 @@ protected function initData(): void
file_put_contents($path, '[]');
}

$this->data = json_decode(file_get_contents($path), true);
$this->data = $this->getDbData();

$this->hash = sha1(time()+mt_rand(0, 999999));
}

protected function getDbData(): array
{
return json_decode(file_get_contents($this->path . $this->db), true);
}
}

0 comments on commit ef1a71e

Please sign in to comment.