From db9d7be6022b2552342948b58c357596248140a9 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 19 Jul 2012 11:20:19 +0800 Subject: [PATCH 1/3] MDL-25012 blogs: Remove bloglevelupgrade tool This was used for 1.9->2.x upgrade and is not longer relevant. --- admin/tool/bloglevelupgrade/db/install.php | 33 ---- admin/tool/bloglevelupgrade/index.php | 174 ------------------ .../lang/en/tool_bloglevelupgrade.php | 33 ---- admin/tool/bloglevelupgrade/settings.php | 30 --- admin/tool/bloglevelupgrade/version.php | 30 --- lib/pluginlib.php | 2 +- 6 files changed, 1 insertion(+), 301 deletions(-) delete mode 100644 admin/tool/bloglevelupgrade/db/install.php delete mode 100644 admin/tool/bloglevelupgrade/index.php delete mode 100644 admin/tool/bloglevelupgrade/lang/en/tool_bloglevelupgrade.php delete mode 100644 admin/tool/bloglevelupgrade/settings.php delete mode 100644 admin/tool/bloglevelupgrade/version.php diff --git a/admin/tool/bloglevelupgrade/db/install.php b/admin/tool/bloglevelupgrade/db/install.php deleted file mode 100644 index cdff384e77d..00000000000 --- a/admin/tool/bloglevelupgrade/db/install.php +++ /dev/null @@ -1,33 +0,0 @@ -. - -/** - * Post installation and migration code. - * - * @package tool - * @subpackage bloglevelupgrade - * @copyright 2011 Petr Skoda {@link http://skodak.org} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die; - -function xmldb_tool_bloglevelupgrade_install() { - global $CFG, $OUTPUT; - -} - - diff --git a/admin/tool/bloglevelupgrade/index.php b/admin/tool/bloglevelupgrade/index.php deleted file mode 100644 index 823f2109194..00000000000 --- a/admin/tool/bloglevelupgrade/index.php +++ /dev/null @@ -1,174 +0,0 @@ -. - -/** - * Create "blog" forums in each course and copy blog entries from these courses' participants in these forums - * - * @package tool - * @subpackage bloglevelupgrade - * @copyright 2009 Nicolas Connault - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -define('NO_OUTPUT_BUFFERING', true); - -require('../../../config.php'); -require_once($CFG->dirroot.'/course/lib.php'); -require_once($CFG->dirroot.'/blog/lib.php'); -require_once($CFG->dirroot.'/mod/forum/lib.php'); -require_once($CFG->libdir.'/adminlib.php'); - -admin_externalpage_setup('toolbloglevelupgrade'); -$PAGE->set_pagelayout('maintenance'); - -$go = optional_param('go', 0, PARAM_BOOL); - -echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('pluginname', 'tool_bloglevelupgrade')); - -$strbloglevelupgrade = get_string('bloglevelupgradeinfo', 'tool_bloglevelupgrade'); - -if (!$go or !data_submitted() or !confirm_sesskey()) { /// Print a form - $optionsyes = array('go'=>1, 'sesskey'=>sesskey()); - echo $OUTPUT->confirm($strbloglevelupgrade, new moodle_url('/admin/tool/bloglevelupgrade/index.php', $optionsyes), new moodle_url('/admin/index.php')); - echo $OUTPUT->footer(); - die; -} - -echo $OUTPUT->box_start(); - -/// Turn off time limits, sometimes upgrades can be slow. - -set_time_limit(0); - -$i = 0; - -// If $CFG->bloglevel is set to BLOG_GROUP_LEVEL or BLOG_COURSE_LEVEL, create a new "blog" forum in each course -// whose enrolled students have written blog entries, copy these entries in that forum and switch off blogs at site level - -if ($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) { - $pbar = new progress_bar('toolbloglevelupgrade', 500, true); - - $bloggers = $DB->get_records_sql("SELECT userid FROM {post} WHERE module = 'blog' GROUP BY userid"); - require_once($CFG->dirroot.'/mod/forum/lib.php'); - - $a = new stdClass(); - $a->userscount = 0; - $a->blogcount = 0; - - foreach ($bloggers as $blogger) { - $courses = enrol_get_users_courses($blogger->userid, true, 'groupmode,groupmodeforce'); - $blogentries = $DB->get_records('post', array('module' => 'blog', 'userid' => $blogger->userid)); - - foreach ($courses as $course) { - $forum = forum_get_course_forum($course->id, 'blog'); - $cm = get_coursemodule_from_instance('forum', $forum->id); - - if ($CFG->bloglevel == BLOG_GROUP_LEVEL && $course->groupmode != NOGROUPS) { - // Unless the course is set to separate groups forced, force the forum to Separate groups - if (!($course->groupmode == SEPARATEGROUPS && $course->groupmodeforce)) { - $cm->groupmode = SEPARATEGROUPS; - $DB->update_record('course_modules', $cm); - } - - $groups = groups_get_user_groups($course->id, $blogger->userid); - foreach ($groups[0] as $groupid) { // [0] is for all groupings combined - $a->blogcount += bloglevelupgrade_entries($blogentries, $forum, $cm, $groupid); - } - } else { - $a->blogcount += bloglevelupgrade_entries($blogentries, $forum, $cm); - } - } - - $a->userscount = $i . '/' . count($bloggers); - $pbar->update($i, count($bloggers), get_string('bloglevelupgradeprogress', 'tool_bloglevelupgrade', $a)); - $i++; - } -} - -function bloglevelupgrade_entries($blogentries, $forum, $cm, $groupid=-1) { - $count = 0; - - $forumcontext = context_module::instance($cm->id); - $sitecontext = context_system::instance(); - - foreach ($blogentries as $blogentry) { - $discussion = new stdClass(); - $discussion->course = $forum->course; - $discussion->forum = $forum->id; - $discussion->name = $blogentry->subject; - $discussion->assessed = $forum->assessed; - $discussion->message = $blogentry->summary; - $discussion->messageformat = $blogentry->summaryformat; - $discussion->messagetrust = 0; - $discussion->attachments = 0; - $discussion->mailnow = false; - $discussion->timemodified = $blogentry->created; - $discussion->itemid = null; - $discussion->groupid = $groupid; - $message = ''; - - $discussionid = forum_add_discussion($discussion, null, $message, $blogentry->userid); - - // Copy file attachment records - $fs = get_file_storage(); - $files = $fs->get_area_files($sitecontext->id, 'blog', 'attachment', $blogentry->id); - - if (!empty($files)) { - foreach ($files as $storedfile) { - $newfile = new stdClass(); - $newfile->component = 'mod_forum'; - $newfile->filearea = 'attachment'; - $newfile->itemid = $discussion->firstpost; - $newfile->contextid = $forumcontext->id; - $fs->create_file_from_storedfile($newfile, $storedfile->get_id()); - } - } - - $files = $fs->get_area_files($sitecontext->id, 'blog', 'post', $blogentry->id); - - if (!empty($files)) { - foreach ($files as $storedfile) { - $newfile = new stdClass(); - $newfile->component = 'mod_forum'; - $newfile->filearea = 'post'; - $newfile->itemid = $discussion->firstpost; - $newfile->contextid = $forumcontext->id; - $fs->create_file_from_storedfile($newfile, $storedfile->get_id()); - } - } - $count++; - } - return $count; -} -// END OF LOOP - -// set conversion flag - switches to new plugin automatically -unset_config('tool_bloglevelupgrade_pending'); -// Finally switch bloglevel to 0 (disabled) -set_config('bloglevel', 0); - -echo $OUTPUT->box_end(); - -/// Rebuild course cache which might be incorrect now -echo $OUTPUT->notification('Rebuilding course cache...', 'notifysuccess'); -rebuild_course_cache(); -echo $OUTPUT->notification('...finished', 'notifysuccess'); - -echo $OUTPUT->continue_button(new moodle_url('/admin/index.php')); - -echo $OUTPUT->footer(); -die; diff --git a/admin/tool/bloglevelupgrade/lang/en/tool_bloglevelupgrade.php b/admin/tool/bloglevelupgrade/lang/en/tool_bloglevelupgrade.php deleted file mode 100644 index b73749e6e1a..00000000000 --- a/admin/tool/bloglevelupgrade/lang/en/tool_bloglevelupgrade.php +++ /dev/null @@ -1,33 +0,0 @@ -. - -/** - * Strings for component 'tool_bloglevelupgrade', language 'en', branch 'MOODLE_22_STABLE' - * - * @package tool - * @subpackage bloglevelupgrade - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$string['bloglevelupgradedescription'] = '

This site has recently been upgraded to Moodle 2.0.

-

Blog visibility was simplified in 2.0, but your site still uses one of the old visibility types.

-

To preserve the course-based or group-based visibility of the blog entries on your site, you need to run the following upgrade script, which will create a special "blog" type forum in each course whose enrolled users have posted blog entries, and will copy these blog entries in this special forum.

-

Blogs will then be entirely switched off at the site level. No blog entries will be deleted in the process.

-

You can run the script by visiting the blog level upgrade page.

'; -$string['bloglevelupgradeinfo'] = 'Blog visibility was simplified in 2.0, but your site still uses one of the old visibility types. To preserve the course-based or group-based visibility of the blog entries on your site, the following upgrade script will create a special "blog" type forum in each course whose enrolled users have posted blog entries, and will copy these blog entries in this special forum. Blogs will then be entirely switched off at the site level. No blog entries will be deleted in the process.'; -$string['bloglevelupgradeprogress'] = 'Conversion progress: {$a->userscount} users reviewed, {$a->blogcount} entries converted.'; -$string['pluginname'] = 'Blog visibility upgrade'; diff --git a/admin/tool/bloglevelupgrade/settings.php b/admin/tool/bloglevelupgrade/settings.php deleted file mode 100644 index 646126fcde4..00000000000 --- a/admin/tool/bloglevelupgrade/settings.php +++ /dev/null @@ -1,30 +0,0 @@ -. - -/** - * Capability overview settings - * - * @package tool - * @subpackage bloglevelupgrade - * @copyright 2011 Petr Skoda - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die; - -if ($hassiteconfig) { - $ADMIN->add('root', new admin_externalpage('toolbloglevelupgrade', get_string('pluginname', 'tool_bloglevelupgrade'), $CFG->wwwroot.'/'.$CFG->admin.'/tool/bloglevelupgrade/index.php', 'moodle/site:config', empty($CFG->tool_bloglevelupgrade_pending))); -} diff --git a/admin/tool/bloglevelupgrade/version.php b/admin/tool/bloglevelupgrade/version.php deleted file mode 100644 index 92585d6a29b..00000000000 --- a/admin/tool/bloglevelupgrade/version.php +++ /dev/null @@ -1,30 +0,0 @@ -. - -/** - * Version details. - * - * @package tool - * @subpackage bloglevelupgrade - * @copyright 2011 Petr Skoda - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -$plugin->version = 2012061700; // The current plugin version (Date: YYYYMMDDXX) -$plugin->requires = 2012061700; // Requires this Moodle version -$plugin->component = 'tool_bloglevelupgrade'; // Full name of the plugin (used for diagnostics) diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 43de5106d6a..0653f37ec27 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -527,7 +527,7 @@ class plugin_manager { ), 'tool' => array( - 'assignmentupgrade', 'bloglevelupgrade', 'capability', 'customlang', 'dbtransfer', 'generator', + 'assignmentupgrade', 'capability', 'customlang', 'dbtransfer', 'generator', 'health', 'innodb', 'langimport', 'multilangupgrade', 'phpunit', 'profiling', 'qeupgradehelper', 'replace', 'spamcleaner', 'timezoneimport', 'unittest', 'uploaduser', 'unsuproles', 'xmldb' From 850d2db82af5570d252d1e68e79bc8b0e877c733 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 19 Jul 2012 11:30:05 +0800 Subject: [PATCH 2/3] MDL-25012 - blogs: introduce a specific 'enabled' config setting Rather than overloading the $CFG->bloglevel setting which had a confusing UI in the appearance subsystem. In order to achieve this we modify take the defaults from the existing bloglevel setting and set that for $CFG->enableblogs. Note that in order to prevent a bad default settings from being set we also set $CFG->bloglevel to a valid 'enabled' setting. --- admin/settings/appearance.php | 3 +-- admin/settings/subsystems.php | 6 +----- blocks/blog_menu/block_blog_menu.php | 2 +- blocks/blog_recent/block_blog_recent.php | 2 +- blog/edit.php | 2 +- blog/index.php | 2 +- blog/lib.php | 7 +++---- blog/locallib.php | 2 +- blog/preferences.php | 2 +- lang/en/admin.php | 2 ++ lang/en/blog.php | 1 - lib/cronlib.php | 4 ++-- lib/db/upgrade.php | 20 ++++++++++++++++++++ lib/filelib.php | 2 +- lib/navigationlib.php | 6 +++--- version.php | 2 +- 16 files changed, 40 insertions(+), 25 deletions(-) diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 9995af38048..212554b0950 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -75,8 +75,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $temp->add(new admin_setting_configcheckbox('useblogassociations', new lang_string('useblogassociations', 'blog'), new lang_string('configuseblogassociations','blog'), 1)); $temp->add(new admin_setting_bloglevel('bloglevel', new lang_string('bloglevel', 'admin'), new lang_string('configbloglevel', 'admin'), 4, array(BLOG_GLOBAL_LEVEL => new lang_string('worldblogs','blog'), BLOG_SITE_LEVEL => new lang_string('siteblogs','blog'), - BLOG_USER_LEVEL => new lang_string('personalblogs','blog'), - 0 => new lang_string('disableblogs','blog')))); + BLOG_USER_LEVEL => new lang_string('personalblogs','blog')))); $temp->add(new admin_setting_configcheckbox('useexternalblogs', new lang_string('useexternalblogs', 'blog'), new lang_string('configuseexternalblogs','blog'), 1)); $temp->add(new admin_setting_configselect('externalblogcrontime', new lang_string('externalblogcrontime', 'blog'), new lang_string('configexternalblogcrontime', 'blog'), 86400, array(43200 => new lang_string('numhours', '', 12), diff --git a/admin/settings/subsystems.php b/admin/settings/subsystems.php index 0e629b805c0..0d3db2ed1d2 100644 --- a/admin/settings/subsystems.php +++ b/admin/settings/subsystems.php @@ -26,11 +26,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $optionalsubsystems->add(new admin_setting_configcheckbox('enablerssfeeds', new lang_string('enablerssfeeds', 'admin'), new lang_string('configenablerssfeeds', 'admin'), 0)); - $optionalsubsystems->add(new admin_setting_bloglevel('bloglevel', new lang_string('bloglevel', 'admin'), - new lang_string('configbloglevel', 'admin'), 4, array(5 => new lang_string('worldblogs','blog'), - 4 => new lang_string('siteblogs','blog'), - 1 => new lang_string('personalblogs','blog'), - 0 => new lang_string('disableblogs','blog')))); + $optionalsubsystems->add(new admin_setting_configcheckbox('enableblogs', new lang_string('enableblogs', 'admin'), new lang_string('configenableblogs', 'admin'), 1)); $options = array('off'=>new lang_string('off', 'mnet'), 'strict'=>new lang_string('on', 'mnet')); $optionalsubsystems->add(new admin_setting_configselect('mnet_dispatcher_mode', new lang_string('net', 'mnet'), new lang_string('configmnet', 'mnet'), 'off', $options)); diff --git a/blocks/blog_menu/block_blog_menu.php b/blocks/blog_menu/block_blog_menu.php index c85576a0f26..bdbe4573830 100644 --- a/blocks/blog_menu/block_blog_menu.php +++ b/blocks/blog_menu/block_blog_menu.php @@ -58,7 +58,7 @@ class block_blog_menu extends block_base { return $this->content; } - if (empty($CFG->bloglevel)) { + if (empty($CFG->enableblogs)) { $this->content = new stdClass(); $this->content->text = ''; if ($this->page->user_is_editing()) { diff --git a/blocks/blog_recent/block_blog_recent.php b/blocks/blog_recent/block_blog_recent.php index fe6c970c8fe..1bee81e6c96 100644 --- a/blocks/blog_recent/block_blog_recent.php +++ b/blocks/blog_recent/block_blog_recent.php @@ -52,7 +52,7 @@ class block_blog_recent extends block_base { } // verify blog is enabled - if (empty($CFG->bloglevel)) { + if (empty($CFG->enableblogs)) { $this->content = new stdClass(); $this->content->text = ''; if ($this->page->user_is_editing()) { diff --git a/blog/edit.php b/blog/edit.php index 3ed91554cdb..d39ec414c13 100644 --- a/blog/edit.php +++ b/blog/edit.php @@ -69,7 +69,7 @@ if ($action == 'edit') { $id = required_param('entryid', PARAM_INT); } -if (empty($CFG->bloglevel)) { +if (empty($CFG->enableblogs)) { print_error('blogdisable', 'blog'); } diff --git a/blog/index.php b/blog/index.php index feb320e9cbd..94bc527cfcb 100644 --- a/blog/index.php +++ b/blog/index.php @@ -34,7 +34,7 @@ foreach ($url_params as $var => $val) { } $PAGE->set_url('/blog/index.php', $url_params); -if (empty($CFG->bloglevel)) { +if (empty($CFG->enableblogs)) { print_error('blogdisable', 'blog'); } diff --git a/blog/lib.php b/blog/lib.php index 764fc64a060..280102965b0 100644 --- a/blog/lib.php +++ b/blog/lib.php @@ -64,7 +64,7 @@ function blog_user_can_edit_entry($blogentry) { function blog_user_can_view_user_entry($targetuserid, $blogentry=null) { global $CFG, $USER, $DB; - if (empty($CFG->bloglevel)) { + if (empty($CFG->enableblogs)) { return false; // blog system disabled } @@ -349,8 +349,7 @@ function blog_get_context_url($context=null) { */ function blog_is_enabled_for_user() { global $CFG; - //return (!empty($CFG->bloglevel) && $CFG->bloglevel <= BLOG_GLOBAL_LEVEL && isloggedin() && !isguestuser()); - return (!empty($CFG->bloglevel) && (isloggedin() || ($CFG->bloglevel == BLOG_GLOBAL_LEVEL))); + return (!empty($CFG->enableblogs) && (isloggedin() || ($CFG->bloglevel == BLOG_GLOBAL_LEVEL))); } /** @@ -406,7 +405,7 @@ function blog_get_all_options(moodle_page $page, stdClass $userid = null) { } // If blog level is global then display a link to view all site entries - if (!empty($CFG->bloglevel) && $CFG->bloglevel >= BLOG_GLOBAL_LEVEL && has_capability('moodle/blog:view', context_system::instance())) { + if (!empty($CFG->enableblogs) && $CFG->bloglevel >= BLOG_GLOBAL_LEVEL && has_capability('moodle/blog:view', context_system::instance())) { $options[CONTEXT_SYSTEM] = array('viewsite' => array( 'string' => get_string('viewsiteentries', 'blog'), 'link' => new moodle_url('/blog/index.php') diff --git a/blog/locallib.php b/blog/locallib.php index 813b6c6a7d8..0356e24abaa 100644 --- a/blog/locallib.php +++ b/blog/locallib.php @@ -602,7 +602,7 @@ class blog_entry { global $CFG, $USER, $DB; $sitecontext = context_system::instance(); - if (empty($CFG->bloglevel) || !has_capability('moodle/blog:view', $sitecontext)) { + if (empty($CFG->enableblogs) || !has_capability('moodle/blog:view', $sitecontext)) { return false; // blog system disabled or user has no blog view capability } diff --git a/blog/preferences.php b/blog/preferences.php index 3ab869b2eaa..9bbc3fcf6c0 100644 --- a/blog/preferences.php +++ b/blog/preferences.php @@ -64,7 +64,7 @@ if ($courseid == SITEID) { $context = context_course::instance($courseid); } -if (empty($CFG->bloglevel)) { +if (empty($CFG->enableblogs)) { print_error('blogdisable', 'blog'); } diff --git a/lang/en/admin.php b/lang/en/admin.php index 9c143985d96..63d3bf4e96e 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -180,6 +180,7 @@ $string['configdefaultuserroleid'] = 'All logged in users will be given the capa $string['configdeleteincompleteusers'] = 'After this period, old not fully setup accounts are deleted.'; $string['configdeleteunconfirmed'] = 'If you are using email authentication, this is the period within which a response will be accepted from users. After this period, old unconfirmed accounts are deleted.'; $string['configdenyemailaddresses'] = 'To deny email addresses from particular domains list them here in the same way. All other domains will be accepted. To deny subdomains add the domain with a preceding \'.\'. eg hotmail.com yahoo.co.uk .live.com'; +$string['configenableblogs'] = 'This switch provides all site users with their own blog.'; $string['configenabledevicedetection'] = 'Enables detection of mobiles, smartphones, tablets or default devices (desktop PCs, laptops, etc) for the application of themes and other features.'; $string['configdisableuserimages'] = 'Disable the ability for users to change user profile images.'; $string['configdisplayloginfailures'] = 'This will display information to selected users about previous failed logins.'; @@ -464,6 +465,7 @@ $string['emoticons_desc'] = 'This form defines the emoticons (or smileys) used a $string['emoticonsreset'] = 'Reset emoticons setting to default values'; $string['emptysettingvalue'] = 'Empty'; $string['enableajax'] = 'Enable AJAX'; +$string['enableblogs'] = 'Enable blogs'; $string['enablecalendarexport'] = 'Enable calendar export'; $string['enablecomments'] = 'Enable comments'; $string['enablecourserequests'] = 'Enable course requests'; diff --git a/lang/en/blog.php b/lang/en/blog.php index 197931e0c15..546753e80ea 100644 --- a/lang/en/blog.php +++ b/lang/en/blog.php @@ -74,7 +74,6 @@ $string['deleteexternalblog'] = 'Unregister this external blog'; $string['deleteotagswarn'] = 'Are you sure you want to remove these tags from all blog posts and remove it from the system?'; $string['description'] = 'Description'; $string['description_help'] = 'Enter a sentence or two summarising the contents of your external blog. (If no description is supplied, the description recorded in your external blog will be used).'; -$string['disableblogs'] = 'Disable blog system completely'; $string['donothaveblog'] = 'You do not have your own blog, sorry.'; $string['editentry'] = 'Edit a blog entry'; $string['editexternalblog'] = 'Edit this external blog'; diff --git a/lib/cronlib.php b/lib/cronlib.php index 8535689effe..7ec99e5c0f0 100644 --- a/lib/cronlib.php +++ b/lib/cronlib.php @@ -352,7 +352,7 @@ function cron_run() { // Run external blog cron if needed - if ($CFG->useexternalblogs) { + if (!empty($CFG->enableblogs) && $CFG->useexternalblogs) { require_once($CFG->dirroot . '/blog/lib.php'); mtrace("Fetching external blog entries...", ''); $sql = "timefetched < ? OR timefetched = 0"; @@ -364,7 +364,7 @@ function cron_run() { mtrace('done.'); } // Run blog associations cleanup - if ($CFG->useblogassociations) { + if (!empty($CFG->enableblogs) && $CFG->useblogassociations) { require_once($CFG->dirroot . '/blog/lib.php'); // delete entries whose contextids no longer exists mtrace("Deleting blog associations linked to non-existent contexts...", ''); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 726428213b3..6079ed35da4 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1081,5 +1081,25 @@ function xmldb_main_upgrade($oldversion) { // Main savepoint reached upgrade_main_savepoint(true, 2012072600.01); } + + if ($oldversion < 2012080600.00) { + // Move the ability to disable blogs to its own setting MDL-25012. + + if (isset($CFG->bloglevel)) { + // Only change settings if existing setting was set. + if (empty($CFG->bloglevel)) { + set_config('enableblogs', 0); + // Now set the bloglevel to a valid setting as the disabled setting has been removed. + // This prevents confusing results when users enable the blog system in future. + set_config('bloglevel', BLOG_USER_LEVEL); + } else { + set_config('enableblogs', 1); + } + } + + // Main savepoint reached + upgrade_main_savepoint(true, 2012080600.00); + } + return true; } diff --git a/lib/filelib.php b/lib/filelib.php index 32df4bceee7..366b1593037 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -3451,7 +3451,7 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) { send_file_not_found(); } - if (empty($CFG->bloglevel)) { + if (empty($CFG->enableblogs)) { print_error('siteblogdisable', 'blog'); } diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 0317445fd87..43dfe9eefb4 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -2296,7 +2296,7 @@ class global_navigation extends navigation_node { } // Add blog nodes - if (!empty($CFG->bloglevel)) { + if (!empty($CFG->enableblogs)) { if (!$this->cache->cached('userblogoptions'.$user->id)) { require_once($CFG->dirroot.'/blog/lib.php'); // Get all options for the user @@ -2658,7 +2658,7 @@ class global_navigation extends navigation_node { $filterselect = 0; // Blogs - if (!empty($CFG->bloglevel) + if (!empty($CFG->enableblogs) and ($CFG->bloglevel == BLOG_GLOBAL_LEVEL or ($CFG->bloglevel == BLOG_SITE_LEVEL and (isloggedin() and !isguestuser()))) and has_capability('moodle/blog:view', context_system::instance())) { $blogsurls = new moodle_url('/blog/index.php', array('courseid' => $filterselect)); @@ -4196,7 +4196,7 @@ class settings_navigation extends navigation_node { } // Blogs - if ($currentuser && !empty($CFG->bloglevel)) { + if ($currentuser && !empty($CFG->enableblogs)) { $blog = $usersetting->add(get_string('blogs', 'blog'), null, navigation_node::TYPE_CONTAINER, null, 'blogs'); $blog->add(get_string('preferences', 'blog'), new moodle_url('/blog/preferences.php'), navigation_node::TYPE_SETTING); if (!empty($CFG->useexternalblogs) && $CFG->maxexternalblogsperuser > 0 && has_capability('moodle/blog:manageexternal', context_system::instance())) { diff --git a/version.php b/version.php index 6f790c025fb..cc69f894e03 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012080200.01; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012080600.00; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes From 6a2a055edc4723a6ef69bfb512ab22b6aa79e7a8 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Thu, 19 Jul 2012 11:51:52 +0800 Subject: [PATCH 3/3] MDL-25012 - blogs: only show the settings page when blogs enabled --- admin/settings/appearance.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 212554b0950..8130da4a9e6 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -71,21 +71,23 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $ADMIN->add('appearance', $temp); // blog - $temp = new admin_settingpage('blog', new lang_string('blog','blog')); - $temp->add(new admin_setting_configcheckbox('useblogassociations', new lang_string('useblogassociations', 'blog'), new lang_string('configuseblogassociations','blog'), 1)); - $temp->add(new admin_setting_bloglevel('bloglevel', new lang_string('bloglevel', 'admin'), new lang_string('configbloglevel', 'admin'), 4, array(BLOG_GLOBAL_LEVEL => new lang_string('worldblogs','blog'), - BLOG_SITE_LEVEL => new lang_string('siteblogs','blog'), - BLOG_USER_LEVEL => new lang_string('personalblogs','blog')))); - $temp->add(new admin_setting_configcheckbox('useexternalblogs', new lang_string('useexternalblogs', 'blog'), new lang_string('configuseexternalblogs','blog'), 1)); - $temp->add(new admin_setting_configselect('externalblogcrontime', new lang_string('externalblogcrontime', 'blog'), new lang_string('configexternalblogcrontime', 'blog'), 86400, - array(43200 => new lang_string('numhours', '', 12), - 86400 => new lang_string('numhours', '', 24), - 172800 => new lang_string('numdays', '', 2), - 604800 => new lang_string('numdays', '', 7)))); - $temp->add(new admin_setting_configtext('maxexternalblogsperuser', new lang_string('maxexternalblogsperuser','blog'), new lang_string('configmaxexternalblogsperuser', 'blog'), 1)); - $temp->add(new admin_setting_configcheckbox('blogusecomments', new lang_string('enablecomments', 'admin'), new lang_string('configenablecomments', 'admin'), 1)); - $temp->add(new admin_setting_configcheckbox('blogshowcommentscount', new lang_string('showcommentscount', 'admin'), new lang_string('configshowcommentscount', 'admin'), 1)); - $ADMIN->add('appearance', $temp); + if (!empty($CFG->enableblogs)) { + $temp = new admin_settingpage('blog', new lang_string('blog','blog')); + $temp->add(new admin_setting_configcheckbox('useblogassociations', new lang_string('useblogassociations', 'blog'), new lang_string('configuseblogassociations','blog'), 1)); + $temp->add(new admin_setting_bloglevel('bloglevel', new lang_string('bloglevel', 'admin'), new lang_string('configbloglevel', 'admin'), 4, array(BLOG_GLOBAL_LEVEL => new lang_string('worldblogs','blog'), + BLOG_SITE_LEVEL => new lang_string('siteblogs','blog'), + BLOG_USER_LEVEL => new lang_string('personalblogs','blog')))); + $temp->add(new admin_setting_configcheckbox('useexternalblogs', new lang_string('useexternalblogs', 'blog'), new lang_string('configuseexternalblogs','blog'), 1)); + $temp->add(new admin_setting_configselect('externalblogcrontime', new lang_string('externalblogcrontime', 'blog'), new lang_string('configexternalblogcrontime', 'blog'), 86400, + array(43200 => new lang_string('numhours', '', 12), + 86400 => new lang_string('numhours', '', 24), + 172800 => new lang_string('numdays', '', 2), + 604800 => new lang_string('numdays', '', 7)))); + $temp->add(new admin_setting_configtext('maxexternalblogsperuser', new lang_string('maxexternalblogsperuser','blog'), new lang_string('configmaxexternalblogsperuser', 'blog'), 1)); + $temp->add(new admin_setting_configcheckbox('blogusecomments', new lang_string('enablecomments', 'admin'), new lang_string('configenablecomments', 'admin'), 1)); + $temp->add(new admin_setting_configcheckbox('blogshowcommentscount', new lang_string('showcommentscount', 'admin'), new lang_string('configshowcommentscount', 'admin'), 1)); + $ADMIN->add('appearance', $temp); + } // Navigation settings $temp = new admin_settingpage('navigation', new lang_string('navigation'));