From 3c2568cbfc3c9a327886ed88a1ffcba7127fb2b0 Mon Sep 17 00:00:00 2001 From: cajus Date: Thu, 16 Feb 2006 13:16:27 +0000 Subject: [PATCH] Added function to diff arrays Added functionality convert certain single attribute arrays to the destination type, if needed git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2698 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_plugin.inc | 31 ++++++++++++++++++++++++++----- include/functions.inc | 20 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/include/class_plugin.inc b/include/class_plugin.inc index 5b57ce3d1..ef0256633 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -317,26 +317,47 @@ class plugin } + function cleanup() { foreach ($this->attrs as $index => $value){ + /* Convert arrays with one element to non arrays, if the saved + attributes are no array, too */ + if (is_array($this->attrs[$index]) && + count ($this->attrs[$index]) == 1 && + isset($this->saved_attributes[$index]) && + !is_array($this->saved_attributes[$index])){ + + $tmp= $this->attrs[$index][0]; + $this->attrs[$index]= $tmp; + } + /* Remove emtpy arrays if they do not differ */ - if (is_array($this->attrs[$index]) && count($this->attrs[$index]) == 0 && !isset($this->saved_attributes[$index])){ + if (is_array($this->attrs[$index]) && + count($this->attrs[$index]) == 0 && + !isset($this->saved_attributes[$index])){ + unset ($this->attrs[$index]); continue; } /* Remove single attributes that do not differ */ - if (!is_array($this->attrs[$index]) && isset($this->saved_attributes[$index]) - && !is_array($this->saved_attributes[$index]) && $value == $this->saved_attributes[$index]){ + if (!is_array($this->attrs[$index]) && + isset($this->saved_attributes[$index]) && + !is_array($this->saved_attributes[$index]) && + $this->attrs[$index] == $this->saved_attributes[$index]){ + unset ($this->attrs[$index]); continue; } /* Remove arrays that do not differ */ - if (is_array($this->attrs[$index]) && isset($this->saved_attributes[$index]) && is_array($this->saved_attributes[$index])){ - if (count(array_diff($this->attrs[$index],$this->saved_attributes[$index]))==0 ){ + if (is_array($this->attrs[$index]) && + isset($this->saved_attributes[$index]) && + is_array($this->saved_attributes[$index])){ + + if (!array_differs($this->attrs[$index],$this->saved_attributes[$index])){ unset ($this->attrs[$index]); continue; } diff --git a/include/functions.inc b/include/functions.inc index 1fa462740..0d64f1e28 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -1845,5 +1845,25 @@ function search_config($arr, $name, $return) return (""); } + +function array_differs($src, $dst) +{ + /* If the count is differing, the arrays differ */ + if (count ($src) != count ($dst)){ + return (TRUE); + } + + /* So the count is the same - lets check the contents */ + $differs= FALSE; + foreach($src as $value){ + if (!in_array($value, $dst)){ + $differs= TRUE; + } + } + + return ($differs); +} + + // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> -- 2.30.2