├── .github └── workflows │ └── ci.yml ├── .gitignore ├── README.md ├── classes ├── clean.php ├── plugininfo │ └── cleaner.php ├── privacy │ └── provider.php ├── schema_add_cascade_delete.php └── table_scrambler.php ├── cleaner ├── README.txt ├── backup │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_backup.php │ ├── settings.php │ ├── tests │ │ └── cleaner_test.php │ └── version.php ├── completion │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_completion.php │ ├── settings.php │ └── version.php ├── config │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_config.php │ ├── settings.php │ ├── tests │ │ └── config_test.php │ └── version.php ├── core │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_core.php │ ├── settings.php │ └── version.php ├── courses │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_courses.php │ ├── settings.php │ └── version.php ├── custom_sql_post │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_custom_sql_post.php │ ├── settings.php │ └── version.php ├── custom_sql_pre │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_custom_sql_pre.php │ ├── settings.php │ └── version.php ├── delete_users │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_delete_users.php │ ├── settings.php │ └── version.php ├── email │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_email.php │ ├── settings.php │ ├── tests │ │ └── cleaner_email_test.php │ └── version.php ├── environment_matrix │ ├── README.md │ ├── amd │ │ ├── build │ │ │ └── matrix.min.js │ │ └── src │ │ │ └── matrix.js │ ├── classes │ │ ├── clean.php │ │ ├── form │ │ │ └── matrix.php │ │ ├── local │ │ │ └── matrix.php │ │ └── privacy │ │ │ └── provider.php │ ├── cli │ │ └── matrix_replace.php │ ├── db │ │ ├── install.xml │ │ └── upgrade.php │ ├── index.php │ ├── lang │ │ └── en │ │ │ └── cleaner_environment_matrix.php │ ├── settings.php │ ├── styles.css │ └── version.php ├── grades │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_grades.php │ ├── settings.php │ └── version.php ├── logstore_standard │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_logstore_standard.php │ └── version.php ├── orphaned_sitedata │ ├── classes │ │ ├── backup_cleaner.php │ │ ├── cache_cleaner.php │ │ ├── clean.php │ │ ├── orphan_cleaner.php │ │ ├── privacy │ │ │ └── provider.php │ │ └── tempfiles_cleaner.php │ ├── lang │ │ └── en │ │ │ └── cleaner_orphaned_sitedata.php │ ├── settings.php │ ├── tests │ │ └── unit │ │ │ ├── backup_cleaner_test.php │ │ │ ├── cache_cleaner_test.php │ │ │ ├── orphan_cleaner_test.php │ │ │ ├── orphaned_sitedata_testcase.php │ │ │ └── tempfiles_cleaner_test.php │ └── version.php ├── replace_urls │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_replace_urls.php │ ├── settings.php │ ├── tests │ │ └── replace_urls_test.php │ └── version.php ├── scheduled_tasks │ ├── classes │ │ ├── clean.php │ │ ├── form │ │ │ └── task_form.php │ │ └── privacy │ │ │ └── provider.php │ ├── db │ │ └── install.xml │ ├── index.php │ ├── lang │ │ └── en │ │ │ └── cleaner_scheduled_tasks.php │ ├── settings.php │ └── version.php ├── sitedata │ ├── TODO │ ├── classes │ │ ├── clean.php │ │ ├── privacy │ │ │ └── provider.php │ │ └── supported_file_types.php │ ├── fixtures │ │ ├── placeholder │ │ ├── placeholder.7z │ │ ├── placeholder.bmp │ │ ├── placeholder.bz2 │ │ ├── placeholder.css │ │ ├── placeholder.csv │ │ ├── placeholder.doc │ │ ├── placeholder.docx │ │ ├── placeholder.gif │ │ ├── placeholder.gz │ │ ├── placeholder.html │ │ ├── placeholder.ico │ │ ├── placeholder.jpg │ │ ├── placeholder.js │ │ ├── placeholder.odg │ │ ├── placeholder.odp │ │ ├── placeholder.ods │ │ ├── placeholder.odt │ │ ├── placeholder.otp │ │ ├── placeholder.pdf │ │ ├── placeholder.png │ │ ├── placeholder.ppt │ │ ├── placeholder.pptx │ │ ├── placeholder.psd │ │ ├── placeholder.rar │ │ ├── placeholder.rtf │ │ ├── placeholder.tar │ │ ├── placeholder.tif │ │ ├── placeholder.txt │ │ ├── placeholder.xcf │ │ ├── placeholder.xls │ │ ├── placeholder.xlsx │ │ ├── placeholder.xlt │ │ ├── placeholder.xml │ │ └── placeholder.zip │ ├── lang │ │ └── en │ │ │ └── cleaner_sitedata.php │ ├── settings.php │ └── version.php ├── tasklogs │ ├── classes │ │ ├── clean.php │ │ └── privacy │ │ │ └── provider.php │ ├── lang │ │ └── en │ │ │ └── cleaner_tasklogs.php │ ├── settings.php │ └── version.php └── users │ ├── classes │ ├── clean.php │ └── privacy │ │ └── provider.php │ ├── db │ └── upgrade.php │ ├── lang │ └── en │ │ └── cleaner_users.php │ ├── settings.php │ └── version.php ├── cli ├── clean.php ├── lib.php └── sitedata_file_list.php ├── db ├── caches.php ├── subplugins.json ├── subplugins.php └── upgrade.php ├── index.php ├── lang └── en │ └── local_datacleaner.php ├── lib.php ├── settings.php ├── tests ├── privacy │ └── privacy.php └── unit │ ├── custom_test.php │ └── table_scrambler_test.php └── version.php /.gitignore: -------------------------------------------------------------------------------- 1 | .buildpath 2 | .project 3 | .settings 4 | -------------------------------------------------------------------------------- /classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package local_datacleaner 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace local_datacleaner\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package local_datacleaner\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/README.txt: -------------------------------------------------------------------------------- 1 | 2 | A cleaner can do almost anything. But they broadly fit into a few categories: 3 | 4 | * A cleaner delete data 5 | 6 | * A cleaner transforms data, by inserting random data or randomizing the existing data 7 | 8 | 9 | As a general rule for speed, all the data removal steps should be run first 10 | so we aren't wasting time transforming them only to be deleted later. Each 11 | task has a sortorder which reflects this order, a good rule of thunb is to 12 | use the CONTEXT_ numbers, so CONTEXT_SYSTEM (10) cleaners will be run first, 13 | then CONTEXT_USER (30) etc. 14 | -------------------------------------------------------------------------------- /cleaner/backup/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Completion cleaner. 19 | * 20 | * @package cleaner_backup 21 | * @copyright 2020 Peter Burnett 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | namespace cleaner_backup; 26 | 27 | defined('MOODLE_INTERNAL') || die(); 28 | 29 | class clean extends \local_datacleaner\clean { 30 | const TASK = 'Deleting course backups'; 31 | 32 | /** 33 | * Execute the cleaner. 34 | */ 35 | public static function execute() { 36 | self::new_task(1); 37 | self::delete_backups(); 38 | self::next_step(); 39 | } 40 | 41 | public static function delete_backups() { 42 | global $DB; 43 | $storage = get_file_storage(); 44 | 45 | $fastdelete = get_config('cleaner_backup', 'fastdelete'); 46 | $likefrag = $DB->sql_like('filename', ':like'); 47 | $like = '%.mbz'; 48 | 49 | // If this is a fast delete, do a quick delete from files table and return. 50 | if ($fastdelete) { 51 | $sql = "DELETE FROM {files} 52 | WHERE " . $likefrag; 53 | 54 | $DB->execute($sql, ['like' => $like]); 55 | return; 56 | } 57 | 58 | // Do a "proper" delete. 59 | $sql = "SELECT * 60 | FROM {files} 61 | WHERE " . $likefrag; 62 | $rs = $DB->get_recordset_sql($sql, ['like' => $like]); 63 | 64 | foreach ($rs as $record) { 65 | // Get the file record, then delete it from table. 66 | $file = $storage->get_file_instance($record); 67 | 68 | if ($file) { 69 | $file->delete(); 70 | } 71 | } 72 | $rs->close(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /cleaner/backup/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_backup 20 | * @author 2020 Peter Burnett (peterburnett@catalyst-au.net) 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | namespace cleaner_backup\privacy; 24 | defined('MOODLE_INTERNAL') || die; 25 | use core_privacy\local\metadata\null_provider; 26 | use core_privacy\local\legacy_polyfill; 27 | /** 28 | * Class provider 29 | * @package cleaner_completion\privacy 30 | */ 31 | class provider implements null_provider { 32 | use legacy_polyfill; 33 | /** 34 | * Get the language string identifier with the component's language 35 | * file to explain why this plugin stores no data. 36 | * 37 | * @return string 38 | */ 39 | public static function _get_reason() { 40 | return 'privacy:metadata'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /cleaner/backup/lang/en/cleaner_backup.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_backup 21 | * @copyright 2020 Peter Burnett 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['pluginname'] = 'Delete backup files'; 26 | $string['privacy:metadata'] = 'The Delete backup files plugin does not store any personal data.'; 27 | $string['fastdelete'] = 'Fast delete'; 28 | $string['fastdelete_desc'] = 'Perform a fast delete. This will delete file references from the file table, but will not delete the actual files on disk. This is useful when the filesystem stores files in a remote location, or files are shared between environments.'; 29 | -------------------------------------------------------------------------------- /cleaner/backup/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Settings. 19 | * 20 | * @package cleaner_backup 21 | * @copyright 2020 Peter Burnett 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | if (!$ADMIN->fulltree) { 28 | return; 29 | } 30 | 31 | $settings->add(new admin_setting_configcheckbox('cleaner_backup/fastdelete', 32 | new lang_string('fastdelete', 'cleaner_backup'), 33 | new lang_string('fastdelete_desc', 'cleaner_backup'), 0)); 34 | -------------------------------------------------------------------------------- /cleaner/backup/tests/cleaner_test.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Tests for the cleaner. 19 | * 20 | * @package cleaner_backup 21 | * @copyright 2020 Peter Burnett 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_backup\tests; 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | class cleaner_backup_test extends \advanced_testcase { 29 | 30 | public function delete_provider() { 31 | // Array of filename, deleted. 32 | return [ 33 | ['myfile.txt', false], 34 | ['myfile.mbz', true], 35 | ['myfile.mbzz', false], 36 | ['mbz.txt', false], 37 | ['mbz.mbz', true], 38 | ['myfile.mbz.txt', false], 39 | ['myfile.mbz.mbz', true], 40 | ]; 41 | } 42 | 43 | /** 44 | * @dataProvider delete_provider 45 | */ 46 | public function test_delete_backups($filename, $deleted) { 47 | global $DB; 48 | $this->resetAfterTest(); 49 | 50 | // Create a course, and create a file in the course area. 51 | $course = $this->getDataGenerator()->create_course(); 52 | $context = \context_course::instance($course->id); 53 | $storage = get_file_storage(); 54 | 55 | $file = $storage->create_file_from_string([ 56 | 'contextid' => $context->id, 57 | 'component' => 'cleaner_backup', 58 | 'filearea' => 'backup', 59 | 'itemid' => 0, 60 | 'filepath' => '/', 61 | 'filename' => $filename 62 | ], 'content'); 63 | 64 | \cleaner_backup\clean::delete_backups(); 65 | 66 | $this->assertEquals($deleted, !$storage->file_exists( 67 | $file->get_contextid(), 68 | $file->get_component(), 69 | $file->get_filearea(), 70 | $file->get_itemid(), 71 | $file->get_filepath(), 72 | $file->get_filename() 73 | )); 74 | 75 | // Purge the files table to be sure its fresh. 76 | $DB->delete_records('files', []); 77 | 78 | // Now recreate this file, and process a fast delete. 79 | $file = $storage->create_file_from_string([ 80 | 'contextid' => $context->id, 81 | 'component' => 'cleaner_backup', 82 | 'filearea' => 'backup', 83 | 'itemid' => 0, 84 | 'filepath' => '/', 85 | 'filename' => $filename 86 | ], 'content'); 87 | 88 | set_config('fastdelete', 1, 'cleaner_backup'); 89 | \cleaner_backup\clean::delete_backups(); 90 | 91 | $this->assertEquals($deleted, !$storage->file_exists( 92 | $file->get_contextid(), 93 | $file->get_component(), 94 | $file->get_filearea(), 95 | $file->get_itemid(), 96 | $file->get_filepath(), 97 | $file->get_filename() 98 | )); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /cleaner/backup/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_backup 21 | * @copyright 2020 Peter Burnett 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | $plugin->version = 2020102201; 28 | $plugin->release = '2.3.2'; 29 | $plugin->maturity = MATURITY_STABLE; 30 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 31 | $plugin->component = 'cleaner_backup'; 32 | $plugin->sortorder = 7; 33 | -------------------------------------------------------------------------------- /cleaner/completion/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_completion 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_completion\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_completion\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/completion/lang/en/cleaner_completion.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_completion 21 | * @copyright 2015 Dmitrii Metelkin 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['pluginname'] = 'Clean completion'; 26 | $string['privacy:metadata'] = 'The cleaner completion plugin does not store any personal data.'; 27 | $string['deleteactivitycompletion'] = 'Delete activity completion'; 28 | $string['deleteactivitycompletiondesc'] = 'Delete activity completion.'; 29 | $string['deletecoursecompletion'] = 'Delete course completion'; 30 | $string['deletecoursecompletiondesc'] = 'Delete course completion.'; 31 | $string['category'] = 'Category'; 32 | $string['categories'] = 'Categories'; 33 | $string['categoriesdesc'] = 'Delete completion data for the courses in the selected categories only. If not selected all categories will be processed.'; 34 | $string['coursename'] = 'Full name of course to keep completion'; 35 | $string['courses'] = 'Courses to skip'; 36 | $string['coursesdesc'] = 'Shortname of courses that should never be cleaned, separated by a new line.'; 37 | -------------------------------------------------------------------------------- /cleaner/completion/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_completion 21 | * @copyright 2015 Dmitrii Metelkin 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | $plugin->version = 2015122200; 28 | $plugin->release = '2.3.2'; 29 | $plugin->maturity = MATURITY_STABLE; 30 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 31 | $plugin->component = 'cleaner_completion'; 32 | $plugin->sortorder = 6; 33 | -------------------------------------------------------------------------------- /cleaner/config/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_config 19 | * @copyright 2015 Catalyst IT 20 | * @author Nigel Cunningham 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | namespace cleaner_config; 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | class clean extends \local_datacleaner\clean { 29 | const TASK = 'Removing config settings'; 30 | 31 | /** 32 | * Define the config names and values to be cleaned. 33 | */ 34 | public static function get_where() { 35 | 36 | // Get the settings, handling the case where new ones (dev) 37 | // haven't been set yet. 38 | $config = get_config('cleaner_config'); 39 | 40 | $where = ''; 41 | $params = []; 42 | 43 | $names = isset($config->names) ? explode("\n", $config->names) : array(); 44 | foreach ($names as $name) { 45 | $name = trim($name); 46 | if (empty($name)) { 47 | continue; 48 | } 49 | if ($where) { 50 | $where .= " OR "; 51 | } 52 | $where .= " name LIKE ?"; 53 | $params[] = $name; 54 | } 55 | $values = isset($config->vals) ? explode("\n", $config->vals) : array(); 56 | foreach ($values as $val) { 57 | $val = trim($val); 58 | if (empty($val)) { 59 | continue; 60 | } 61 | if ($where) { 62 | $where .= " OR "; 63 | } 64 | $where .= " value LIKE ?"; 65 | $params[] = $val; 66 | } 67 | 68 | return [$where, $params]; 69 | } 70 | 71 | /** 72 | * Do the hard work of removing config settings. 73 | */ 74 | static public function execute() { 75 | global $DB; 76 | 77 | list($where, $params) = self::get_where(); 78 | 79 | if ($where) { 80 | self::new_task(2); 81 | if (self::$options['dryrun']) { 82 | $count = $DB->count_records_select('config', $where, $params); 83 | echo "Would delete {$count} records from the config table.\n"; 84 | } else { 85 | $DB->delete_records_select("config", $where, $params); 86 | } 87 | self::next_step(); 88 | if (self::$options['dryrun']) { 89 | $count = $DB->count_records_select('config_plugins', $where, $params); 90 | echo "Would delete {$count} records from the config_plugins table.\n"; 91 | } else { 92 | $DB->delete_records_select("config_plugins", $where, $params); 93 | } 94 | self::next_step(); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /cleaner/config/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_config 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_config\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_config\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/config/lang/en/cleaner_config.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_config 19 | * @copyright 2015 Brendan Heywood 20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 | */ 22 | 23 | $string['pluginname'] = 'Delete config'; 24 | $string['privacy:metadata'] = 'The cleaner config plugin does not store any personal data.'; 25 | $string['names'] = 'Config items to delete'; 26 | $string['namesdesc'] = 'A list of config item names, one per line, which if matched will be deleted. You can use the % wildcard to match multiple names.'; 27 | $string['vals'] = 'Config values to delete'; 28 | $string['valsdesc'] = 'A list of config item values, one per line, which if found in any config item will be deleted. You can use the % wildcard to match multiple values.'; 29 | 30 | $string['name'] = 'Config name'; 31 | $string['value'] = 'Config value to be deleted'; 32 | -------------------------------------------------------------------------------- /cleaner/config/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_courses 19 | * @copyright 2015 Brendan Heywood 20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 | */ 22 | 23 | use cleaner_config\clean; 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | if ($ADMIN->fulltree) { 28 | 29 | $settings->add(new admin_setting_configtextarea( 30 | 'cleaner_config/names', 31 | new lang_string('names', 'cleaner_config'), 32 | new lang_string('namesdesc', 'cleaner_config'), 33 | "siteidentifier\n%salt%", PARAM_RAW, 60, 5)); 34 | 35 | $table = new html_table(); 36 | $table->data = array(); 37 | $table->head = array( 38 | get_string('plugin'), 39 | get_string('name', 'cleaner_config'), 40 | get_string('value', 'cleaner_config'), 41 | ); 42 | 43 | $configclean = new clean(); 44 | list($where, $params) = $configclean::get_where(); 45 | 46 | if ($where) { 47 | $itemstoremove = $DB->get_records_sql("SELECT * 48 | FROM {config} 49 | WHERE $where 50 | ORDER BY name ", $params); 51 | foreach ($itemstoremove as $r) { 52 | $table->data[] = array('core', $r->name, $r->value); 53 | } 54 | 55 | $itemstoremove = $DB->get_records_sql("SELECT * 56 | FROM {config_plugins} 57 | WHERE ($where) 58 | ORDER BY plugin, name", $params); 59 | foreach ($itemstoremove as $r) { 60 | $table->data[] = array($r->plugin, $r->name, $r->value); 61 | } 62 | } 63 | 64 | $settings->add(new admin_setting_configtextarea( 65 | 'cleaner_config/vals', 66 | new lang_string('vals', 'cleaner_config'), 67 | new lang_string('valsdesc', 'cleaner_config') . "
\n" . html_writer::table($table), 68 | 'test', PARAM_RAW, 60, 5)); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /cleaner/config/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_config 19 | * @copyright 2015 Brendan Heywood 20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 | */ 22 | 23 | defined('MOODLE_INTERNAL') || die; 24 | 25 | $plugin->version = 2015072200; 26 | $plugin->release = '2.3.2'; 27 | $plugin->maturity = MATURITY_STABLE; 28 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 29 | $plugin->component = 'cleaner_config'; 30 | $plugin->sortorder = 2; 31 | -------------------------------------------------------------------------------- /cleaner/core/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_core 19 | * @copyright 2015 Catalyst IT 20 | * @author Nigel Cunningham 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | namespace cleaner_core; 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | class clean extends \local_datacleaner\clean { 29 | const TASK = 'Removing config settings'; 30 | 31 | /** 32 | * Do the work of truncating any unneeded tables. 33 | */ 34 | static public function execute() { 35 | global $DB, $CFG; 36 | 37 | // Get the settings. 38 | $config = get_config('cleaner_core'); 39 | 40 | $deletemucfile = isset($config->deletemucfile) && $config->deletemucfile == 1 ? true : false; 41 | 42 | // Set the default directories. 43 | $mucdirectory = $CFG->dataroot . '/muc'; 44 | 45 | $tables = $DB->get_tables(); 46 | $tablelist = array(); 47 | 48 | foreach ($tables as $table) { 49 | switch ($table) { 50 | case 'events_queue': 51 | case 'events_queue_handlers': 52 | case 'events_handlers': 53 | case 'task_adhoc': 54 | case 'message': 55 | case 'message_popup': 56 | case 'message_read': 57 | case 'message_working': 58 | case 'tool_monitor': 59 | $tablelist[] = $table; 60 | break; 61 | default: 62 | if (substr($table, 0, 5) == 'back_' || 63 | substr($table, 0, 6) == 'stats_' || 64 | substr($table, 0, 9) == 'sessions_' || 65 | substr($table, 0, 13) == 'webdav_locks_') { 66 | $tablelist[] = $table; 67 | } 68 | } 69 | } 70 | 71 | if (self::$options['dryrun']) { 72 | // This always gets run. 73 | printf("\n\r " . get_string('wouldtruncatetables', 'cleaner_core', count($tablelist)) . "\n"); 74 | 75 | if ($deletemucfile) { 76 | // There's only one file here. 77 | printf("\n\r " . get_string('woulddeletemuc', 'cleaner_core') . "\n"); 78 | } 79 | 80 | } else { 81 | // This always gets run. 82 | printf("\n\r " . get_string('willtruncatetables', 'cleaner_core', count($tablelist)) . "\n"); 83 | foreach ($tablelist as $table) { 84 | $DB->delete_records($table); 85 | } 86 | 87 | if ($deletemucfile) { 88 | printf("\n\r " . get_string('willdeletemuc', 'cleaner_core') . "\n"); 89 | if (!remove_dir($mucdirectory, true)) { 90 | printf("\r " . get_string('errordeletingdir', 'local_datacleaner', $mucdirectory) . "\n"); 91 | } 92 | } 93 | 94 | } 95 | 96 | printf("\n"); 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /cleaner/core/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_core 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_core\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_core\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/core/lang/en/cleaner_core.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_core 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['pluginname'] = 'Cleanup core'; 26 | $string['privacy:metadata'] = 'The cleaner core plugin does not store any personal data.'; 27 | 28 | $string['deletemucfile'] = 'Delete muc file'; 29 | $string['deletemucfiledesc'] = 'Delete the muc configuration file.'; 30 | 31 | $string['woulddeletemuc'] = 'Would delete muc file.'; 32 | $string['willdeletemuc'] = 'Will delete muc file.'; 33 | 34 | $string['wouldtruncatetables'] = 'Would truncate {$a} tables.'; 35 | $string['willtruncatetables'] = 'Will truncate {$a} tables.'; 36 | -------------------------------------------------------------------------------- /cleaner/core/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_core 19 | * @copyright 2015 Catalyst IT 20 | * @author Ghada El-Zoghbi 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$ADMIN->fulltree) { 27 | return; 28 | } 29 | 30 | $settings->add(new admin_setting_configcheckbox('cleaner_core/deletemucfile', 31 | new lang_string('deletemucfile', 'cleaner_core'), 32 | new lang_string('deletemucfiledesc', 'cleaner_core'), 1)); 33 | 34 | -------------------------------------------------------------------------------- /cleaner/core/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_core 19 | * @copyright 2015 Brendan Heywood 20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 | */ 22 | 23 | defined('MOODLE_INTERNAL') || die; 24 | 25 | $plugin->version = 2015091400; 26 | $plugin->release = '2.3.2'; 27 | $plugin->maturity = MATURITY_STABLE; 28 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 29 | $plugin->component = 'cleaner_core'; 30 | $plugin->sortorder = 1; 31 | -------------------------------------------------------------------------------- /cleaner/courses/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_courses 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_courses\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_courses\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/courses/lang/en/cleaner_courses.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_courses 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['pluginname'] = 'Delete courses'; 26 | $string['privacy:metadata'] = 'The cleaner courses plugin does not store any personal data.'; 27 | $string['category'] = 'Category'; 28 | $string['categories'] = 'Categories'; 29 | $string['categoriesdesc'] = 'Delete courses in the selected categories only.'; 30 | $string['coursename'] = 'Full name of course to keep'; 31 | $string['courses'] = 'Courses'; 32 | $string['coursesdesc'] = 'Shortname of courses that should never be deleted, separated by a new line.'; 33 | $string['minimumage'] = 'Minimum age'; 34 | $string['minimumagedesc'] = ''; 35 | -------------------------------------------------------------------------------- /cleaner/courses/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_courses 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | $plugin->version = 2015072200; 28 | $plugin->release = '2.3.2'; 29 | $plugin->maturity = MATURITY_STABLE; 30 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 31 | $plugin->component = 'cleaner_courses'; 32 | $plugin->sortorder = 10; 33 | -------------------------------------------------------------------------------- /cleaner/custom_sql_post/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_custom_sql_post 19 | * @copyright 2019 Catalyst IT 20 | * @author Srdjan Janković 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | namespace cleaner_custom_sql_post; 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | class clean extends \local_datacleaner\clean { 29 | const TASK = 'Custom SQL query in post phase'; 30 | 31 | /** 32 | * Execute custom tasks 33 | */ 34 | static public function execute() { 35 | global $DB; 36 | 37 | $dryrun = (bool)self::$options['dryrun']; 38 | $verbose = (bool)self::$options['verbose']; 39 | 40 | $config = get_config('cleaner_custom_sql_post'); 41 | 42 | if (isset($config->sql)) { 43 | self::execute_sql($config->sql); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /cleaner/custom_sql_post/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_custom_sql_post 20 | * @author Srdjan Janković (srdjan@catalyst.net.nz) 21 | * @copyright 2019 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_custom_sql_post\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_environment_matrix\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /cleaner/custom_sql_post/lang/en/cleaner_custom_sql_post.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_custom_sql_post 21 | * @copyright 2019 Catalyst IT 22 | * @author Srdjan Janković 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | $string['pluginname'] = 'Execute custom database query at post-wash'; 27 | $string['privacy:metadata'] = 'The cleaner custom post-wash database query plugin does not store any personal data.'; 28 | $string['sql'] = 'SQL'; 29 | $string['sqldesc'] = 'SQL to be executed at the end of post-wash.'; 30 | -------------------------------------------------------------------------------- /cleaner/custom_sql_post/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_custom_sql_post 19 | * @copyright 2019 Catalyst IT 20 | * @author Srdjan Janković 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$ADMIN->fulltree) { 27 | return; 28 | } 29 | 30 | $settings->add(new admin_setting_configtextarea('cleaner_custom_sql_post/sql', 31 | new lang_string('sql', 'cleaner_custom_sql_post'), 32 | new lang_string('sqldesc', 'cleaner_custom_sql_post'), '', PARAM_RAW)); 33 | -------------------------------------------------------------------------------- /cleaner/custom_sql_post/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_custom_sql_post 21 | * @copyright 2019 Catalyst IT 22 | * @author Srdjan Janković 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die; 27 | 28 | $plugin->version = 2019072900; 29 | $plugin->release = '2019072900'; 30 | $plugin->maturity = MATURITY_STABLE; 31 | $plugin->requires = 2013111800; // Moodle 2.6 release and upwards. 32 | $plugin->component = 'cleaner_custom_sql_post'; 33 | $plugin->sortorder = 390; 34 | -------------------------------------------------------------------------------- /cleaner/custom_sql_pre/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_custom_sql_pre 19 | * @copyright 2019 Catalyst IT 20 | * @author Srdjan Janković 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | namespace cleaner_custom_sql_pre; 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | class clean extends \local_datacleaner\clean { 29 | const TASK = 'Custom SQL query in pre phase'; 30 | 31 | /** 32 | * Execute custom tasks 33 | */ 34 | static public function execute() { 35 | global $DB; 36 | 37 | $dryrun = (bool)self::$options['dryrun']; 38 | $verbose = (bool)self::$options['verbose']; 39 | 40 | $config = get_config('cleaner_custom_sql_pre'); 41 | 42 | if (isset($config->sql)) { 43 | self::execute_sql($config->sql); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /cleaner/custom_sql_pre/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_custom_sql_pre 20 | * @author Srdjan Janković (srdjan@catalyst.net.nz) 21 | * @copyright 2019 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_custom_sql_pre\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_environment_matrix\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /cleaner/custom_sql_pre/lang/en/cleaner_custom_sql_pre.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_custom_sql_pre 21 | * @copyright 2019 Catalyst IT 22 | * @author Srdjan Janković 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | $string['pluginname'] = 'Execute custom database query at pre-wash'; 27 | $string['privacy:metadata'] = 'The cleaner custom pre-wash database query plugin does not store any personal data.'; 28 | $string['sql'] = 'SQL'; 29 | $string['sqldesc'] = 'SQL to be executed at the end of pre-wash.'; 30 | -------------------------------------------------------------------------------- /cleaner/custom_sql_pre/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_custom_sql_pre 19 | * @copyright 2019 Catalyst IT 20 | * @author Srdjan Janković 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$ADMIN->fulltree) { 27 | return; 28 | } 29 | 30 | $settings->add(new admin_setting_configtextarea('cleaner_custom_sql_pre/sql', 31 | new lang_string('sql', 'cleaner_custom_sql_pre'), 32 | new lang_string('sqldesc', 'cleaner_custom_sql_pre'), '', PARAM_RAW)); 33 | -------------------------------------------------------------------------------- /cleaner/custom_sql_pre/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_custom_sql_pre 21 | * @copyright 2019 Catalyst IT 22 | * @author Srdjan Janković 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die; 27 | 28 | $plugin->version = 2019072900; 29 | $plugin->release = '2019072900'; 30 | $plugin->maturity = MATURITY_STABLE; 31 | $plugin->requires = 2013111800; // Moodle 2.6 release and upwards. 32 | $plugin->component = 'cleaner_custom_sql_pre'; 33 | $plugin->sortorder = 190; 34 | -------------------------------------------------------------------------------- /cleaner/delete_users/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_delete_users 19 | * @copyright 2015 Catalyst IT 20 | * @author Nigel Cunningham 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | namespace cleaner_delete_users; 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | class clean extends \local_datacleaner\clean { 29 | const TASK = 'Removing old users'; 30 | protected $needscascadedelete = true; 31 | 32 | /** 33 | * Do the hard work of cleaning up users. 34 | */ 35 | static public function execute() { 36 | global $DB; 37 | 38 | // Get the settings, handling the case where new ones (dev) haven't been set yet. 39 | $config = get_config('cleaner_delete_users'); 40 | $numusers = self::get_user_count($config); 41 | 42 | if (!$numusers) { 43 | echo "No users to delete.\n"; 44 | return; 45 | } 46 | 47 | // Get on with the real work! 48 | if (self::$options['dryrun']) { 49 | echo 'Would delete ' . $numusers . " users.\n"; 50 | } else { 51 | self::new_task($numusers); 52 | $users = self::get_user_chunk($config); 53 | while (!empty($users)) { 54 | list($sql, $params) = $DB->get_in_or_equal($users); 55 | $DB->delete_records_select('user', 'id ' . $sql, $params); 56 | self::next_step(count($users)); 57 | $users = self::get_user_chunk($config); 58 | } 59 | echo 'Deleted ' . $numusers . " users.\n"; 60 | 61 | // Now clean broken contexts. 62 | echo "Cleaning up context records.\n"; 63 | \context_helper::cleanup_instances(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /cleaner/delete_users/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_delete_users 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_delete_users\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_delete_users\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/delete_users/lang/en/cleaner_delete_users.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_delete_users 21 | * @copyright 2015 Catalyst IT 22 | * @author Nigel Cunningham 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | $string['pluginname'] = 'Delete users'; 27 | $string['privacy:metadata'] = 'The cleaner delete users plugin does not store any personal data.'; 28 | $string['minimumage'] = 'Minimum age'; 29 | $string['minimumagedesc'] = 'Keep users who logged in within the last n days.'; 30 | $string['keepsiteadmins'] = 'Keep site admins'; 31 | $string['keepsiteadminsdesc'] = 'Tick to retain site administrator accounts.'; 32 | $string['keepusernames'] = 'Non site administrator usernames'; 33 | $string['keepusernamesdesc'] = 'A comma separated list of non site administrator usernames that should be retained.'; 34 | -------------------------------------------------------------------------------- /cleaner/delete_users/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_delete_users 19 | * @copyright 2015 Catalyst IT 20 | * @author Nigel Cunningham 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$ADMIN->fulltree) { 27 | return; 28 | } 29 | 30 | $settings->add(new admin_setting_configtext('cleaner_delete_users/minimumage', 31 | new lang_string('minimumage', 'cleaner_delete_users'), 32 | new lang_string('minimumagedesc', 'cleaner_delete_users'), 365, PARAM_INT)); 33 | 34 | $settings->add(new admin_setting_configcheckbox('cleaner_delete_users/keepsiteadmins', 35 | new lang_string('keepsiteadmins', 'cleaner_delete_users'), 36 | new lang_string('keepsiteadminsdesc', 'cleaner_delete_users'), 1)); 37 | 38 | $settings->add(new admin_setting_configtext('cleaner_delete_users/keepusernames', 39 | new lang_string('keepusernames', 'cleaner_delete_users'), 40 | new lang_string('keepusernamesdesc', 'cleaner_delete_users'), '', PARAM_RAW)); 41 | -------------------------------------------------------------------------------- /cleaner/delete_users/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_delete_users 21 | * @copyright 2015 Catalyst IT 22 | * @author Nigel Cunningham 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die; 27 | 28 | $plugin->version = 2015072200; 29 | $plugin->release = '2.3.2'; 30 | $plugin->maturity = MATURITY_STABLE; 31 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 32 | $plugin->component = 'cleaner_delete_users'; 33 | $plugin->sortorder = 5; 34 | -------------------------------------------------------------------------------- /cleaner/email/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_email 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_email\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_email\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/email/lang/en/cleaner_email.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings. 19 | * 20 | * @package cleaner_email 21 | * @author Nicholas Hoobin 22 | * @copyright 2017 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | 27 | $string['divertallemailsexcept'] = 'Divert all emails except'; 28 | $string['divertallemailsexceptdesc'] = 'Set this value to $CFG->divertallemailsexcept'; 29 | $string['divertallemailsto'] = 'Divert all emails to'; 30 | $string['divertallemailstodesc'] = 'Set this value to $CFG->divertallemailsto'; 31 | $string['emailsuffix'] = 'Suffix append'; 32 | $string['emailsuffixdesc'] = 'Append a suffix to all user addresses'; 33 | $string['emailsuffixignore'] = 'Suffix ignore'; 34 | $string['emailsuffixignoredesc'] = 'Do not append the suffix to these addresses. This is a regular expression, do not include the slashes.'; 35 | $string['noemailever'] = 'No email ever'; 36 | $string['noemaileverdesc'] = 'Enable the setting $CFG->noemailever'; 37 | $string['pluginname'] = 'Cleanup email'; 38 | $string['privacy:metadata'] = 'The cleaner email plugin does not store any personal data.'; -------------------------------------------------------------------------------- /cleaner/email/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Settings for the Email cleaner. 19 | * 20 | * @package cleaner_email 21 | * @author Nicholas Hoobin 22 | * @copyright 2017 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | 27 | if (!defined('MOODLE_INTERNAL')) { 28 | die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. 29 | } 30 | 31 | if (!$hassiteconfig) { // Needs this condition or there is error on login page. 32 | return; 33 | } 34 | 35 | $settings->add(new admin_setting_configcheckbox('cleaner_email/noemailever', 36 | new lang_string('noemailever', 'cleaner_email'), 37 | new lang_string('noemaileverdesc', 'cleaner_email'), 0)); 38 | 39 | $settings->add(new admin_setting_configtext('cleaner_email/divertallemailsto', 40 | new lang_string('divertallemailsto', 'cleaner_email'), 41 | new lang_string('divertallemailstodesc', 'cleaner_email'), '')); 42 | 43 | $settings->add(new admin_setting_configtext('cleaner_email/divertallemailsexcept', 44 | new lang_string('divertallemailsexcept', 'cleaner_email'), 45 | new lang_string('divertallemailsexceptdesc', 'cleaner_email'), '')); 46 | 47 | $settings->add(new admin_setting_configtext('cleaner_email/emailsuffix', 48 | new lang_string('emailsuffix', 'cleaner_email'), 49 | new lang_string('emailsuffixdesc', 'cleaner_email'), '.invalid')); 50 | 51 | $settings->add(new admin_setting_configtext('cleaner_email/emailsuffixignore', 52 | new lang_string('emailsuffixignore', 'cleaner_email'), 53 | new lang_string('emailsuffixignoredesc', 'cleaner_email'), '')); -------------------------------------------------------------------------------- /cleaner/email/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_email 21 | * @author Nicholas Hoobin 22 | * @copyright 2017 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | 27 | if (!defined('MOODLE_INTERNAL')) { 28 | die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. 29 | } 30 | 31 | $plugin->version = 2017030600; 32 | $plugin->release = 2017030600; 33 | $plugin->maturity = MATURITY_STABLE; 34 | $plugin->requires = 2013111800; // Moodle 2.6 release and upwards. 35 | $plugin->component = 'cleaner_email'; 36 | $plugin->sortorder = 190; -------------------------------------------------------------------------------- /cleaner/environment_matrix/README.md: -------------------------------------------------------------------------------- 1 | # Environment Matrix Cleaner 2 | 3 | Use 4 | --- 5 | This subplugin will swap configurations in the admin settings, depending on the environment that the wash is being run on. Configure the environments in production, and the configs that need to be swapped, and during refresh, the data will be swapped in. 6 | 7 | The plugin uses set_config to update the database with the new configuration, then it constructs an admin_settings tree, to get the updated value back out in a format that the admin_setting can use. After this, it passes that value back in, using write_setting, to perform any addition checks, validation, or custom functionality that controls, including custom controls, that may be required. 8 | 9 | Testing 10 | ------- 11 | 12 | | Config | Type | Action | Status | 13 | |---------------------------------------|---------------------------|----------------------------------------------------------|---------| 14 | |core:profileroles | config_multicheckbox | Requires array for write_setting, defaults to set_config | WORKING | 15 | |core:lockoutwindow | config_duration | Requires array for write_setting, defaults to set_config | WORKING | 16 | |core:passwordpolicy | config_checkbox | Set using write_setting | WORKING | 17 | |core:maxbytes | config_select | Requires array for write_setting, defaults to set_config | WORKING | 18 | |core:userquota | config_text | Set using write_setting | WORKING | 19 | |tool_securityquestions:questionfile | config_text | Set using write_setting | WORKING | 20 | |tool_securityquestions:questionduration| config_duration | Requires array for write_setting, defaults to set_config | WORKING | 21 | |auth_saml2:idpmetadata | custom_config_idpmetadata | Set using write_setting, correctly updates IDP list | WORKING | 22 | |auth_saml2:idpname | config_text | Set using write_setting | WORKING | 23 | |auth_saml2:showidplink | config_select | Requires array for write_setting, defaults to set_config | WORKING | 24 | 25 | -------------------------------------------------------------------------------- /cleaner/environment_matrix/amd/build/matrix.min.js: -------------------------------------------------------------------------------- 1 | define ("cleaner_environment_matrix/matrix",["jquery"],function(a){return{init:function init(){a("input[type=text], textarea").each(function(){var b=a(this);b.keypress(function(){var b=a(this).closest(".fgroup, .row").find("input[type=\"checkbox\"]");b.prop("checked",1)})})}}}); 2 | //# sourceMappingURL=matrix.min.js.map 3 | -------------------------------------------------------------------------------- /cleaner/environment_matrix/amd/src/matrix.js: -------------------------------------------------------------------------------- 1 | define(['jquery'], function($) { 2 | return { 3 | init: function() { 4 | $("input[type=text], textarea").each(function() { 5 | var input = $(this); 6 | input.keypress(function() { 7 | var cb = $(this).closest('.fgroup, .row').find('input[type="checkbox"]'); 8 | cb.prop('checked', 1); 9 | }); 10 | }); 11 | } 12 | }; 13 | }); 14 | -------------------------------------------------------------------------------- /cleaner/environment_matrix/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_environment_matrix 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_environment_matrix\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_environment_matrix\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/environment_matrix/cli/matrix_replace.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Settings for Environment matrix. 19 | * 20 | * @package cleaner_environment_matrix 21 | * @author Nicholas Hoobin 22 | * @copyright 2017 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | define('CLI_SCRIPT', true); 27 | require_once(__DIR__ . '/../../../../../config.php'); 28 | require_once($CFG->libdir.'/clilib.php'); 29 | 30 | // Now get cli options. 31 | list($options, $unrecognized) = cli_get_params( 32 | array( 33 | 'help' => false, 34 | 'run' => false, 35 | 'verbose' => false, 36 | 'reset' => false, 37 | ), 38 | array('h' => 'help') 39 | ); 40 | 41 | if ($unrecognized) { 42 | $unrecognized = implode("\n ", $unrecognized); 43 | cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); 44 | } 45 | 46 | $help = "Standalone Environment matrix cleaner. 47 | 48 | Options: 49 | -h, --help Print out this help 50 | --run Actually run the clean process 51 | --verbose Be noisy about what is being done or would be done 52 | --reset This will clear the configured items for other environments. 53 | 54 | Example: 55 | \$sudo -u www-data /usr/bin/php local/datacleaner/cleanerenvironment_matrix/cli/matrix_replace.php --run 56 | "; 57 | 58 | if (!$options['run']) { 59 | echo $help; 60 | die; 61 | } 62 | 63 | if ($options['help']) { 64 | echo $help; 65 | die; 66 | } 67 | 68 | $options['dryrun'] = 0; 69 | 70 | $cleaner = new cleaner_environment_matrix\clean(); 71 | 72 | // Cheat a little. 73 | $reflection = new \ReflectionProperty(get_class($cleaner), 'options'); 74 | $reflection->setAccessible(true); 75 | $reflection->setValue($cleaner, $options); 76 | 77 | $cleaner::execute(); 78 | -------------------------------------------------------------------------------- /cleaner/environment_matrix/db/install.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | -------------------------------------------------------------------------------- /cleaner/environment_matrix/db/upgrade.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Upgrade script for clener_environment_matrix 19 | * 20 | * @package cleaner_environment_matrix 21 | * @author Nicholas Hoobin 22 | * @copyright 2017 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | 27 | if (!defined('MOODLE_INTERNAL')) { 28 | die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. 29 | } 30 | 31 | /** 32 | * @param int $oldversion the version we are upgrading from 33 | * @return bool result 34 | */ 35 | function xmldb_cleaner_environment_matrix_upgrade($oldversion) { 36 | global $DB; 37 | 38 | $dbman = $DB->get_manager(); 39 | 40 | if ($oldversion < 2017053000) { 41 | 42 | // Define field textarea to be added to cleaner_environment_matrixd. 43 | $table = new xmldb_table('cleaner_environment_matrixd'); 44 | $field = new xmldb_field('textarea', XMLDB_TYPE_INTEGER, '10', null, null, null, '0', 'value'); 45 | 46 | // Conditionally launch add field textarea. 47 | if (!$dbman->field_exists($table, $field)) { 48 | $dbman->add_field($table, $field); 49 | } 50 | 51 | // Environment_matrix savepoint reached. 52 | upgrade_plugin_savepoint(true, 2017053000, 'cleaner', 'environment_matrix'); 53 | } 54 | 55 | return true; 56 | } 57 | -------------------------------------------------------------------------------- /cleaner/environment_matrix/lang/en/cleaner_environment_matrix.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language en for 'cleaner_environment_matrix' 19 | * 20 | * @package cleaner_environment_matrix 21 | * @author Nicholas Hoobin 22 | * @copyright 2017 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | 27 | $string['button_search'] = 'Search'; 28 | $string['existing_configuration'] = 'Existing configuration'; 29 | $string['missingenvbar'] = 'Environment bar missing'; 30 | $string['pluginname'] = 'Environment matrix'; 31 | $string['privacy:metadata'] = 'The cleaner environment matrix plugin does not store any personal data.'; 32 | $string['search_placeholder'] = 'Search for a named configuration item.'; 33 | $string['search_results'] = 'Search results'; 34 | -------------------------------------------------------------------------------- /cleaner/environment_matrix/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Settings for Environment matrix. 19 | * 20 | * @package cleaner_environment_matrix 21 | * @author Nicholas Hoobin 22 | * @copyright 2017 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | 27 | if (!defined('MOODLE_INTERNAL')) { 28 | die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. 29 | } 30 | 31 | $settings = null; 32 | 33 | if (!$hassiteconfig) { // Needs this condition or there is error on login page. 34 | return; 35 | } 36 | 37 | $externalpage = new admin_externalpage('cleaner_environment_matrix', 38 | get_string('pluginname', 'cleaner_environment_matrix'), 39 | new moodle_url('/local/datacleaner/cleaner/environment_matrix/index.php')); 40 | 41 | $ADMIN->add('datacleaner', $externalpage); 42 | -------------------------------------------------------------------------------- /cleaner/environment_matrix/styles.css: -------------------------------------------------------------------------------- 1 | .cleaner_environment_matrix .mform .cb_header:nth-of-type(1) { 2 | margin-left: 26px; 3 | } 4 | 5 | .cleaner_environment_matrix .mform .fitem .felement { 6 | white-space: nowrap; 7 | flex-wrap: nowrap; 8 | } 9 | 10 | .cleaner_environment_matrix .mform .fitem .felement input { 11 | width: initial; 12 | } 13 | 14 | .cleaner_environment_matrix .mform .fitem .felement textarea { 15 | width: initial; 16 | resize: both; 17 | } 18 | 19 | .cleaner_environment_matrix .hiddencb { 20 | visibility: hidden; 21 | } 22 | -------------------------------------------------------------------------------- /cleaner/environment_matrix/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_environment_matrix 21 | * @author Nicholas Hoobin 22 | * @copyright 2017 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | 27 | if (!defined('MOODLE_INTERNAL')) { 28 | die('Direct access to this script is forbidden.'); // It must be included from a Moodle page. 29 | } 30 | 31 | $plugin->version = 2019102400; 32 | $plugin->release = 2019102400; 33 | $plugin->maturity = MATURITY_STABLE; 34 | $plugin->requires = 2013111800; // Moodle 2.6 release and upwards. 35 | $plugin->component = 'cleaner_environment_matrix'; 36 | $plugin->sortorder = 200; 37 | -------------------------------------------------------------------------------- /cleaner/grades/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_delete_users 19 | * @copyright 2015 Catalyst IT 20 | * @author Nigel Cunningham 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | namespace cleaner_grades; 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | class clean extends \local_datacleaner\clean { 29 | const TASK = 'Removing grades'; 30 | 31 | /** 32 | * Do the hard work of cleaning up users. 33 | */ 34 | static public function execute() { 35 | 36 | global $DB; 37 | 38 | // Get the settings, handling the case where new ones (dev) haven't been set yet. 39 | $config = get_config('cleaner_grades'); 40 | 41 | if ($config->deleteall) { 42 | if (self::$options['dryrun']) { 43 | echo "Would truncate the grade_grades and grade_grades_history tables.\n"; 44 | } else { 45 | self::new_task(2); 46 | $DB->delete_records('grade_grades'); 47 | self::next_step(); 48 | $DB->delete_records('grade_grades_history'); 49 | self::next_step(); 50 | } 51 | } else { 52 | if (self::$options['dryrun']) { 53 | $count = $DB->count_records_select('grade_grades', 'rawgrademax > 0'); 54 | $count += $DB->count_records_select('grade_grades', 'rawgrademax = 0'); 55 | $count += $DB->count_records_select('grade_grades_history', 'rawgrademax > 0'); 56 | $count += $DB->count_records_select('grade_grades_history', 'rawgrademax = 0'); 57 | echo "Would update 2 fields on {$count} records in the grade_grades and grade_grades_history tables.\n"; 58 | } else { 59 | self::new_task(8); 60 | $DB->execute('UPDATE {grade_grades} SET rawgrade = (id % rawgrademax) WHERE rawgrademax > 0'); 61 | self::next_step(); 62 | $DB->execute('UPDATE {grade_grades} SET rawgrade = 0 WHERE rawgrademax = 0'); 63 | self::next_step(); 64 | $DB->execute('UPDATE {grade_grades} SET finalgrade = (id % rawgrademax) WHERE rawgrademax > 0'); 65 | self::next_step(); 66 | $DB->execute('UPDATE {grade_grades} SET finalgrade = 0 WHERE rawgrademax = 0'); 67 | self::next_step(); 68 | $DB->execute('UPDATE {grade_grades_history} SET rawgrade = (id % rawgrademax) WHERE rawgrademax > 0'); 69 | self::next_step(); 70 | $DB->execute('UPDATE {grade_grades_history} SET rawgrade = 0 WHERE rawgrademax = 0'); 71 | self::next_step(); 72 | $DB->execute('UPDATE {grade_grades_history} SET finalgrade = (id % rawgrademax) WHERE rawgrademax > 0'); 73 | self::next_step(); 74 | $DB->execute('UPDATE {grade_grades_history} SET finalgrade = 0 WHERE rawgrademax = 0'); 75 | self::next_step(); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /cleaner/grades/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_grades 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_grades\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_grades\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/grades/lang/en/cleaner_grades.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_grades 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['pluginname'] = 'Clean grades'; 26 | $string['privacy:metadata'] = 'The cleaner grades plugin does not store any personal data.'; 27 | $string['deleteall'] = 'Delete all'; 28 | $string['deletealldesc'] = 'Delete all grade history. The alternative is to replace the values with fake data based on the user\'s ID number.'; 29 | -------------------------------------------------------------------------------- /cleaner/grades/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_delete_users 19 | * @copyright 2015 Catalyst IT 20 | * @author Nigel Cunningham 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$ADMIN->fulltree) { 27 | return; 28 | } 29 | 30 | $settings->add(new admin_setting_configcheckbox('cleaner_grades/deleteall', 31 | new lang_string('deleteall', 'cleaner_grades'), 32 | new lang_string('deletealldesc', 'cleaner_grades'), 1)); 33 | -------------------------------------------------------------------------------- /cleaner/grades/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_grades 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | $plugin->version = 2015072200; 28 | $plugin->release = '2.3.2'; 29 | $plugin->maturity = MATURITY_STABLE; 30 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 31 | $plugin->component = 'cleaner_grades'; 32 | $plugin->sortorder = 90; 33 | -------------------------------------------------------------------------------- /cleaner/logstore_standard/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_logstore_standard 19 | * @copyright 2015 Brendan Heywood 20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 | */ 22 | 23 | namespace cleaner_logstore_standard; 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | class clean extends \local_datacleaner\clean { 28 | const TASK = 'Truncating standard logs'; 29 | 30 | static public function execute() { 31 | 32 | global $DB; 33 | 34 | if (self::$options['dryrun']) { 35 | echo "Would truncate the logstore_standard_log table.\n"; 36 | } else { 37 | self::new_task(1); 38 | $DB->delete_records('logstore_standard_log'); 39 | self::next_step(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /cleaner/logstore_standard/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_logstore_standard 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_logstore_standard\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_logstore_standard\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/logstore_standard/lang/en/cleaner_logstore_standard.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_logstore_standard 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['pluginname'] = 'Delete standard logs'; 26 | $string['privacy:metadata'] = 'The cleaner logstore standard plugin does not store any personal data.'; 27 | $string['truncate'] = 'Truncate all standard database logs'; 28 | -------------------------------------------------------------------------------- /cleaner/logstore_standard/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_logstore_standard 19 | * @copyright 2015 Brendan Heywood 20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 | */ 22 | 23 | defined('MOODLE_INTERNAL') || die; 24 | 25 | $plugin->version = 2015072200; 26 | $plugin->release = '2.3.2'; 27 | $plugin->maturity = MATURITY_STABLE; 28 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 29 | $plugin->component = 'cleaner_logstore_standard'; 30 | $plugin->sortorder = 3; 31 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/classes/cache_cleaner.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * cache_cleaner class. 19 | * 20 | * @package cleaner_orphaned_sitedata 21 | * @author Ghada El-Zoghbi 22 | * @author Daniel Thee Roperto 23 | * @copyright 2016 Catalyst IT Australia {@link http://www.catalyst-au.net} 24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 | */ 26 | namespace cleaner_orphaned_sitedata; 27 | 28 | use cache_helper; 29 | 30 | defined('MOODLE_INTERNAL') || die(); 31 | 32 | /** 33 | * cache_cleaner class. 34 | * 35 | * @package cleaner_orphaned_sitedata 36 | * @author Ghada El-Zoghbi 37 | * @author Daniel Thee Roperto 38 | * @copyright 2016 Catalyst IT Australia {@link http://www.catalyst-au.net} 39 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 | */ 41 | class cache_cleaner { 42 | private $dryrun; 43 | 44 | public function __construct($dryrun) { 45 | $this->dryrun = $dryrun; 46 | } 47 | 48 | public function execute() { 49 | clean::println( 50 | get_string($this->dryrun ? 'wouldpurgecache' : 'willpurgecache', 'cleaner_orphaned_sitedata') 51 | ); 52 | 53 | if (!$this->dryrun) { 54 | cache_helper::purge_all(true); 55 | purge_all_caches(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_orphaned_sitedata 19 | * @author Ghada El-Zoghbi 20 | * @copyright 2015 Catalyst IT 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | namespace cleaner_orphaned_sitedata; 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | require_once($CFG->libdir.'/moodlelib.php'); 29 | 30 | class clean extends \local_datacleaner\clean { 31 | const TASK = 'Delete orphaned sitedata files'; 32 | 33 | static public function execute() { 34 | $config = get_config('cleaner_orphaned_sitedata'); 35 | $dryrun = (bool)self::$options['dryrun']; 36 | 37 | $cleaners = [ 38 | 'deletebackups' => backup_cleaner::class, 39 | 'deletecachedfiles' => cache_cleaner::class, 40 | 'deletetmpfiles' => tempfiles_cleaner::class, 41 | 'deleteorphanedfiles' => orphan_cleaner::class, 42 | ]; 43 | 44 | self::debugmemory(); 45 | foreach ($cleaners as $option => $cleaner) { 46 | if (!isset($config->$option) || !$config->$option) { 47 | continue; 48 | } 49 | self::debug($cleaner.' starting...'); 50 | (new $cleaner($dryrun))->execute(); 51 | self::debug($cleaner.' finished!'); 52 | self::debugmemory(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_orphaned_sitedata 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_orphaned_sitedata\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_orphaned_sitedata\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/classes/tempfiles_cleaner.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * tempfiles_cleaner class. 19 | * 20 | * @package cleaner_orphaned_sitedata 21 | * @author Ghada El-Zoghbi 22 | * @author Daniel Thee Roperto 23 | * @copyright 2016 Catalyst IT Australia {@link http://www.catalyst-au.net} 24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 | */ 26 | namespace cleaner_orphaned_sitedata; 27 | 28 | defined('MOODLE_INTERNAL') || die(); 29 | 30 | /** 31 | * tempfiles_cleaner class. 32 | * 33 | * @package cleaner_orphaned_sitedata 34 | * @author Ghada El-Zoghbi 35 | * @author Daniel Thee Roperto 36 | * @copyright 2016 Catalyst IT Australia {@link http://www.catalyst-au.net} 37 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 | */ 39 | class tempfiles_cleaner { 40 | private $dryrun; 41 | 42 | public function __construct($dryrun) { 43 | $this->dryrun = $dryrun; 44 | } 45 | 46 | public function execute() { 47 | global $CFG; 48 | $tempdirectory = $CFG->tempdir; 49 | 50 | clean::println( 51 | get_string( 52 | $this->dryrun ? 'woulddeletetemp' : 'willdeletetemp', 53 | 'cleaner_orphaned_sitedata', 54 | $tempdirectory 55 | ) 56 | ); 57 | 58 | if (!$this->dryrun) { 59 | if (!remove_dir($tempdirectory, true)) { 60 | clean::println(get_string('errordeletingdir', 'local_datacleaner', $tempdirectory)); 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/lang/en/cleaner_orphaned_sitedata.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_orphaned_sitedata 21 | * @author Ghada El-Zoghbi 22 | * @copyright 2015 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | $string['pluginname'] = 'Cleanup orphaned sitedata'; 27 | $string['privacy:metadata'] = 'The cleaner orphaned sitedata plugin does not store any personal data.'; 28 | 29 | // Settings page. 30 | $string['deletebackups'] = 'Delete backups'; 31 | $string['deletebackupsdesc'] = 'Delete all backups (orphaned or not) from site data and the files table.'; 32 | 33 | $string['deleteorphanedfiles'] = 'Delete orphaned files'; 34 | $string['deleteorphanedfilesdesc'] = 'Delete all orphaned files in site data that are no longer referenced in the database.'; 35 | 36 | $string['deletetmpfiles'] = 'Delete temporary files'; 37 | $string['deletetmpfilesdesc'] = 'Delete all temporary files.'; 38 | 39 | $string['deletecachedfiles'] = 'Delete cached files'; 40 | $string['deletecachedfilesdesc'] = 'Delete all cached files.'; 41 | 42 | $string['woulddeletebackups'] = 'Would delete {$a} backup file(s).'; 43 | $string['willdeletebackups'] = 'Will delete {$a} backup file(s).'; 44 | 45 | $string['wouldpurgecache'] = 'Would purge the cache.'; 46 | $string['willpurgecache'] = 'Will purge the cache.'; 47 | 48 | $string['woulddeletetemp'] = 'Would delete temporary files from: {$a}'; 49 | $string['willdeletetemp'] = 'Will delete temporary files: {$a}'; 50 | 51 | $string['woulddeleteorphanedfiles'] = 'Would delete orphaned file(s).'; 52 | $string['willdeleteorphanedfiles'] = 'Will delete orphaned file(s).'; 53 | 54 | $string['errordeletingfile'] = "ERROR\n\n*** Cound not delete: {\$a}\n\n"; 55 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_orphaned_sitedata 19 | * @copyright 2015 Catalyst IT 20 | * @author Ghada El-Zoghbi 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$ADMIN->fulltree) { 27 | return; 28 | } 29 | 30 | $settings->add(new admin_setting_configcheckbox('cleaner_orphaned_sitedata/deletebackups', 31 | new lang_string('deletebackups', 'cleaner_orphaned_sitedata'), 32 | new lang_string('deletebackupsdesc', 'cleaner_orphaned_sitedata'), 0)); 33 | 34 | $settings->add(new admin_setting_configcheckbox('cleaner_orphaned_sitedata/deletecachedfiles', 35 | new lang_string('deletecachedfiles', 'cleaner_orphaned_sitedata'), 36 | new lang_string('deletecachedfilesdesc', 'cleaner_orphaned_sitedata'), 1)); 37 | 38 | $settings->add(new admin_setting_configcheckbox('cleaner_orphaned_sitedata/deletetmpfiles', 39 | new lang_string('deletetmpfiles', 'cleaner_orphaned_sitedata'), 40 | new lang_string('deletetmpfilesdesc', 'cleaner_orphaned_sitedata'), 1)); 41 | 42 | $settings->add(new admin_setting_configcheckbox('cleaner_orphaned_sitedata/deleteorphanedfiles', 43 | new lang_string('deleteorphanedfiles', 'cleaner_orphaned_sitedata'), 44 | new lang_string('deleteorphanedfilesdesc', 'cleaner_orphaned_sitedata'), 0)); 45 | 46 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/tests/unit/backup_cleaner_test.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * backup_cleaner test class. 19 | * 20 | * @package backup_cleaner_test 21 | * @author Daniel Thee Roperto 22 | * @copyright 2016 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | namespace cleaner_orphaned_sitedata\tests\unit; 27 | 28 | use cleaner_orphaned_sitedata\backup_cleaner; 29 | 30 | defined('MOODLE_INTERNAL') || die(); 31 | 32 | global $CFG; 33 | require_once($CFG->libdir.'/adminlib.php'); 34 | require_once(__DIR__.'/orphaned_sitedata_testcase.php'); 35 | 36 | /** 37 | * backup_cleaner test class. 38 | * 39 | * @package backup_cleaner_test 40 | * @author Daniel Thee Roperto 41 | * @copyright 2016 Catalyst IT 42 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 43 | * @SuppressWarnings(public) Allow as many methods as needed. 44 | */ 45 | class backup_cleaner_test extends orphaned_sitedata_testcase { 46 | private $initialfiles; 47 | 48 | public function setUp() : void { 49 | parent::setUp(); 50 | $this->initialfiles = $this->get_files(); 51 | } 52 | 53 | public function tearDown() : void { 54 | $this->initialfiles = null; 55 | parent::tearDown(); 56 | } 57 | 58 | public function test_it_exists() { 59 | $cleaner = new backup_cleaner(true); 60 | self::assertNotNull($cleaner); 61 | } 62 | 63 | public function test_it_does_nothing_if_no_backup_files_exist() { 64 | $this->execute(new backup_cleaner(true)); 65 | self::assertSame($this->initialfiles, $this->get_files()); 66 | } 67 | 68 | public function test_it_removes_backup_files() { 69 | $this->resetAfterTest(true); 70 | $file = $this->create_backup_file('test_it_removes_backup_files.backup'); 71 | self::assertTrue($this->file_is_readable($file)); 72 | $this->execute(new backup_cleaner(false)); 73 | self::assertFalse($this->file_is_readable($file)); 74 | } 75 | 76 | public function test_it_does_not_remove_backup_files_in_dry_run() { 77 | $this->resetAfterTest(true); 78 | $file = $this->create_backup_file('test_it_does_not_remove_backup_files_in_dry_run.backup'); 79 | self::assertTrue($this->file_is_readable($file)); 80 | $this->execute(new backup_cleaner(true)); 81 | self::assertTrue($this->file_is_readable($file)); 82 | } 83 | 84 | public function create_backup_file($filename) { 85 | $file = $this->create_file('backup', '/somebackups/', $filename); 86 | return $file; 87 | } 88 | 89 | private function get_files() { 90 | global $DB; 91 | $found = $DB->get_records_select('files', "filename <> '.'", null, 'id ASC'); 92 | array_walk($found, function(&$value) { 93 | $value = $value->filename; 94 | }); 95 | return $found; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/tests/unit/cache_cleaner_test.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * cache_cleaner test class. 19 | * 20 | * @package cache_cleaner_test 21 | * @author Daniel Thee Roperto 22 | * @copyright 2016 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | namespace cleaner_orphaned_sitedata\tests\unit; 27 | 28 | use cleaner_orphaned_sitedata\cache_cleaner; 29 | 30 | defined('MOODLE_INTERNAL') || die(); 31 | 32 | global $CFG; 33 | require_once($CFG->libdir.'/adminlib.php'); 34 | require_once(__DIR__.'/orphaned_sitedata_testcase.php'); 35 | 36 | /** 37 | * cache_cleaner test class. 38 | * 39 | * @package cache_cleaner_test 40 | * @author Daniel Thee Roperto 41 | * @copyright 2016 Catalyst IT 42 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 43 | * @SuppressWarnings(public) Allow as many methods as needed. 44 | */ 45 | class cache_cleaner_test extends orphaned_sitedata_testcase { 46 | public function test_it_exists() { 47 | self::assertNotNull(new cache_cleaner(true)); 48 | } 49 | 50 | public function test_it_runs() { 51 | self::resetAfterTest(true); 52 | // It is only testing if the call is not exploding. 53 | // It is a fairly complex to test caches and we are only making Moodle API calls. 54 | $this->execute(new cache_cleaner(false)); 55 | } 56 | 57 | public function test_it_runs_in_dry_mode() { 58 | // By not calling self::resetAfterTest() we ensure this test cannot modify DB or $CFG. 59 | // If caches are cleaned, it will fail because it changes DB and $CFG. 60 | $this->execute(new cache_cleaner(true)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/tests/unit/orphan_cleaner_test.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * orphan_cleaner test class. 19 | * 20 | * @package orphan_cleaner_test 21 | * @author Daniel Thee Roperto 22 | * @copyright 2016 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | namespace cleaner_orphaned_sitedata\tests\unit; 27 | 28 | use cleaner_orphaned_sitedata\orphan_cleaner; 29 | 30 | defined('MOODLE_INTERNAL') || die(); 31 | 32 | global $CFG; 33 | require_once($CFG->libdir.'/adminlib.php'); 34 | require_once(__DIR__.'/orphaned_sitedata_testcase.php'); 35 | 36 | /** 37 | * orphan_cleaner test class. 38 | * 39 | * @package orphan_cleaner_test 40 | * @author Daniel Thee Roperto 41 | * @copyright 2016 Catalyst IT 42 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 43 | * @SuppressWarnings(public) Allow as many methods as needed. 44 | */ 45 | class orphan_cleaner_test extends orphaned_sitedata_testcase { 46 | public function test_it_exists() { 47 | self::assertNotNull(new orphan_cleaner(true)); 48 | } 49 | 50 | public function test_it_removes_orphaned_files() { 51 | global $DB; 52 | $this->resetAfterTest(true); 53 | 54 | $file = $this->create_test_file('test_it_removes_orphaned_files.test'); 55 | self::assertTrue($this->file_is_readable($file)); 56 | 57 | $DB->delete_records('files', ['id' => $file->get_id()]); // Make it orphaned. 58 | 59 | $this->execute(new orphan_cleaner(false)); 60 | 61 | self::assertFalse($this->file_is_readable($file)); 62 | } 63 | 64 | public function test_it_does_not_remove_orphaned_files_in_dry_run() { 65 | global $DB; 66 | $this->resetAfterTest(true); 67 | 68 | $file = $this->create_test_file('test_it_does_not_remove_orphaned_files_in_dry_run.test'); 69 | self::assertTrue($this->file_is_readable($file)); 70 | 71 | $DB->delete_records('files', ['id' => $file->get_id()]); // Make it orphaned. 72 | 73 | $this->execute(new orphan_cleaner(true)); 74 | 75 | self::assertTrue($this->file_is_readable($file)); 76 | } 77 | 78 | public function test_it_does_not_remove_non_orphaned_files() { 79 | $this->resetAfterTest(true); 80 | 81 | $file = $this->create_test_file('test_it_does_not_remove_non_orphaned_files.test'); 82 | self::assertTrue($this->file_is_readable($file)); 83 | 84 | $this->execute(new orphan_cleaner(false)); 85 | 86 | self::assertTrue($this->file_is_readable($file)); 87 | } 88 | 89 | private function create_test_file($filename) { 90 | return $this->create_file('course', '/orphanfiles/', $filename); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/tests/unit/orphaned_sitedata_testcase.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * orphaned_sitedata testcase. 19 | * 20 | * @package cache_cleaner_test 21 | * @author Daniel Thee Roperto 22 | * @copyright 2016 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | namespace cleaner_orphaned_sitedata\tests\unit; 27 | 28 | use advanced_testcase; 29 | use context_course; 30 | use ReflectionMethod; 31 | use stored_file; 32 | 33 | defined('MOODLE_INTERNAL') || die(); 34 | 35 | global $CFG; 36 | require_once($CFG->libdir.'/adminlib.php'); 37 | 38 | /** 39 | * orphaned_sitedata testcase. 40 | * 41 | * @package cache_cleaner_test 42 | * @author Daniel Thee Roperto 43 | * @copyright 2016 Catalyst IT 44 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 45 | * @SuppressWarnings(public) Allow as many methods as needed. 46 | */ 47 | class orphaned_sitedata_testcase extends advanced_testcase { 48 | protected function execute($cleaner) { 49 | ob_start(); 50 | $cleaner->execute(); 51 | $output = ob_get_contents(); 52 | ob_end_clean(); 53 | return $output; 54 | } 55 | 56 | protected function create_file($component, $filepath, $filename) { 57 | $syscontext = context_course::instance(1); 58 | $filerecord = [ 59 | 'contextid' => $syscontext->id, 60 | 'component' => $component, 61 | 'filearea' => 'unittest', 62 | 'itemid' => 0, 63 | 'filepath' => $filepath, 64 | 'filename' => $filename, 65 | ]; 66 | $fs = get_file_storage(); 67 | return $fs->create_file_from_string($filerecord, 'backup data'); 68 | } 69 | 70 | protected function file_is_readable(stored_file $file) { 71 | if (class_exists('file_system')) { 72 | $filestorage = get_file_storage(); 73 | $filesystem = $filestorage->get_file_system(); 74 | $contenthash = $file->get_contenthash(); // Bypass trash recovery. 75 | return $filesystem->is_file_readable_locally_by_hash($contenthash); 76 | } else { 77 | // Let's be a little naughty and hack access the protected method in stored_file. 78 | $reflection = new ReflectionMethod(stored_file::class, 'get_pathname_by_contenthash'); 79 | $reflection->setAccessible(true); 80 | $path = $reflection->invoke($file); 81 | $isreadable = is_readable($path); 82 | } 83 | return $isreadable; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/tests/unit/tempfiles_cleaner_test.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * cache_cleaner test class. 19 | * 20 | * @package cache_cleaner_test 21 | * @author Daniel Thee Roperto 22 | * @copyright 2016 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | namespace cleaner_orphaned_sitedata\tests\unit; 27 | 28 | use cleaner_orphaned_sitedata\orphan_cleaner; 29 | use cleaner_orphaned_sitedata\tempfiles_cleaner; 30 | use FilesystemIterator; 31 | 32 | defined('MOODLE_INTERNAL') || die(); 33 | 34 | global $CFG; 35 | require_once($CFG->libdir.'/adminlib.php'); 36 | require_once(__DIR__.'/orphaned_sitedata_testcase.php'); 37 | 38 | /** 39 | * cache_cleaner test class. 40 | * 41 | * @package cache_cleaner_test 42 | * @author Daniel Thee Roperto 43 | * @copyright 2016 Catalyst IT 44 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 45 | * @SuppressWarnings(public) Allow as many methods as needed. 46 | */ 47 | class tempfiles_cleaner_test extends orphaned_sitedata_testcase { 48 | public function test_it_exists() { 49 | self::assertNotNull(new tempfiles_cleaner(true)); 50 | } 51 | 52 | public function test_it_removes_tempfiles() { 53 | global $CFG; 54 | $file = $CFG->tempdir.'/test_it_removes_tempfiles.test'; 55 | touch($file); 56 | self::assertFileExists($file); 57 | $this->execute(new tempfiles_cleaner(false)); 58 | if (method_exists($this, 'assertFileDoesNotExist')) { 59 | self::assertFileDoesNotExist($file); 60 | } else { 61 | self::assertFileNotExists($file); 62 | } 63 | } 64 | 65 | public function test_it_removes_all_files_and_subdirs() { 66 | global $CFG; 67 | $tmpdir = $CFG->tempdir.'/test/it/removes/subdirs'; 68 | $file = $tmpdir.'/test_it_removes_all_files_and_subdirs.test'; 69 | mkdir($tmpdir, 0777, true); 70 | touch($file); 71 | self::assertFileExists($file); 72 | $this->execute(new tempfiles_cleaner(false)); 73 | 74 | // Temporary directory should be empty. 75 | $hascontents = (new FilesystemIterator($CFG->tempdir))->valid(); 76 | self::assertFalse($hascontents); 77 | } 78 | 79 | 80 | public function test_it_does_not_remove_tempfiles_in_dry_run() { 81 | global $CFG; 82 | $file = $CFG->tempdir.'/test_it_does_not_remove_tempfiles_in_dry_run.test'; 83 | touch($file); 84 | self::assertFileExists($file); 85 | $this->execute(new tempfiles_cleaner(true)); 86 | self::assertFileExists($file); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /cleaner/orphaned_sitedata/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_orphaned_sitedata 21 | * @author Ghada El-Zoghbi 22 | * @copyright 2015 Catalyst IT 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die; 27 | 28 | $plugin->version = 2016122300; 29 | $plugin->release = '2.3.7'; 30 | $plugin->maturity = MATURITY_STABLE; 31 | $plugin->requires = 2013111800; // Moodle 2.6 release and upwards. 32 | $plugin->component = 'cleaner_orphaned_sitedata'; 33 | // Run this before cleaner_sitedata sub-plugin. 34 | $plugin->sortorder = 180; 35 | -------------------------------------------------------------------------------- /cleaner/replace_urls/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_replace_urls 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_replace_urls\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_replace_urls\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/replace_urls/lang/en/cleaner_replace_urls.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_replace_urls 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['cleanconfig'] = 'Replace in config tables'; 26 | $string['cleanconfigdesc'] = 'This will enable replacing URLs in the config and config_plugins tables.'; 27 | $string['cleanwysiwyg'] = 'Replace in wysiwyg elements'; 28 | $string['cleanwysiwygdesc'] = 'This will enable replacing URLs in all rich text editor fields.'; 29 | $string['cleantext'] = 'Relace in database fields text / varchar'; 30 | $string['cleantextdesc'] = 'This will enable replacing URLs in all database columns of type text and varchar.'; 31 | $string['pluginname'] = 'Replace URLs'; 32 | $string['privacy:metadata'] = 'The cleaner replace urls plugin does not store any personal data.'; 33 | $string['origsiteurl'] = 'Original site URL'; 34 | $string['origsiteurldesc'] = 'The URL of the production site.'; 35 | $string['newsiteurl'] = 'New site URL'; 36 | $string['newsiteurldesc'] = 'The URL of the datacleansed site.'; 37 | $string['skiptables'] = 'Tables to skip'; 38 | $string['skiptablesdesc'] = 'Names of tables to skip, separated by a comma. E.g. user, log, config.'; -------------------------------------------------------------------------------- /cleaner/replace_urls/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_replace_urls 19 | * @copyright 2015 Catalyst IT 20 | * @author Nigel Cunningham 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$ADMIN->fulltree) { 27 | return; 28 | } 29 | 30 | $settings->add(new admin_setting_configtext('cleaner_replace_urls/origsiteurl', 31 | new lang_string('origsiteurl', 'cleaner_replace_urls'), 32 | new lang_string('origsiteurldesc', 'cleaner_replace_urls'), 'http://', PARAM_URL)); 33 | 34 | $settings->add(new admin_setting_configtext('cleaner_replace_urls/newsiteurl', 35 | new lang_string('newsiteurl', 'cleaner_replace_urls'), 36 | new lang_string('newsiteurldesc', 'cleaner_replace_urls'), 'http://localhost', PARAM_URL)); 37 | 38 | $defaultskiptables = "config, config_plugins, config_log, upgrade_log, log, filter_config, sessions, events_queue, " . 39 | "repository_instance_config, block_instances, files, files_reference"; 40 | $settings->add(new admin_setting_configtextarea( 41 | 'cleaner_replace_urls/skiptables', 42 | new lang_string('skiptables', 'cleaner_replace_urls'), 43 | new lang_string('skiptablesdesc', 'cleaner_replace_urls'), $defaultskiptables, PARAM_TEXT, 60, 5)); 44 | 45 | $settings->add(new admin_setting_configcheckbox('cleaner_replace_urls/cleanconfig', 46 | new lang_string('cleanconfig', 'cleaner_replace_urls'), 47 | new lang_string('cleanconfigdesc', 'cleaner_replace_urls'), 0)); 48 | 49 | $settings->add(new admin_setting_configcheckbox('cleaner_replace_urls/cleanwysiwyg', 50 | new lang_string('cleanwysiwyg', 'cleaner_replace_urls'), 51 | new lang_string('cleanwysiwygdesc', 'cleaner_replace_urls'), 0)); 52 | 53 | $settings->add(new admin_setting_configcheckbox('cleaner_replace_urls/cleantext', 54 | new lang_string('cleantext', 'cleaner_replace_urls'), 55 | new lang_string('cleantextdesc', 'cleaner_replace_urls'), 0)); -------------------------------------------------------------------------------- /cleaner/replace_urls/tests/replace_urls_test.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Unit tests for replace_urls 19 | * 20 | * @package local_datacleaner 21 | * @subpackage cleaner_replace_urls 22 | * @author Marcus Boon 23 | */ 24 | 25 | use cleaner_replace_urls\clean; 26 | 27 | defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden'); 28 | 29 | /** 30 | * Tests 31 | */ 32 | class cleaner_replace_urls_test extends advanced_testcase { 33 | 34 | /** @var Course values */ 35 | private $course; 36 | 37 | /** 38 | * Insert some config make sure they are gone 39 | */ 40 | protected function setUp() : void { 41 | parent::setup(); 42 | $this->resetAfterTest(true); 43 | 44 | // Set config for original and new site 45 | set_config('origsiteurl', 'local.origin', 'cleaner_replace_urls'); 46 | set_config('enabled', 1, 'cleaner_replace_urls'); 47 | set_config('cleantext', 1, 'cleaner_replace_urls'); 48 | 49 | // create a course to test 50 | $coursearray = array( 51 | 'fullname' => get_config('cleaner_replace_urls', 'origsiteurl'), 52 | ); 53 | $this->course = $this->getDataGenerator()->create_course($coursearray); 54 | 55 | } 56 | 57 | /** 58 | * Teardown unit tests. 59 | */ 60 | protected function tearDown() : void { 61 | $this->course = null; 62 | parent::tearDown(); 63 | } 64 | 65 | /** 66 | * Regression test for old functions 67 | * @group test_replace_url 68 | */ 69 | public function test_replace_url() { 70 | global $DB; 71 | 72 | $this->resetAfterTest(true); 73 | 74 | // Set the newsiteurl config 75 | set_config('newsiteurl', 'new.origin', 'cleaner_replace_urls'); 76 | 77 | $configcleaner = new clean(); 78 | $configcleaner::execute(); 79 | 80 | $namesafter = $DB->get_record_sql('SELECT fullname FROM {course} WHERE id=:name', ['name' => $this->course->id]); 81 | 82 | $this->assertEquals(get_config('cleaner_replace_urls', 'newsiteurl'), $namesafter->fullname); 83 | 84 | } 85 | 86 | /** 87 | * Test the replace without newsite 88 | * @group without 89 | */ 90 | public function test_replace_url_with_wwwroot() { 91 | global $DB, $CFG; 92 | 93 | $this->resetAfterTest(true); 94 | 95 | // Set the newsiteurl to null 96 | set_config('newsiteurl', '', 'cleaner_replace_urls'); 97 | 98 | $configcleaner = new clean(); 99 | $configcleaner::execute(); 100 | 101 | $namesafter = $DB->get_record_sql('SELECT fullname FROM {course} WHERE id=:name', ['name' => $this->course->id]); 102 | 103 | $this->assertEquals($CFG->wwwroot, $namesafter->fullname); 104 | 105 | } 106 | } -------------------------------------------------------------------------------- /cleaner/replace_urls/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_replace 19 | * @copyright 2015 Brendan Heywood 20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 | */ 22 | 23 | defined('MOODLE_INTERNAL') || die; 24 | 25 | $plugin->version = 2015072200; 26 | $plugin->release = '2.3.2'; 27 | $plugin->maturity = MATURITY_STABLE; 28 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 29 | $plugin->component = 'cleaner_replace_urls'; 30 | $plugin->sortorder = 210; 31 | -------------------------------------------------------------------------------- /cleaner/scheduled_tasks/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_scheduled_tasks 19 | * @copyright 2019 Catalyst IT 20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 | */ 22 | 23 | namespace cleaner_scheduled_tasks; 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | class clean extends \local_datacleaner\clean { 28 | 29 | /** 30 | * Get the settings section url. 31 | * @return \moodle_url the settings section URL 32 | */ 33 | public static function get_settings_section_url($name) { 34 | return new \moodle_url('/local/datacleaner/cleaner/scheduled_tasks/index.php'); 35 | } 36 | 37 | /** 38 | * Disable the scheduled tasks that we don't want. 39 | */ 40 | static public function execute() { 41 | global $DB; 42 | $dryrun = self::$options['dryrun']; 43 | 44 | $disabledtasks = $DB->get_records_sql("SELECT * 45 | FROM {cleaner_scheduled_tasks} cst 46 | JOIN {task_scheduled} ts ON ts.id=cst.taskscheduledid"); 47 | 48 | $count = count($disabledtasks); 49 | $increment = 1; 50 | $taskstoupdate = array(); 51 | 52 | if ($count == 0) { 53 | mtrace("No tasks selected to disable, skipping this task"); 54 | return; 55 | } 56 | 57 | if ($dryrun) { 58 | mtrace("Would disable the {$count} following tasks:"); 59 | } else { 60 | mtrace("Disabling the {$count} following tasks:"); 61 | } 62 | 63 | // Disable every task that has a record in our table. 64 | foreach ($disabledtasks as $disabledtask) { 65 | if ($disabledtask->disabled == 1) { 66 | mtrace("Task $increment/$count: $disabledtask->classname selected to disable but is already disabled, skipping.."); 67 | $increment++; 68 | } else { 69 | if ($dryrun) { 70 | mtrace("Task $increment/$count: Would disable task: $disabledtask->classname"); 71 | $increment++; 72 | } else { 73 | mtrace("Task $increment/$count: Disabling task: $disabledtask->classname"); 74 | 75 | // Collect all the tasks to update and update in one query 76 | $taskstoupdate[] = $disabledtask->taskscheduledid; 77 | $increment++; 78 | } 79 | } 80 | } 81 | if ($taskstoupdate) { 82 | list($sql, $params) = $DB->get_in_or_equal($taskstoupdate); 83 | $DB->set_field_select('task_scheduled', 'disabled', 1, "id $sql", $params); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /cleaner/scheduled_tasks/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_scheduled_tasks 20 | * @copyright 2019 Catalyst IT 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | namespace cleaner_scheduled_tasks\privacy; 24 | defined('MOODLE_INTERNAL') || die; 25 | use core_privacy\local\metadata\null_provider; 26 | use core_privacy\local\legacy_polyfill; 27 | /** 28 | * Class provider 29 | * @package cleaner_scheduled_tasks\privacy 30 | */ 31 | class provider implements null_provider { 32 | use legacy_polyfill; 33 | /** 34 | * Get the language string identifier with the component's language 35 | * file to explain why this plugin stores no data. 36 | * 37 | * @return string 38 | */ 39 | public static function _get_reason() { 40 | return 'privacy:metadata'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /cleaner/scheduled_tasks/db/install.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |
19 | -------------------------------------------------------------------------------- /cleaner/scheduled_tasks/index.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * 19 | * @package cleaner_scheduled_tasks 20 | * @copyright 2019 Catalyst IT 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | require_once(__DIR__ . '/../../../../config.php'); 25 | require_once($CFG->libdir . '/adminlib.php'); 26 | 27 | admin_externalpage_setup('cleaner_scheduled_tasks_settings'); 28 | 29 | $PAGE->add_body_class('cleaner_scheduled_tasks'); 30 | 31 | // Grab the data that we are going to display. This is a list of all scheduled tasks. 32 | $tasks = \core\task\manager::get_all_scheduled_tasks(); 33 | 34 | // Grab this url to redirect to. 35 | $post = new moodle_url('/local/datacleaner/cleaner/scheduled_tasks/index.php'); 36 | 37 | // Then send this data to the form 38 | $taskform = new \cleaner_scheduled_tasks\form\task_form($post, $tasks); 39 | 40 | // We have created the form with the correct fields and data, but we don't want to display this one. 41 | if ($taskform->is_cancelled()) { 42 | // redirect to settings page if we cancelled. 43 | redirect($post); 44 | } else if ($data = $taskform->get_data()) { 45 | // If we submit the form, then we should look at the data here and for each record insert the data into our cleaner_scheduled_tasks table. 46 | global $DB; 47 | 48 | $taskdata = isset($data->selected) ? $data->selected : false; 49 | $taskdata = $taskdata ? $taskdata : (array)$data; 50 | 51 | // Get an associative array so we can match submitted tasks to the tasks in the task_scheduled table 52 | $scheduledtasks = $DB->get_records_select_menu('task_scheduled', '', [], 'id', 'classname, id'); 53 | 54 | foreach ($taskdata as $key => $taskenabled) { 55 | 56 | if (!isset($scheduledtasks["\\$key"])) { 57 | continue; 58 | } 59 | 60 | $record = $DB->get_record('cleaner_scheduled_tasks', ['taskscheduledid' => $scheduledtasks["\\$key"]]); 61 | if ($record && $taskenabled == 0) { 62 | // We have a record in our table but haven't selected it in our form. Should be deleted. 63 | $DB->delete_records('cleaner_scheduled_tasks', ['taskscheduledid' => $scheduledtasks["\\$key"]]); 64 | } else if ($record && $taskenabled == 1) { 65 | // The record already exists in our table with the correct setting, no update needed 66 | continue; 67 | } else if (!$record && $taskenabled == 1) { 68 | // The record doesn't exist, but it should because we selected it, insert it 69 | $taskinsert = new stdClass; 70 | $taskinsert->taskscheduledid = $scheduledtasks["\\$key"]; 71 | $taskinsert->lastmodified = time(); 72 | 73 | $DB->insert_record('cleaner_scheduled_tasks', $taskinsert); 74 | } 75 | } 76 | } 77 | 78 | // If we are here, then we are just displaying the form, and haven't cancelled or submitted it on this page. 79 | echo $OUTPUT->header(); 80 | $taskform->display(); 81 | echo $OUTPUT->footer(); 82 | -------------------------------------------------------------------------------- /cleaner/scheduled_tasks/lang/en/cleaner_scheduled_tasks.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_scheduled_tasks 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | $string['pluginname'] = 'Cleaner scheduled tasks'; 25 | 26 | // Settings page. 27 | $string['privacy:metadata'] = 'The cleaner scheduled tasks plugin does not store any personal data.'; 28 | $string['subtitle'] = 'Select a task to disable it in the pre wash task. 29 | Unselected tasks will be unaffected and will remain in their current enabled/disabled state.'; 30 | $string['noscheduledtasks'] = 'Could not find any scheduled tasks, cannot display the task disabling form.'; 31 | $string['title'] = 'Scheduled task disabling form'; 32 | $string['enabled'] = 'enabled'; 33 | $string['disabled'] = 'disabled'; 34 | -------------------------------------------------------------------------------- /cleaner/scheduled_tasks/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_scheduled_tasks 19 | * @subpackage local_datacleaner 20 | * @copyright 2019 Catalyst IT 21 | * @var $ADMIN admin_root 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$hassiteconfig) { 27 | return; 28 | } 29 | 30 | // Add the new settings page. 31 | $ADMIN->add('datacleaner', new admin_externalpage( 32 | 'cleaner_scheduled_tasks_settings', 33 | get_string('pluginname', 'cleaner_scheduled_tasks'), 34 | new moodle_url('/local/datacleaner/cleaner/scheduled_tasks/index.php') 35 | )); 36 | -------------------------------------------------------------------------------- /cleaner/scheduled_tasks/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_scheduled_tasks 19 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 20 | */ 21 | 22 | defined('MOODLE_INTERNAL') || die; 23 | 24 | $plugin->version = 2019030401; 25 | $plugin->release = '3.6.0'; 26 | $plugin->maturity = MATURITY_STABLE; 27 | $plugin->requires = 2013111800; // Moodle 2.6 release and upwards. 28 | $plugin->component = 'cleaner_scheduled_tasks'; 29 | $plugin->sortorder = 150; 30 | -------------------------------------------------------------------------------- /cleaner/sitedata/TODO: -------------------------------------------------------------------------------- 1 | 2 | TODO: 3 | a) runs very ealry before any API calls in other plugins 4 | b) generate more placeholder files for the following: 5 | - avi 6 | - bz (probably not required) 7 | - flv 8 | - gtar 9 | - mov 10 | - mp3 11 | - mp4 12 | - odb 13 | - odc 14 | - odf 15 | - odi 16 | - odm 17 | - swf 18 | - wmv 19 | -------------------------------------------------------------------------------- /cleaner/sitedata/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_sitedata 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_sitedata\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_sitedata\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.7z -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.bmp -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.bz2 -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | 3 | body { 4 | /* 5 | This is a placeholder. 6 | */ 7 | } 8 | -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.csv: -------------------------------------------------------------------------------- 1 | col1,col2,col3,col4,col4,col6,col7 2 | row1_col1,row1_col2,row1_col3,row1_col4,row1_col5,row1_col6,row1_col7 3 | row2_col1,row2_col2,row2_col3,row2_col4,row2_col5,row2_col6,row2_col7 4 | row3_col1,row3_col2,row3_col3,row3_col4,row3_col5,row3_col6,row3_col7 5 | row4_col1,row4_col2,row4_col3,row4_col4,row4_col5,row4_col6,row4_col7 6 | row5_col1,row5_col2,row5_col3,row5_col4,row5_col5,row5_col6,row5_col7 7 | row6_col1,row6_col2,row6_col3,row6_col4,row6_col5,row6_col6,row6_col7 8 | row7_col1,row7_col2,row7_col3,row7_col4,row7_col5,row7_col6,row7_col7 9 | row8_col1,row8_col2,row8_col3,row8_col4,row8_col5,row8_col6,row8_col7 10 | row9_col1,row9_col2,row9_col3,row9_col4,row9_col5,row9_col6,row9_col7 11 | -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.doc -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.docx -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.gif -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.gz -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Placeholder 6 | 7 | 8 | This is a placeholder. 9 | 10 | -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.ico -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.jpg -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.js: -------------------------------------------------------------------------------- 1 | /* This is a placeholder. */ -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.odg -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.odp -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.ods -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.odt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.odt -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.otp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.otp -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.pdf -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.png -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.ppt -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.pptx -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.psd -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.rar -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\deff3\adeflang1025 2 | {\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\froman\fprq2\fcharset2 Symbol;}{\f2\fswiss\fprq2\fcharset0 Arial;}{\f3\froman\fprq2\fcharset0 Liberation Serif{\*\falt Times New Roman};}{\f4\fswiss\fprq2\fcharset0 Liberation Sans{\*\falt Arial};}{\f5\fnil\fprq2\fcharset0 Droid Sans Fallback;}{\f6\fnil\fprq2\fcharset0 FreeSans;}{\f7\fswiss\fprq0\fcharset0 FreeSans;}} 3 | {\colortbl;\red0\green0\blue0;\red128\green128\blue128;} 4 | {\stylesheet{\s0\snext0\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\aspalpha\ltrpar\cf0\kerning1\dbch\af5\langfe2052\dbch\af6\afs24\alang1081\loch\f3\fs24\lang3081 Normal;} 5 | {\s15\sbasedon0\snext16\sb240\sa120\keepn\dbch\af5\dbch\af6\afs28\loch\f4\fs28 Heading;} 6 | {\s16\sbasedon0\snext16\sl288\slmult1\sb0\sa140 Text Body;} 7 | {\s17\sbasedon16\snext17\sl288\slmult1\sb0\sa140\dbch\af7 List;} 8 | {\s18\sbasedon0\snext18\sb120\sa120\noline\i\dbch\af7\afs24\ai\fs24 Caption;} 9 | {\s19\sbasedon0\snext19\noline\dbch\af7 Index;} 10 | }{\info{\author Ghada El-Zoghbi}{\creatim\yr2015\mo9\dy1\hr14\min54}{\author Ghada El-Zoghbi}{\revtim\yr2015\mo9\dy1\hr14\min55}{\printim\yr0\mo0\dy0\hr0\min0}{\comment LibreOffice}{\vern67241986}}\deftab709 11 | \viewscale100 12 | {\*\pgdsctbl 13 | {\pgdsc0\pgdscuse451\pgwsxn11906\pghsxn16838\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\pgdscnxt0 Default Style;}} 14 | \formshade\paperh16838\paperw11906\margl1134\margr1134\margt1134\margb1134\sectd\sbknone\sectunlocked1\pgndec\pgwsxn11906\pghsxn16838\marglsxn1134\margrsxn1134\margtsxn1134\margbsxn1134\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc 15 | \pgndec\pard\plain \s0\nowidctlpar{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\aspalpha\ltrpar\cf0\kerning1\dbch\af5\langfe2052\dbch\af6\afs24\alang1081\loch\f3\fs24\lang3081{\rtlch \ltrch\loch 16 | This is a }{\rtlch \ltrch\loch 17 | place-holder}{\rtlch \ltrch\loch 18 | document.} 19 | \par } -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.tar: -------------------------------------------------------------------------------- 1 | placeholder.txt000664 024026 024026 00000000044 12571471145 014264 0ustar00ghadaghada000000 000000 This is a place-holder document. 2 | -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.tif -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.txt: -------------------------------------------------------------------------------- 1 | This is a place-holder document. 2 | -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.xcf -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.xls -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.xlsx -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.xlt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.xlt -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | This is a place-holder document. 4 | 5 | -------------------------------------------------------------------------------- /cleaner/sitedata/fixtures/placeholder.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/catalyst/moodle-local_datacleaner/5b6af38b62527ffe83c65b204c09597075b4009f/cleaner/sitedata/fixtures/placeholder.zip -------------------------------------------------------------------------------- /cleaner/sitedata/lang/en/cleaner_sitedata.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_sitedata 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['pluginname'] = 'Cleanup sitedata'; 26 | 27 | // Settings page. 28 | $string['allfiletypes'] = 'All file types'; 29 | $string['allfiletypesdesc'] = 'Replace all files, of all types, with a generic default'; 30 | $string['filetypes'] = 'File types'; 31 | $string['filetypesdesc'] = 'Files of only the selected types will be replaced (if All file types is not set).'; 32 | $string['allcontextlevels'] = 'All context levels'; 33 | $string['allcontextlevelsdesc'] = 'Replace all files in every context level, with a generic default'; 34 | $string['contextlevels'] = 'Context levels'; 35 | $string['contextlevelsdesc'] = 'Files in only the selected contexts will be replaced (if all context levels is not set).'; 36 | $string['privacy:metadata'] = 'The cleaner sitedata plugin does not store any personal data.'; 37 | 38 | $string['wouldreplace'] = 'Would update {$a->total} record(s) from the files table. 39 | File type = \'{$a->mimetype}\'. 40 | File extension(s) = \'{$a->extensions}\'. 41 | Placeholder file = \'{$a->placeholderfilename}\'.'; 42 | 43 | $string['wouldreplaceunknowntype'] = 'Would update {$a->total} record(s) from the files table. 44 | Unsupported file type = \'{$a->mimetype}\'. 45 | New file type = \'{$a->newmimetype}\'. 46 | File extension(s)= \'{$a->extensions}\'. 47 | Placeholder file = \'{$a->placeholderfilename}\'.'; 48 | 49 | $string['willreplace'] = 'Will update {$a->total} record(s) in files table. 50 | File type = \'{$a->mimetype}\'. 51 | File extension(s) = \'{$a->extensions}\'. 52 | Placeholder file = \'{$a->placeholderfilename}\'.'; 53 | 54 | $string['willreplaceunknowntype'] = 'Will update {$a->total} record(s) in files table. 55 | Unsupported file type = \'{$a->mimetype}\'. 56 | New file type = \'{$a->newmimetype}\'. 57 | File extension(s) = \'{$a->extensions}\'. 58 | Placeholder file = \'{$a->placeholderfilename}\'.'; 59 | 60 | $string['nothingtoupdate'] = 'Nothing to update.'; 61 | 62 | $string['checkcontextsettings'] = 'Please check your settings. No context selected.'; 63 | $string['checkfiletypesettings'] = 'Please check your settings. No file types selected.'; 64 | $string['filecopyerror'] = '-- ERROR -- An error was encountered while copying the placeholder file to sitedata. Please ensure you have the right permissions.'; 65 | -------------------------------------------------------------------------------- /cleaner/sitedata/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_sitedata 19 | * @copyright 2015 Catalyst IT 20 | * @author Tim Price 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$ADMIN->fulltree) { 27 | return; 28 | } 29 | 30 | require_once($CFG->dirroot . '/local/datacleaner/cleaner/sitedata/classes/supported_file_types.php'); 31 | 32 | $settings->add(new admin_setting_configcheckbox('cleaner_sitedata/allfiletypes', 33 | new lang_string('allfiletypes', 'cleaner_sitedata'), 34 | new lang_string('allfiletypesdesc', 'cleaner_sitedata'), 0)); 35 | 36 | $filetypes = new cleaner_sitedata\cleaner_sitedata_supported_file_types(); 37 | $supportedfiletypes = $filetypes->get_supported_file_types(); 38 | 39 | if ($supportedfiletypes) { 40 | 41 | $settings->add(new admin_setting_configmultiselect('cleaner_sitedata/filetypes', 42 | new lang_string('filetypes', 'cleaner_sitedata'), 43 | new lang_string('filetypesdesc', 'cleaner_sitedata'), 44 | array(), 45 | $supportedfiletypes)); 46 | } 47 | 48 | $settings->add(new admin_setting_configcheckbox('cleaner_sitedata/allcontextlevels', 49 | new lang_string('allcontextlevels', 'cleaner_sitedata'), 50 | new lang_string('allcontextlevelsdesc', 'cleaner_sitedata'), 0)); 51 | 52 | $settings->add(new admin_setting_configmultiselect('cleaner_sitedata/contextlevels', 53 | new lang_string('contextlevels', 'cleaner_sitedata'), 54 | new lang_string('contextlevelsdesc', 'cleaner_sitedata'), array(CONTEXT_USER), 55 | array(CONTEXT_SYSTEM => 'System', 56 | CONTEXT_USER => 'User', 57 | CONTEXT_COURSECAT => 'Course category', 58 | CONTEXT_COURSE => 'Course', 59 | CONTEXT_MODULE => 'Module', 60 | CONTEXT_BLOCK => 'Block'))); 61 | -------------------------------------------------------------------------------- /cleaner/sitedata/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_sitedata 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | $plugin->version = 2015072200; 28 | $plugin->release = '2.3.2'; 29 | $plugin->maturity = MATURITY_STABLE; 30 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 31 | $plugin->component = 'cleaner_sitedata'; 32 | $plugin->sortorder = 4; 33 | -------------------------------------------------------------------------------- /cleaner/tasklogs/classes/clean.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_tasklogs 19 | * @copyright 2025 Brendan Heywood 20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 | */ 22 | 23 | namespace cleaner_tasklogs; 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | class clean extends \local_datacleaner\clean { 28 | 29 | /** 30 | * Removes all task logs 31 | * 32 | * @var string 33 | */ 34 | public static function execute() { 35 | global $DB; 36 | 37 | // Get on with the real work! 38 | if (self::$options['dryrun']) { 39 | echo "Would delete all task logs.\n"; 40 | } else { 41 | $DB->delete_records('task_log'); 42 | echo "Deleted all task logs.\n"; 43 | 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /cleaner/tasklogs/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_tasklogs 20 | * @copyright 2025 Catalyst IT 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | namespace cleaner_tasklogs\privacy; 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | class provider implements 29 | // This plugin does not store any personal user data. 30 | \core_privacy\local\metadata\null_provider { 31 | 32 | /** 33 | * Get the language string identifier with the component's language 34 | * file to explain why this plugin stores no data. 35 | * 36 | * @return string 37 | */ 38 | public static function get_reason(): string { 39 | return 'privacy:metadata'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /cleaner/tasklogs/lang/en/cleaner_tasklogs.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_tasklogs 21 | * @copyright 2025 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['pluginname'] = 'Delete task logs'; 26 | $string['privacy:metadata'] = 'The task logs cleaner plugin does not store any personal data.'; 27 | -------------------------------------------------------------------------------- /cleaner/tasklogs/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_tasklogs 19 | * @copyright 2025 Catalyst IT 20 | * @author Nigel Cunningham 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$ADMIN->fulltree) { 27 | return; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /cleaner/tasklogs/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_tasklogs 21 | * @copyright 2025 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | $plugin->version = 2025010100; 28 | $plugin->release = 2025010100; 29 | $plugin->maturity = MATURITY_STABLE; 30 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 31 | $plugin->component = 'cleaner_tasklogs'; 32 | $plugin->sortorder = 8; 33 | -------------------------------------------------------------------------------- /cleaner/users/classes/privacy/provider.php: -------------------------------------------------------------------------------- 1 | . 16 | /** 17 | * Privacy provider. 18 | * 19 | * @package cleaner_users 20 | * @author Ilya Tregubov (ilyatregubov@catalyst-au.net) 21 | * @copyright 2018 Catalyst IT 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | namespace cleaner_users\privacy; 25 | defined('MOODLE_INTERNAL') || die; 26 | use core_privacy\local\metadata\null_provider; 27 | use core_privacy\local\legacy_polyfill; 28 | /** 29 | * Class provider 30 | * @package cleaner_users\privacy 31 | */ 32 | class provider implements null_provider { 33 | use legacy_polyfill; 34 | /** 35 | * Get the language string identifier with the component's language 36 | * file to explain why this plugin stores no data. 37 | * 38 | * @return string 39 | */ 40 | public static function _get_reason() { 41 | return 'privacy:metadata'; 42 | } 43 | } -------------------------------------------------------------------------------- /cleaner/users/db/upgrade.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Upgrade script for cleaner_users_upgrade. 19 | * 20 | * @package cleaner_users 21 | * @author Kevin Pham 22 | * @copyright Catalyst IT, 2021 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | function xmldb_cleaner_users_upgrade($oldversion) { 29 | global $DB; 30 | 31 | if ($oldversion < 2021120100) { 32 | // Standardise user clean passwords on update. 33 | $sqllike = $DB->sql_like('email', ':email', false, false); 34 | $params = [ 35 | 'email' => '%cleaned@datacleaner.example%', 36 | ]; 37 | $select = "$sqllike and password <> '" . AUTH_PASSWORD_NOT_CACHED . "'"; 38 | $DB->set_field_select('user', 'password', AUTH_PASSWORD_NOT_CACHED, $select, $params); 39 | upgrade_plugin_savepoint(true, 2021120100, 'cleaner', 'users'); 40 | } 41 | 42 | return true; 43 | } 44 | -------------------------------------------------------------------------------- /cleaner/users/lang/en/cleaner_users.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package cleaner_users 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['pluginname'] = 'Scramble user data'; 26 | $string['privacy:metadata'] = 'The cleaner users plugin does not store any personal data.'; 27 | $string['keepsiteadmins'] = 'Keep site admins unmodified'; 28 | $string['keepsiteadminsdesc'] = 'Tick to avoid modifying site administrator accounts and data.'; 29 | $string['keepusernames'] = 'Non site administrator usernames'; 30 | $string['keepusernamesdesc'] = 'A comma separated list of non site administrator usernames that should be untouched.'; 31 | -------------------------------------------------------------------------------- /cleaner/users/settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner_courses 19 | * @copyright 2015 Catalyst IT 20 | * @author Nigel Cunningham 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die; 25 | 26 | if (!$ADMIN->fulltree) { 27 | return; 28 | } 29 | 30 | $settings->add(new admin_setting_configcheckbox('cleaner_users/keepsiteadmins', new lang_string('keepsiteadmins', 'cleaner_users'), 31 | new lang_string('keepsiteadminsdesc', 'cleaner_users'), 1)); 32 | 33 | $settings->add(new admin_setting_configtextarea('cleaner_users/keepusernames', 34 | new lang_string('keepusernames', 'cleaner_users'), 35 | new lang_string('keepusernamesdesc', 'cleaner_users'), '', PARAM_RAW)); 36 | -------------------------------------------------------------------------------- /cleaner/users/version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package cleaner_users 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | $plugin->version = 2021120100; 28 | $plugin->release = 2021120100; 29 | $plugin->maturity = MATURITY_STABLE; 30 | $plugin->requires = 2011120500; // Moodle 2.2 release and upwards. 31 | $plugin->component = 'cleaner_users'; 32 | $plugin->sortorder = 80; 33 | -------------------------------------------------------------------------------- /cli/sitedata_file_list.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package local_datacleaner 19 | * @copyright 2015 Nigel Cunningham 20 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 | */ 22 | 23 | define('CLI_SCRIPT', true); 24 | require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); 25 | require_once($CFG->libdir.'/clilib.php'); 26 | 27 | global $DB; 28 | 29 | // Emit a throwaway line that can be used to ensure this script has been spawned 30 | // before ownership on the target directory is modified. 31 | echo "Remaining files...\n"; 32 | 33 | $sql = "SELECT DISTINCT contenthash FROM {files} WHERE filename != '.'"; 34 | $result = $DB->get_records_sql($sql); 35 | foreach ($result as $hash) { 36 | echo "{$hash->contenthash}\n"; 37 | } 38 | -------------------------------------------------------------------------------- /db/caches.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Cache definitions. 19 | * 20 | * @package local_datacleaner 21 | * @copyright 2015 Catalyst IT 22 | * @author Nigel Cunningham 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | $definitions = array( 29 | 'courses' => array( 30 | 'mode' => cache_store::MODE_APPLICATION, 31 | ), 32 | 'schema' => array( 33 | 'mode' => cache_store::MODE_APPLICATION, 34 | ) 35 | ); 36 | -------------------------------------------------------------------------------- /db/subplugins.json: -------------------------------------------------------------------------------- 1 | { 2 | "subplugintypes": { 3 | "cleaner": "cleaner" 4 | }, 5 | "plugintypes": { 6 | "cleaner": "local\/datacleaner\/cleaner" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /db/subplugins.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package local_datacleaner 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die(); 26 | 27 | $subplugins = (array) json_decode(file_get_contents(__DIR__ . "/subplugins.json"))->plugintypes; 28 | -------------------------------------------------------------------------------- /db/upgrade.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Upgrade logic. 19 | * 20 | * @package local_datacleaner 21 | * @copyright 2024 Catalyst IT 22 | * @author Scott Verbeek 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | 27 | /** 28 | * Performs data migrations and updates on upgrade. 29 | * 30 | * @param int $oldversion 31 | * @return bool 32 | */ 33 | function xmldb_local_datacleaner_upgrade($oldversion = 0): bool{ 34 | global $DB; 35 | $dbman = $DB->get_manager(); 36 | if ($oldversion < 2022020301) { 37 | // Clean up table. 38 | $table = new xmldb_table('cleaner_muc_configs'); 39 | if ($dbman->table_exists($table)) { 40 | $dbman->drop_table($table); 41 | } 42 | 43 | upgrade_plugin_savepoint(true, 2022020301, 'local', 'datacleaner'); 44 | } 45 | 46 | return true; 47 | } 48 | -------------------------------------------------------------------------------- /lang/en/local_datacleaner.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Language strings 19 | * 20 | * @package local_datacleaner 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | $string['pluginname'] = 'Data cleaner'; 26 | $string['subplugintype_cleaner'] = 'Data Cleaner'; 27 | $string['subplugintype_cleaner_plural'] = 'Data Cleaners'; 28 | $string['privacy:metadata'] = 'The local datacleaner plugin does not store any personal data.'; 29 | $string['cachedef_courses'] = 'Course cache'; 30 | $string['cachedef_schema'] = 'Schema cache'; 31 | $string['cleaning'] = 'Cleaning'; 32 | $string['enabledisable'] = 'Enabled'; 33 | $string['disable'] = 'Disable'; 34 | $string['enable'] = 'Enable'; 35 | $string['error:explicitconfigphp'] = 'Please set the local_datacleaner_allowexecution in config.php'; 36 | $string['info'] = '

You can configure what and how data will be cleaned after it is cloned from production.

After the database and sitedata are cloned into another environment a CLI is run which will perform the cleaning. Several checks are performed to ensure that this cannot be run on the production environment.

'; 37 | $string['manage'] = 'Manage cleaning tasks'; 38 | $string['notes'] = 'Notes'; 39 | $string['sortorder'] = 'Sort order'; 40 | $string['noplugins'] = 'No data cleansing plugins found.'; 41 | $string['progress'] = 'Progress'; 42 | $string['errordeletingdir'] = '-- ERROR -- An error was encountered while deleting the directory: {$a}'; 43 | $string['cascadedeletesettings'] = 'Cascade delete settings'; 44 | $string['mismatch_threshold'] = 'Mismatch threshold'; 45 | $string['mismatch_thresholddesc'] = 'The data cleaner uses a heuristic to create cascade delete rules in the database that 46 | aren\'t normally there. Prior to creating a rule, it checks how many records would violate the potential relationship. This setting 47 | controls the threshold above which the relationship will not be created (which also means records in the target table will not be 48 | deleted). The threshold is expressed as a percentage of the total number of records involved. If the total number of records in a 49 | table is less than 100, this value is ignored and any conflicts cause the rule not to be created.'; 50 | -------------------------------------------------------------------------------- /lib.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * @package cleaner 19 | * @copyright 2015 Catalyst IT 20 | * @author Nigel Cunningham 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 | */ 23 | 24 | defined('MOODLE_INTERNAL') || die(); 25 | 26 | /** 27 | * This function should be called instead of core_course_external::get_categories(). 28 | * 29 | * See Issue #2. 30 | * 31 | * @return array Categories. 32 | */ 33 | function local_datacleaner_get_categories() { 34 | global $DB; 35 | static $categories = null; 36 | 37 | if (is_null($categories)) { 38 | // Fetch from database. 39 | $categories = $DB->get_records('course_categories'); 40 | 41 | // Sort by path. 42 | usort($categories, function ($a, $b) { 43 | return strcmp($a->path, $b->path); 44 | }); 45 | 46 | // Convert all to array. 47 | for ($i = 0; $i < count($categories); $i++) { 48 | $categories[$i] = (array)$categories[$i]; 49 | } 50 | } 51 | 52 | return $categories; 53 | } 54 | -------------------------------------------------------------------------------- /settings.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Add page to admin menu. 19 | * 20 | * @package local_datacleaner 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | if (!$hassiteconfig) { // Needs this condition or there is error on login page. 28 | return; 29 | } 30 | 31 | $ADMIN->add('localplugins', new admin_category('datacleaner', get_string('pluginname', 'local_datacleaner'))); 32 | 33 | $ADMIN->add('datacleaner', new admin_externalpage('local_datacleaner', 34 | get_string('manage', 'local_datacleaner'), 35 | new moodle_url('/local/datacleaner/index.php'))); 36 | 37 | $temp = new admin_settingpage('cascadedeletesettings', new lang_string('cascadedeletesettings', 'local_datacleaner')); 38 | 39 | $temp->add(new admin_setting_configtext('local_datacleaner/mismatch_threshold', 40 | new lang_string('mismatch_threshold', 'local_datacleaner'), 41 | new lang_string('mismatch_thresholddesc', 'local_datacleaner'), '5', PARAM_INT)); 42 | $ADMIN->add('datacleaner', $temp); 43 | 44 | $plugins = \local_datacleaner\plugininfo\cleaner::get_plugins_by_sortorder(); 45 | foreach ($plugins as $plugin) { 46 | 47 | $pagename = 'cleaner_' . $plugin->name . '_settings'; 48 | $plugin->load_settings($ADMIN, 'datacleaner', $hassiteconfig); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /tests/unit/custom_test.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Testcase for cleaner_custom_sql_* 19 | * 20 | * @package local_datacleaner 21 | * @author Srdjan Janković 22 | * @copyright 2019 Catalyst IT Australia {@link http://www.catalyst-au.net} 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 | */ 25 | 26 | defined('MOODLE_INTERNAL') || die(); 27 | 28 | /** 29 | * Testcase for cleaner_custom_sql_* 30 | * 31 | * @package local_datacleaner 32 | * @author Srdjan Janković 33 | * @copyright 2019 Catalyst IT Australia {@link http://www.catalyst-au.net} 34 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 | * @SuppressWarnings(public) Allow as many methods as needed. 36 | */ 37 | class local_datacleaner_custom_sql_test extends advanced_testcase { 38 | 39 | /** 40 | * Initialise a cleaner object to reset static options. 41 | * 42 | * This prevents impact on other tests which assume default options. 43 | * 44 | * @return void 45 | * @throws coding_exception 46 | */ 47 | public function tearDown(): void { 48 | new \cleaner_custom_sql_pre\clean(['verbose' => false, 'dryrun' => false]); 49 | } 50 | 51 | public function test_executes_sql() { 52 | global $DB; 53 | 54 | $this->resetAfterTest(true); 55 | 56 | $sql = "SELECT * FROM {table_that_is_not}"; 57 | $prefix = $DB->get_prefix(); 58 | $realsql = "SELECT * FROM {$prefix}table_that_is_not"; 59 | 60 | foreach (['pre', 'post'] as $when) { 61 | $module = "cleaner_custom_sql_$when"; 62 | $param = "run-$when-wash"; 63 | $class = "$module\\clean"; 64 | 65 | set_config('sql', $sql, $module); 66 | $cleaner = new $class([$param => true, 'dryrun' => false, 'verbose' => false]); 67 | try { 68 | $cleaner->execute(); 69 | $this->fail("Should have thrown an exception"); 70 | } catch (dml_write_exception $e) { 71 | $this->assertEquals($realsql, $e->sql); 72 | } 73 | 74 | set_config('sql', "SELECT 1;\nSELECT 2", $module); 75 | $cleaner = new $class([$param => true, 'dryrun' => true, 'verbose' => false]); 76 | $cleaner->execute(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /version.php: -------------------------------------------------------------------------------- 1 | . 16 | 17 | /** 18 | * Version details. 19 | * 20 | * @package local_datacleaner 21 | * @copyright 2015 Brendan Heywood 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 | */ 24 | 25 | defined('MOODLE_INTERNAL') || die; 26 | 27 | $plugin->version = 2022020301; 28 | $plugin->release = '2.3.10'; 29 | $plugin->maturity = MATURITY_STABLE; 30 | $plugin->requires = 2021051700; // Moodle 3.11 release and upwards. 31 | $plugin->supports = [311, 405]; 32 | $plugin->component = 'local_datacleaner'; 33 | --------------------------------------------------------------------------------