Skip to content

Commit

Permalink
Merge pull request #34 from catalyst/broken-notify
Browse files Browse the repository at this point in the history
Notify about broken rules
  • Loading branch information
dmitriim authored Mar 8, 2024
2 parents 8c2fe8f + e26f759 commit cec01f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core\notification;
use core_reportbuilder\system_report_factory;
use tool_dynamic_cohorts\rule;
use tool_dynamic_cohorts\reportbuilder\local\systemreports\rules;

require_once(__DIR__ . '/../../../config.php');
Expand All @@ -33,6 +35,13 @@
$manageurl = new moodle_url('/admin/tool/dynamic_cohorts/index.php');
$editurl = new moodle_url('/admin/tool/dynamic_cohorts/edit.php');

foreach (rule::get_records() as $rule) {
if ($rule->is_broken(true)) {
notification::warning(get_string('brokenruleswarning', 'tool_dynamic_cohorts'));
break;
}
}

$report = system_report_factory::create(rules::class, context_system::instance(), 'tool_dynamic_cohorts');

$PAGE->requires->js_call_amd('tool_dynamic_cohorts/manage_rules', 'init');
Expand Down
3 changes: 2 additions & 1 deletion lang/en/tool_dynamic_cohorts.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
$string['addrule'] = 'Add a new rule';
$string['add_rule'] = 'Add new rule';
$string['backtolistofrules'] = 'Back to the list of rules';
$string['brokenruleswarning'] = 'There are some broken rules require your attention. <br /> To fix a broken rule you should remove all broken conditions. <br />Sometimes a rule becomes broken when matching users SQL failed. In this case all condition are ok, but the rule is marked as broken. You should check Moodle logs for "Matching users failed" event and related SQL errors. <br />Please note, that in any case you have to re-save the rule to mark it as unbroken.';
$string['bulkprocessing'] = 'Bulk processing';
$string['bulkprocessing_help'] = 'If this option is enabled, users will be added and removed from cohort in bulk. This will significantly improve processing performance. However, using this option will suppress triggering events when users added or removed from cohort.';
$string['cachedef_conditionrecords'] = 'Conditions for a rule';
Expand Down Expand Up @@ -89,7 +90,7 @@
$string['privacy:metadata:tool_dynamic_cohorts_c:usermodified'] = 'The ID of the user who created or updated a condition';
$string['processrulestask'] = 'Process dynamic cohort rules';
$string['profilefield'] = 'Profile field';
$string['ruleisbroken'] = 'Rule is broken';
$string['cannotenablebrokenrule'] = 'A broken rule can\'t be enabled';
$string['ruledisabledpleasereview'] = 'Newly created or updated rules are disabled by default. Please review the rule below and enable it when ready.';
$string['ruledeleted'] = 'Rule has been deleted';
$string['ruleenabled'] = 'Rule has been enabled';
Expand Down
2 changes: 1 addition & 1 deletion toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
}
} else {
$newvalue = 0;
$message = get_string('ruleisbroken', 'tool_dynamic_cohorts');
$message = get_string('cannotenablebrokenrule', 'tool_dynamic_cohorts');
$messagetype = notification::NOTIFY_ERROR;

$rule->set('enabled', $newvalue);
Expand Down

0 comments on commit cec01f9

Please sign in to comment.