Skip to content

Commit 6a51049

Browse files
committed
closes (#96)-3; ref. assignment_submission to assign_submission
The backup and restore functions referenced the old `assignment_submission` table, which is replaced by the `assign_submission` table in MOODLE 3.x and 4.x. There were also several fields previously added to the database and were never included in the activity backup or restore.
1 parent 1195b52 commit 6a51049

File tree

5 files changed

+103
-105
lines changed

5 files changed

+103
-105
lines changed

clients/mod/assign/feedback/onlinejudge/backup/moodle2/backup_assignfeedback_onlinejudge_subplugin.class.php

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
// This file is part of Moodle - https://moodle.org
2+
3+
// This file is part of Moodle - http://moodle.org/
34
//
45
// Moodle is free software: you can redistribute it and/or modify
56
// it under the terms of the GNU General Public License as published by
@@ -19,6 +20,7 @@
1920
* @subpackage backup-moodle2
2021
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
2122
* @copyright 2011 onwards Sun Zhigang (sunner) {@link http://sunner.cn}
23+
* @copyright 2017 onwards Andrew Naguib (ndrwnaguib) {@link http://ndrwnaguib.com}
2224
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2325
*/
2426

@@ -31,7 +33,7 @@ class backup_assignfeedback_onlinejudge_subplugin extends backup_subplugin {
3133
/**
3234
* Returns the subplugin information to attach at assignment element
3335
*/
34-
protected function define_assignment_subplugin_structure() {
36+
protected function define_grade_subplugin_structure() {
3537

3638
/**
3739
* Any activity sublugins is always rooted by one backup_subplugin_element()
@@ -55,7 +57,7 @@ protected function define_assignment_subplugin_structure() {
5557
* levels (get_recommended_name() and 'config' in the example below). That will make things
5658
* on restore easier, as far as subplugin information will be clearly separated from module information.
5759
*/
58-
$subplugin = $this->get_subplugin_element(null, '/assignment/assignmenttype', 'onlinejudge');
60+
$subplugin = $this->get_subplugin_element();
5961

6062
/**
6163
* Here we define the real structure the subplugin is going to generate - see note above. Obviously the
@@ -71,7 +73,7 @@ protected function define_assignment_subplugin_structure() {
7173
$assassoff = new backup_nested_element($this->get_recommended_name());
7274

7375
$onlinejudges = new backup_nested_element('onlinejudges');
74-
$onlinejudge = new backup_nested_element('onlinejudge', array('id'), array('language', 'memlimit', 'cpulimit', 'compileonly', 'ratiope', 'ideoneuser', 'ideonepass'));
76+
$onlinejudge = new backup_nested_element('onlinejudge', array('id'), array('language', 'memlimit', 'cpulimit', 'compileonly', 'ratiope', 'clientid', 'accesstoken', 'compile_lm_option', 'compile_warnings_option', 'compile_static_option'));
7577
$testcases = new backup_nested_element('testcases');
7678
$testcase = new backup_nested_element('testcase', array('id'), array('input', 'output', 'usefile', 'feedback', 'subgrade', 'sortorder'));
7779

@@ -84,39 +86,36 @@ protected function define_assignment_subplugin_structure() {
8486
$onlinejudge->set_source_table('assignment_oj', array('assignment' => backup::VAR_PARENTID));
8587
$testcase->set_source_table('assignment_oj_testcases', array('assignment' => backup::VAR_PARENTID));
8688

87-
$testcase->annotate_files('assign', 'onlinejudge_input', 'id');
88-
$testcase->annotate_files('assign', 'onlinejudge_output', 'id');
89-
90-
return $subplugin; // And we return the root subplugin element
91-
}
92-
93-
/**
94-
* Returns the subplugin information to attach at submission element
95-
*/
96-
protected function define_submission_subplugin_structure() {
89+
$testcase->annotate_files('assignfeedback_onlinejudge', 'onlinejudge_input', 'id');
90+
$testcase->annotate_files('assignfeedback_onlinejudge', 'onlinejudge_output', 'id');
9791

98-
// remember this has not XML representation
99-
$subplugin = $this->get_subplugin_element(null, '/assignment/assignmenttype', 'onlinejudge');
92+
// Returns the subplugin information to attach at submission element
10093

101-
// type of the subplugin, name of the subplugin and name of the connection point (recommended)
102-
$asssuboff = new backup_nested_element($this->get_recommended_name());
10394
// onlinejudge assignment type does not copy task details. So must backup from local onlinejudge
104-
$onlinejudgesubmissions = new backup_nested_element('onlinejudgesubmissions');
105-
$onlinejudgesubmission = new backup_nested_element('onlinejudgesubmission', array('id'), array('submission', 'testcase', 'task', 'latest'));
95+
$onlinejudge_submissions = new backup_nested_element('onlinejudge_submissions');
96+
$onlinejudge_submission = new backup_nested_element('onlinejudge_submission', array('id'), array('submission', 'testcase', 'task', 'latest'));
10697
$tasks = new backup_nested_element('tasks');
107-
$task = new backup_nested_element('task', array('id'), array('cmid', 'userid', 'language', 'memlimit', 'cpulimit', 'imput', 'output', 'compileonly', 'component', 'status', 'stdout', 'stderr', 'compileroutput', 'infoteacher', 'infostudent', 'cpuusage', 'memusage', 'submittime', 'judgetime', 'var1', 'var2', 'var3', 'var4', 'deleted'));
108-
109-
$subplugin->add_child($asssuboff);
110-
$asssuboff->add_child($onlinejudgesubmissions);
111-
$onlinejudgesubmissions->add_child($onlinejudgesubmission);
112-
$onlinejudgesubmission->add_child($tasks);
98+
$task = new backup_nested_element(
99+
'task',
100+
array('id'),
101+
array(
102+
'cmid', 'userid', 'language', 'memlimit', 'cpulimit', 'input', 'output',
103+
'compileonly', 'compile_lm_option', 'compile_warnings_option', 'compile_static_option',
104+
'component', 'status', 'stdout', 'stderr', 'compileroutput', 'infoteacher', 'infostudent',
105+
'cpuusage', 'memusage', 'submittime', 'judgetime', 'var1', 'var2', 'var3', 'var4', 'deleted'
106+
)
107+
);
108+
109+
$assassoff->add_child($onlinejudge_submissions);
110+
$onlinejudge_submissions->add_child($onlinejudge_submission);
111+
$onlinejudge_submission->add_child($tasks);
113112
$tasks->add_child($task);
114113

115-
$onlinejudgesubmission->set_source_table('assignment_oj_submissions', array('submission' => backup::VAR_PARENTID));
114+
$onlinejudge_submission->set_source_table('assignment_oj_submissions', array('submission' => backup::VAR_PARENTID));
116115
$task->set_source_table('onlinejudge_tasks', array('cmid' => backup::VAR_MODID, 'id' => '../../task'));
117116

118117
$task->annotate_ids('user', 'userid');
119118

120119
return $subplugin; // And we return the root subplugin element
121120
}
122-
}
121+
}
Lines changed: 41 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
// This file is part of Moodle - https://moodle.org
2+
3+
// This file is part of Moodle - http://moodle.org/
34
//
45
// Moodle is free software: you can redistribute it and/or modify
56
// it under the terms of the GNU General Public License as published by
@@ -14,33 +15,12 @@
1415
// You should have received a copy of the GNU General Public License
1516
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1617

17-
/**
18-
* NOTICE OF COPYRIGHT
19-
*
20-
* Online Judge for Moodle
21-
* https://github.com/hit-moodle/moodle-local_onlinejudge
22-
*
23-
* Copyright (C) 2009 onwards
24-
* Sun Zhigang http://sunner.cn
25-
* Andrew Naguib <andrew at fci helwan edu eg>
26-
* This program is free software; you can redistribute it and/or modify
27-
* it under the terms of the GNU General Public License as published by
28-
* the Free Software Foundation; either version 3 of the License, or
29-
* (at your option) any later version.
30-
*
31-
* This program is distributed in the hope that it will be useful,
32-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34-
* GNU General Public License for more details:
35-
*
36-
* http://www.gnu.org/copyleft/gpl.html
37-
*/
38-
3918
/**
4019
* @package local_onlinejudge
4120
* @subpackage backup-moodle2
4221
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
4322
* @copyright 2011 onwards Sun Zhigang (sunner) {@link http://sunner.cn}
23+
* @copyright 2017 onwards Andrew Naguib (ndrwnaguib) {@link http://ndrwnaguib.com}
4424
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4525
*/
4626

@@ -55,10 +35,38 @@
5535
*/
5636
class restore_assignfeedback_onlinejudge_subplugin extends restore_subplugin {
5737

38+
/**
39+
* Returns the paths to be handled by the subplugin at assignment level
40+
*/
41+
protected function define_grade_subplugin_structure() {
42+
43+
$paths = array();
44+
45+
$elename = $this->get_namefor('onlinejudge');
46+
$elepath = $this->get_pathfor('/onlinejudges/onlinejudge'); // because we used get_recommended_name() in backup this works
47+
$paths[] = new restore_path_element($elename, $elepath);
48+
49+
$elename = $this->get_namefor('testcase');
50+
$elepath = $this->get_pathfor('/testcases/testcase'); // because we used get_recommended_name() in backup this works
51+
$paths[] = new restore_path_element($elename, $elepath);
52+
53+
// Returns the paths to be handled by the subplugin at submission level
54+
55+
$elename = $this->get_namefor('onlinejudge_submission');
56+
$elepath = $this->get_pathfor('/onlinejudge_submissions/onlinejudge_submission'); // because we used get_recommended_name() in backup this works
57+
$paths[] = new restore_path_element($elename, $elepath);
58+
59+
$elename = $this->get_namefor('task');
60+
$elepath = $this->get_pathfor('/onlinejudge_submissions/onlinejudge_submission/tasks/task'); // because we used get_recommended_name() in backup this works
61+
$paths[] = new restore_path_element($elename, $elepath);
62+
63+
return $paths; // And we return the interesting paths
64+
}
65+
5866
/**
5967
* This method processes the onlinejudge element inside one onlinejudge assignment (see onlinejudge subplugin backup)
6068
*/
61-
public function process_assignfeedback_onlinejudge_assign($data) {
69+
public function process_assignfeedback_onlinejudge_onlinejudge($data) {
6270
global $DB;
6371

6472
$data = (object)$data;
@@ -73,25 +81,25 @@ public function process_assignfeedback_onlinejudge_assign($data) {
7381
/**
7482
* This method processes the testcase element inside one onlinejudge assignment (see onlinejudge subplugin backup)
7583
*/
76-
public function process_assignment_onlinejudge_testcase($data) {
84+
public function process_assignfeedback_onlinejudge_testcase($data) {
7785
global $DB;
7886

7987
$data = (object)$data;
8088
$oldid = $data->id;
8189

82-
$data->assignment = $this->get_new_parentid('assignment');
90+
$data->assignment = $this->get_new_parentid('assign');
8391

8492
$newitemid = $DB->insert_record('assignment_oj_testcases', $data);
8593
$this->set_mapping($this->get_namefor('testcase'), $oldid, $newitemid, true);
8694

87-
$this->add_related_files('assign', 'onlinejudge_input', $this->get_namefor('testcase'), null, $oldid);
88-
$this->add_related_files('assign', 'onlinejudge_output', $this->get_namefor('testcase'), null, $oldid);
95+
$this->add_related_files('assignfeedback_onlinejudge', 'onlinejudge_input', $this->get_namefor('testcase'), null, $oldid);
96+
$this->add_related_files('assignfeedback_onlinejudge', 'onlinejudge_output', $this->get_namefor('testcase'), null, $oldid);
8997
}
9098

9199
/**
92100
* This method processes the task element inside one onlinejudge assignment (see onlinejudge subplugin backup)
93101
*/
94-
public function process_assignment_onlinejudge_task($data) {
102+
public function process_assignfeedback_onlinejudge_task($data) {
95103
global $DB;
96104

97105
$data = (object)$data;
@@ -102,9 +110,9 @@ public function process_assignment_onlinejudge_task($data) {
102110

103111
$newitemid = $DB->insert_record('onlinejudge_tasks', $data);
104112

105-
// Since process_assignment_onlinejudge_onlinejudge_submission() is called before this function,
113+
// Since process_assignfeedback_onlinejudge_onlinejudge_submission() is called before this function,
106114
// we must update assignment_oj_submissions table's task by this way
107-
$DB->set_field('assignment_oj_submissions', 'task', $newitemid, array('task' => $oldid, 'submission' => $this->get_new_parentid('assignment_submission')));
115+
$DB->set_field('assignment_oj_submissions', 'task', $newitemid, array('task' => $oldid, 'submission' => $this->get_new_parentid('assign_submission')));
108116
}
109117

110118
/**
@@ -116,44 +124,8 @@ public function process_assignfeedback_onlinejudge_onlinejudge_submission($data)
116124
$data = (object)$data;
117125

118126
$data->testcase = $this->get_mappingid($this->get_namefor('testcase'), $data->testcase);
119-
$data->submission = $this->get_mappingid('assignment_submission', $data->submission);
127+
$data->submission = $this->get_mappingid('submission', $data->submission);
120128

121129
$DB->insert_record('assignment_oj_submissions', $data);
122130
}
123-
124-
/**
125-
* Returns the paths to be handled by the subplugin at assignment level
126-
*/
127-
protected function define_assignment_subplugin_structure() {
128-
129-
$paths = array();
130-
131-
$elename = $this->get_namefor('onlinejudge');
132-
$elepath = $this->get_pathfor('/onlinejudges/onlinejudge'); // because we used get_recommended_name() in backup this works
133-
$paths[] = new restore_path_element($elename, $elepath);
134-
135-
$elename = $this->get_namefor('testcase');
136-
$elepath = $this->get_pathfor('/testcases/testcase'); // because we used get_recommended_name() in backup this works
137-
$paths[] = new restore_path_element($elename, $elepath);
138-
139-
return $paths; // And we return the interesting paths
140-
}
141-
142-
/**
143-
* Returns the paths to be handled by the subplugin at submission level
144-
*/
145-
protected function define_submission_subplugin_structure() {
146-
147-
$paths = array();
148-
149-
$elename = $this->get_namefor('onlinejudge_submission');
150-
$elepath = $this->get_pathfor('/onlinejudge_submissions/onlinejudge_submission'); // because we used get_recommended_name() in backup this works
151-
$paths[] = new restore_path_element($elename, $elepath);
152-
153-
$elename = $this->get_namefor('task');
154-
$elepath = $this->get_pathfor('/onlinejudge_submissions/onlinejudge_submission/tasks/task'); // because we used get_recommended_name() in backup this works
155-
$paths[] = new restore_path_element($elename, $elepath);
156-
157-
return $paths; // And we return the interesting paths
158-
}
159-
}
131+
}

clients/mod/assign/feedback/onlinejudge/db/install.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</FIELDS>
4141
<KEYS>
4242
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="assignment"/>
43-
<KEY NAME="assignment" TYPE="foreign" FIELDS="assignment" REFTABLE="assignment" REFFIELDS="id"
43+
<KEY NAME="assignment" TYPE="foreign" FIELDS="assignment" REFTABLE="assign" REFFIELDS="id"
4444
COMMENT="assignment foreign key" PREVIOUS="primary"/>
4545
</KEYS>
4646
</TABLE>
@@ -60,8 +60,8 @@
6060
</FIELDS>
6161
<KEYS>
6262
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="submission"/>
63-
<KEY NAME="submission" TYPE="foreign" FIELDS="submission" REFTABLE="assignment_submissions"
64-
REFFIELDS="id" COMMENT="assignment_submissions foreign key" PREVIOUS="primary" NEXT="testcase"/>
63+
<KEY NAME="submission" TYPE="foreign" FIELDS="submission" REFTABLE="assign_submission"
64+
REFFIELDS="id" COMMENT="assign_submission foreign key" PREVIOUS="primary" NEXT="testcase"/>
6565
<KEY NAME="testcase" TYPE="foreign" FIELDS="testcase" REFTABLE="assignment_oj_testcases" REFFIELDS="id"
6666
PREVIOUS="submission"/>
6767
</KEYS>
@@ -92,12 +92,12 @@
9292
</FIELDS>
9393
<KEYS>
9494
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="assignment"/>
95-
<KEY NAME="assignment" TYPE="foreign" FIELDS="assignment" REFTABLE="assignment" REFFIELDS="id"
95+
<KEY NAME="assignment" TYPE="foreign" FIELDS="assignment" REFTABLE="assign" REFFIELDS="id"
9696
COMMENT="assignment foreign key" PREVIOUS="primary"/>
9797
</KEYS>
9898
<INDEXES>
9999
<INDEX NAME="sortorder" UNIQUE="false" FIELDS="sortorder"/>
100100
</INDEXES>
101101
</TABLE>
102102
</TABLES>
103-
</XMLDB>
103+
</XMLDB>

clients/mod/assign/feedback/onlinejudge/db/upgrade.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function xmldb_assignfeedback_onlinejudge_upgrade($oldversion = 0) {
107107

108108
// Adding keys to table assignment_oj_submissions
109109
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
110-
$table->add_key('submission', XMLDB_KEY_FOREIGN, array('submission'), 'assignment_submissions', array('id'));
110+
$table->add_key('submission', XMLDB_KEY_FOREIGN, array('submission'), 'assignment_submission', array('id'));
111111
$table->add_key('testcase', XMLDB_KEY_FOREIGN, array('testcase'), 'assignment_oj_testcases', array('id'));
112112
// Adding indexes to table assignment_oj_submissions
113113
$table->add_index('latest', XMLDB_INDEX_NOTUNIQUE, array('latest'));
@@ -286,6 +286,33 @@ function xmldb_assignfeedback_onlinejudge_upgrade($oldversion = 0) {
286286
}
287287
}
288288
}
289+
// define table assignment_oj_submissions to be dropped
290+
$table = new xmldb_table('assignment_oj_submissions');
291+
// conditionally launch drop table for assignment_oj_submissions
292+
if ($dbman->table_exists($table)) {
293+
$dbman->drop_table($table);
294+
}
295+
296+
// Define table assignment_oj_submissions to be created
297+
$table = new xmldb_table('assignment_oj_submissions');
298+
// Adding fields to table assignment_oj_submissions
299+
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
300+
$table->add_field('submission', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
301+
$table->add_field('testcase', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
302+
$table->add_field('task', XMLDB_TYPE_INTEGER, '20', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
303+
$table->add_field('latest', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
304+
305+
// Adding keys to table assignment_oj_submissions
306+
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
307+
$table->add_key('submission', XMLDB_KEY_FOREIGN, array('submission'), 'assign_submission', array('id'));
308+
$table->add_key('testcase', XMLDB_KEY_FOREIGN, array('testcase'), 'assignment_oj_testcases', array('id'));
309+
// Adding indexes to table assignment_oj_submissions
310+
$table->add_index('latest', XMLDB_INDEX_NOTUNIQUE, array('latest'));
311+
// Conditionally launch create table for assignment_oj_submissions
312+
if (!$dbman->table_exists($table)) {
313+
$dbman->create_table($table);
314+
}
315+
289316
upgrade_plugin_savepoint(true, 2018061400, 'assignfeedback', 'onlinejudge');
290317
}
291318

clients/mod/assign/feedback/onlinejudge/locallib.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function delete_instance() {
244244
global $CFG, $DB;
245245

246246
// delete onlinejudge submissions
247-
$submissions = $DB->get_records('assignment_submissions', array('assignment' => $this->assignment->get_instance()->id));
247+
$submissions = $DB->get_records('assign_submission', array('assignment' => $this->assignment->get_instance()->id));
248248
foreach ($submissions as $submission) {
249249
if (!$DB->delete_records('assignment_oj_submissions', array('submission' => $submission->id))) return false;
250250
}
@@ -566,4 +566,4 @@ public function view_page($action) {
566566
return '';
567567
}
568568

569-
}
569+
}

0 commit comments

Comments
 (0)