Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'w22_MDL-25031_m22_blockupgrade' of git://github.com/sko…

…dak/moodle into MOODLE_22_STABLE
  • Loading branch information...
commit 1efdabfb91266d0367ba1751786f9225bc4eafa0 2 parents 57af11e + a7cdeac
@danpoltawski danpoltawski authored
Showing with 26 additions and 2 deletions.
  1. +26 −2 lib/db/upgrade.php
View
28 lib/db/upgrade.php
@@ -1663,6 +1663,8 @@ function xmldb_main_upgrade($oldversion) {
if ($oldversion < 2009050613) {
/// fill in contextid and subpage, and update pagetypepattern from pagetype and pageid
+ upgrade_set_timeout(60*20);
+
/// site-index
$frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID);
$DB->execute("UPDATE {block_instances} SET contextid = " . $frontpagecontext->id . ",
@@ -1670,6 +1672,17 @@ function xmldb_main_upgrade($oldversion) {
subpagepattern = NULL
WHERE pagetypepattern = 'site-index'");
+ /// delete all blocks from incorrectly deleted courses
+ $rs = $DB->get_recordset_sql(
+ "SELECT bi.id
+ FROM {block_instances} bi
+ LEFT JOIN {course} c ON (c.id = bi.pageid)
+ WHERE bi.pagetypepattern = 'course-view' AND c.id IS NULL");
+ foreach ($rs as $bi) {
+ $DB->delete_records('block_instances', array('id'=>$bi->id));
+ }
+ $rs->close();
+
/// course-view
$DB->execute("UPDATE {block_instances} SET
contextid = (
@@ -1727,6 +1740,17 @@ function xmldb_main_upgrade($oldversion) {
if (!$dbman->table_exists($modname)) {
continue;
}
+ /// delete all blocks that belonged to incorrectly deleted activities
+ $rs = $DB->get_recordset_sql(
+ "SELECT bi.id
+ FROM {block_instances} bi
+ LEFT JOIN {{$modname}} m ON (m.id = bi.pageid)
+ WHERE bi.pagetypepattern = 'mod-$modname-view' AND m.id IS NULL");
+ foreach ($rs as $bi) {
+ $DB->delete_records('block_instances', array('id'=>$bi->id));
+ }
+ $rs->close();
+
$DB->execute("UPDATE {block_instances} SET
contextid = (
SELECT {context}.id
@@ -1736,9 +1760,9 @@ function xmldb_main_upgrade($oldversion) {
JOIN {{$modname}} ON {course_modules}.instance = {{$modname}}.id
WHERE {{$modname}}.id = pageid
),
- pagetypepattern = 'blog-index',
+ pagetypepattern = 'mod-$modname-view',
subpagepattern = NULL
- WHERE pagetypepattern = 'blog-view'");
+ WHERE pagetypepattern = 'mod-$modname-view'");
}
/// Main savepoint reached

0 comments on commit 1efdabf

Please sign in to comment.
Something went wrong with that request. Please try again.