modifs.mineures sans commentaires
This commit is contained in:
parent
2fbe3ec09c
commit
83b041e970
|
@ -143,46 +143,47 @@ class CapacitorChannel {
|
|||
return array_key_exists("modified_", $rowValues);
|
||||
}
|
||||
|
||||
final function serialize($item): string {
|
||||
return serialize($item);
|
||||
final function serialize($item): ?string {
|
||||
return $item !== null? serialize($item): null;
|
||||
}
|
||||
|
||||
final function unserialize(string $string) {
|
||||
return unserialize($string);
|
||||
final function unserialize(?string $serial) {
|
||||
return $serial !== null? unserialize($serial): null;
|
||||
}
|
||||
|
||||
const SUM_DEFINITION = "varchar(40)";
|
||||
|
||||
final function sum(?string $string): string {
|
||||
return sha1($string);
|
||||
final function sum(?string $serial, $value=null): ?string {
|
||||
if ($serial === null) $serial = $this->serialize($value);
|
||||
return $serial !== null? sha1($serial): null;
|
||||
}
|
||||
|
||||
final function isSerialKey(string &$key): bool {
|
||||
final function isSerialCol(string &$key): bool {
|
||||
return str::del_suffix($key, "__");
|
||||
}
|
||||
|
||||
final function getSumKeys(string $key): array {
|
||||
final function getSumCols(string $key): array {
|
||||
return ["${key}__", "${key}__sum_"];
|
||||
}
|
||||
|
||||
function getSum(string $key, $value): array {
|
||||
$keys = $this->getSumKeys($key);
|
||||
if ($value !== null) $value = $this->serialize($value);
|
||||
$sum = $this->sum($value);
|
||||
return array_combine($keys, [$value, $sum]);
|
||||
$sumCols = $this->getSumCols($key);
|
||||
$serial = $this->serialize($value);
|
||||
$sum = $this->sum($serial, $value);
|
||||
return array_combine($sumCols, [$serial, $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));
|
||||
$sumCol = $this->getSumCols($key)[1];
|
||||
$sum = $this->sum(null, $value);
|
||||
$psum = $prowValues[$sumCol] ?? $this->sum(null, $prowValues[$key] ?? null);
|
||||
return $sum !== $psum;
|
||||
}
|
||||
|
||||
function _wasSumModified(string $key, array $row, array $prow): bool {
|
||||
$sumKey = $this->getSumKeys($key)[1];
|
||||
$sum = $row[$sumKey] ?? null;
|
||||
$psum = $prow[$sumKey] ?? null;
|
||||
$sumCol = $this->getSumCols($key)[1];
|
||||
$sum = $row[$sumCol] ?? null;
|
||||
$psum = $prow[$sumCol] ?? null;
|
||||
return $sum !== $psum;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,9 +58,14 @@ abstract class CapacitorStorage {
|
|||
$key = $col;
|
||||
if ($key === $index) {
|
||||
$index++;
|
||||
} elseif ($channel->isSerialKey($key)) {
|
||||
} elseif ($channel->isSerialCol($key)) {
|
||||
[$serialCol, $sumCol] = $channel->getSumCols($key);
|
||||
if (array_key_exists($key, $values)) {
|
||||
A::merge($row, $channel->getSum($key, $values[$key]));
|
||||
$sum = $channel->getSum($key, $values[$key]);
|
||||
$row[$serialCol] = $sum[$serialCol];
|
||||
if (array_key_exists($sumCol, $cols)) {
|
||||
$row[$sumCol] = $sum[$sumCol];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (array_key_exists($key, $values)) {
|
||||
|
@ -82,7 +87,7 @@ abstract class CapacitorStorage {
|
|||
if ($key === $index) {
|
||||
$index++;
|
||||
} elseif (!array_key_exists($col, $row)) {
|
||||
} elseif ($channel->isSerialKey($key)) {
|
||||
} elseif ($channel->isSerialCol($key)) {
|
||||
$value = $row[$col];
|
||||
if ($value !== null) $value = $channel->unserialize($value);
|
||||
$values[$key] = $value;
|
||||
|
|
Loading…
Reference in New Issue