From b5104c34f1d387e9fc3d61269c44c8cd0d956252 Mon Sep 17 00:00:00 2001
From: stronk7 <stronk7>
Date: Fri, 10 Dec 2004 18:27:53 +0000
Subject: [PATCH] Skipping empty categories in restore. They shouldn't exist
 but I've received some examples of this these days.

Merged from MOODLE_14_STABLE
---
 backup/restorelib.php | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/backup/restorelib.php b/backup/restorelib.php
index 2b62887649..d0e3f324e8 100644
--- a/backup/restorelib.php
+++ b/backup/restorelib.php
@@ -990,13 +990,16 @@
             if ($info !== true) {
                 //Iterate over each category
                 foreach ($info as $category) {
-                    $catrestore = "quiz_restore_question_categories";
-                    if (function_exists($catrestore)) {
-                        //print_object ($category);                                                //Debug
-                        $status = $catrestore($category,$restore);
-                    } else {
-                        //Something was wrong. Function should exist.
-                        $status = false;
+                    //Skip empty categories (some backups can contain them)
+                    if (!empty($category->id)) {
+                        $catrestore = "quiz_restore_question_categories";
+                        if (function_exists($catrestore)) {
+                            //print_object ($category);                                                //Debug
+                            $status = $catrestore($category,$restore);
+                        } else {
+                            //Something was wrong. Function should exist.
+                            $status = false;
+                        }
                     }
                 }
             }
-- 
2.39.5