first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
<?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/>.
/**
* The library file for the file cache store.
*
* This file is part of the file cache store, it contains the API for interacting with an instance of the store.
* This is used as a default cache store within the Cache API. It should never be deleted.
*
* @package cachestore_file
* @category cache
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot.'/cache/forms.php');
/**
* Form for adding a file instance.
*
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cachestore_file_addinstance_form extends cachestore_addinstance_form {
/**
* Adds the desired form elements.
*/
protected function configuration_definition() {
$form = $this->_form;
$form->addElement('text', 'path', get_string('path', 'cachestore_file'));
$form->setType('path', PARAM_RAW);
$form->addHelpButton('path', 'path', 'cachestore_file');
$form->addElement('checkbox', 'autocreate', get_string('autocreate', 'cachestore_file'));
$form->setType('autocreate', PARAM_BOOL);
$form->addHelpButton('autocreate', 'autocreate', 'cachestore_file');
$form->disabledIf('autocreate', 'path', 'eq', '');
$form->addElement('checkbox', 'singledirectory', get_string('singledirectory', 'cachestore_file'));
$form->setType('singledirectory', PARAM_BOOL);
$form->addHelpButton('singledirectory', 'singledirectory', 'cachestore_file');
$form->addElement('checkbox', 'prescan', get_string('prescan', 'cachestore_file'));
$form->setType('prescan', PARAM_BOOL);
$form->addHelpButton('prescan', 'prescan', 'cachestore_file');
$form->addElement('checkbox', 'asyncpurge', get_string('asyncpurge', 'cachestore_file'));
$form->setType('asyncpurge', PARAM_BOOL);
$form->addHelpButton('asyncpurge', 'asyncpurge', 'cachestore_file');
$form->addElement('text', 'lockwait', get_string('lockwait', 'cachestore_file'));
$form->setDefault('lockwait', 60);
$form->setType('lockwait', PARAM_INT);
$form->addHelpButton('lockwait', 'lockwait', 'cachestore_file');
}
}
+46
View File
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for cachestore_file.
*
* @package cachestore_file
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace cachestore_file\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for cachestore_file implementing null_provider.
*
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+53
View File
@@ -0,0 +1,53 @@
<?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/>.
namespace cachestore_file\task;
/**
* Task deletes old cache revision directory.
*
* @package cachestore_file
* @copyright Catalyst IT Europe Ltd 2021
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Jackson D'Souza <jackson.dsouza@catalyst-eu.net>
*/
class asyncpurge extends \core\task\adhoc_task {
/**
* Executes the scheduled task.
*
* @return boolean True if old cache revision directory exists and is deleted. False otherwise.
*/
public function execute(): bool {
$returnvar = true;
$output = 'Cleaning up file store old cache revision directory:' . PHP_EOL;
$data = $this->get_custom_data();
if (is_dir($data->path)) {
remove_dir($data->path);
$output .= 'Directory deleted: ' . $data->path;
} else {
$output .= 'Directory not found: ' . $data->path;
$returnvar = false;
}
if (!PHPUNIT_TEST) {
mtrace($output);
}
return $returnvar;
}
}
+61
View File
@@ -0,0 +1,61 @@
<?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/>.
/**
* The library file for the file cache store.
*
* This file is part of the file cache store, it contains the API for interacting with an instance of the store.
* This is used as a default cache store within the Cache API. It should never be deleted.
*
* @package cachestore_file
* @category cache
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['asyncpurge'] = 'Asynchronously purge directory';
$string['asyncpurge_help'] = 'If enabled, the new directory is created with cache revision and the old directory will be deleted asynchronously via a scheduled task.';
$string['autocreate'] = 'Auto create directory';
$string['autocreate_help'] = 'If enabled the directory specified in path will be automatically created if it does not already exist.';
$string['lockwait'] = 'Maximum lock wait time';
$string['lockwait_help'] = 'The maximum amount of time in seconds to wait for an exclusive lock before reading or writing a cache key. This is only used for cache definitions that have read or write locking required.';
$string['path'] = 'Cache path';
$string['path_help'] = 'The directory that should be used to store files for this cache store. If left blank (default) a directory will be automatically created in the moodledata directory. This can be used to point a file store towards a directory on a better performing drive (such as one in memory).';
$string['pluginname'] = 'File cache';
$string['privacy:metadata'] = 'The File cache cachestore plugin stores data briefly as part of its caching functionality but this data is regularly cleared.';
$string['prescan'] = 'Prescan directory';
$string['prescan_help'] = 'If enabled the directory is scanned when the cache is first used and requests for files are first checked against the scan data. This can help if you have a slow file system and are finding that file operations are causing you a bottle neck.';
$string['singledirectory'] = 'Single directory store';
$string['singledirectory_help'] = 'If enabled files (cached items) will be stored in a single directory rather than being broken up into multiple directories.
Enabling this will speed up file interactions but comes at the cost of increased risk of hitting file system limitations.
It is advisable to only turn this on if the following is true:
* If you know the number of items in the cache is going to be small enough that it won\'t cause issues on the file system you are running with.
* The data being cached is not expensive to generate. If it is then sticking with the default may still be the better option as it reduces the chance of issues.';
$string['task_asyncpurge'] = 'Asynchronously purge file store old cache revision directories';
/**
* This is is like the file store, but designed for siutations where:
* - many more things are likely to be stored in the cache, so CRC hashing is
* too likely to give collisions, and storing everything in a completely flat
* directory structure is inadvisable.
* - the things we are caching are more expensive to calculate, so the extra
* time to computer a better hash is a worthwhile trade-off.
*/
+1042
View File
File diff suppressed because it is too large Load Diff
+97
View File
@@ -0,0 +1,97 @@
<?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/>.
namespace cachestore_file;
use cache_definition;
use cache_store;
use cachestore_file;
/**
* Async purge support test for File cache.
*
* @package cachestore_file
* @copyright Catalyst IT Europe Ltd 2021
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Jackson D'Souza <jackson.dsouza@catalyst-eu.net>
* @coversDefaultClass \cachestore_file
*/
class asyncpurge_test extends \advanced_testcase {
/**
* Testing Asynchronous file store cache purge
*
* @covers ::initialise
* @covers ::set
* @covers ::get
* @covers ::purge
*/
public function test_cache_async_purge(): void {
$this->resetAfterTest(true);
// Cache definition.
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_file', 'phpunit_test');
// Extra config, set async purge = true.
$extraconfig = ['asyncpurge' => true, 'filecacherev' => time()];
$configuration = array_merge(cachestore_file::unit_test_configuration(), $extraconfig);
$name = 'File async test';
// Create file cache store.
$cache = new cachestore_file($name, $configuration);
// Initialise file cache store.
$cache->initialise($definition);
$cache->set('foo', 'bar');
$this->assertSame('bar', $cache->get('foo'));
// Purge this file cache store.
$cache->purge();
// Purging file cache store shouldn't purge the data but create a new cache revision directory.
$this->assertSame('bar', $cache->get('foo'));
$cache->set('foo', 'bar 2');
$this->assertSame('bar 2', $cache->get('foo'));
}
/**
* Testing Adhoc Cron - deletes old cache revision directory
*
* @covers \cachestore_file\task
*/
public function test_cache_async_purge_cron(): void {
global $CFG, $USER;
$this->resetAfterTest(true);
$tmpdir = realpath($CFG->tempdir);
$directorypath = '/cachefile_store';
$cacherevdir = $tmpdir . $directorypath;
// Create cache revision directory.
mkdir($cacherevdir, $CFG->directorypermissions, true);
// Create / execute adhoc task to delete cache revision directory.
$asynctask = new cachestore_file\task\asyncpurge();
$asynctask->set_custom_data(['path' => $cacherevdir]);
$asynctask->set_userid($USER->id);
\core\task\manager::queue_adhoc_task($asynctask);
$asynctask->execute();
// Check if cache revision directory has been deleted.
$this->assertDirectoryDoesNotExist($cacherevdir);
}
}
+114
View File
@@ -0,0 +1,114 @@
<?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/>.
namespace cachestore_file;
use cache_definition;
use cache_store;
use cachestore_file;
defined('MOODLE_INTERNAL') || die();
// Include the necessary evils.
global $CFG;
require_once($CFG->dirroot.'/cache/tests/fixtures/stores.php');
require_once($CFG->dirroot.'/cache/stores/file/lib.php');
/**
* File unit test class.
*
* @package cachestore_file
* @copyright 2013 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \cachestore_file
*/
class store_test extends \cachestore_tests {
/**
* Returns the file class name
* @return string
*/
protected function get_class_name() {
return 'cachestore_file';
}
/**
* Testing cachestore_file::get with prescan enabled and with
* deleting the cache between the prescan and the call to get.
*
* The deleting of cache simulates some other process purging
* the cache.
*/
public function test_cache_get_with_prescan_and_purge(): void {
global $CFG;
$definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'cachestore_file', 'phpunit_test');
$name = 'File test';
$path = make_cache_directory('cachestore_file_test');
$cache = new cachestore_file($name, array('path' => $path, 'prescan' => true));
$cache->initialise($definition);
$cache->set('testing', 'value');
$path = make_cache_directory('cachestore_file_test');
$cache = new cachestore_file($name, array('path' => $path, 'prescan' => true));
$cache->initialise($definition);
// Let's pretend that some other process purged caches.
remove_dir($CFG->cachedir.'/cachestore_file_test', true);
make_cache_directory('cachestore_file_test');
$cache->get('testing');
}
/**
* Tests the get_last_read byte count.
*/
public function test_get_last_io_bytes(): void {
$definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'cachestore_file', 'phpunit_test');
$store = new \cachestore_file('Test');
$store->initialise($definition);
$store->set('foo', 'bar');
$store->set('frog', 'ribbit');
$store->get('foo');
// It's not 3 bytes, because the data is stored serialized.
$this->assertEquals(10, $store->get_last_io_bytes());
$store->get('frog');
$this->assertEquals(13, $store->get_last_io_bytes());
$store->get_many(['foo', 'frog']);
$this->assertEquals(23, $store->get_last_io_bytes());
$store->set('foo', 'goo');
$this->assertEquals(10, $store->get_last_io_bytes());
$store->set_many([
['key' => 'foo', 'value' => 'bar'],
['key' => 'frog', 'value' => 'jump']
]);
$this->assertEquals(21, $store->get_last_io_bytes());
}
public function test_lock(): void {
$store = new \cachestore_file('Test');
$this->assertTrue($store->acquire_lock('lock', '123'));
$this->assertTrue($store->check_lock_state('lock', '123'));
$this->assertFalse($store->check_lock_state('lock', '321'));
$this->assertNull($store->check_lock_state('notalock', '123'));
$this->assertFalse($store->release_lock('lock', '321'));
$this->assertTrue($store->release_lock('lock', '123'));
}
}
+32
View File
@@ -0,0 +1,32 @@
<?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/>.
/**
* Cache file store version information.
*
* This is used as a default cache store within the Cache API. It should never be deleted.
*
* @package cachestore_file
* @category cache
* @copyright 2012 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$plugin->version = 2024042200; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'cachestore_file'; // Full name of the plugin.