MDL-36322 Errors when updating a Moodle instance with some misconfigured cache stores
This commit is contained in:
committed by
Sam Hemelryk
parent
a8e927e26c
commit
447475e5d7
Vendored
+13
-6
@@ -106,7 +106,15 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
|
||||
$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 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
|
||||
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 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
|
||||
* @return boolean True on success. False otherwise.
|
||||
*/
|
||||
public function purge() {
|
||||
$this->connection->flush();
|
||||
if ($this->isready) {
|
||||
$this->connection->flush();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+19
-10
@@ -127,7 +127,21 @@ class cachestore_memcached extends cache_store implements cache_is_configurable
|
||||
$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 @@ class cachestore_memcached extends cache_store implements cache_is_configurable
|
||||
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 @@ class cachestore_memcached extends cache_store implements cache_is_configurable
|
||||
* @return boolean True on success. False otherwise.
|
||||
*/
|
||||
public function purge() {
|
||||
$this->connection->flush();
|
||||
if ($this->isready) {
|
||||
$this->connection->flush();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+13
-5
@@ -130,7 +130,13 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
|
||||
$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 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
|
||||
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 @@ class cachestore_mongodb extends cache_store implements cache_is_configurable {
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+2
@@ -361,6 +361,8 @@ class cachestore_session extends session_data_store implements cache_is_key_awar
|
||||
*/
|
||||
public function purge() {
|
||||
$this->store = array();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Vendored
+1
@@ -358,6 +358,7 @@ class cachestore_static extends static_data_store implements cache_is_key_aware
|
||||
public function purge() {
|
||||
$this->flush_store_by_id($this->storeid);
|
||||
$this->store = &self::register_store_id($this->storeid);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user