Import: always store dictionaries ordered

This commit is contained in:
Thomas Gelf 2015-11-02 09:25:39 +01:00
parent b7cd26b597
commit 5f333b0ea7
1 changed files with 27 additions and 1 deletions

View File

@ -61,7 +61,7 @@ class Import
$pval = json_encode($pval);
$format = 'json';
} elseif ($pval instanceof stdClass) {
$pval = json_encode($pval);
$pval = json_encode($this->sortObject($pval));
$format = 'json';
} else {
$format = 'string';
@ -159,6 +159,32 @@ class Import
return $id;
}
protected function sortObject($object)
{
$array = (array) $object;
foreach ($array as $key => $val) {
$this->sortElement($val);
}
ksort($array);
return (object) $array;
}
protected function sortArrayObject(& $array)
{
foreach ($array as $key => $val) {
$this->sortElement($val);
}
}
protected function sortElement(& $el)
{
if (is_array($el)) {
$this->sortArrayObject($el);
} elseif ($el instanceof stdClass) {
$el = $this->sortObject($el);
}
}
protected function rowSetExists($checksum)
{
return count($this->newChecksums('imported_rowset', array($checksum))) === 0;