Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-31314 gradebook restore: fix category.depth on restore.

Without this, restoring backups made with the OU's custom 'restore from
1.9' feature, and possibly other people's custom converstion code, does
not work properly.

Also, fix poor recordset code.
  • Loading branch information...
commit a3b0c9462f050904d0b279aa703b03abb3b0fbe2 1 parent d4b3034
Tim Hunt authored January 20, 2012

Showing 1 changed file with 16 additions and 21 deletions. Show diff stats Hide diff stats

  1. 37  backup/moodle2/restore_stepslib.php
37  backup/moodle2/restore_stepslib.php
@@ -371,40 +371,35 @@ protected function after_execute() {
371 371
         }
372 372
         $rs->close();
373 373
 
374  
-        //need to correct the grade category path and parent
  374
+        // Need to correct the grade category path and parent
375 375
         $conditions = array(
376 376
             'courseid' => $this->get_courseid()
377 377
         );
378  
-        $grade_category = new stdclass();
379 378
 
380 379
         $rs = $DB->get_recordset('grade_categories', $conditions);
381  
-        if (!empty($rs)) {
382  
-            //get all the parents correct first as grade_category::build_path() loads category parents from the DB
383  
-            foreach($rs as $gc) {
384  
-                if (!empty($gc->parent)) {
385  
-                    $grade_category->id = $gc->id;
386  
-                    $grade_category->parent = $this->get_mappingid('grade_category', $gc->parent);
387  
-                    $DB->update_record('grade_categories', $grade_category);
388  
-                }
  380
+        // Get all the parents correct first as grade_category::build_path() loads category parents from the DB
  381
+        foreach ($rs as $gc) {
  382
+            if (!empty($gc->parent)) {
  383
+                $grade_category = new stdClass();
  384
+                $grade_category->id = $gc->id;
  385
+                $grade_category->parent = $this->get_mappingid('grade_category', $gc->parent);
  386
+                $DB->update_record('grade_categories', $grade_category);
389 387
             }
390 388
         }
391  
-        if (isset($grade_category->parent)) {
392  
-            unset($grade_category->parent);
393  
-        }
394 389
         $rs->close();
395 390
 
  391
+        // Now we can rebuild all the paths
396 392
         $rs = $DB->get_recordset('grade_categories', $conditions);
397  
-        if (!empty($rs)) {
398  
-            //now we can rebuild all the paths
399  
-            foreach($rs as $gc) {
400  
-                $grade_category->id = $gc->id;
401  
-                $grade_category->path = grade_category::build_path($gc);
402  
-                $DB->update_record('grade_categories', $grade_category);
403  
-            }
  393
+        foreach ($rs as $gc) {
  394
+            $grade_category = new stdClass();
  395
+            $grade_category->id = $gc->id;
  396
+            $grade_category->path = grade_category::build_path($gc);
  397
+            $grade_category->depth = substr_count($grade_category->path, '/') - 1;
  398
+            $DB->update_record('grade_categories', $grade_category);
404 399
         }
405 400
         $rs->close();
406 401
 
407  
-        //Restore marks items as needing update. Update everything now.
  402
+        // Restore marks items as needing update. Update everything now.
408 403
         grade_regrade_final_grades($this->get_courseid());
409 404
     }
410 405
 }

0 notes on commit a3b0c94

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