MDL-36506 mod_book: Skip legacy files migration if missing a CM record
authorTim Lock <tim.lock@netspot.com.au>
Wed, 8 Jan 2014 23:38:41 +0000 (10:08 +1030)
committerTim Lock <tim.lock@netspot.com.au>
Tue, 24 Mar 2015 02:15:51 +0000 (12:45 +1030)
mod/book/db/upgradelib.php

index fa0dc47..73d0a0a 100644 (file)
@@ -108,12 +108,16 @@ function mod_book_migrate_moddata_dir_to_legacy($book, $context, $path) {
  * @return void
  */
 function mod_book_migrate_all_areas() {
-    global $DB;
+    global $DB, $OUTPUT;
 
     $rsbooks = $DB->get_recordset('book');
     foreach($rsbooks as $book) {
         upgrade_set_timeout(360); // set up timeout, may also abort execution
         $cm = get_coursemodule_from_instance('book', $book->id);
+        if (empty($cm) || empty($cm->id)) {
+             echo $OUTPUT->notification("Course module not found, skipping: {$book->name}");
+             continue;
+        }
         $context = context_module::instance($cm->id);
         mod_book_migrate_area($book, 'intro', 'book', $book->course, $context, 'mod_book', 'intro', 0);