Import: comment and move sort methods to the bottom

This commit is contained in:
Thomas Gelf 2015-11-03 10:18:24 +01:00
parent e2239f2269
commit eee48e3238
1 changed files with 38 additions and 26 deletions

View File

@ -159,32 +159,6 @@ 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;
@ -200,4 +174,42 @@ class Import
return array_diff($checksums, $existing);
}
/**
* Sort a given stdClass object by property name
*/
protected function sortObject($object)
{
$array = (array) $object;
foreach ($array as $key => $val) {
$this->sortElement($val);
}
ksort($array);
return (object) $array;
}
/**
* Walk through a given array and sort all children
*
* Please note that the array itself will NOT be sorted, as arrays must
* keep their ordering
*/
protected function sortArrayObject(& $array)
{
foreach ($array as $key => $val) {
$this->sortElement($val);
}
}
/**
* Recursively sort a given property
*/
protected function sortElement(& $el)
{
if (is_array($el)) {
$this->sortArrayObject($el);
} elseif ($el instanceof stdClass) {
$el = $this->sortObject($el);
}
}
}