/** * Removes this plugin's user settings for all users. * * Use {@link removeAllUserSettings()} if you just want to remove * settings for a single user. * * @return bool */ public function unsetAllUsersSettings() { $db_prefix = _elgg_services()->configTable->get('dbprefix'); $ps_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID()); $q = "DELETE FROM {$db_prefix}private_settings\n\t\t\tWHERE name LIKE '{$ps_prefix}%'"; return $this->getDatabase()->deleteData($q); }
/** * Get an attribute or private setting value * * @param string $name Name of the attribute or private setting * @return mixed */ public function __get($name) { // rewrite for old and inaccurate plugin:setting if (strstr($name, 'plugin:setting:')) { $msg = 'Direct access of user settings is deprecated. Use ElggPlugin->getUserSetting()'; elgg_deprecated_notice($msg, 1.8); $name = str_replace('plugin:setting:', '', $name); $name = _elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID()); } // See if its in our base attribute if (array_key_exists($name, $this->attributes)) { return $this->attributes[$name]; } // @todo clean below - getPrivateSetting() should return null now // No, so see if its in the private data store. // get_private_setting() returns false if it doesn't exist $meta = $this->getPrivateSetting($name); if ($meta === false) { // Can't find it, so return null return null; } return $meta; }
/** * Returns entities based upon plugin user settings. * Takes all the options for {@link elgg_get_entities_from_private_settings()} * in addition to the ones below. * * @param array $options Array in the format: * * plugin_id => STR The plugin id. Required. * * plugin_user_setting_names => null|ARR private setting names * * plugin_user_setting_values => null|ARR metadata values * * plugin_user_setting_name_value_pairs => null|ARR ( * name => 'name', * value => 'value', * 'operand' => '=', * ) * Currently if multiple values are sent via * an array (value => array('value1', 'value2') * the pair's operand will be forced to "IN". * * plugin_user_setting_name_value_pairs_operator => null|STR The operator to use for combining * (name = value) OPERATOR (name = value); default AND * * @return mixed int If count, int. If not count, array. false on errors. */ function getEntitiesFromUserSettings(array $options = array()) { if (!isset($options['plugin_id'])) { elgg_deprecated_notice("'plugin_id' is now required for elgg_get_entities_from_plugin_user_settings()", 1.9); $options['plugin_id'] = elgg_get_calling_plugin_id(); } $singulars = array('plugin_user_setting_name', 'plugin_user_setting_value', 'plugin_user_setting_name_value_pair'); $options = _elgg_normalize_plural_options_array($options, $singulars); // rewrite plugin_user_setting_name_* to the right PS ones. $map = array('plugin_user_setting_names' => 'private_setting_names', 'plugin_user_setting_values' => 'private_setting_values', 'plugin_user_setting_name_value_pairs' => 'private_setting_name_value_pairs', 'plugin_user_setting_name_value_pairs_operator' => 'private_setting_name_value_pairs_operator'); foreach ($map as $plugin => $private) { if (!isset($options[$plugin])) { continue; } if (isset($options[$private])) { if (!is_array($options[$private])) { $options[$private] = array($options[$private]); } $options[$private] = array_merge($options[$private], $options[$plugin]); } else { $options[$private] = $options[$plugin]; } } $prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $options['plugin_id']); $options['private_setting_name_prefix'] = $prefix; return elgg_get_entities_from_private_settings($options); }
$site = get_config('site'); $old_plugin_order = unserialize($site->pluginorder); $old_enabled_plugins = $site->enabled_plugins; $db_prefix = get_config('dbprefix'); $plugin_subtype_id = get_subtype_id('object', 'plugin'); // easy one first: make sure the the site owns all plugin entities. $q = "UPDATE {$db_prefix}entities e\n\tSET owner_guid = {$site->guid}, container_guid = {$site->guid}\n\tWHERE e.type = 'object' AND e.subtype = {$plugin_subtype_id}"; $r = update_data($q); // rewrite all plugin:setting:* to ELGG_PLUGIN_USER_SETTING_PREFIX . * $q = "UPDATE {$db_prefix}private_settings\n\tSET name = replace(name, 'plugin:settings:', '" . ELGG_PLUGIN_USER_SETTING_PREFIX . "')\n\tWHERE name LIKE 'plugin:settings:%'"; $r = update_data($q); // grab current plugin GUIDs to add a temp priority $q = "SELECT * FROM {$db_prefix}entities e\n\tJOIN {$db_prefix}objects_entity oe ON e.guid = oe.guid\n\tWHERE e.type = 'object' AND e.subtype = {$plugin_subtype_id}"; $plugins = get_data($q); foreach ($plugins as $plugin) { $priority = _elgg_namespace_plugin_private_setting('internal', 'priority'); set_private_setting($plugin->guid, $priority, 0); } // force regenerating plugin entities _elgg_generate_plugin_entities(); // set the priorities for all plugins // this function rewrites it to a normal index so use the current one. _elgg_set_plugin_priorities($old_plugin_order); // add relationships for enabled plugins if ($old_enabled_plugins) { // they might only have one plugin enabled. if (!is_array($old_enabled_plugins)) { $old_enabled_plugins = array($old_enabled_plugins); } // sometimes there were problems and you'd get 1000s of enabled plugins. $old_enabled_plugins = array_unique($old_enabled_plugins);