MDL-23479 backup - assignment revised & old code deleted (but restore logs). Support...
[moodle.git] / mod / assignment / restorelib.php
CommitLineData
e7521559 1<?php
d7c93ec8 2 //This php script contains all the stuff to backup/restore
3 //assignment mods
4
5 //This is the "graphical" structure of the assignment mod:
6 //
7 // assignment
e7521559 8 // (CL,pk->id)
d7c93ec8 9 // |
10 // |
11 // |
e7521559 12 // assignment_submisions
d7c93ec8 13 // (UL,pk->id, fk->assignment,files)
14 //
15 // Meaning: pk->primary key field of the table
16 // fk->foreign key to link with parent
17 // nt->nested field (recursive data)
18 // CL->course level info
19 // UL->user level info
20 // files->table may have files)
21 //
22 //-----------------------------------------------------------
23
85b9471f 24
25 //This function returns a log record with all the necessay transformations
0f318c26 26 //done. It's used by restore_log_module() to restore modules log.
27 function assignment_restore_logs($restore,$log) {
e7521559 28
0f318c26 29 $status = false;
e7521559 30
0f318c26 31 //Depending of the action, we recode different things
32 switch ($log->action) {
33 case "add":
34 if ($log->cmid) {
35 //Get the new_id of the module (to recode the info field)
36 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
37 if ($mod) {
38 $log->url = "view.php?id=".$log->cmid;
39 $log->info = $mod->new_id;
40 $status = true;
41 }
42 }
43 break;
44 case "update":
45 if ($log->cmid) {
46 //Get the new_id of the module (to recode the info field)
47 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
48 if ($mod) {
49 $log->url = "view.php?id=".$log->cmid;
50 $log->info = $mod->new_id;
51 $status = true;
52 }
53 }
54 break;
55 case "view":
56 if ($log->cmid) {
57 //Get the new_id of the module (to recode the info field)
58 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
59 if ($mod) {
60 $log->url = "view.php?id=".$log->cmid;
61 $log->info = $mod->new_id;
62 $status = true;
63 }
64 }
65 break;
66 case "view all":
67 $log->url = "index.php?id=".$log->course;
68 $status = true;
69 break;
70 case "upload":
71 if ($log->cmid) {
72 //Get the new_id of the module (to recode the info field)
73 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
74 if ($mod) {
75 $log->url = "view.php?a=".$mod->new_id;
76 $log->info = $mod->new_id;
77 $status = true;
78 }
79 }
80 break;
81 case "view submission":
82 if ($log->cmid) {
83 //Get the new_id of the module (to recode the info field)
84 $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
85 if ($mod) {
86 $log->url = "submissions.php?id=".$mod->new_id;
87 $log->info = $mod->new_id;
88 $status = true;
89 }
90 }
91 break;
92 case "update grades":
93 if ($log->cmid) {
e7521559 94 //Extract the assignment id from the url field
0f318c26 95 $assid = substr(strrchr($log->url,"="),1);
96 //Get the new_id of the module (to recode the info field)
97 $mod = backup_getid($restore->backup_unique_code,$log->module,$assid);
98 if ($mod) {
99 $log->url = "submissions.php?id=".$mod->new_id;
100 $status = true;
101 }
102 }
103 break;
104 default:
f90666aa 105 if (!defined('RESTORE_SILENTLY')) {
2070370c 106 echo "action (".$log->module."-".$log->action.") unknown. Not restored<br />"; //Debug
f90666aa 107 }
0f318c26 108 break;
109 }
110
111 if ($status) {
112 $status = $log;
113 }
114 return $status;
115 }
e7521559 116