Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-36322 Errors when updating a Moodle instance with some misconfigu…

…red cache stores
  • Loading branch information...
commit f4cec2ec875708d5fd9f1164465589eeaf7959a4 1 parent 1918a24
Matteo Scaramuccia scara authored samhemelryk committed
19 cache/stores/memcache/lib.php
View
@@ -106,7 +106,15 @@ public function __construct($name, array $configuration = array()) {
$this->servers[] = $server;
}
- $this->isready = true;
+ $this->connection = new Memcache;
+ foreach ($this->servers as $server) {
+ $this->connection->addServer($server[0], $server[1], true, $server[2]);
+ // Test the connection to this server.
+ if (@$this->connection->set("$server[0]:$server[1]:$server[2]", 'ping', MEMCACHE_COMPRESSED, 1)) {
+ // We can connect at least to this server.
+ $this->isready = true;
+ }
+ }
}
/**
@@ -121,10 +129,6 @@ public function initialise(cache_definition $definition) {
throw new coding_exception('This memcache instance has already been initialised.');
}
$this->definition = $definition;
- $this->connection = new Memcache;
- foreach ($this->servers as $server) {
- $this->connection->addServer($server[0], $server[1], true, $server[2]);
- }
}
/**
@@ -276,7 +280,10 @@ public function delete_many(array $keys) {
* @return boolean True on success. False otherwise.
*/
public function purge() {
- $this->connection->flush();
+ if ($this->isready) {
+ $this->connection->flush();
+ }
+
return true;
}
29 cache/stores/memcached/lib.php
View
@@ -127,7 +127,21 @@ public function __construct($name, array $configuration = array()) {
$this->options[Memcached::OPT_HASH] = $hashmethod;
$this->options[Memcached::OPT_BUFFER_WRITES] = $bufferwrites;
- $this->isready = true;
+ $this->connection = new Memcached(crc32($this->name));
+ $servers = $this->connection->getServerList();
+ if (empty($servers)) {
+ foreach ($this->options as $key => $value) {
+ $this->connection->setOption($key, $value);
+ }
+ $this->connection->addServers($this->servers);
+ foreach ($this->servers as $server) {
+ // Test the connection to this server.
+ if (@$this->connection->set("$server[0]:$server[1]:$server[2]", 'ping', MEMCACHE_COMPRESSED, 1)) {
+ // We can connect at least to this server.
+ $this->isready = true;
+ }
+ }
+ }
}
/**
@@ -142,14 +156,6 @@ public function initialise(cache_definition $definition) {
throw new coding_exception('This memcached instance has already been initialised.');
}
$this->definition = $definition;
- $this->connection = new Memcached(crc32($this->name));
- $servers = $this->connection->getServerList();
- if (empty($servers)) {
- foreach ($this->options as $key => $value) {
- $this->connection->setOption($key, $value);
- }
- $this->connection->addServers($this->servers);
- }
}
/**
@@ -302,7 +308,10 @@ public function delete_many(array $keys) {
* @return boolean True on success. False otherwise.
*/
public function purge() {
- $this->connection->flush();
+ if ($this->isready) {
+ $this->connection->flush();
+ }
+
return true;
}
18 cache/stores/mongodb/lib.php
View
@@ -130,7 +130,13 @@ public function __construct($name, array $configuration = array()) {
$this->extendedmode = $configuration['extendedmode'];
}
- $this->isready = self::are_requirements_met();
+ try {
+ $this->connection = new Mongo($this->server, $this->options);
+ $this->database = $this->connection->selectDB($this->databasename);
+ $this->isready = true;
+ } catch (Exception $e) {
+ // Tipically, a MongoConnectionException.
+ }
}
/**
@@ -176,8 +182,6 @@ public function initialise(cache_definition $definition) {
throw new coding_exception('This mongodb instance has already been initialised.');
}
$this->definitionhash = $definition->generate_definition_hash();
- $this->connection = new Mongo($this->server, $this->options);
- $this->database = $this->connection->selectDB($this->databasename);
$this->collection = $this->database->selectCollection($this->definitionhash);
$this->collection->ensureIndex(array('key' => 1), array(
'safe' => $this->usesafe,
@@ -366,8 +370,12 @@ public function delete_many(array $keys) {
* @return boolean True on success. False otherwise.
*/
public function purge() {
- $this->collection->drop();
- $this->collection = $this->database->selectCollection($this->definitionhash);
+ if ($this->isready) {
+ $this->collection->drop();
+ $this->collection = $this->database->selectCollection($this->definitionhash);
+ }
+
+ return true;
}
/**
2  cache/stores/session/lib.php
View
@@ -361,6 +361,8 @@ public function delete_many(array $keys) {
*/
public function purge() {
$this->store = array();
+
+ return true;
}
/**
1  cache/stores/static/lib.php
View
@@ -358,6 +358,7 @@ public function delete_many(array $keys) {
public function purge() {
$this->flush_store_by_id($this->storeid);
$this->store = &self::register_store_id($this->storeid);
+ return true;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.