MDL-63279 messaging: Add admin setting for toggling site-wide messaging
authorAmaia Anabitarte <amaia@moodle.com>
Wed, 5 Sep 2018 17:17:23 +0000 (18:17 +0100)
committerAmaia Anabitarte <amaia@moodle.com>
Fri, 14 Sep 2018 11:20:18 +0000 (13:20 +0200)
admin/settings/subsystems.php
lang/en/admin.php
lib/db/upgrade.php
version.php

index f2b50d5..dce0ecf 100644 (file)
@@ -15,6 +15,12 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
 
     $optionalsubsystems->add(new admin_setting_configcheckbox('messaging', new lang_string('messaging', 'admin'), new lang_string('configmessaging','admin'), 1));
 
+    $optionalsubsystems->add(new admin_setting_configcheckbox('messagingallusers',
+        new lang_string('messagingallusers', 'admin'),
+        new lang_string('configmessagingallusers', 'admin'),
+        0)
+    );
+
     $optionalsubsystems->add(new admin_setting_configcheckbox('messaginghidereadnotifications', new lang_string('messaginghidereadnotifications', 'admin'), new lang_string('configmessaginghidereadnotifications','admin'), 0));
 
     $options = array(DAYSECS=>new lang_string('secondstotime86400'), WEEKSECS=>new lang_string('secondstotime604800'), 2620800=>new lang_string('nummonths', 'moodle', 1), 15724800=>new lang_string('nummonths', 'moodle', 6),0=>new lang_string('never'));
index 740b253..cffe2bb 100644 (file)
@@ -272,10 +272,11 @@ $string['configmaxbytes'] = 'This specifies a maximum size for files uploaded to
 $string['configmaxconsecutiveidentchars'] = 'Passwords must not have more than this number of consecutive identical characters. Use 0 to disable this check.';
 $string['configmaxeditingtime'] = 'This specifies the amount of time people have to re-edit forum postings, glossary comments etc.  Usually 30 minutes is a good value.';
 $string['configmaxevents'] = 'Events to Lookahead';
-$string['configmessaging'] = 'Should the messaging system between site users be enabled?';
+$string['configmessaging'] = 'If enabled, users can send messages to other users on the site.';
 $string['configmessagingallowemailoverride'] = 'Allow users to have email message notifications sent to an email address other than the email address in their profile';
 $string['configmessaginghidereadnotifications'] = 'Hide read notifications of events like forum posts when viewing messaging history';
 $string['configmessagingdeletereadnotificationsdelay'] = 'Read notifications can be deleted to save space. How long after a notification is read can it be deleted?';
+$string['configmessagingallusers'] = 'If enabled, users can choose to allow anyone on the site to send them a message. Otherwise, users can choose to allow only their contacts or others in their courses to send them messages.';
 $string['configminpassworddigits'] = 'Passwords must have at least these many digits.';
 $string['configminpasswordlength'] = 'Passwords must be at least these many characters long.';
 $string['configminpasswordlower'] = 'Passwords must have at least these many lower case letters.';
@@ -748,6 +749,7 @@ $string['mediapluginyoutube'] = 'Enable YouTube links filter';
 $string['messaging'] = 'Enable messaging system';
 $string['messagingallowemailoverride'] = 'Notification email override';
 $string['messaginghidereadnotifications'] = 'Hide read notifications';
+$string['messagingallusers'] = 'Allow messages from anyone on the site';
 $string['messagingdeletereadnotificationsdelay'] = 'Delete read notifications';
 $string['minpassworddigits'] = 'Digits';
 $string['minpasswordlength'] = 'Password length';
index df3883a..fca6c1c 100644 (file)
@@ -2329,12 +2329,28 @@ function xmldb_main_upgrade($oldversion) {
     }
 
     if ($oldversion < 2018091200.00) {
-        if (!file_exists($CFG->dirroot.'/cache/stores/memcache/settings.php')) {
+        if (!file_exists($CFG->dirroot . '/cache/stores/memcache/settings.php')) {
             unset_all_config_for_plugin('cachestore_memcache');
         }
 
         upgrade_main_savepoint(true, 2018091200.00);
     }
 
+    if ($oldversion < 2018091400.01) {
+        if (!isset($CFG->messagingallusers)) {
+            // For existing instances, $CFG->messagingallusers would be same value $CFG->messaging has.
+            if (isset($CFG->messaging)) {
+                set_config('messagingallusers', $CFG->messaging);
+            } else {
+                // When $CFG->messaging is not set, default value for $CFG->messaging should be true,
+                // so $CFG->messagingallusers value should be true as well.
+                set_config('messagingallusers', 1);
+            }
+        }
+
+        // Main savepoint reached.
+        upgrade_main_savepoint(true, 2018091400.01);
+    }
+
     return true;
 }
index a92f3b5..5787a6e 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2018091400.00;              // YYYYMMDD      = weekly release date of this DEV branch.
+$version  = 2018091400.01;              // YYYYMMDD      = weekly release date of this DEV branch.
                                         //         RR    = release increments - 00 in DEV branches.
                                         //           .XX = incremental changes.