Permalink
Browse files

MDL-25290 cache_mongodb: Added Mongo DB cache store

  • Loading branch information...
1 parent 5f2836e commit 2e638e3d35aa3ea1b9112b8f2128d6e785664d78 Sam Hemelryk committed Sep 10, 2012
@@ -0,0 +1,99 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The MongoDB plugin form for adding an instance.
+ *
+ * The following settings are provided:
+ * - server
+ * - username
+ * - password
+ * - database
+ * - replicaset
+ * - usesafe
+ * - extendedmode
+ *
+ * @package cache_mongodb
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Include the necessary evils.
+ */
+require_once($CFG->dirroot.'/cache/forms.php');
+require_once($CFG->dirroot.'/cache/stores/mongodb/lib.php');
+
+/**
+ * The form to add an instance of the MongoDB store to the system.
+ *
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class cache_store_mongodb_addinstance_form extends cache_store_addinstance_form {
+
+ /**
+ * The forms custom definitions.
+ */
+ protected function configuration_definition() {
+ $form = $this->_form;
+
+ $form->addElement('text', 'server', get_string('server', 'cache_mongodb'), array('size' => 72));
+ $form->addHelpButton('server', 'server', 'cache_mongodb');
+ $form->addRule('server', get_string('required'), 'required');
+ $form->setDefault('server', 'mongodb://127.0.0.1:27017');
+ $form->setType('server', PARAM_RAW);
+
+ $form->addElement('text', 'database', get_string('database', 'cache_mongodb'));
+ $form->addHelpButton('database', 'database', 'cache_mongodb');
+ $form->addRule('database', get_string('required'), 'required');
+ $form->setType('database', PARAM_ALPHANUMEXT);
+ $form->setDefault('database', 'mcache');
+
+ $form->addElement('text', 'username', get_string('username', 'cache_mongodb'));
+ $form->addHelpButton('username', 'username', 'cache_mongodb');
+ $form->setType('username', PARAM_ALPHANUMEXT);
+
+ $form->addElement('text', 'password', get_string('password', 'cache_mongodb'));
+ $form->addHelpButton('password', 'password', 'cache_mongodb');
+ $form->setType('password', PARAM_TEXT);
+
+ $form->addElement('text', 'replicaset', get_string('replicaset', 'cache_mongodb'));
+ $form->addHelpButton('replicaset', 'replicaset', 'cache_mongodb');
+ $form->setType('replicaset', PARAM_ALPHANUMEXT);
+ $form->setAdvanced('replicaset');
+
+ $form->addElement('checkbox', 'usesafe', get_string('usesafe', 'cache_mongodb'));
+ $form->addHelpButton('usesafe', 'usesafe', 'cache_mongodb');
+ $form->setDefault('usesafe', 1);
+ $form->setAdvanced('usesafe');
+ $form->setType('usesafe', PARAM_BOOL);
+
+ $form->addElement('text', 'usesafevalue', get_string('usesafevalue', 'cache_mongodb'));
+ $form->addHelpButton('usesafevalue', 'usesafevalue', 'cache_mongodb');
+ $form->disabledIf('usesafevalue', 'usesafe', 'notchecked');
+ $form->setType('usesafevalue', PARAM_INT);
+ $form->setAdvanced('usesafevalue');
+
+ $form->addElement('checkbox', 'extendedmode', get_string('extendedmode', 'cache_mongodb'));
+ $form->addHelpButton('extendedmode', 'extendedmode', 'cache_mongodb');
+ $form->setDefault('extendedmode', 0);
+ $form->setAdvanced('extendedmode');
+ $form->setType('extendedmode', PARAM_BOOL);
+ }
+}
@@ -0,0 +1,43 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The language strings for the MongoDB store plugin.
+ *
+ * @package cache_mongodb
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+$string['database'] = 'Database';
+$string['database_help'] = 'The name of the database to make use of.';
+$string['extendedmode'] = 'Use extended keys';
+$string['extendedmode_help'] = 'If enabled full key sets will be used when working with the plugin. This isn\'t used internally yet but would allow you to easily search and investigate the MongoDB plugin manually if you so choose. Turning this on will add an small overhead so should only be done if you require it.';
+$string['password'] = 'Password';
+$string['password_help'] = 'The password of the user being used for the connection.';
+$string['pluginname'] = 'MongoDB';
+$string['replicaset'] = 'Replica set';
+$string['replicaset_help'] = 'The name of the replica set to connect to. If this is given the master will be determined by using the ismaster database command on the seeds, so the driver may end up connecting to a server that was not even listed.';
+$string['server'] = 'Server';
+$string['server_help'] = 'This is the connection string for the server you want to use. Multiple servers can be specified by separating them with comma\'s';
+$string['testserver'] = 'Test server';
+$string['testserver_desc'] = 'This is the connection string for the test server you want to use. Test servers are entirely optional, by specifiying a test server you can run PHPunit tests for this store and can run the performance tests.';
+$string['username'] = 'Username';
+$string['username_help'] = 'The username to use when making a connection.';
+$string['usesafe'] = 'Use safe';
+$string['usesafe_help'] = 'If enabled the usesafe option will be used during insert, get, and remove operations. If you\'ve specified a replica set this will be forced on anyway.';
+$string['usesafevalue'] = 'Use safe value';
+$string['usesafevalue_help'] = 'You can choose to provide a specific value for use safe. This will determine the number of servers that operations must be completed on before they are deemed to have been completed.';
Oops, something went wrong.

0 comments on commit 2e638e3

Please sign in to comment.