Unverified Commit 96cb7bfa authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(core) Fix array_remove_entries for array of arrays

This will fix webservice removing of array values on complex
 multivaluated attributes.

issue #6165
Showing with 23 additions and 8 deletions
+23 -8
......@@ -232,7 +232,7 @@ function get_template_path ($filename = '', $plugin = FALSE, $path = '')
*/
function array_remove_entries (array $needles, array $haystack)
{
return array_values(array_diff($haystack, $needles));
return array_values(array_udiff($haystack, $needles, 'array_cmp_recursive'));
}
......@@ -241,6 +241,7 @@ function array_remove_entries (array $needles, array $haystack)
*
* Removes every element that is in $needles from the
* array given as $haystack but case insensitive
* Only works on array of stringable
*
* \param array $needles array of the entries to remove
*
......@@ -1075,25 +1076,39 @@ function array_differs (array $src, array $dst)
* \return boolean TRUE or FALSE
*/
function array_differs_recursive ($src, $dst)
{
return (array_cmp_recursive($src, $dst) !== 0);
}
/*!
* \brief Determine if two arrays are different using recursion for sublevels
*
* \param array $src The source
*
* \param array $dst The destination
*
* \return <0, 0 or >0 if $src is <, = or > $dst
*/
function array_cmp_recursive ($src, $dst): int
{
if (is_array($src)) {
if (!is_array($dst)) {
return TRUE;
return 1;
}
if (count($src) != count($dst)) {
return TRUE;
return count($src) - count($dst);
}
foreach ($src as $key => $value) {
if (!isset($dst[$key])) {
return TRUE;
return 1;
}
if (array_differs_recursive($dst[$key], $value)) {
return TRUE;
if (($cmp = array_cmp_recursive($dst[$key], $value)) !== 0) {
return $cmp;
}
}
return FALSE;
return 0;
}
return ((string)$src != (string)$dst);
return strcmp($src, $dst);
}
/*!
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment