Skip to content

Commit

Permalink
Merge branch 'MDL-73926-master-v7' of https://github.com/TomoTsuyuki/…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Dec 18, 2023
2 parents e6b01af + f4597c9 commit 8a187ce
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions backup/upgrade.txt
Expand Up @@ -7,6 +7,7 @@ information provided here is intended especially for developers.
async backups (See MDL-69983).
* During restore the function create_included_users has been updated to convert backups containing
legacy MD5 hashed passwords to the new password hashing scheme (See MDL-79134).
* New get_excluded_events hook for excluding events from automated backup has been implemented (See MDL-73926).

=== 4.1 ===

Expand Down
15 changes: 14 additions & 1 deletion backup/util/helper/backup_cron_helper.class.php
Expand Up @@ -778,18 +778,31 @@ protected static function get_backups_to_delete($backupfiles, $now) {
* intentional, since we cannot reliably determine if any modification was made or not.
*/
protected static function is_course_modified($courseid, $since) {
global $DB;
$logmang = get_log_manager();
$readers = $logmang->get_readers('core\log\sql_reader');
$params = array('courseid' => $courseid, 'since' => $since);

// Exclude events defined by hook.
$hook = new \core\hook\backup\get_excluded_events();
\core\hook\manager::get_instance()->dispatch($hook);
$excludedevents = $hook->get_events();

foreach ($readers as $readerpluginname => $reader) {
$where = "courseid = :courseid and timecreated > :since and crud <> 'r'";

$excludeevents = [];
// Prevent logs of prevous backups causing a false positive.
if ($readerpluginname != 'logstore_legacy') {
$where .= " and target <> 'course_backup'";
$excludeevents[] = '\core\event\course_backup_created';
}

$excludeevents = array_merge($excludeevents, $excludedevents);
if ($excludeevents) {
list($notinsql, $notinparams) = $DB->get_in_or_equal($excludeevents, SQL_PARAMS_NAMED, 'eventname', false);
$where .= 'AND eventname ' . $notinsql;
$params = array_merge($params, $notinparams);
}
if ($reader->get_events_select_exists($where, $params)) {
return true;
}
Expand Down
74 changes: 74 additions & 0 deletions lib/classes/hook/backup/get_excluded_events.php
@@ -0,0 +1,74 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace core\hook\backup;

use core\hook\described_hook;

/**
* Get a list of event names which are excluded to trigger from course changes in automated backup.
*
* @package core
* @copyright 2023 Tomo Tsuyuki <tomotsuyuki@catalyst-au.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class get_excluded_events implements described_hook {

/**
* @var string[] Array of event names.
*/
private $events = [];

/**
* Describes the hook purpose.
*
* @return string
*/
public static function get_hook_description(): string {
return 'Get a list of event names which are excluded to trigger from course changes in automated backup.';
}

/**
* List of tags that describe this hook.
*
* @return string[]
*/
public static function get_hook_tags(): array {
return ['backup'];
}

/**
* Add an array of event names which are excluded to trigger from course changes in automated backup.
* This is set from plugin hook.
* e.g. ['\local_course\event\update', '\local_course\event\sync']
*
* @param string[] $events Array of event name strings
* @return void
*/
public function add_events(array $events): void {
$this->events = array_merge($this->events, $events);
}

/**
* Get an array of event names which are excluded to trigger from course changes in automated backup.
* This is called after dispatch for the hook and use values to exclude events for backup.
*
* @return array
*/
public function get_events(): array {
return $this->events;
}
}
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2023121500.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2023121800.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.4dev (Build: 20231215)'; // Human-friendly version name
Expand Down

0 comments on commit 8a187ce

Please sign in to comment.