Commit e5744df3 authored by Aaron Wells's avatar Aaron Wells Committed by Robert Lyon

Change the format for plugin configs in config.php (Bug 1327921)

Old format: $CFG->plugin->blocktype->clippy->agent = 'merlin';
New format: $CFG->plugin_blocktype_clippy_agent = 'merlin';

The old format caused a strict standards warning.

Change-Id: I8ae2735ea3d3df913c0527bae7771e6f01dc82ca
parent 32162e98
......@@ -494,23 +494,23 @@ $cfg->cleanurlusereditable = true;
/**
* Settings used by the "elasticsearch" search plugin.
* See the helpfiles on the plugin's configuration page for details.
* @global string $cfg->plugin->search->elasticsearch->host
* @global int $cfg->plugin->search->elasticsearch->port
* @global string $cfg->plugin->search->elasticsearch->username
* @global string $cfg->plugin->search->elasticsearch->password
* @global string $cfg->plugin->search->elasticsearch->indexname
* @global string $cfg->plugin->search->elasticsearch->bypassindexname
* @global string $cfg->plugin->search->elasticsearch->analyzer
* @global string $cfg->plugin->search->elasticsearch->types
*/
// @$cfg->plugin->search->elasticsearch->host = '127.0.0.1';
// @$cfg->plugin->search->elasticsearch->port = 9200;
// @$cfg->plugin->search->elasticsearch->username = '';
// @$cfg->plugin->search->elasticsearch->password = '';
// @$cfg->plugin->search->elasticsearch->indexname = 'mahara';
// @$cfg->plugin->search->elasticsearch->bypassindexname = null;
// @$cfg->plugin->search->elasticsearch->analyzer = 'mahara_analyzer';
// @$cfg->plugin->search->elasticsearch->types = 'usr,interaction_instance,interaction_forum_post,group,view,artefact';
* @global string $cfg->plugin_search_elasticsearch_host
* @global int $cfg->plugin_search_elasticsearch_port
* @global string $cfg->plugin_search_elasticsearch_username
* @global string $cfg->plugin_search_elasticsearch_password
* @global string $cfg->plugin_search_elasticsearch_indexname
* @global string $cfg->plugin_search_elasticsearch_bypassindexname
* @global string $cfg->plugin_search_elasticsearch_analyzer
* @global string $cfg->plugin_search_elasticsearch_types
*/
// $cfg->plugin_search_elasticsearch_host = '127.0.0.1';
// $cfg->plugin_search_elasticsearch_port = 9200;
// $cfg->plugin_search_elasticsearch_username = '';
// $cfg->plugin_search_elasticsearch_password = '';
// $cfg->plugin_search_elasticsearch_indexname = 'mahara';
// $cfg->plugin_search_elasticsearch_bypassindexname = null;
// $cfg->plugin_search_elasticsearch_analyzer = 'mahara_analyzer';
// $cfg->plugin_search_elasticsearch_types = 'usr,interaction_instance,interaction_forum_post,group,view,artefact';
/**
* Additional HTML: Use these settings to put snippets of HTML at the top of every page on the site.
......
......@@ -891,7 +891,7 @@ function set_config($key, $value) {
* or null if it is not found.
*
* It will give precedence to config values set in config.php like so:
* $cfg->plugin->{$plugintype}->{$pluginname}->{$key} = 'whatever';
* $cfg->plugin_{$plugintype}_{$pluginname}_{$key} = 'whatever';
*
* If it doesn't find one of those, it will look for the config value in
* the database.
......@@ -903,54 +903,47 @@ function set_config($key, $value) {
*/
function get_config_plugin($plugintype, $pluginname, $key) {
global $CFG;
static $pluginsfetched = array();
// If we've already fetched this value, then return it
if (isset($CFG->plugin->{$plugintype}->{$pluginname}->{$key})) {
$typename = "{$plugintype}_{$pluginname}";
$configname = "plugin_{$typename}_{$key}";
if (isset($CFG->{$configname})) {
return $CFG->{$configname};
}
else if (isset($CFG->plugin->{$plugintype}->{$pluginname}->{$key})) {
log_warn(
"Mahara 1.9-format plugin config detected in your config.php: \$cfg->plugin->{$plugintype}->{$pluginname}->{$key}."
. " You should change this to the Mahara 1.10 format: \$cfg->plugin_{$plugintype}_{$pluginname}_{$key}."
);
return $CFG->plugin->{$plugintype}->{$pluginname}->{$key};
}
// If we have already fetched this plugin's data from the database, then return NULL.
// (Note that some values may come from config.php before we hit the database.)
else if (isset($CFG->plugin->pluginsfetched->{$plugintype}->{$pluginname})) {
else if (in_array($typename, $pluginsfetched)) {
return null;
}
// We haven't fetched this plugin's data yet. So do it!
else {
// First build the object structure for it.
if (!isset($CFG->plugin)) {
$CFG->plugin = new stdClass();
}
if (!isset($CFG->plugin->{$plugintype})) {
$CFG->plugin->{$plugintype} = new stdClass();
}
if (!isset($CFG->plugin->{$plugintype}->{$pluginname})) {
$CFG->plugin->{$plugintype}->{$pluginname} = new stdClass();
}
// To minimize database calls, get all the records for this plugin from the database at once.
$records = get_records_array($plugintype . '_config', 'plugin', $pluginname, 'field');
if (!empty($records)) {
foreach ($records as $record) {
if (!isset($CFG->plugin->{$plugintype}->{$pluginname}->{$record->field})) {
$CFG->plugin->{$plugintype}->{$pluginname}->{$record->field} = $record->value;
$storeconfigname = "plugin_{$typename}_{$record->field}";
if (!isset($CFG->{$storeconfigname})) {
$CFG->{$storeconfigname} = $record->value;
}
}
}
// Make a note that we've now hit the database over this one.
if (!isset($CFG->plugin->pluginsfetched)) {
$CFG->plugin->pluginsfetched = new stdClass();
}
if (!isset($CFG->plugin->pluginsfetched->{$plugintype})) {
$CFG->plugin->pluginsfetched->{$plugintype} = new stdClass();
}
$CFG->plugin->pluginsfetched->{$plugintype}->{$pluginname} = true;
$pluginsfetched[] = $typename;
// Now, return it if we found it, otherwise null.
// (This could be done by a recursive call to get_config_plugin(), but it's
// less error-prone to do it this way and it doesn't cause that much duplication)
if (isset($CFG->plugin->{$plugintype}->{$pluginname}->{$key})) {
return $CFG->plugin->{$plugintype}->{$pluginname}->{$key};
if (isset($CFG->{$configname})) {
return $CFG->{$configname};
}
else {
return null;
......@@ -958,36 +951,34 @@ function get_config_plugin($plugintype, $pluginname, $key) {
}
}
/**
* Set or update a plugin config value.
*
* @param string $plugintype The plugin type: 'artefact', 'blocktype', etc
* @param string $pluginname The plugin name: 'file', 'creativecommons', etc
* @param string $key The config name
* @param string $value The config's new value
* @return boolean Whether or not the config was updated successfully
*/
function set_config_plugin($plugintype, $pluginname, $key, $value) {
global $CFG;
$table = $plugintype . '_config';
$success = false;
if (false !== get_field($table, 'value', 'plugin', $pluginname, 'field', $key)) {
//if (set_field($table, 'value', $key, 'plugin', $pluginname, 'field', $value)) {
if (set_field($table, 'value', $value, 'plugin', $pluginname, 'field', $key)) {
$status = true;
}
$success = set_field($table, 'value', $value, 'plugin', $pluginname, 'field', $key);
}
else {
$pconfig = new StdClass;
$pconfig = new stdClass();
$pconfig->plugin = $pluginname;
$pconfig->field = $key;
$pconfig->value = $value;
$status = insert_record($table, $pconfig);
$success = insert_record($table, $pconfig);
}
// Now update the cached version
if ($status) {
if (!isset($CFG->plugin)) {
$CFG->plugin = new stdClass();
}
if (!isset($CFG->plugin->{$plugintype})) {
$CFG->plugin->{$plugintype} = new stdClass();
}
if (!isset($CFG->plugin->{$plugintype}->{$pluginname})) {
$CFG->plugin->{$plugintype}->{$pluginname} = new stdClass();
}
$CFG->plugin->{$plugintype}->{$pluginname}->{$key} = $value;
if ($success) {
$configname = "plugin_{$plugintype}_{$pluginname}_{$key}";
$CFG->{$configname} = $value;
return true;
}
return false;
......
......@@ -6,6 +6,6 @@
<p>The Maraha system uses the built-in <strong>mahara_analyzer</strong>.</p>
<p><a href="http://www.elasticsearch.org/guide/reference/index-modules/analysis/custom-analyzer/">Read the Elasticsearch instructions</a> if you wish to use a different analyzer.</p>
<p>This setting cannot be changed through the web interface. You may change it by setting a value in your config.php file for the following config variable:</p>
<p><code>$cfg->plugin->search->elasticsearch->analyzer</code>.</p>
<p><code>$cfg->plugin_search_elasticsearch_analyzer</code>.</p>
<p>It is recommended that you don't change the default "mahara_analyzer"
unless you know what you are doing.</p>
......@@ -5,6 +5,6 @@
<p>Most of the time, this setting should be left blank.</p>
<p>If this setting is populated, then Mahara will load new index data into the Elasticsearch index of this name while still retrieving search results from the Elasticsearch index stored under the "Index name" field.</p>
<p>If you want to reindex the whole site in a new index, but don't want to bring your current search capability down until reindexing finishes, you can use this field to point the reindexing cron at a new index, while the search functionality continues to use the old index.</p>
<p>Once the queue is empty, copy this index's name to the <code>$cfg->plugin->search->elasticsearch->indexname</code> variable in your config.php.</p>
<p>Once the queue is empty, copy this index's name to the <code>$cfg->plugin_search_elasticsearch_indexname</code> variable in your config.php.</p>
<p>This setting cannot be changed through the web interface. You may change it by setting a value in your config.php file for the following config variable:</p>
<p><code>$cfg->plugin->search->elasticsearch->bypassindexname</code>.</p>
<p><code>$cfg->plugin_search_elasticsearch_bypassindexname</code>.</p>
......@@ -4,4 +4,4 @@
<p>The hostname or IP address of the Elasticsearch server.</p>
<p>This setting cannot be changed through the web interface. You may change it by setting a value in your config.php file for the following config variable:</p>
<p><code>$cfg->plugin->search->elasticsearch->host</code>.</p>
<p><code>$cfg->plugin_search_elasticsearch_host</code>.</p>
......@@ -8,4 +8,4 @@ setting.</p>
<p>If you change this to a new value, you may need to use the "reset ALL indexes"
button to trigger the creation of the new index.</p>
<p>This setting cannot be changed through the web interface. You may change it by setting a value in your config.php file for the following config variable:</p>
<p><code>$cfg->plugin->search->elasticsearch->indexname</code>.</p>
<p><code>$cfg->plugin_search_elasticsearch_indexname</code>.</p>
......@@ -4,4 +4,4 @@
<p>If your Elasticsearch server requires an HTTP basic auth username and password to access it, you may provide the <strong>password</strong> here. <strong>Note:</strong> The core Elasticsearch software itself does not provide username or password features, but you may achieve this functionality by using a plugin or by accessing it through a proxy.</p>
<p>This setting cannot be changed through the web interface. You may change it by setting a value in your config.php file for the following config variable:</p>
<p><code>$cfg->plugin->search->elasticsearch->password</code>.</p>
<p><code>$cfg->plugin_search_elasticsearch_password</code>.</p>
......@@ -4,4 +4,4 @@
<p>The port number to access the Elasticsearch server on.</p>
<p>This setting cannot be changed through the web interface. You may change it by setting a value in your config.php file for the following config variable:</p>
<p><code>$cfg->plugin->search->elasticsearch->port</code>.</p>
<p><code>$cfg->plugin_search_elasticsearch_port</code>.</p>
......@@ -5,4 +5,4 @@
<p>This is a comma-separated list of the elements to index. Each of these must match an ElasticsearchType subclass under search/elasticsearch/type.</p>
<p>You shouldn't need to change this unless you have implemented a new search type, or want to disable a particular search type.</p>
<p>This setting cannot be changed through the web interface. You may change it by setting a value in your config.php file for the following config variable:</p>
<p><code>$cfg->plugin->search->elasticsearch->types</code>.</p>
<p><code>$cfg->plugin_search_elasticsearch_types</code>.</p>
......@@ -4,4 +4,4 @@
<p>If your Elasticsearch server requires an HTTP basic auth username and password to access it, you may provide the <strong>username</strong> here. <strong>Note:</strong> The core Elasticsearch software itself does not provide username or password features, but you may achieve this functionality by using a plugin or by accessing it through a proxy.</p>
<p>This setting cannot be changed through the web interface. You may change it by setting a value in your config.php file for the following config variable:</p>
<p><code>$cfg->plugin->search->elasticsearch->username</code>.</p>
<p><code>$cfg->plugin_search_elasticsearch_username</code>.</p>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment