]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16526 - added admin notifications for misconfigured portfolio plugins.
authormjollnir_ <mjollnir_>
Tue, 16 Sep 2008 19:09:30 +0000 (19:09 +0000)
committermjollnir_ <mjollnir_>
Tue, 16 Sep 2008 19:09:30 +0000 (19:09 +0000)
does not get triggered while admin is currently editing, only when users use it.

lang/en_utf8/portfolio.php
lib/adminlib.php
lib/portfoliolib.php

index 8054b5ce49323fc5ac93744c05fdbbfd34d969a7..06db246079ac6cf798c45b70b1e2267260bd4766 100644 (file)
@@ -50,6 +50,21 @@ $string['highfilesizethreshold'] = 'High transfer filesize';
 $string['highfilesizethresholddesc'] = 'Filesizes over this threshold will be considered to take a high amount of time to transfer';
 $string['highdbsizethreshold'] = 'High transfer dbsize';
 $string['highdbsizethresholddesc'] = 'Number of db records over which will be considered to take a high amount of time to transfer';
+$string['insanesubject'] = 'Some portfolio instances automatically disabled';
+$string['insanebody'] = 'Hi!  You are receiving this message as an administrator of $a->sitename.
+
+Some portfolio plugin instances have been automatically disabled due to misconfigurations.  This means that users can not currently export content to these portfolios.
+
+The list of portfolio plugin instances that have been disabled is:
+
+$a->textlist
+
+This should be corrected as soon as possible, by visiting $a->fixurl.
+';
+$string['insanebodyhtml'] = '<p>Hi! You are receiving this message as an administrator of $a->sitename.</p>
+$a->htmllist
+<p>This should be corrected as soon as possible, by visiting <a href=\"$a->fixurl\">the portfolio configuration pages</a></p>';
+$string['insanebodysmall'] = 'Hi!  You are receiving this message as an administrator of $a->sitename.  Some portfolio plugin instances have been automatically disabled due to misconfigurations.  This means that users can not currently export content to these portfolios.  This should be corrected as soon as possible, by visiting $a->fixurl.';
 $string['instancedeleted'] = 'Portfolio deleted successfully';
 $string['instanceismisconfigured'] = 'Portfolio instance is misconfigured, skipping.  Error was: $a';
 $string['instancenotsaved'] = 'Failed to save portfolio';
@@ -85,20 +100,22 @@ $string['nopermissions'] = 'Sorry but you do not have the required permissions t
 $string['nonprimative'] = 'A non primative value was passed as a callback argument to portfolio_add_button.  Refusing to continue.  The key was $a->key and the value was $a->value';
 $string['notexportable'] = 'Sorry, but the type of content you are trying to export is not exportable';
 $string['notimplemented'] = 'Sorry, but you are trying to export content in some format that is not yet implemented ($a)';
+$string['notyetselected'] = 'Not yet selected';
 $string['notyours'] = 'You are trying to resume a portfolio export that doesn\'t belong to you!';
 $string['nouploaddirectory'] = 'Could not create a temporary directory to package your data into';
 $string['portfolio'] = 'Portfolio';
 $string['portfolios'] = 'Portfolios';
 $string['plugin'] = 'Portfolio Plugin';
 $string['plugincouldnotpackage'] = 'Failed to package up your data for export: original error was $a';
+$string['pluginismisconfigured'] = 'Portfolio plugin is misconfigured, skipping.  Error was: $a';
 $string['queuesummary'] = 'Currently queued transfers';
 $string['returntowhereyouwere'] = 'Return to where you were';
 $string['save'] = 'Save';
 $string['selectedformat'] = 'Selected export format';
 $string['selectedwait'] = 'Selected to wait?';
 $string['selectplugin'] = 'Select portfolio plugin to export to';
-$string['someinstancesdisabled'] = 'Some configured plugin instances have been disabled either because they are misconfigured or rely on something else that is';
-$string['somepluginsdisabled']  = 'Some entire plugins have been disabled because they are either misconfigured or rely on something else that is:';
+$string['someinstancesdisabled'] = 'Some configured portfolio plugin instances have been disabled either because they are misconfigured or rely on something else that is';
+$string['somepluginsdisabled']  = 'Some entire portfolio plugins have been disabled because they are either misconfigured or rely on something else that is:';
 $string['sure'] = 'Are you sure you want to delete \'$a\'?  This cannot be undone.';
 $string['thirdpartyexception'] = 'A third party exception was thrown during portfolio export ($a). Caught and rethrown but this should really be fixed';
 $string['transfertime'] = 'Transfer time';
index 56fc2ecfe9794c9f6e0f9db51c6a4c44f5c6a4d0..a2d13859e2654ec1c86e013efb84ded6e01af28f 100644 (file)
@@ -5195,6 +5195,9 @@ class admin_setting_manageportfolio extends admin_setting {
         $instances = portfolio_instances(false, false);
         $alreadyplugins = array();
 
+        // to avoid notifications being sent out while admin is editing the page
+        define('ADMIN_EDITING_PORTFOLIO', true);
+
         $insane = portfolio_plugin_sanity_check($plugins);
         $insaneinstances = portfolio_instance_sanity_check($instances);
 
index e7fa61053f834dabbcb4871c27cfd1a49e3a1b16..2304d7a16697c975b941bab7b4564788844e6639 100644 (file)
@@ -371,6 +371,8 @@ function portfolio_instance_select($instances, $callerformats, $callbackclass, $
     }
 
     $insane = portfolio_instance_sanity_check();
+    $pinsane = portfolio_plugin_sanity_check();
+
     $count = 0;
     $selectoutput = "\n" . '<select name="' . $selectname . '">' . "\n";
     foreach ($instances as $instance) {
@@ -381,7 +383,11 @@ function portfolio_instance_select($instances, $callerformats, $callbackclass, $
         }
         if (array_key_exists($instance->get('id'), $insane)) {
             // bail, plugin is misconfigured
-            debugging(get_string('instancemisconfigured', 'portfolio', get_string($insane[$instance->get('id')], 'portfolio_' . $instance->get('plugin'))));
+            debugging(get_string('instanceismisconfigured', 'portfolio', get_string($insane[$instance->get('id')], 'portfolio_' . $instance->get('plugin'))));
+            continue;
+        } else if (array_key_exists($instance->get('plugin'), $pinsane)) {
+            // bail, plugin is misconfigured
+            debugging(get_string('pluginismisconfigured', 'portfolio', get_string($pinsane[$instance->get('plugin')], 'portfolio_' . $instance->get('plugin'))));
             continue;
         }
         $count++;
@@ -651,6 +657,7 @@ function portfolio_plugin_sanity_check($plugins=null) {
     list($where, $params) = $DB->get_in_or_equal(array_keys($insane));
     $where = ' plugin ' . $where;
     $DB->set_field_select('portfolio_instance', 'visible', 0, $where, $params);
+    portfolio_insane_notify_admins($insane);
     return $insane;
 }
 
@@ -691,6 +698,7 @@ function portfolio_instance_sanity_check($instances=null) {
     list ($where, $params) = $DB->get_in_or_equal(array_keys($insane));
     $where = ' id ' . $where;
     $DB->set_field_select('portfolio_instance', 'visible', 0, $where, $params);
+    portfolio_insane_notify_admins($insane, true);
     return $insane;
 }
 
@@ -899,4 +907,59 @@ function portfolio_expected_time_db($recordcount) {
     return PORTFOLIO_TIME_HIGH;
 }
 
+function portfolio_insane_notify_admins($insane, $instances=false) {
+
+    global $CFG;
+
+    if (defined('ADMIN_EDITING_PORTFOLIO')) {
+        return true;
+    }
+
+    $admins = get_admins();
+
+    if (empty($admins)) {
+        return;
+    }
+    if ($instances) {
+        $instances = portfolio_instances(false, false);
+    }
+
+    $site = get_site();
+
+    $a = new StdClass;
+    $a->sitename = $site->fullname;
+    $a->fixurl   = $CFG->wwwroot . '/admin/settings.php?section=manageportfolios';
+    $a->htmllist = portfolio_report_insane($insane, $instances, true);
+    $a->textlist = '';
+
+    foreach ($insane as $k => $reason) {
+        if ($instances) {
+            $a->textlist = $instances[$k]->get('name') . ': ' . $reason . "\n";
+        } else {
+            $a->textlist = $k . ': ' . $reason . "\n";
+        }
+    }
+
+    $subject   = get_string('insanesubject', 'portfolio');
+    $plainbody = get_string('insanebody', 'portfolio', $a);
+    $htmlbody  = get_string('insanebodyhtml', 'portfolio', $a);
+    $smallbody = get_string('insanebodysmall', 'portfolio', $a);
+
+    foreach ($admins as $admin) {
+        $eventdata = new object();
+        $eventdata->modulename = 'portfolio';
+        $eventdata->component = 'portfolio';
+        $eventdata->name = 'notices';
+        $eventdata->userfrom = $admin;
+        $eventdata->userto = $admin;
+        $eventdata->subject = $subject;
+        $eventdata->fullmessage = $plainbody;
+        $eventdata->fullmessageformat = FORMAT_PLAIN;
+        $eventdata->fullmessagehtml = $htmlbody;
+        $eventdata->smallmessage = $smallbody;
+        error_log(print_r($eventdata, true));
+        events_trigger('message_send', $eventdata);
+    }
+}
+
 ?>