From 8e4c1a80b4ed52547d35a036b76dd7bc7377f3e3 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 17 Sep 2011 14:49:34 +0200 Subject: [PATCH] MDL-29029 move blog upgrade to admin tools AMOS BEGIN MOV [bloglevelupgrade,core_admin],[pluginname,tool_bloglevelupgrade] MOV [bloglevelupgradedescription,core_admin],[bloglevelupgradedescription,tool_bloglevelupgrade] MOV [bloglevelupgradeinfo,core_admin],[bloglevelupgradeinfo,tool_bloglevelupgrade] MOV [bloglevelupgradeprogress,core_admin],[bloglevelupgradeprogress,tool_bloglevelupgrade] AMOS END --- admin/index.php | 6 -- admin/settings/server.php | 1 - admin/tool/bloglevelupgrade/db/install.php | 64 +++++++++++++++++++ .../bloglevelupgrade/index.php} | 42 +++++++++--- .../lang/en/tool_bloglevelupgrade.php | 33 ++++++++++ admin/tool/bloglevelupgrade/settings.php | 30 +++++++++ admin/tool/bloglevelupgrade/version.php | 30 +++++++++ lang/en/admin.php | 9 --- lib/db/upgrade.php | 16 +---- lib/pluginlib.php | 2 +- 10 files changed, 191 insertions(+), 42 deletions(-) create mode 100644 admin/tool/bloglevelupgrade/db/install.php rename admin/{bloglevelupgrade.php => tool/bloglevelupgrade/index.php} (77%) create mode 100644 admin/tool/bloglevelupgrade/lang/en/tool_bloglevelupgrade.php create mode 100644 admin/tool/bloglevelupgrade/settings.php create mode 100644 admin/tool/bloglevelupgrade/version.php diff --git a/admin/index.php b/admin/index.php index 232924828ea..9a54e70f5bc 100644 --- a/admin/index.php +++ b/admin/index.php @@ -445,12 +445,6 @@ if (time() - $lastcron > 3600 * 24) { echo $OUTPUT->box(get_string('cronwarning', 'admin').' '.$helpbutton, 'generalbox adminwarning'); } -// Hidden bloglevel upgrade -$showbloglevelupgrade = ($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) && empty($CFG->bloglevel_upgrade_complete); -if ($showbloglevelupgrade) { - echo $OUTPUT->box(get_string('bloglevelupgradenotice', 'admin'), 'generalbox adminwarning'); -} - // diagnose DB, especially the sloppy MyISAM tables $diagnose = $DB->diagnose(); if ($diagnose !== NULL) { diff --git a/admin/settings/server.php b/admin/settings/server.php index 0348cd39251..884681958cb 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -220,6 +220,5 @@ $ADMIN->add('server', $temp); $ADMIN->add('server', new admin_externalpage('adminregistration', get_string('registration','admin'), "$CFG->wwwroot/$CFG->admin/registration/index.php")); -$ADMIN->add('root', new admin_externalpage('bloglevelupgrade', get_string('bloglevelupgrade', 'admin'), $CFG->wwwroot.'/'.$CFG->admin.'/blocklevelupgrade.php', 'moodle/site:config', true)); } // end of speedup diff --git a/admin/tool/bloglevelupgrade/db/install.php b/admin/tool/bloglevelupgrade/db/install.php new file mode 100644 index 00000000000..758e09dfea1 --- /dev/null +++ b/admin/tool/bloglevelupgrade/db/install.php @@ -0,0 +1,64 @@ +. + +/** + * 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; + + // this is a hack - admins were long ago instructed to upgrade blog levels, + // the problem is that blog is not supposed to be course level activity!! + + if (!empty($CFG->bloglevel_upgrade_complete)) { + // somebody already upgrades, we do not need this any more + unset_config('bloglevel_upgrade_complete'); + return; + } + + if (!isset($CFG->bloglevel)) { + // fresh install? + return; + } + + if (($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL)) { + // inform admins that some settings require attention after upgrade + $site = get_site(); + + $a = new StdClass; + $a->sitename = $site->fullname; + $a->fixurl = "$CFG->wwwroot/$CFG->admin/tool/bloglevelupgrade/index.php"; + + $subject = get_string('bloglevelupgrade', 'tool_bloglevelupgrade'); + $description = get_string('bloglevelupgradedescription', 'tool_bloglevelupgrade', $a); + + // can not use messaging here because it is not configured yet! + upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description); + set_config('tool_bloglevelupgrade_pending', 1); + + echo $OUTPUT->notification($description); + } +} + + diff --git a/admin/bloglevelupgrade.php b/admin/tool/bloglevelupgrade/index.php similarity index 77% rename from admin/bloglevelupgrade.php rename to admin/tool/bloglevelupgrade/index.php index 0c069c12011..9c87eec8227 100644 --- a/admin/bloglevelupgrade.php +++ b/admin/tool/bloglevelupgrade/index.php @@ -1,27 +1,49 @@ . + +/** + * 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_once('../config.php'); +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('bloglevelupgrade'); +admin_externalpage_setup('toolbloglevelupgrade'); $PAGE->set_pagelayout('maintenance'); $go = optional_param('go', 0, PARAM_BOOL); echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('bloglevelupgrade', 'admin')); +echo $OUTPUT->heading(get_string('pluginname', 'tool_bloglevelupgrade')); -$strbloglevelupgrade = get_string('bloglevelupgradeinfo', 'admin'); +$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('bloglevelupgrade.php', $optionsyes), 'index.php'); + echo $OUTPUT->confirm($strbloglevelupgrade, new moodle_url('/admin/tool/bloglevelupgrade/index.php', $optionsyes), new moodle_url('/admin/index.php')); echo $OUTPUT->footer(); die; } @@ -38,7 +60,7 @@ $i = 0; // 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('bloglevelupgrade', 500, true); + $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'); @@ -72,7 +94,7 @@ if ($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) } $a->userscount = $i . '/' . count($bloggers); - $pbar->update($i, count($bloggers), get_string('bloglevelupgradeprogress', 'admin', $a)); + $pbar->update($i, count($bloggers), get_string('bloglevelupgradeprogress', 'tool_bloglevelupgrade', $a)); $i++; } } @@ -135,7 +157,7 @@ function bloglevelupgrade_entries($blogentries, $forum, $cm, $groupid=-1) { // END OF LOOP // set conversion flag - switches to new plugin automatically -set_config('bloglevel_upgrade_complete', 1); +unset_config('tool_bloglevelupgrade_pending'); // Finally switch bloglevel to 0 (disabled) set_config('bloglevel', 0); @@ -146,7 +168,7 @@ echo $OUTPUT->notification('Rebuilding course cache...', 'notifysuccess'); rebuild_course_cache(); echo $OUTPUT->notification('...finished', 'notifysuccess'); -echo $OUTPUT->continue_button('index.php'); +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 new file mode 100644 index 00000000000..b73749e6e1a --- /dev/null +++ b/admin/tool/bloglevelupgrade/lang/en/tool_bloglevelupgrade.php @@ -0,0 +1,33 @@ +. + +/** + * 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 new file mode 100644 index 00000000000..646126fcde4 --- /dev/null +++ b/admin/tool/bloglevelupgrade/settings.php @@ -0,0 +1,30 @@ +. + +/** + * 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 new file mode 100644 index 00000000000..f69babd8d9d --- /dev/null +++ b/admin/tool/bloglevelupgrade/version.php @@ -0,0 +1,30 @@ +. + +/** + * 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 = 2011091700; // The current plugin version (Date: YYYYMMDDXX) +$plugin->requires = 2011091600; // Requires this Moodle version +$plugin->component = 'tool_bloglevelupgrade'; // Full name of the plugin (used for diagnostics) diff --git a/lang/en/admin.php b/lang/en/admin.php index 5b8622c7b3a..264be023330 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -79,15 +79,6 @@ $string['blockprotect_help'] = 'Selected block instances will be protected from $string['blockunprotect'] = 'Unprotect'; $string['blocksettings'] = 'Manage blocks'; $string['bloglevel'] = 'Blog visibility'; -$string['bloglevelupgrade'] = 'Blog visibility upgrade'; -$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['bloglevelupgradenotice'] = 'Your site is using an old blog visibility setting, the blog visibility upgrade is recommended.'; -$string['bloglevelupgradeprogress'] = 'Conversion progress: {$a->userscount} users reviewed, {$a->blogcount} entries converted.'; $string['bookmarkadded'] = 'Bookmark added.'; $string['bookmarkalreadyexists'] = 'You have already bookmarked this page.'; $string['bookmarkdeleted'] = 'Bookmark deleted.'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 2df6246fd40..9be33f8a1cc 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2338,22 +2338,8 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); } $dbman->create_table($table); - // now inform admins that some settings require attention after upgrade - if (($CFG->bloglevel == BLOG_COURSE_LEVEL || $CFG->bloglevel == BLOG_GROUP_LEVEL) && empty($CFG->bloglevel_upgrade_complete)) { - echo $OUTPUT->notification(get_string('bloglevelupgradenotice', 'admin')); + // upgrade notice is now in admin/tool/bloglevelupgrade/ - $site = get_site(); - - $a = new StdClass; - $a->sitename = $site->fullname; - $a->fixurl = "$CFG->wwwroot/$CFG->admin/bloglevelupgrade.php"; - - $subject = get_string('bloglevelupgrade', 'admin'); - $description = get_string('bloglevelupgradedescription', 'admin', $a); - - // can not use messaging here because it is not configured yet! - upgrade_log(UPGRADE_LOG_NOTICE, null, $subject, $description); - } /// Main savepoint reached upgrade_main_savepoint(true, 2009103000); } diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 19945770df1..d09d629e0f0 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -367,7 +367,7 @@ class plugin_manager { ), 'tool' => array( - 'capability', 'generator', 'profiling', 'unittest', 'unsuproles' + 'bloglevelupgrade', 'capability', 'generator', 'profiling', 'unittest', 'unsuproles' ), 'webservice' => array(