MDL-54592 cachestore_mongodb: MongoDB cache store use new driver.
[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 *
6fec1820 29 * @package cachestore_mongodb
2e638e3d
SH
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
170f821b 36// Include the necessary evils.
2e638e3d 37require_once($CFG->dirroot.'/cache/forms.php');
2e638e3d
SH
38
39/**
40 * The form to add an instance of the MongoDB store to the system.
41 *
42 * @copyright 2012 Sam Hemelryk
43 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44 */
6fec1820 45class cachestore_mongodb_addinstance_form extends cachestore_addinstance_form {
2e638e3d
SH
46
47 /**
48 * The forms custom definitions.
49 */
50 protected function configuration_definition() {
6deb0813 51 global $OUTPUT;
2e638e3d
SH
52 $form = $this->_form;
53
2a944b5b 54 if (!version_compare(phpversion('mongodb'), '1.5', 'ge')) {
6deb0813
SH
55 $form->addElement('html', $OUTPUT->notification(get_string('pleaseupgrademongo', 'cachestore_mongodb')));
56 }
57
6fec1820
SH
58 $form->addElement('text', 'server', get_string('server', 'cachestore_mongodb'), array('size' => 72));
59 $form->addHelpButton('server', 'server', 'cachestore_mongodb');
2e638e3d
SH
60 $form->addRule('server', get_string('required'), 'required');
61 $form->setDefault('server', 'mongodb://127.0.0.1:27017');
62 $form->setType('server', PARAM_RAW);
63
6fec1820
SH
64 $form->addElement('text', 'database', get_string('database', 'cachestore_mongodb'));
65 $form->addHelpButton('database', 'database', 'cachestore_mongodb');
2e638e3d
SH
66 $form->addRule('database', get_string('required'), 'required');
67 $form->setType('database', PARAM_ALPHANUMEXT);
68 $form->setDefault('database', 'mcache');
69
6fec1820
SH
70 $form->addElement('text', 'username', get_string('username', 'cachestore_mongodb'));
71 $form->addHelpButton('username', 'username', 'cachestore_mongodb');
2e638e3d
SH
72 $form->setType('username', PARAM_ALPHANUMEXT);
73
6fec1820
SH
74 $form->addElement('text', 'password', get_string('password', 'cachestore_mongodb'));
75 $form->addHelpButton('password', 'password', 'cachestore_mongodb');
2e638e3d
SH
76 $form->setType('password', PARAM_TEXT);
77
6fec1820
SH
78 $form->addElement('text', 'replicaset', get_string('replicaset', 'cachestore_mongodb'));
79 $form->addHelpButton('replicaset', 'replicaset', 'cachestore_mongodb');
2e638e3d
SH
80 $form->setType('replicaset', PARAM_ALPHANUMEXT);
81 $form->setAdvanced('replicaset');
82
6fec1820
SH
83 $form->addElement('checkbox', 'usesafe', get_string('usesafe', 'cachestore_mongodb'));
84 $form->addHelpButton('usesafe', 'usesafe', 'cachestore_mongodb');
2e638e3d
SH
85 $form->setDefault('usesafe', 1);
86 $form->setAdvanced('usesafe');
87 $form->setType('usesafe', PARAM_BOOL);
88
6fec1820
SH
89 $form->addElement('text', 'usesafevalue', get_string('usesafevalue', 'cachestore_mongodb'));
90 $form->addHelpButton('usesafevalue', 'usesafevalue', 'cachestore_mongodb');
2e638e3d
SH
91 $form->disabledIf('usesafevalue', 'usesafe', 'notchecked');
92 $form->setType('usesafevalue', PARAM_INT);
93 $form->setAdvanced('usesafevalue');
94
6fec1820
SH
95 $form->addElement('checkbox', 'extendedmode', get_string('extendedmode', 'cachestore_mongodb'));
96 $form->addHelpButton('extendedmode', 'extendedmode', 'cachestore_mongodb');
2e638e3d
SH
97 $form->setDefault('extendedmode', 0);
98 $form->setAdvanced('extendedmode');
99 $form->setType('extendedmode', PARAM_BOOL);
100 }
101}