summaryrefslogtreecommitdiffstats
path: root/lib/private/memcache/factory.php
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@karoshi.org.uk>2015-07-15 15:21:07 +0100
committerRobin McCorkell <rmccorkell@karoshi.org.uk>2015-07-15 22:53:14 +0100
commit7830434d784ee85507a53499906cee8dbc232ae1 (patch)
tree469bb452f971fb577f2163271cbc763c13ec0a9e /lib/private/memcache/factory.php
parente46ec4a6b6fd48cf7684daa1e2d6b266162600c6 (diff)
downloadnextcloud-server-7830434d784ee85507a53499906cee8dbc232ae1.tar.gz
nextcloud-server-7830434d784ee85507a53499906cee8dbc232ae1.zip
Missing memcache should not cause occ hard-fail
Warning is now printed to logs, but occ and cron will still work.
Diffstat (limited to 'lib/private/memcache/factory.php')
-rw-r--r--lib/private/memcache/factory.php49
1 files changed, 39 insertions, 10 deletions
diff --git a/lib/private/memcache/factory.php b/lib/private/memcache/factory.php
index 5bb7e42c808..a3fc8dfe62c 100644
--- a/lib/private/memcache/factory.php
+++ b/lib/private/memcache/factory.php
@@ -29,6 +29,7 @@
namespace OC\Memcache;
use \OCP\ICacheFactory;
+use \OCP\ILogger;
class Factory implements ICacheFactory {
const NULL_CACHE = '\\OC\\Memcache\\NullCache';
@@ -39,6 +40,11 @@ class Factory implements ICacheFactory {
private $globalPrefix;
/**
+ * @var ILogger $logger
+ */
+ private $logger;
+
+ /**
* @var string $localCacheClass
*/
private $localCacheClass;
@@ -55,13 +61,15 @@ class Factory implements ICacheFactory {
/**
* @param string $globalPrefix
+ * @param ILogger $logger
* @param string|null $localCacheClass
* @param string|null $distributedCacheClass
* @param string|null $lockingCacheClass
*/
- public function __construct($globalPrefix,
+ public function __construct($globalPrefix, ILogger $logger,
$localCacheClass = null, $distributedCacheClass = null, $lockingCacheClass = null)
{
+ $this->logger = $logger;
$this->globalPrefix = $globalPrefix;
if (!$localCacheClass) {
@@ -71,22 +79,43 @@ class Factory implements ICacheFactory {
$distributedCacheClass = $localCacheClass;
}
+ $missingCacheMessage = 'Memcache {class} not available for {use} cache';
+ $missingCacheHint = 'Is the matching PHP module installed and enabled?';
if (!$localCacheClass::isAvailable()) {
- throw new \OC\HintException(
- 'Missing memcache class ' . $localCacheClass . ' for local cache',
- 'Is the matching PHP module installed and enabled ?'
- );
+ if (\OC::$CLI) {
+ // CLI should not hard-fail on broken memcache
+ $this->logger->info($missingCacheMessage, [
+ 'class' => $localCacheClass,
+ 'use' => 'local',
+ 'app' => 'cli'
+ ]);
+ $localCacheClass = self::NULL_CACHE;
+ } else {
+ throw new \OC\HintException(strtr($missingCacheMessage, [
+ '{class}' => $localCacheClass, '{use}' => 'local'
+ ]), $missingCacheHint);
+ }
}
if (!$distributedCacheClass::isAvailable()) {
- throw new \OC\HintException(
- 'Missing memcache class ' . $distributedCacheClass . ' for distributed cache',
- 'Is the matching PHP module installed and enabled ?'
- );
+ if (\OC::$CLI) {
+ // CLI should not hard-fail on broken memcache
+ $this->logger->info($missingCacheMessage, [
+ 'class' => $distributedCacheClass,
+ 'use' => 'distributed',
+ 'app' => 'cli'
+ ]);
+ $distributedCacheClass = self::NULL_CACHE;
+ } else {
+ throw new \OC\HintException(strtr($missingCacheMessage, [
+ '{class}' => $distributedCacheClass, '{use}' => 'distributed'
+ ]), $missingCacheHint);
+ }
}
if (!($lockingCacheClass && $lockingCacheClass::isAvailable())) {
// dont fallback since the fallback might not be suitable for storing lock
- $lockingCacheClass = '\OC\Memcache\NullCache';
+ $lockingCacheClass = self::NULL_CACHE;
}
+
$this->localCacheClass = $localCacheClass;
$this->distributedCacheClass = $distributedCacheClass;
$this->lockingCacheClass = $lockingCacheClass;