/** * Updates existing configuration map removing obsolete options, adding new * options and tweaking options which need to be updated. * * @param string $name Extension code * @param array $options Configuration options * @param bool $is_module TRUE for modules, FALSE for plugins * @param string $category Structure category code. Only for per-category config options * @param string $donor Extension name for extension-to-extension config implantations * @return int Number of entries affected */ function cot_config_update($name, $options, $is_module = false, $category = '', $donor = '') { $affected = 0; $old_options = cot_config_load($name, $is_module, $category, $donor); // Find and remove options which no longer exist $remove_opts = array(); foreach ($old_options as $old_opt) { $keep = false; foreach ($options as $opt) { if ($opt['name'] == $old_opt['name']) { $keep = true; break; } } if (!$keep && $old_opt['type'] != COT_CONFIG_TYPE_HIDDEN) { $remove_opts[] = $old_opt['name']; } } if (count($remove_opts) > 0) { $affected += cot_config_remove($name, $is_module, $remove_opts, $category, $donor); } // Find new options and options which have been modified $new_options = array(); $upd_options = array(); foreach ($options as $opt) { $existed = false; foreach ($old_options as $old_opt) { if ($opt['name'] == $old_opt['name']) { $changed = array_diff($opt, $old_opt); if (count($changed) > 0) { // Values for modified options are set to default // only if both type and default value have changed if ($opt['type'] != $old_opt['type'] && $opt['default'] != $old_opt['default']) { $opt['value'] = $opt['default']; } $upd_options[] = $opt; } $existed = true; break; } } if (!$existed) { $new_options[] = $opt; } } if (count($new_options) > 0) { $affected += cot_config_add($name, $new_options, $is_module, $category); } if (count($upd_options) > 0) { $affected += cot_config_modify($name, $upd_options, $is_module, $category); } return $affected; }
/** * Remove a user image type * * @param string $code User image code * @return DB query result * @global CotDB $db * @global Cache $cache */ function cot_userimages_config_remove($code, $dropcolumn = true) { global $cache, $db, $db_users; if (empty($code)) { return FALSE; } $result = cot_config_remove('userimages', false, strtolower($code)); if ($result && $dropcolumn) { $db->query("ALTER TABLE {$db_users} DROP `user_" . $db->prep($code) . "`"); } $cache && $cache->db->remove('cot_userimages_config', 'users'); return $result; }