diff --git a/index.php b/index.php
index d4e0ba1..ca0c743 100644
--- a/index.php
+++ b/index.php
@@ -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');
@@ -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');
diff --git a/lang/en/tool_dynamic_cohorts.php b/lang/en/tool_dynamic_cohorts.php
index 399cc31..bcabc5e 100644
--- a/lang/en/tool_dynamic_cohorts.php
+++ b/lang/en/tool_dynamic_cohorts.php
@@ -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.
To fix a broken rule you should remove all broken conditions.
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.
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';
@@ -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';
diff --git a/toggle.php b/toggle.php
index baac2dd..c02025d 100644
--- a/toggle.php
+++ b/toggle.php
@@ -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);