MDL-57572 redis: Prevent installation to fail on sites without redis
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 11 Jan 2017 01:22:48 +0000 (02:22 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 11 Jan 2017 01:22:48 +0000 (02:22 +0100)
cache/stores/redis/settings.php

index 92c9c1d..3300b23 100644 (file)
@@ -35,17 +35,20 @@ $settings->add(
     )
 );
 
-$options = array(Redis::SERIALIZER_PHP => get_string('serializer_php', 'cachestore_redis'));
+if (class_exists('Redis')) { // Only if Redis is available.
 
-if (defined('Redis::SERIALIZER_IGBINARY')) {
-    $options[Redis::SERIALIZER_IGBINARY] = get_string('serializer_igbinary', 'cachestore_redis');
-}
+    $options = array(Redis::SERIALIZER_PHP => get_string('serializer_php', 'cachestore_redis'));
 
-$settings->add(new admin_setting_configselect(
-        'cachestore_redis/test_serializer',
-        get_string('test_serializer', 'cachestore_redis'),
-        get_string('test_serializer_desc', 'cachestore_redis'),
-        0,
-        $options
-    )
-);
\ No newline at end of file
+    if (defined('Redis::SERIALIZER_IGBINARY')) {
+        $options[Redis::SERIALIZER_IGBINARY] = get_string('serializer_igbinary', 'cachestore_redis');
+    }
+
+    $settings->add(new admin_setting_configselect(
+            'cachestore_redis/test_serializer',
+            get_string('test_serializer', 'cachestore_redis'),
+            get_string('test_serializer_desc', 'cachestore_redis'),
+            0,
+            $options
+        )
+    );
+}