/** * Recursevely detects differences of multidimensional arrays * and returns a new array containing all differences. Indexes that exists in both arrays are skipped. * (e.g. used to detect differences between the complete SESSION['log'] and the built log of a page-call * in ajax-functions to only return the last changes to the client) * * @param array $array1 Array1 * @param array $array2 Array2 * * @return array Array with differences */ function getArrayDiffAssocRecursive($array1, $array2) { foreach ($array1 as $key => $value) { if (is_array($value)) { if (!isset($array2[$key])) { $difference[$key] = $value; } elseif (!is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = getArrayDiffAssocRecursive($value, $array2[$key]); if ($new_diff != FALSE) { $difference[$key] = $new_diff; } } } elseif (!isset($array2[$key]) || $array2[$key] != $value) { $difference[$key] = $value; } } return !isset($difference) ? 0 : $difference; }
// calculate the estimated time from it // if we restore a backup from another program we need to rely on the filesize //which is not accurate // when the file is gzipped, but we can't help it because there is no way to // get the exact file pointer position in a gzipped file. // So we give our best to guess the corect position (see line 117 above) if ($restore['progress_overall_percent'] > 0) { $percentageDone = $restore['progress_overall_percent']; } else { $percentageDone = $restore['progress_file_percent']; } $estimatedTime = 0; if ($percentageDone > 0) { $estimatedTime = (100 - $percentageDone) * ($elapsed / $percentageDone); $r['estimated_end'] = getTimeFormat($estimatedTime); } else { $r['estimated_end'] = $lang['L_UNKNOWN']; } // check if new log-messages have been added $messages = getArrayDiffAssocRecursive($_SESSION['log'], $_SESSION['temp_log']); if (isset($messages['actions']) && is_array($messages['actions'])) { $r['actions'] = implode('<br />', $messages['actions']); } if (isset($messages['errors']) && is_array($messages['errors'])) { $r['errors'] = implode('<br />', $messages['errors']); } $_SESSION['log'] = $_SESSION['log'] + $_SESSION['temp_log']; // save actual values to session $_SESSION['restore'] = $restore; echo $json->encode($r); obend(true);