mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
Merge branch '45412-27' of git://github.com/samhemelryk/moodle
This commit is contained in:
commit
87f7ae9c46
5
cache/stores/mongodb/addinstanceform.php
vendored
5
cache/stores/mongodb/addinstanceform.php
vendored
@ -48,8 +48,13 @@ class cachestore_mongodb_addinstance_form extends cachestore_addinstance_form {
|
||||
* The forms custom definitions.
|
||||
*/
|
||||
protected function configuration_definition() {
|
||||
global $OUTPUT;
|
||||
$form = $this->_form;
|
||||
|
||||
if (!class_exists('MongoClient')) {
|
||||
$form->addElement('html', $OUTPUT->notification(get_string('pleaseupgrademongo', 'cachestore_mongodb')));
|
||||
}
|
||||
|
||||
$form->addElement('text', 'server', get_string('server', 'cachestore_mongodb'), array('size' => 72));
|
||||
$form->addHelpButton('server', 'server', 'cachestore_mongodb');
|
||||
$form->addRule('server', get_string('required'), 'required');
|
||||
|
@ -28,6 +28,7 @@ $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['pleaseupgrademongo'] = 'You are using an old version of the PHP Mongo extension (> 1.3). Support for old versions of the Mongo extension will be dropped in the future. Please consider upgrading.';
|
||||
$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.';
|
||||
|
53
cache/stores/mongodb/lib.php
vendored
53
cache/stores/mongodb/lib.php
vendored
@ -105,6 +105,14 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
|
||||
*/
|
||||
protected $isready = false;
|
||||
|
||||
/**
|
||||
* Set to true if the Mongo extension is < version 1.3.
|
||||
* If this is the case we must use the legacy Mongo class instead of MongoClient.
|
||||
* Mongo is backwards compatible, although obviously deprecated.
|
||||
* @var bool
|
||||
*/
|
||||
protected $legacymongo = false;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the Mongo store.
|
||||
*
|
||||
@ -140,8 +148,13 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
|
||||
$this->extendedmode = $configuration['extendedmode'];
|
||||
}
|
||||
|
||||
// Test if the MongoClient class exists, if not we need to switch to legacy classes.
|
||||
$this->legacymongo = (!class_exists('MongoClient'));
|
||||
|
||||
// MongoClient from Mongo 1.3 onwards. Mongo for earlier versions.
|
||||
$class = ($this->legacymongo) ? 'Mongo' : 'MongoClient';
|
||||
try {
|
||||
$this->connection = new Mongo($this->server, $this->options);
|
||||
$this->connection = new $class($this->server, $this->options);
|
||||
$this->isready = true;
|
||||
} catch (MongoConnectionException $e) {
|
||||
// We only want to catch MongoConnectionExceptions here.
|
||||
@ -193,10 +206,14 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
|
||||
$this->database = $this->connection->selectDB($this->databasename);
|
||||
$this->definitionhash = $definition->generate_definition_hash();
|
||||
$this->collection = $this->database->selectCollection($this->definitionhash);
|
||||
$this->collection->ensureIndex(array('key' => 1), array(
|
||||
'safe' => $this->usesafe,
|
||||
'name' => 'idx_key'
|
||||
));
|
||||
|
||||
$options = array('name' => 'idx_key');
|
||||
if ($this->legacymongo) {
|
||||
$options['safe'] = $this->usesafe;
|
||||
} else {
|
||||
$options['w'] = $this->usesafe ? 1 : 0;
|
||||
}
|
||||
$this->collection->ensureIndex(array('key' => 1), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -301,11 +318,12 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
|
||||
$record = $key;
|
||||
}
|
||||
$record['data'] = serialize($data);
|
||||
$options = array(
|
||||
'upsert' => true,
|
||||
'safe' => $this->usesafe,
|
||||
'w' => $this->usesafe ? 1 : 0
|
||||
);
|
||||
$options = array('upsert' => true);
|
||||
if ($this->legacymongo) {
|
||||
$options['safe'] = $this->usesafe;
|
||||
} else {
|
||||
$options['w'] = $this->usesafe ? 1 : 0;
|
||||
}
|
||||
$this->delete($key);
|
||||
$result = $this->collection->insert($record, $options);
|
||||
if ($result === true) {
|
||||
@ -354,11 +372,12 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
|
||||
} else {
|
||||
$criteria = $key;
|
||||
}
|
||||
$options = array(
|
||||
'justOne' => false,
|
||||
'safe' => $this->usesafe,
|
||||
'w' => $this->usesafe ? 1 : 0
|
||||
);
|
||||
$options = array('justOne' => false);
|
||||
if ($this->legacymongo) {
|
||||
$options['safe'] = $this->usesafe;
|
||||
} else {
|
||||
$options['w'] = $this->usesafe ? 1 : 0;
|
||||
}
|
||||
$result = $this->collection->remove($criteria, $options);
|
||||
|
||||
if ($result === true) {
|
||||
@ -483,7 +502,9 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
|
||||
$connection = $this->connection;
|
||||
} else {
|
||||
try {
|
||||
$connection = new Mongo($this->server, $this->options);
|
||||
// MongoClient from Mongo 1.3 onwards. Mongo for earlier versions.
|
||||
$class = ($this->legacymongo) ? 'Mongo' : 'MongoClient';
|
||||
$connection = new $class($this->server, $this->options);
|
||||
} catch (MongoConnectionException $e) {
|
||||
// We only want to catch MongoConnectionExceptions here.
|
||||
// If the server cannot be connected to we cannot clean it.
|
||||
|
Loading…
x
Reference in New Issue
Block a user