modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-06 17:06:11 +04:00
parent 06b1bce249
commit 5e140610c1
4 changed files with 26 additions and 33 deletions

View File

@ -172,6 +172,13 @@ class CapacitorChannel {
return array_combine($keys, [$value, $sum]);
}
function wasSumModified(string $key, $value, array $prowValues): bool {
$sumKey = $this->getSumKeys($key)[1];
$sum = $this->getSum($key, $value)[$sumKey];
$psum = $prowValues[$sumKey] ?? sha1(serialize($prowValues[$key] ?? null));
return $sum !== $psum;
}
function _wasSumModified(string $key, array $row, array $prow): bool {
$sumKey = $this->getSumKeys($key)[1];
$sum = $row[$sumKey] ?? null;
@ -179,13 +186,6 @@ class CapacitorChannel {
return $sum !== $psum;
}
function wasSumModified(string $key, array $rowValues, array $prowValues): bool {
$sumKey = $this->getSumKeys($key)[1];
$sum = $this->getSum($key, $rowValues[$key] ?? null)[$sumKey];
$psum = $prowValues[$sumKey] ?? sha1(serialize($prowValues[$key] ?? null));
return $sum !== $psum;
}
/**
* méthode appelée lors du chargement avec {@link Capacitor::charge()} pour
* créer un nouvel élément

View File

@ -58,11 +58,14 @@ abstract class CapacitorStorage {
$key = $col;
if ($key === $index) {
$index++;
} elseif (!array_key_exists($key, $values)) {
} elseif ($channel->isSerialKey($key)) {
A::merge($row, $channel->getSum($key, $values[$key]));
if (array_key_exists($key, $values)) {
A::merge($row, $channel->getSum($key, $values[$key]));
}
} else {
$row[$col] = $values[$key];
if (array_key_exists($key, $values)) {
$row[$col] = $values[$key];
}
}
}
return $row;

View File

@ -200,22 +200,17 @@ class MysqlStorage extends CapacitorStorage {
$commitThreshold = $channel->getEachCommitThreshold();
try {
$args ??= [];
foreach ($this->_all($channel, $filter) as $row) {
$rowIds = $this->getRowIds($channel, $row);
$updates = func::_call($onEach, [$row["item"], $row, ...$args]);
foreach ($this->_all($channel, $filter) as $rowValues) {
$rowIds = $this->getRowIds($channel, $rowValues);
$updates = func::_call($onEach, [$rowValues["item"], $rowValues, ...$args]);
if (is_array($updates)) {
$updates = $this->serialize($channel, $updates);
if (array_key_exists("item__", $updates)) {
# si item a été mis à jour, il faut mettre à jour sum_
$updates["sum_"] = sha1($updates["item__"]);
if (!array_key_exists("modified_", $updates)) {
$updates["modified_"] = date("Y-m-d H:i:s");
}
if (!array_key_exists("modified_", $updates)) {
$updates["modified_"] = date("Y-m-d H:i:s");
}
$mysql->exec([
"update",
"table" => $tableName,
"values" => $updates,
"values" => $this->serialize($channel, $updates),
"where" => $rowIds,
]);
if ($commitThreshold !== null) {

View File

@ -198,22 +198,17 @@ class SqliteStorage extends CapacitorStorage {
$commitThreshold = $channel->getEachCommitThreshold();
try {
$args ??= [];
foreach ($this->_all($channel, $filter) as $row) {
$rowIds = $this->getRowIds($channel, $row);
$updates = func::_call($onEach, [$row["item"], $row, ...$args]);
if (is_array($updates)) {
$updates = $this->serialize($channel, $updates);
if (array_key_exists("item__", $updates)) {
# si item a été mis à jour, il faut mettre à jour sum_
$updates["sum_"] = sha1($updates["item__"]);
if (!array_key_exists("modified_", $updates)) {
$updates["modified_"] = date("Y-m-d H:i:s");
}
foreach ($this->_all($channel, $filter) as $rowValues) {
$rowIds = $this->getRowIds($channel, $rowValues);
$updates = func::_call($onEach, [$rowValues["item"], $rowValues, ...$args]);
if (is_array($updates) && $updates) {
if (!array_key_exists("modified_", $updates)) {
$updates["modified_"] = date("Y-m-d H:i:s");
}
$sqlite->exec([
"update",
"table" => $tableName,
"values" => $updates,
"values" => $this->serialize($channel, $updates),
"where" => $rowIds,
]);
if ($commitThreshold !== null) {