Skip to content

Commit

Permalink
Merge branch 'wip_MDL-46660_m28_memcache' of https://github.com/skoda…
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Aug 12, 2014
2 parents 62e30bf + 67dabb5 commit 57fdca8
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
49 changes: 49 additions & 0 deletions cache/stores/memcache/classes/environment_check.php
@@ -0,0 +1,49 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Validate that the current db structure matches the install.xml files.
*
* @package core
* @copyright 2014 Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Petr Skoda <petr.skoda@totaralms.com>
*/

class cachestore_memcache_environment_check {
public static function check_memcache_version(environment_results $result) {
global $CFG;

if (empty($CFG->version) or !get_config('cachestore_memcache', 'testservers')) {
// Do not display warnings when plugin not configured,
// admins will see the warning after setting memcache server.
return null;
}
if (!extension_loaded('memcache') or !$version = phpversion('memcache')) {
// No need to mention this when not used.
return null;
}
$minversion = '3.0.3';
$result->setInfo(get_string('memcacheversioncheck', 'cachestore_memcache'));
if (version_compare($version, $minversion) < 0) {
$result->setStatus(false);
$result->setFeedbackStr(array('memcacheversionwarning', 'cachestore_memcache', array('minversion' => $minversion, 'version' => $version)));
} else {
$result->setStatus(true);
}
return $result;
}
}
9 changes: 9 additions & 0 deletions cache/stores/memcache/environment.xml
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<COMPATIBILITY_MATRIX>
<MOODLE version="2.7">
<CUSTOM_CHECKS>
<CUSTOM_CHECK function="cachestore_memcache_environment_check::check_memcache_version" level="optional">
</CUSTOM_CHECK>
</CUSTOM_CHECKS>
</MOODLE>
</COMPATIBILITY_MATRIX>
4 changes: 3 additions & 1 deletion cache/stores/memcache/lang/en/cachestore_memcache.php
Expand Up @@ -33,6 +33,8 @@
When this setting is enabled, the server listed above will be used for fetching.';
$string['clusteredheader'] = 'Split servers';
$string['memcacheversioncheck'] = 'memcache PHP extension';
$string['memcacheversionwarning'] = 'The installed memcache extension {$a->version} is lower than the recommended version {$a->minversion}, upgrading to at least the minimum version will result in better performance when using memcache.';
$string['pluginname'] = 'Memcache';
$string['prefix'] = 'Key prefix';
$string['prefix_help'] = 'This prefix is used for all key names on the memcache server.
Expand Down Expand Up @@ -67,4 +69,4 @@
$string['sessionhandlerconflict'] = 'Warning: A memcache instance ({$a}) has being configured to use the same memcached server as sessions. Purging all caches will lead to sessions also being purged.';
$string['testservers'] = 'Test servers';
$string['testservers_desc'] = 'The test servers get used for unit tests and for performance tests. It is entirely optional to set up test servers. Servers should be defined one per line and consist of a server address and optionally a port and weight.
If no port is provided then the default port (11211) is used.';
If no port is provided then the default port (11211) is used.';
16 changes: 15 additions & 1 deletion cache/stores/memcache/settings.php
Expand Up @@ -26,8 +26,22 @@

defined('MOODLE_INTERNAL') || die;

$settings->add(new admin_setting_configtextarea(
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configtextarea(
'cachestore_memcache/testservers',
new lang_string('testservers', 'cachestore_memcache'),
new lang_string('testservers_desc', 'cachestore_memcache'),
'', PARAM_RAW, 60, 3));

// This is an ugly hack, but the env page skips the warning if server not set...
require_once("$CFG->libdir/environmentlib.php");
$result = new environment_results('custom_check');
$result = cachestore_memcache_environment_check::check_memcache_version($result);
if ($result and $feedbackstr = $result->getFeedbackStr()) {
$settings->add(new admin_setting_heading(
'cachestoremucwarning',
new lang_string('warning'),
$result->strToReport($feedbackstr, 'statuswarning')));
}
unset($result);
}
2 changes: 1 addition & 1 deletion cache/stores/memcache/version.php
Expand Up @@ -26,6 +26,6 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2014051200; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2014080400; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2014050800; // Requires this Moodle version.
$plugin->component = 'cachestore_memcache'; // Full name of the plugin.

0 comments on commit 57fdca8

Please sign in to comment.