Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions classes/admin_setting_configencodedtext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

namespace local_datacleaner;


/**
* The text setting where input is encoded before save.
*
* @package local_datacleaner
* @author Dustin Huynh <dustinhuynh@catalyst-au.net>
* @copyright 2025, Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_configencodedtext extends \admin_setting_configtext {

/**
* Return the setting
*
* @return mixed returns config if successful else null
*/
public function get_setting() {
global $CFG;
return base64_decode($CFG->original_wwwroot) ?? null;
}

/**
* Write the setting
*/
public function write_setting($data) {
global $CFG;
if ($this->paramtype === PARAM_INT && $data === '') {
$data = 0;
}
$validated = $this->validate($data);
if ($validated !== true) {
return $validated;
}
$originalwwwroot = base64_encode($data);
return set_config('original_wwwroot', $originalwwwroot) ? '' : get_string('errorsetting', 'admin');
}

/**
* Return an XHTML string for the setting
* @return string Returns an XHTML string
*/
public function output_html($data, $query = '') {
global $CFG;
$elementid = $this->get_id();
$textbox = parent::output_html($data, $query);
$resetbutton = \html_writer::tag('button',
get_string('resetbutton', 'local_datacleaner'),
[
'type' => 'button',
'onclick' => "document.getElementById('{$elementid}').value = '{$CFG->wwwroot}'",
'class' => 'btn btn-secondary',
],
);
$html = \html_writer::div(
$textbox . $resetbutton,
'mb-3'
);
return $html;
}
}
29 changes: 29 additions & 0 deletions db/install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* Install script for databases.
*
* @package local_datacleaner
* @author Dustin Huynh <dustinhuynh@catalyst-au.net>
* @copyright 2025, Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_local_datacleaner_install() {
global $CFG;
$originalwwwroot = base64_encode($CFG->wwwroot);
set_config('original_wwwroot', $originalwwwroot);
}
12 changes: 10 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
* @param int $oldversion
* @return bool
*/
function xmldb_local_datacleaner_upgrade($oldversion = 0): bool{
global $DB;
function xmldb_local_datacleaner_upgrade($oldversion = 0): bool {
global $DB, $CFG;
$dbman = $DB->get_manager();
if ($oldversion < 2022020301) {
// Clean up table.
Expand All @@ -43,5 +43,13 @@ function xmldb_local_datacleaner_upgrade($oldversion = 0): bool{
upgrade_plugin_savepoint(true, 2022020301, 'local', 'datacleaner');
}

if ($oldversion < 2022020302) {
if (!isset($CFG->original_wwwroot)) {
$originalwwwroot = base64_encode($CFG->wwwroot);
set_config('original_wwwroot', $originalwwwroot);
}
upgrade_plugin_savepoint(true, 2022020302, 'local', 'datacleaner');
}

return true;
}
6 changes: 4 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
admin_externalpage_setup('local_datacleaner');

// Save the wwwroot for checking from the CLI that we're not in prod.
$originalwwwroot = base64_encode($CFG->wwwroot);
set_config('original_wwwroot', $originalwwwroot);
if (!isset($CFG->original_wwwroot)) {
$originalwwwroot = base64_encode($CFG->wwwroot);
set_config('original_wwwroot', $originalwwwroot);
}

// Allows the admin to configure subplugins (enable/disable, configure).

Expand Down
5 changes: 5 additions & 0 deletions lang/en/local_datacleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@
controls the threshold above which the relationship will not be created (which also means records in the target table will not be
deleted). The threshold is expressed as a percentage of the total number of records involved. If the total number of records in a
table is less than 100, this value is ignored and any conflicts cause the rule not to be created.';
$string['generalsettings'] = 'General settings';
$string['original_wwwroot'] = 'Production Site URL';
$string['original_wwwrootdesc'] = 'We store the hostname in the cleaning configuration data. If the hostname matches production,
DataCleaner will not run. If this data is missing then it will not run.';
$string['resetbutton'] = 'Reset URL';
8 changes: 8 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
get_string('manage', 'local_datacleaner'),
new moodle_url('/local/datacleaner/index.php')));


$general = new admin_settingpage('generalsettings', new lang_string('generalsettings', 'local_datacleaner'));

$general->add(new \local_datacleaner\admin_setting_configencodedtext('local_datacleaner/original_wwwroot',
new lang_string('original_wwwroot', 'local_datacleaner'),
new lang_string('original_wwwrootdesc', 'local_datacleaner'), $CFG->wwwroot, PARAM_URL));
$ADMIN->add('datacleaner', $general);

$temp = new admin_settingpage('cascadedeletesettings', new lang_string('cascadedeletesettings', 'local_datacleaner'));

$temp->add(new admin_setting_configtext('local_datacleaner/mismatch_threshold',
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2022020301;
$plugin->release = '2.3.10';
$plugin->version = 2022020302;
$plugin->release = 2022020302;
$plugin->maturity = MATURITY_STABLE;
$plugin->requires = 2021051700; // Moodle 3.11 release and upwards.
$plugin->supports = [311, 405];
Expand Down