MDL-25290 cache_mongodb: Added Mongo DB cache store
[moodle.git] / cache / stores / mongodb / addinstanceform.php
CommitLineData
2e638e3d
SH
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * The MongoDB plugin form for adding an instance.
19 *
20 * The following settings are provided:
21 * - server
22 * - username
23 * - password
24 * - database
25 * - replicaset
26 * - usesafe
27 * - extendedmode
28 *
29 * @package cache_mongodb
30 * @copyright 2012 Sam Hemelryk
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 */
33
34defined('MOODLE_INTERNAL') || die();
35
36/**
37 * Include the necessary evils.
38 */
39require_once($CFG->dirroot.'/cache/forms.php');
40require_once($CFG->dirroot.'/cache/stores/mongodb/lib.php');
41
42/**
43 * The form to add an instance of the MongoDB store to the system.
44 *
45 * @copyright 2012 Sam Hemelryk
46 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
47 */
48class cache_store_mongodb_addinstance_form extends cache_store_addinstance_form {
49
50 /**
51 * The forms custom definitions.
52 */
53 protected function configuration_definition() {
54 $form = $this->_form;
55
56 $form->addElement('text', 'server', get_string('server', 'cache_mongodb'), array('size' => 72));
57 $form->addHelpButton('server', 'server', 'cache_mongodb');
58 $form->addRule('server', get_string('required'), 'required');
59 $form->setDefault('server', 'mongodb://127.0.0.1:27017');
60 $form->setType('server', PARAM_RAW);
61
62 $form->addElement('text', 'database', get_string('database', 'cache_mongodb'));
63 $form->addHelpButton('database', 'database', 'cache_mongodb');
64 $form->addRule('database', get_string('required'), 'required');
65 $form->setType('database', PARAM_ALPHANUMEXT);
66 $form->setDefault('database', 'mcache');
67
68 $form->addElement('text', 'username', get_string('username', 'cache_mongodb'));
69 $form->addHelpButton('username', 'username', 'cache_mongodb');
70 $form->setType('username', PARAM_ALPHANUMEXT);
71
72 $form->addElement('text', 'password', get_string('password', 'cache_mongodb'));
73 $form->addHelpButton('password', 'password', 'cache_mongodb');
74 $form->setType('password', PARAM_TEXT);
75
76 $form->addElement('text', 'replicaset', get_string('replicaset', 'cache_mongodb'));
77 $form->addHelpButton('replicaset', 'replicaset', 'cache_mongodb');
78 $form->setType('replicaset', PARAM_ALPHANUMEXT);
79 $form->setAdvanced('replicaset');
80
81 $form->addElement('checkbox', 'usesafe', get_string('usesafe', 'cache_mongodb'));
82 $form->addHelpButton('usesafe', 'usesafe', 'cache_mongodb');
83 $form->setDefault('usesafe', 1);
84 $form->setAdvanced('usesafe');
85 $form->setType('usesafe', PARAM_BOOL);
86
87 $form->addElement('text', 'usesafevalue', get_string('usesafevalue', 'cache_mongodb'));
88 $form->addHelpButton('usesafevalue', 'usesafevalue', 'cache_mongodb');
89 $form->disabledIf('usesafevalue', 'usesafe', 'notchecked');
90 $form->setType('usesafevalue', PARAM_INT);
91 $form->setAdvanced('usesafevalue');
92
93 $form->addElement('checkbox', 'extendedmode', get_string('extendedmode', 'cache_mongodb'));
94 $form->addHelpButton('extendedmode', 'extendedmode', 'cache_mongodb');
95 $form->setDefault('extendedmode', 0);
96 $form->setAdvanced('extendedmode');
97 $form->setType('extendedmode', PARAM_BOOL);
98 }
99}