mirrored from git://git.moodle.org/moodle.git
/
restorelib.php
executable file
·865 lines (700 loc) · 33 KB
/
restorelib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
<?php //$Id$
//This php script contains all the stuff to backup/restore
//reservation mods
//This is the "graphical" structure of the scorm mod:
//
// scorm
// (CL,pk->id)---------------------
// | |
// | |
// | |
// scorm_scoes |
// (UL,pk->id, fk->scorm) |
// | |
// | |
// | |
// scorm_scoes_track |
// (UL,pk->id, fk->scormid, fk->scoid, fk->userid)--
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
// nt->nested field (recursive data)
// CL->course level info
// UL->user level info
// files->table may have files)
//
//-----------------------------------------------------------
//This function executes all the restore procedure about this mod
function scorm_restore_mods($mod,$restore) {
global $CFG;
$status = true;
//Get record from backup_ids
$data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
if ($data) {
//Now get completed xmlized object
$info = $data->info;
//traverse_xmlize($info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, build the SCORM record structure
$scorm->course = $restore->course_id;
$scorm->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
$scorm->reference = backup_todb($info['MOD']['#']['REFERENCE']['0']['#']);
$scorm->version = backup_todb($info['MOD']['#']['VERSION']['0']['#']);
$scorm->md5hash = backup_todb($info['MOD']['#']['MD5HASH']['0']['#']);
$scorm->maxgrade = backup_todb($info['MOD']['#']['MAXGRADE']['0']['#']);
if (!is_int($scorm->maxgrade)) {
$scorm->maxgrade = 0;
}
$scorm->updatefreq = backup_todb($info['MOD']['#']['UPDATEFREQ']['0']['#']);
if (!is_int($scorm->updatefreq)) {
$scorm->updatefreq = 0;
}
$scorm->maxattempt = backup_todb($info['MOD']['#']['MAXATTEMPT']['0']['#']);
if (!is_int($scorm->maxattempt)) {
$scorm->maxattempt = 0;
}
$scorm->grademethod = backup_todb($info['MOD']['#']['GRADEMETHOD']['0']['#']);
if (!is_int($scorm->grademethod)) {
$scorm->grademethod = 0;
}
if ($restore->backup_version < 2005041500) {
$scorm->datadir = substr(backup_todb($info['MOD']['#']['DATADIR']['0']['#']),1);
} else {
$scorm->datadir = backup_todb($info['MOD']['#']['ID']['0']['#']);
}
$oldlaunch = backup_todb($info['MOD']['#']['LAUNCH']['0']['#']);
if ($restore->backup_version < 2006102600) {
$scorm->skipview = 1;
} else {
$scorm->skipview = backup_todb($info['MOD']['#']['SKIPVIEW']['0']['#']);
}
$scorm->summary = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
$scorm->hidebrowse = backup_todb($info['MOD']['#']['HIDEBROWSE']['0']['#']);
$scorm->hidetoc = backup_todb($info['MOD']['#']['HIDETOC']['0']['#']);
$scorm->hidenav = backup_todb($info['MOD']['#']['HIDENAV']['0']['#']);
$scorm->auto = backup_todb($info['MOD']['#']['AUTO']['0']['#']);
if ($restore->backup_version < 2005040200) {
$oldpopup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
if (!empty($oldpopup)) {
$scorm->popup = 1;
// Parse old popup field
$options = array();
$oldoptions = explode(',',$scorm->popup);
foreach ($oldoptions as $oldoption) {
list($element,$value) = explode('=',$oldoption);
$element = trim($element);
$value = trim($value);
switch ($element) {
case 'width':
$scorm->width = $value;
break;
case 'height':
$scorm->height = $value;
break;
default:
$options[] = $element.'='.$value;
break;
}
}
$scorm->options = implode($options,',');
} else {
$scorm->popup = 0;
$scorm->options = '';
$scorm->width = '100%';
$scorm->height = 500;
}
} else {
$scorm->popup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
$scorm->width = backup_todb($info['MOD']['#']['WIDTH']['0']['#']);
if ($scorm->width == 0) {
$scorm->width = '100%';
}
$scorm->height = backup_todb($info['MOD']['#']['HEIGHT']['0']['#']);
if ($scorm->height == 0) {
$scorm->height = 500;
}
}
$scorm->timemodified = time();
//The structure is equal to the db, so insert the scorm
$newid = insert_record ("scorm",$scorm);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
echo "<li>".get_string("modulename","scorm")." \"".format_string(stripslashes($scorm->name),true)."\"</li>";
}
backup_flush(300);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,$mod->modtype,
$mod->id, $newid);
$scorm->id = $newid;
//Now copy moddata associated files
$status = scorm_restore_files ($scorm, $restore);
if ($status) {
$status = scorm_scoes_restore_mods ($newid,$info,$restore,$mod->id);
if ($status) {
$launchsco = backup_getid($restore->backup_unique_code,"scorm_scoes",$oldlaunch);
$scorm->launch = $launchsco->new_id;
update_record('scorm',$scorm);
}
}
} else {
$status = false;
}
} else {
$status = false;
}
return $status;
}
//This function restores the scorm_scoes
function scorm_scoes_restore_mods($scorm_id,$info,$restore,$oldmodid) {
global $CFG;
$status = true;
//Get the sco array
$scoes = $info['MOD']['#']['SCOES']['0']['#']['SCO'];
//Iterate over scoes
for($i = 0; $i < sizeof($scoes); $i++) {
$sub_info = $scoes[$i];
//We'll need this later!!
$oldid = backup_todb($sub_info['#']['ID']['0']['#']);
//Now, build the scorm_scoes record structure
$sco->scorm = $scorm_id;
$sco->manifest = backup_todb($sub_info['#']['MANIFEST']['0']['#']);
$sco->organization = backup_todb($sub_info['#']['ORGANIZATION']['0']['#']);
$sco->parent = backup_todb($sub_info['#']['PARENT']['0']['#']);
$sco->identifier = backup_todb($sub_info['#']['IDENTIFIER']['0']['#']);
$sco->launch = backup_todb($sub_info['#']['LAUNCH']['0']['#']);
$sco->title = backup_todb($sub_info['#']['TITLE']['0']['#']);
if ($restore->backup_version < 2005031300) {
$sco->scormtype = backup_todb($sub_info['#']['TYPE']['0']['#']);
} else {
$sco->scormtype = backup_todb($sub_info['#']['SCORMTYPE']['0']['#']);
}
//The structure is equal to the db, so insert the scorm_scoes
$newid = insert_record ("scorm_scoes",$sco);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"scorm_scoes", $oldid, $newid);
} else {
$status = false;
}
}
//Now check if want to restore user data and do it.
scorm_scoes_seq_objective_restore_mods ($newid,$info,$restore);
scorm_scoes_seq_rolluprule_restore_mods ($newid,$info,$restore);
scorm_scoes_seq_ruleconds_restore_mods ($newid,$info,$restore);
if (restore_userdata_selected($restore,'scorm',$oldmodid)) {
//Restore scorm_scoes
if ($status) {
if ($restore->backup_version < 2005031300) {
$status = scorm_scoes_tracks_restore_mods_pre15 ($scorm_id,$info,$restore);
} else {
$status = scorm_scoes_tracks_restore_mods ($scorm_id,$info,$restore);
}
}
}
return $status;
}
function scorm_scoes_seq_objective_restore_mods($sco_id,$info,$restore) {
global $CFG;
$status = true;
//Get the discussions array
$objectives = array();
if (!empty($info['MOD']['#']['SEQ_OBJECTIVES']['0']['#']['SEQ_OBJECTIVE'])) {
$objectives = $info['MOD']['#']['SEQ_OBJECTIVES']['0']['#']['SEQ_OBJECTIVE'];
}
//Iterate over discussions
for($i = 0; $i < sizeof($objectives); $i++) {
$obj_info = $objectives[$i];
//Debug
//We'll need this later!!
$oldid = backup_todb($obj_info['#']['ID']['0']['#']);
//Now, build the FORUM_DISCUSSIONS record structure
$objective->scoid = $sco_id;
$objective->primaryobj = backup_todb($obj_info['#']['PRIMARYOBJ']['0']['#']);
$objective->objectiveid = backup_todb($obj_info['#']['OBJECTIVEID']['0']['#']);
$objective->satisfiedbymeasure = backup_todb($obj_info['#']['SATISFIEDBYMEASURE']['0']['#']);
$objective->minnormalizedmeasure = backup_todb($obj_info['#']['MINNORMALIZEDMEASURE']['0']['#']);
//The structure is equal to the db, so insert the forum_discussions
$newid = insert_record ("scorm_seq_objective",$objective);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"scorm_seq_objective", $oldid, $newid);
} else {
$status = false;
}
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
//Now restore the scorm_seq_mapinfo for each objective
$status = scorm_seq_mapinfo_restore_mods ($sco_id,$newid,$obj_info,$restore);
}
return $status;
}
function scorm_scoes_seq_rolluprule_restore_mods($sco_id,$info,$restore) {
global $CFG;
$status = true;
//Get the discussions array
$rolluprules = array();
if (!empty($info['MOD']['#']['SEQ_ROLLUPRULES']['0']['#']['SEQ_ROLLUPRULE'])) {
$rolluprules = $info['MOD']['#']['SEQ_ROLLUPRULES']['0']['#']['SEQ_ROLLUPRULE'];
}
//Iterate over discussions
for($i = 0; $i < sizeof($rolluprules); $i++) {
$rol_info = $rolluprules[$i];
//Debug
//We'll need this later!!
$oldid = backup_todb($rol_info['#']['ID']['0']['#']);
//Now, build the FORUM_DISCUSSIONS record structure
$rolluprule->scoid = $sco_id;
$rolluprule->childactivityset = backup_todb($rol_info['#']['CHILDACTIVITYSET']['0']['#']);
$rolluprule->minimumrule = backup_todb($rol_info['#']['MINIMUMCOUNT']['0']['#']);
$rolluprule->minimumpercent = backup_todb($rol_info['#']['MINIMUMPERCENT']['0']['#']);
$rolluprule->conditioncombination = backup_todb($rol_info['#']['CONDITIONCOMBINATION']['0']['#']);
$rolluprule->action = backup_todb($rol_info['#']['ACTION']['0']['#']);
//The structure is equal to the db, so insert the forum_discussions
$newid = insert_record ("scorm_seq_rolluprule",$rolluprule);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"scorm_seq_rolluprule", $oldid, $newid);
} else {
$status = false;
}
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
//Now restore the scorm_seq_mapinfo for each objective
$status = scorm_seq_rolluprulecond_restore_mods ($sco_id, $newid,$obj_info,$restore);
}
return $status;
}
function scorm_scoes_seq_ruleconds_restore_mods($sco_id,$info,$restore) {
global $CFG;
$status = true;
//Get the discussions array
$ruleconds = array();
if (!empty($info['MOD']['#']['SEQ_RULECONDS']['0']['#']['SEQ_RULECOND'])) {
$ruleconds = $info['MOD']['#']['SEQ_RULECONDS']['0']['#']['SEQ_RULECOND'];
}
//Iterate over discussions
for($i = 0; $i < sizeof($ruleconds); $i++) {
$rul_info = $ruleconds[$i];
//Debug
//We'll need this later!!
$oldid = backup_todb($rul_info['#']['ID']['0']['#']);
$rulecond->scoid = $sco_id;
$rulecond->conditioncombination = backup_todb($rul_info['#']['CONDITIONCOMBINATION']['0']['#']);
$rulecond->minimumpercent = backup_todb($rul_info['#']['RULETYPE']['0']['#']);
$rulecond->action = backup_todb($rul_info['#']['ACTION']['0']['#']);
//The structure is equal to the db, so insert the forum_discussions
$newid = insert_record ("scorm_seq_ruleconds",$rulecond);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"scorm_seq_ruleconds", $oldid, $newid);
} else {
$status = false;
}
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
//Now restore the scorm_seq_mapinfo for each objective
$status = scorm_seq_rulecond_restore_mods ($sco_id, $newid,$obj_info,$restore);
}
return $status;
}
function scorm_scoes_seq_rulecond_restore_mods($sco_id,$rulecondid,$info,$restore) {
global $CFG;
$status = true;
//Get the discussions array
$rulecondsd = array();
if (!empty($info['MOD']['#']['SEQ_RULECOND_DATAS']['0']['#']['SEQ_RULECOND_DATA'])) {
$rulecondsd = $info['MOD']['#']['SEQ_RULECOND_DATAS']['0']['#']['SEQ_RULECOND_DATA'];
}
for($i = 0; $i < sizeof($rulecondsd); $i++) {
$ruld_info = $rulecondsd[$i];
//Debug
//We'll need this later!!
$oldid = backup_todb($rul_info['#']['ID']['0']['#']);
$rulecondd->scoid = $sco_id;
$rulecondd->ruleconditions = $rulecondid;
$rulecondd->refrencedobjective = backup_todb($ruld_info['#']['REFRENCEDOBJECTIVE']['0']['#']);
$rulecondd->measurethreshold = backup_todb($ruld_info['#']['MEASURETHRESHOLD']['0']['#']);
$rulecondd->operator = backup_todb($ruld_info['#']['OPERATOR']['0']['#']);
$rulecondd->cond = backup_todb($ruld_info['#']['COND']['0']['#']);
//The structure is equal to the db, so insert the forum_discussions
$newid = insert_record ("scorm_seq_rulecond",$rulecondd);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"scorm_seq_rulecond", $oldid, $newid);
} else {
$status = false;
}
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
//Now restore the scorm_seq_mapinfo for each objective
}
return $status;
}
function scorm_scoes_seq_rolluprulecond_restore_mods($sco_id,$rolluprule,$info,$restore) {
global $CFG;
$status = true;
//Get the discussions array
$rollupruleconds = array();
if (!empty($info['MOD']['#']['SEQ_ROLLUPRULECONDS']['0']['#']['SEQ_ROLLUPRULECOND'])) {
$rollupruleconds = $info['MOD']['#']['SEQ_ROLLUPRULECONDS']['0']['#']['SEQ_ROLLUPRULECOND'];
}
for($i = 0; $i < sizeof($rollupruleconds); $i++) {
$rulc_info = $rollupruleconds[$i];
//Debug
//We'll need this later!!
$oldid = backup_todb($rulc_info['#']['ID']['0']['#']);
$rolluprulecond->scoid = $sco_id;
$rolluprulecond->ruleconditions = $rolluprule;
$rolluprulecond->cond = backup_todb($rulc_info['#']['COND']['0']['#']);
$rolluprulecond->operator = backup_todb($rulc_info['#']['OPERATOR']['0']['#']);
//The structure is equal to the db, so insert the forum_discussions
$newid = insert_record ("scorm_seq_rolluprulecond",$rolluprulecond);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"scorm_seq_rolluprulecond", $oldid, $newid);
} else {
$status = false;
}
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
//Now restore the scorm_seq_mapinfo for each objective
}
return $status;
}
function scorm_scoes_seq_mapinfo_restore_mods($sco_id,$objectiveid,$info,$restore) {
global $CFG;
$status = true;
//Get the discussions array
$mapinfos = array();
if (!empty($info['MOD']['#']['SEQ_MAPINFO']['0']['#']['SEQ_MAPINF'])) {
$mapinfos = $info['MOD']['#']['SEQ_MAPINFO']['0']['#']['SEQ_MAPINF'];
}
for($i = 0; $i < sizeof($mapinfos); $i++) {
$map_info = $mapinfos[$i];
//Debug
//We'll need this later!!
$oldid = backup_todb($map_info['#']['ID']['0']['#']);
$mapinfo->scoid = $sco_id;
$mapinfo->objectiveid = $ojectiveid;
$mapinfo->targetobjectiveid = backup_todb($map_info['#']['TARGETOBJECTIVEID']['0']['#']);
$mapinfo->readsatisfiedstatus = backup_todb($map_info['#']['READSATISFIEDSTATUS']['0']['#']);
$mapinfo->readnormalizedmeasure = backup_todb($map_info['#']['READNORMALIZEDMEASURE']['0']['#']);
$mapinfo->writesatisfiedstatus = backup_todb($map_info['#']['WRITESATISFIEDSTATUS']['0']['#']);
$mapinfo->writenormalizedmeasure = backup_todb($map_info['#']['WRITENORMALIZEDMEASURE']['0']['#']);
//The structure is equal to the db, so insert the forum_discussions
$newid = insert_record ("scorm_seq_mapinfo",$mapinfo);
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"scorm_seq_mapinfo", $oldid, $newid);
} else {
$status = false;
}
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
}
}
}
return $status;
}
//This function restores the scorm_scoes_track
function scorm_scoes_tracks_restore_mods($scorm_id,$info,$restore) {
global $CFG;
$status = true;
$scotracks = NULL;
//Get the sco array
if (!empty($info['MOD']['#']['SCO_TRACKS']['0']['#']['SCO_TRACK']))
$scotracks = $info['MOD']['#']['SCO_TRACKS']['0']['#']['SCO_TRACK'];
//Iterate over sco_users
for($i = 0; $i < sizeof($scotracks); $i++) {
$sub_info = $scotracks[$i];
unset($scotrack);
//Now, build the scorm_scoes_track record structure
$scotrack->scormid = $scorm_id;
$scotrack->userid = backup_todb($sub_info['#']['USERID']['0']['#']);
$scotrack->scoid = backup_todb($sub_info['#']['SCOID']['0']['#']);
$scotrack->element = backup_todb($sub_info['#']['ELEMENT']['0']['#']);
$scotrack->attempt = backup_todb($sub_info['#']['ATTEMPT']['0']['#']);
$scotrack->value = backup_todb($sub_info['#']['VALUE']['0']['#']);
//We have to recode the userid field
$user = backup_getid($restore->backup_unique_code,"user",$scotrack->userid);
if (!empty($user)) {
$scotrack->userid = $user->new_id;
}
//We have to recode the scoid field
$sco = backup_getid($restore->backup_unique_code,"scorm_scoes",$scotrack->scoid);
if ($sco != NULL) {
$scotrack->scoid = $sco->new_id;
}
$scotrack->timemodified = time();
//The structure is equal to the db, so insert the scorm_scoes_track
$newid = insert_record ("scorm_scoes_track",$scotrack);
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
}
return $status;
}
//This function restores the scorm_scoes_track from Moodle 1.4
function scorm_scoes_tracks_restore_mods_pre15 ($scorm_id,$info,$restore) {
global $CFG;
$status = true;
$scousers = NULL;
//Get the sco array
if (!empty($info['MOD']['#']['SCO_USERS']['0']['#']['SCO_USER'])) {
$scousers = $info['MOD']['#']['SCO_USERS']['0']['#']['SCO_USER'];
}
$oldelements = array ('CMI_CORE_LESSON_LOCATION',
'CMI_CORE_LESSON_STATUS',
'CMI_CORE_EXIT',
'CMI_CORE_TOTAL_TIME',
'CMI_CORE_SCORE_RAW',
'CMI_SUSPEND_DATA');
$newelements = array ('cmi.core.lesson_location',
'cmi.core.lesson_status',
'cmi.core.exit',
'cmi.core.total_time',
'cmi.core.score.raw',
'cmi.suspend_data');
//Iterate over sco_users
for ($i = 0; $i < sizeof($scousers); $i++) {
$sub_info = $scousers[$i];
unset($scotrack);
//We'll need this later!!
$oldid = backup_todb($sub_info['#']['ID']['0']['#']);
$oldscoid = backup_todb($sub_info['#']['SCOID']['0']['#']);
$olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
//Now, build the scorm_scoes_track record structure
$scotrack->scormid = $scorm_id;
$scotrack->userid = backup_todb($sub_info['#']['USERID']['0']['#']);
$scotrack->scoid = backup_todb($sub_info['#']['SCOID']['0']['#']);
$pos = 0;
foreach ($oldelements as $oldelement) {
$elementvalue = backup_todb($sub_info['#'][$oldelement]['0']['#']);
if (!empty($elementvalue)) {
$scotrack->element = $newelements[$pos];
$scotrack->value = backup_todb($sub_info['#'][strtoupper($oldelement)]['0']['#']);
//We have to recode the userid field
$user = backup_getid($restore->backup_unique_code,"user",$scotrack->userid);
if (!empty($user)) {
$scotrack->userid = $user->new_id;
}
//We have to recode the scoid field
$sco = backup_getid($restore->backup_unique_code,"scorm_scoes",$scotrack->scoid);
if (!empty($sco)) {
$scotrack->scoid = $sco->new_id;
}
//The structure is equal to the db, so insert the scorm_scoes_track
$newid = insert_record ("scorm_scoes_track",$scotrack);
}
$pos++;
}
//Do some output
if (($i+1) % 50 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 1000 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
}
return $status;
}
//This function copies the scorm related info from backup temp dir to course moddata folder,
//creating it if needed
function scorm_restore_files ($package, $restore) {
global $CFG;
$status = true;
$todo = false;
$moddata_path = "";
$scorm_path = "";
$temp_path = "";
//First, we check to "course_id" exists and create is as necessary
//in CFG->dataroot
$dest_dir = $CFG->dataroot."/".$restore->course_id;
$status = check_dir_exists($dest_dir,true);
//First, locate course's moddata directory
$moddata_path = $CFG->dataroot."/".$restore->course_id."/".$CFG->moddata;
//Check it exists and create it
$status = check_dir_exists($moddata_path,true);
//Now, locate scorm directory
if ($status) {
$scorm_path = $moddata_path."/scorm";
//Check it exists and create it
$status = check_dir_exists($scorm_path,true);
}
//Now locate the temp dir we are restoring from
if ($status) {
$temp_path = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code.
"/moddata/scorm/".$package->datadir;
//Check it exists
if (is_dir($temp_path)) {
$todo = true;
}
}
//If todo, we create the neccesary dirs in course moddata/scorm
if ($status and $todo) {
//Make scorm package directory path
$this_scorm_path = $scorm_path."/".$package->id;
$status = backup_copy_file($temp_path, $this_scorm_path);
}
return $status;
}
//Return a content decoded to support interactivities linking. Every module
//should have its own. They are called automatically from
//scorm_decode_content_links_caller() function in each module
//in the restore process
function scorm_decode_content_links ($content,$restore) {
global $CFG;
$result = $content;
//Link to the list of scorms
$searchstring='/\$@(SCORMINDEX)\*([0-9]+)@\$/';
//We look for it
preg_match_all($searchstring,$content,$foundset);
//If found, then we are going to look for its new id (in backup tables)
if ($foundset[0]) {
//print_object($foundset); //Debug
//Iterate over foundset[2]. They are the old_ids
foreach($foundset[2] as $old_id) {
//We get the needed variables here (course id)
$rec = backup_getid($restore->backup_unique_code,"course",$old_id);
//Personalize the searchstring
$searchstring='/\$@(SCORMINDEX)\*('.$old_id.')@\$/';
//If it is a link to this course, update the link to its new location
if($rec->new_id) {
//Now replace it
$result= preg_replace($searchstring,$CFG->wwwroot.'/mod/scorm/index.php?id='.$rec->new_id,$result);
} else {
//It's a foreign link so leave it as original
$result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/scorm/index.php?id='.$old_id,$result);
}
}
}
//Link to scorm view by moduleid
$searchstring='/\$@(SCORMVIEWBYID)\*([0-9]+)@\$/';
//We look for it
preg_match_all($searchstring,$result,$foundset);
//If found, then we are going to look for its new id (in backup tables)
if ($foundset[0]) {
//print_object($foundset); //Debug
//Iterate over foundset[2]. They are the old_ids
foreach($foundset[2] as $old_id) {
//We get the needed variables here (course_modules id)
$rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id);
//Personalize the searchstring
$searchstring='/\$@(SCORMVIEWBYID)\*('.$old_id.')@\$/';
//If it is a link to this course, update the link to its new location
if($rec->new_id) {
//Now replace it
$result= preg_replace($searchstring,$CFG->wwwroot.'/mod/scorm/view.php?id='.$rec->new_id,$result);
} else {
//It's a foreign link so leave it as original
$result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/scorm/view.php?id='.$old_id,$result);
}
}
}
return $result;
}
//This function makes all the necessary calls to xxxx_decode_content_links()
//function in each module, passing them the desired contents to be decoded
//from backup format to destination site/course in order to mantain inter-activities
//working in the backup/restore process. It's called from restore_decode_content_links()
//function in restore process
function scorm_decode_content_links_caller($restore) {
global $CFG;
$status = true;
if ($scorms = get_records_sql ("SELECT s.id, s.summary
FROM {$CFG->prefix}scorm s
WHERE s.course = $restore->course_id")) {
$i = 0; //Counter to send some output to the browser to avoid timeouts
foreach ($scorms as $scorm) {
//Increment counter
$i++;
$content = $scorm->summary;
$result = restore_decode_content_links_worker($content,$restore);
if ($result != $content) {
//Update record
$scorm->summary = addslashes($result);
$status = update_record("scorm",$scorm);
if (debugging()) {
if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.htmlentities($content).'<br />changed to<br />'.htmlentities($result).'<hr /><br />';
}
}
}
//Do some output
if (($i+1) % 5 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if (($i+1) % 100 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
}
}
return $status;
}
//This function returns a log record with all the necessay transformations
//done. It's used by restore_log_module() to restore modules log.
function scorm_restore_logs($restore,$log) {
$status = true;
return $status;
}
?>