PageRenderTime 78ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/glossary/restorelib.php

https://github.com/manoj240375/moodle_edify
PHP | 221 lines | 165 code | 6 blank | 50 comment | 31 complexity | 2bc44d8f73aaddcb00bef376ba0175f6 MD5 | raw file
  1. <?php
  2. //This php script contains all the stuff to backup/restore
  3. //glossary mods
  4. //This is the "graphical" structure of the glossary mod:
  5. //
  6. // glossary ----------------------------------------- glossary_categories
  7. // (CL,pk->id) (CL,pk->id,fk->glossaryid)
  8. // | |
  9. // | |
  10. // | |
  11. // glossary_entries --------------------------------glossary_entries_categories
  12. // (UL,pk->id, fk->glossaryid, files) | (UL, pk->categoryid,entryid)
  13. // | |
  14. // | |--------------------glossary_ratings
  15. // | | (UL, pk->id, pk->entryid)
  16. // glossary_comments |
  17. // (UL,pk->id, fk->entryid) |---------------------glossary_alias
  18. // (UL, pk->id, pk->entryid)
  19. //
  20. //
  21. // Meaning: pk->primary key field of the table
  22. // fk->foreign key to link with parent
  23. // nt->nested field (recursive data)
  24. // CL->course level info
  25. // UL->user level info
  26. // files->table may have files)
  27. //
  28. //-----------------------------------------------------------
  29. //This function returns a log record with all the necessary transformations
  30. //done. It's used by restore_log_module() to restore modules log.
  31. function glossary_restore_logs($restore,$log) {
  32. $status = false;
  33. //Depending of the action, we recode different things
  34. switch ($log->action) {
  35. case "add":
  36. if ($log->cmid) {
  37. //Get the new_id of the module (to recode the info field)
  38. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  39. if ($mod) {
  40. $log->url = "view.php?id=".$log->cmid;
  41. $log->info = $mod->new_id;
  42. $status = true;
  43. }
  44. }
  45. break;
  46. case "update":
  47. if ($log->cmid) {
  48. //Get the new_id of the module (to recode the info field)
  49. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  50. if ($mod) {
  51. $log->url = "view.php?id=".$log->cmid;
  52. $log->info = $mod->new_id;
  53. $status = true;
  54. }
  55. }
  56. break;
  57. case "view":
  58. if ($log->cmid) {
  59. //Get the new_id of the module (to recode the info field)
  60. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  61. if ($mod) {
  62. $log->url = "view.php?id=".$log->cmid;
  63. $log->info = $mod->new_id;
  64. $status = true;
  65. }
  66. }
  67. break;
  68. case "view all":
  69. $log->url = "index.php?id=".$log->course;
  70. $status = true;
  71. break;
  72. case "add category":
  73. if ($log->cmid) {
  74. //Get the new_id of the glossary_category (to recode the info field)
  75. $cat = backup_getid($restore->backup_unique_code,"glossary_categories",$log->info);
  76. if ($cat) {
  77. $log->url = "editcategories.php?id=".$log->cmid;
  78. $log->info = $cat->new_id;
  79. $status = true;
  80. }
  81. }
  82. break;
  83. case "edit category":
  84. if ($log->cmid) {
  85. //Get the new_id of the glossary_category (to recode the info field)
  86. $cat = backup_getid($restore->backup_unique_code,"glossary_categories",$log->info);
  87. if ($cat) {
  88. $log->url = "editcategories.php?id=".$log->cmid;
  89. $log->info = $cat->new_id;
  90. $status = true;
  91. }
  92. }
  93. break;
  94. case "delete category":
  95. if ($log->cmid) {
  96. //Get the new_id of the glossary_category (to recode the info field)
  97. $cat = backup_getid($restore->backup_unique_code,"glossary_categories",$log->info);
  98. if ($cat) {
  99. $log->url = "editcategories.php?id=".$log->cmid;
  100. $log->info = $cat->new_id;
  101. $status = true;
  102. }
  103. }
  104. break;
  105. case "add entry":
  106. if ($log->cmid) {
  107. //Get the new_id of the glossary_entry (to recode the info and url field)
  108. $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
  109. if ($ent) {
  110. $log->url = "view.php?id=".$log->cmid."&mode=entry&hook=".$ent->new_id;
  111. $log->info = $ent->new_id;
  112. $status = true;
  113. }
  114. }
  115. break;
  116. case "update entry":
  117. if ($log->cmid) {
  118. //Get the new_id of the glossary_entry (to recode the info and url field)
  119. $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
  120. if ($ent) {
  121. $log->url = "view.php?id=".$log->cmid."&mode=entry&hook=".$ent->new_id;
  122. $log->info = $ent->new_id;
  123. $status = true;
  124. }
  125. }
  126. break;
  127. case "delete entry":
  128. if ($log->cmid) {
  129. //Get the new_id of the glossary_entry (to recode the info and url field)
  130. $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
  131. if ($ent) {
  132. $log->url = "view.php?id=".$log->cmid."&mode=entry&hook=".$ent->new_id;
  133. $log->info = $ent->new_id;
  134. $status = true;
  135. }
  136. }
  137. break;
  138. case "approve entry":
  139. if ($log->cmid) {
  140. //Get the new_id of the glossary_entry (to recode the info and url field)
  141. $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
  142. if ($ent) {
  143. $log->url = "showentry.php?id=".$log->cmid."&eid=".$ent->new_id;
  144. $log->info = $ent->new_id;
  145. $status = true;
  146. }
  147. }
  148. break;
  149. case "view entry":
  150. if ($log->cmid) {
  151. //Get the new_id of the glossary_entry (to recode the info and url field)
  152. $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$log->info);
  153. if ($ent) {
  154. $log->url = "showentry.php?&eid=".$ent->new_id;
  155. $log->info = $ent->new_id;
  156. $status = true;
  157. }
  158. }
  159. break;
  160. case "add comment":
  161. if ($log->cmid) {
  162. //Extract the entryid from the url field
  163. $entid = substr(strrchr($log->url,"="),1);
  164. //Get the new_id of the glossary_entry (to recode the url field)
  165. $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$entid);
  166. //Get the new_id of the glossary_comment (to recode the info field)
  167. $com = backup_getid($restore->backup_unique_code,"glossary_comments",$log->info);
  168. if ($ent and $com) {
  169. $log->url = "comments.php?id=".$log->cmid."&eid=".$ent->new_id;
  170. $log->info = $com->new_id;
  171. $status = true;
  172. }
  173. }
  174. break;
  175. case "update comment":
  176. if ($log->cmid) {
  177. //Extract the entryid from the url field
  178. $entid = substr(strrchr($log->url,"="),1);
  179. //Get the new_id of the glossary_entry (to recode the url field)
  180. $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$entid);
  181. //Get the new_id of the glossary_comment (to recode the info field)
  182. $com = backup_getid($restore->backup_unique_code,"glossary_comments",$log->info);
  183. if ($ent and $com) {
  184. $log->url = "comments.php?id=".$log->cmid."&eid=".$ent->new_id;
  185. $log->info = $com->new_id;
  186. $status = true;
  187. }
  188. }
  189. break;
  190. case "delete comment":
  191. if ($log->cmid) {
  192. //Extract the entryid from the url field
  193. $entid = substr(strrchr($log->url,"="),1);
  194. //Get the new_id of the glossary_entry (to recode the url field)
  195. $ent = backup_getid($restore->backup_unique_code,"glossary_entries",$entid);
  196. //Get the new_id of the glossary_comment (to recode the info field)
  197. $com = backup_getid($restore->backup_unique_code,"glossary_comments",$log->info);
  198. if ($ent and $com) {
  199. $log->url = "comments.php?id=".$log->cmid."&eid=".$ent->new_id;
  200. $log->info = $com->new_id;
  201. $status = true;
  202. }
  203. }
  204. break;
  205. default:
  206. if (!defined('RESTORE_SILENTLY')) {
  207. echo "action (".$log->module."-".$log->action.") unknown. Not restored<br />"; //Debug
  208. }
  209. break;
  210. }
  211. if ($status) {
  212. $status = $log;
  213. }
  214. return $status;
  215. }