function controller_settings(&$args, $output = "inline") { $cfg = $this->root->cfg->FlattenConfig($this->root->cfg->LoadServers($this->root->locations["config"] . "/servers.ini", false)); $vars["tfdev"] = !empty($_COOKIE["tf-dev"]) ? json_decode($_COOKIE["tf-dev"], true) : array(); if (!empty($args["clear"])) { Logger::Info("Cleared dev settings"); setcookie("tf-dev", NULL, 0, "/"); $vars["tfdev"] = array(); $this->root->cfg->servers = $cfg; } if (!empty($args["settings"])) { $diff_orig = array_diff_assoc_recursive($args["settings"], $cfg); $diff_curr = array_diff_assoc_recursive($args["settings"], $this->root->cfg->FlattenConfig($this->root->cfg->servers)); $vars["tfdev"]["serveroverrides"] = $diff_orig; setcookie("tf-dev", json_encode($vars["tfdev"]), time() + 86400 * 365, "/"); // dev cookie persists for a year if (!empty($diff_curr)) { foreach ($diff_curr as $setting => $value) { Logger::Info("Override setting: {$setting} = '{$value}'"); $this->root->cfg->AppendSetting($this->root->cfg->servers, $setting, $value); } } else { Logger::Error("No config differences!"); } } $vars["settings"] = $this->root->cfg->FlattenConfig($this->root->cfg->servers); $vars["container"] = $output == "html"; $ret = $this->GetComponentResponse("./settings.tpl", $vars); if ($output == "ajax") { $ret = array("tf_debug_tab_settings" => $ret); } return $ret; }
function array_diff_assoc_recursive($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 = array_diff_assoc_recursive($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; }
/** * Saves permissions changes to the audit log */ public function beforePermissionSetSave() { $event = $this->getEvent(); $aNewPermissions = $event->get('aNewPermissions'); $iSurveyID = $event->get('iSurveyID'); $iUserID = $event->get('iUserID'); $oCurrentUser = $this->api->getCurrentUser(); $oOldPermission = $this->api->getPermissionSet($iUserID, $iSurveyID, 'survey'); $sAction = 'update'; // Permissions are in general only updated (either you have a permission or you don't) if (count(array_diff_assoc_recursive($aNewPermissions, $oOldPermission))) { $oAutoLog = $this->api->newModel($this, 'log'); $oAutoLog->uid = $oCurrentUser->uid; $oAutoLog->entity = 'permission'; $oAutoLog->entityid = $iSurveyID; $oAutoLog->action = $sAction; $oAutoLog->oldvalues = json_encode(array_diff_assoc_recursive($oOldPermission, $aNewPermissions)); $oAutoLog->newvalues = json_encode(array_diff_assoc_recursive($aNewPermissions, $oOldPermission)); $oAutoLog->fields = implode(',', array_keys(array_diff_assoc_recursive($aNewPermissions, $oOldPermission))); $oAutoLog->save(); } }
/** * Similar to array_diff_assoc, but works with multidimensional arrays and stdClass. * * @param array * @param array * @return array */ function array_diff_assoc_recursive(array $a, array $b) { $diff = array(); foreach ($a as $key => $val) { if (!array_key_exists($key, $b) || gettype($val) !== gettype($b[$key])) { $diff[$key] = $val; } elseif (is_array($val)) { $diff2 = array_diff_assoc_recursive($val, $b[$key]); if ($diff2) { $diff[$key] = $diff2; } } elseif ($val instanceof stdClass && $b[$key] instanceof stdClass) { $diff2 = array_diff_assoc_recursive(get_object_vars($val), get_object_vars($b[$key])); if ($diff2) { $diff[$key] = $diff2; } } elseif ($val !== $b[$key]) { $diff[$key] = $val; } } return $diff; }
function array_diff_assoc_recursive($array1, $array2) { foreach ($array1 as $key => $value) { if (is_array($value)) { if (!is_array($array2[$key])) { $difference[$key] = array('previous' => $array2[$key], 'actual' => $value); } else { $new_diff = array_diff_assoc_recursive($value, $array2[$key]); if ($new_diff != false) { $difference[$key] = $new_diff; } } } elseif (!isset($array2[$key]) || $array2[$key] != $value) { $difference[$key] = array('previous' => $array2[$key], 'actual' => $value); } } return !isset($difference) ? false : $difference; }
/** * Modifies the params array to dramatically expand what can be passed in via page type parameters for a publication * @author Nathan White */ function handle_params( $params ) { // This is a slight hack to get publications to default to *not* limiting to the current site. This should allow publications to be displayed anywhere. $this->base_params['limit_to_current_site'] = false; // all params that could be provided in page_types $potential_params = array('use_filters', 'use_pagination', 'num_per_page', 'max_num_items', 'minimum_date_strtotime_format', 'show_login_link', 'show_module_title', 'related_mode', 'related_order', 'date_format', 'related_title', 'limit_by_page_categories', 'related_publication_unique_names', 'related_category_unique_names','css', 'show_featured_items','jump_to_item_if_only_one_result','authorization','comment_form_file_location','post_form_file_location',); $markup_params = array('markup_generator_info' => $this->markup_generator_info, 'item_specific_variables_to_pass' => $this->item_specific_variables_to_pass, 'variables_to_pass' => $this->variables_to_pass); $params_to_add = array_diff_assoc_recursive($params, $markup_params + $potential_params); if (!empty($params_to_add)) { foreach ($params_to_add as $k=>$v) { $this->acceptable_params[$k] = $v; } } $this->acceptable_params['module_displays_search_interface'] = true; $this->acceptable_params['module_displays_filter_interface'] = true; $this->acceptable_params['show_pagination_in_module'] = true; $this->acceptable_params['no_publication_warning'] = true; parent::handle_params( $params ); }
/** * a helper method to test arrays (multidimensional) are identical * * @param array $array1 * @param array $array2 * @return void * @author Craig Ulliott */ function assertArrayEquals(array $array1, array $array2) { if ($difference = array_diff_assoc_recursive($array1, $array2)) { $this->fail('Arrays were expected to be identical but had this difference' . "\n" . var_dump($difference, 1)); } }
function getSyncCache() { if (is_dir(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_user)) { debugLog("StateMachine->getSyncCache: Folder based!"); if (file_exists(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid . "_" . $this->_user)) { $content1 = file_get_contents(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid . "_" . $this->_user); $content1 = ksort_recursive(unserialize($content1)); } else { $content1 = array(); } $content2 = $this->_readSyncCacheFromFolder(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_user); $content2 = ksort_recursive($content2); if (is_array($res = array_diff_assoc_recursive($content1, $content2))) { debugLog("StateMachine->getSyncCache: array_diff_assoc_recursive result is " . print_r($res, true)); } $this->oldsynccache = $content2; return serialize($content2); } else { if (file_exists(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid . "_" . $this->_user)) { debugLog("StateMachine->getSyncCache: File Device User based! (DEPRECIATED SINCE PARALLEL SYNC REQUESTS WILL BREAK FILE CONTENT)"); $content = file_get_contents(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid . "_" . $this->_user); $this->oldsynccache = unserialize($content); return $content; } else { if (file_exists(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid)) { // just for compatibility to take old cache and apply it for new format debugLog("StateMachine->getSyncCache: File Device based! (DEPRECIATED SINCE MORE THAN ONE USERPROFILE COULD BE CREATED ON SOME DEVICES! i.e. iPhone)"); $content = file_get_contents(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid); if (file_put_contents(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid . "_" . $this->_user, $content)) { unlink(STATE_PATH . "/" . $this->_devid . "/cache_" . $this->_devid); } $this->oldsynccache = unserialize($content); return $content; } else { return false; } } } }
/** * returns the difference of arrays with additional index check, preformed in a recursive way * * @param array $array1 * @param array $array2 * @return array * @author Craig Ulliott */ function array_diff_assoc_recursive($array1, $array2) { $diff = false; // Left-to-right foreach ($array1 as $key => $value) { if (!array_key_exists($key, $array2)) { $diff[0][$key] = $value; } elseif (is_array($value)) { if (!is_array($array2[$key])) { $diff[0][$key] = $value; $diff[1][$key] = $array2[$key]; } else { $new = array_diff_assoc_recursive($value, $array2[$key]); if ($new !== false) { if (isset($new[0])) { $diff[0][$key] = $new[0]; } if (isset($new[1])) { $diff[1][$key] = $new[1]; } } } } elseif ($array2[$key] !== $value) { $diff[0][$key] = $value; $diff[1][$key] = $array2[$key]; } } // Right-to-left foreach ($array2 as $key => $value) { if (!array_key_exists($key, $array1)) { $diff[1][$key] = $value; } // No direct comparsion because matching keys were compared in the // left-to-right loop earlier, recursively. } return $diff; }
function array_diff_assoc_recursive($array1, $array2) { foreach ($array1 as $key => $value) { if (is_array($value)) { if (!is_array($array2[$key])) { $difference[$key] = ['previous' => $array2[$key], 'actual' => $value]; } else { $new_diff = array_diff_assoc_recursive($value, $array2[$key]); if ($new_diff != false) { $difference[$key] = $new_diff; } } } else { if (!isset($array2[$key]) || $array2[$key] != $value) { $difference[$key] = ['previous' => $array2[$key], 'actual' => $value]; } } } // Search missing items foreach ($array2 as $key => $value) { if (!isset($array1[$key])) { $difference[$key] = ['previous' => $value, 'actual' => '(missing)']; } } return !isset($difference) ? false : $difference; }
/** * do a recursive comparison */ function equal($otherperm) { $diff = array_diff_assoc_recursive($this->perm, $otherperm); return empty($diff); }
/** * @param \NetteAddons\Model\AddonVersion[] * @param \NetteAddons\Model\AddonVersion[] * @return array */ private function mergeVersions($a, $b) { $merged = array(); $new = array(); $conflicted = array(); foreach ($a as $version) { $merged[$version->version] = $version; } foreach ($b as $version) { if (!isset($merged[$version->version])) { $merged[$version->version] = $version; $new[$version->version] = $version; } else { $diff = array_diff_assoc_recursive(get_object_vars($version), get_object_vars($merged[$version->version])); unset($diff['id']); // ignore ID diff if ($diff) { $conflicted[$version->version] = array('a' => $merged[$version->version], 'b' => $version, 'diff' => $diff); } } } return array('ok' => count($conflicted) === 0, 'merged' => array_values($merged), 'new' => $new, 'conflicted' => $conflicted); }
/** A method to run a single test file. * * @param string $layer The name of a layer group to run. * @param string $folder The folder group to run, not including "tests/unit" * @param string $file The file to run, including ".test.php" */ function runFile($layer, $folder, $file) { $type = $GLOBALS['_MAX']['TEST']['test_type']; // Set up the environment for the test TestRunner::setupEnv($layer); $configBefore = TestEnv::parseConfigFile(); // Add the test file to a SimpleTest group $testName = $this->_testName($layer, $folder, $file); $secondaryName = $this->_secondaryTestName($layer); $test = new GroupTest($testName, $secondaryName); $testFile = MAX_PROJECT_PATH . '/' . $folder . '/' . constant($type . '_TEST_STORE') . '/' . $file; $test->addTestFile($testFile); $this->runCase($test); // Tear down the environment for the test $configAfter = TestEnv::parseConfigFile(); $configDiff = array_diff_assoc_recursive($configBefore, $configAfter); if (!empty($configDiff)) { OA::debug("Config file was changed by test: {$folder} {$file}", PEAR_LOG_DEBUG); } TestRunner::teardownEnv($layer); }
/** * @param array needed_fixes * @return string description of fixes performed and result of data integrity check */ function table_update() { $fix_reason_content = false; $xml_parser =& $this->getXMLParser(); $fields_to_update =& $this->get_fields_that_need_update(); if (isset($xml_parser->document->radiogroup)) foreach ($xml_parser->document->radiogroup as $index => $radiogroup) { $field_id = $radiogroup->tagAttrs['id']; if (isset($fields_to_update[$field_id])) { if ($enum_result = $this->populate_enum($radiogroup->tagChildren)) { $to_process[$field_id]['depth'] = $index; $to_process[$field_id]['options'] = $enum_result['options']; //if (isset($enum_result['selected'])) $to_process[$field_id]['selected'] = $enum_result['selected']; } } } if (isset($xml_parser->document->optiongroup)) foreach ($xml_parser->document->optiongroup as $index => $optiongroup) { $field_id = $optiongroup->tagAttrs['id']; if (isset($fields_to_update[$field_id])) { if ($enum_result = $this->populate_enum($optiongroup->tagChildren)) { $to_process[$field_id]['options'] = $enum_result['options']; if (!isset($optiongroup->tagAttrs['required'])) { // we are forcing these to required since it was not null previously, and not required, // but the interface was basically forcing a simulation of the "required" setting $to_process[$field_id]['required'] = 'required'; } $to_process[$field_id]['label'] = $optiongroup->tagAttrs['label']; } } } //$this->set_report('bones i am updating table id ' . $this->table_id . ' which has name ' . $this->table_name); if (isset($to_process)) { // build query foreach ($to_process as $field_name => $field_data) { $qry = ''; $qry = 'ALTER TABLE `'.$this->get_table_name().'` CHANGE `'.$field_name.'` `'.$field_name.'`'; $qry .= ' ENUM ("'. implode('","', $field_data['options']) . '")'; $qry .= ' NULL '; // thor never sets a default value - we will keep this in the xml //if (isset($field_data['selected'])) //{ // $qry .= ' DEFAULT "'.$field_data['options'][$field_data['selected']].'"'; //} $update_thor[$field_name] = $qry; if (isset($field_data['required'])) { $fix_reason_content = true; $search[] = 'label="' . $field_data['label'] . '" id="' . $field_name . '">'; $replace[] = 'required="required" label="' . $field_data['label'] . '" id="' . $field_name . '">'; $field_to_required[] = $field_name; } } if ($fix_reason_content) { if (!$this->test_mode) { $table_entity = new entity($this->get_table_id()); $table_xml = $table_entity->get_value('thor_content'); $new_table_xml = str_replace($search, $replace, $table_xml); reason_update_entity( $this->get_table_id(), $this->user_id, array('thor_content' => $new_table_xml), false); } $output['update_reason'] = 'option groups with ids ' . implode(", ", $field_to_required) . ' marked required'; } if (!empty($update_thor)) { if (!$this->test_mode) { connectDB(THOR_FORM_DB_CONN); $old_data = $this->get_table_data($this->get_table_name()); foreach ($update_thor as $qry) { db_query($qry); } $new_data = $this->get_table_data($this->get_table_name()); connectDB(REASON_DB); // data check makes sure data in table is the same before and after query. If not - dies with a fatal error. if (array_diff_assoc_recursive($new_data, $old_data)) { echo '<h2>Original data</h2>'; pray ($old_data); echo '<h2>New data</h2>'; pray ($new_data); echo '<h2>Difference detected in new data</h2>'; pray (array_diff_assoc_recursive($new_data, $old_data)); trigger_error('integrity problem - result not the same ... script terminating ... table ' . $this->get_table_name() . ' may be corrupted', FATAL); } } $output['update_thor'] = $update_thor; } $this->set_report($output); } return true; }
public function calcDifference(&$cid, &$torrents, &$dTorrents) { $oldTorrents = $this->load($cid); $cid = $this->store($torrents); $mod = array_diff_assoc_recursive($torrents, $oldTorrents); $del = array_diff_key($oldTorrents, $torrents); foreach ($del as $hash => $val) { $dTorrents[] = $hash; } $torrents = $mod === false ? array() : $mod; return count($oldTorrents) > 0; }
function array_diff_assoc_recursive($array1, $array2) { $difference = array(); foreach ($array1 as $key => $value) { if (is_array($value)) { if (!isset($array2[$key]) || !is_array($array2[$key])) { $difference[$key] = $value; } else { $new_diff = array_diff_assoc_recursive($value, $array2[$key]); if (!empty($new_diff)) { $difference[$key] = $new_diff; } } } else { if (!array_key_exists($key, $array2) || $array2[$key] !== $value) { $difference[$key] = $value; } } } return $difference; }
function array_diff_assoc_recursive(&$a, &$b) { // only keep those entries in $a which actually differ from the ones in $b: those are ready & done translations! foreach ($b as $key => $value) { if (is_array($value)) { if (array_key_exists($key, $a)) { array_diff_assoc_recursive($a[$key], $value); } } else { if (array_key_exists($key, $a) && $a[$key] == $value) { $a[$key] = null; } } } }