Merge branch 'MDL-57610' of git://github.com/aolley/moodle
This commit is contained in:
@@ -575,6 +575,14 @@ $CFG->admin = 'admin';
|
||||
//
|
||||
// $CFG->upgradekey = 'put_some_password-like_value_here';
|
||||
//
|
||||
// Document conversion limit
|
||||
//
|
||||
// How many times the background task should attempt to convert a given attempt
|
||||
// before removing it from the queue. Currently this limit is only used by the
|
||||
// mod_assign conversion task.
|
||||
//
|
||||
// $CFG->conversionattemptlimit = 3;
|
||||
//
|
||||
//=========================================================================
|
||||
// 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!
|
||||
//=========================================================================
|
||||
|
||||
+4
-3
@@ -71,12 +71,11 @@ information provided here is intended especially for developers.
|
||||
- I navigate to "PATH > ITEM" in site administration
|
||||
- I navigate to course participants
|
||||
- I navigate to "TAB1 > TAB2" in the course gradebook
|
||||
* The core\session\util class has been removed. This contained one function only used by the memcached class which has
|
||||
been moved there instead (connection_string_to_memcache_servers).
|
||||
|
||||
If some items are not available without Navigation block at all, one can use combination of:
|
||||
- I add the "Navigation" block if not present
|
||||
- I click on "LINK" "link" in the "Navigation" "block"
|
||||
* The core\session\util class has been removed. This contained one function only used by the memcached class which has
|
||||
been moved there instead (connection_string_to_memcache_servers).
|
||||
* Removed the lib/password_compat/lib/password.php file.
|
||||
* The eventslib.php file has been deleted and its functions have been moved to deprecatedlib.php. The affected functions are:
|
||||
- events_get_cached()
|
||||
@@ -129,6 +128,8 @@ information provided here is intended especially for developers.
|
||||
* New optional parameter $context for the groups_get_members_join() function and ability to filter users that are not members of
|
||||
any group. Besides, groups_get_members_ids_sql, get_enrolled_sql and get_enrolled_users now accepts -1 (USERSWITHOUTGROUP) for
|
||||
the groupid field.
|
||||
* Added $CFG->conversionattemptlimit setting to config.php allowing a maximum number of retries before giving up conversion
|
||||
of a given document by the assignfeedback_editpdf\task\convert_submissions task. Default value: 3.
|
||||
|
||||
=== 3.5 ===
|
||||
|
||||
|
||||
@@ -35,17 +35,7 @@ class observer {
|
||||
* @param \mod_assign\event\submission_created $event
|
||||
*/
|
||||
public static function submission_created(\mod_assign\event\submission_created $event) {
|
||||
global $DB;
|
||||
|
||||
$submissionid = $event->other['submissionid'];
|
||||
$submissionattempt = $event->other['submissionattempt'];
|
||||
$fields = array( 'submissionid' => $submissionid, 'submissionattempt' => $submissionattempt);
|
||||
$record = (object) $fields;
|
||||
|
||||
$exists = $DB->get_records('assignfeedback_editpdf_queue', $fields);
|
||||
if (!$exists) {
|
||||
$DB->insert_record('assignfeedback_editpdf_queue', $record);
|
||||
}
|
||||
self::queue_conversion($event);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,6 +43,14 @@ class observer {
|
||||
* @param \mod_assign\event\submission_updated $event
|
||||
*/
|
||||
public static function submission_updated(\mod_assign\event\submission_updated $event) {
|
||||
self::queue_conversion($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue the submission for processing.
|
||||
* @param \mod_assign\event\base $event The submission created/updated event.
|
||||
*/
|
||||
protected static function queue_conversion($event) {
|
||||
global $DB;
|
||||
|
||||
$submissionid = $event->other['submissionid'];
|
||||
@@ -60,9 +58,13 @@ class observer {
|
||||
$fields = array( 'submissionid' => $submissionid, 'submissionattempt' => $submissionattempt);
|
||||
$record = (object) $fields;
|
||||
|
||||
$exists = $DB->get_records('assignfeedback_editpdf_queue', $fields);
|
||||
$exists = $DB->get_record('assignfeedback_editpdf_queue', $fields);
|
||||
if (!$exists) {
|
||||
$DB->insert_record('assignfeedback_editpdf_queue', $record);
|
||||
} else {
|
||||
// This submission attempt was already queued, so just reset the existing failure counter to ensure it gets processed.
|
||||
$exists->attemptedconversions = 0;
|
||||
$DB->update_record('assignfeedback_editpdf_queue', $exists);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,15 +58,21 @@ class convert_submissions extends scheduled_task {
|
||||
|
||||
$assignmentcache = array();
|
||||
|
||||
$conversionattemptlimit = !empty($CFG->conversionattemptlimit) ? $CFG->conversionattemptlimit : 3;
|
||||
foreach ($records as $record) {
|
||||
$submissionid = $record->submissionid;
|
||||
$submission = $DB->get_record('assign_submission', array('id' => $submissionid), '*', IGNORE_MISSING);
|
||||
if (!$submission) {
|
||||
// Submission no longer exists.
|
||||
if (!$submission || $record->attemptedconversions >= $conversionattemptlimit) {
|
||||
// Submission no longer exists; or we've exceeded the conversion attempt limit.
|
||||
$DB->delete_records('assignfeedback_editpdf_queue', array('id' => $record->id));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Record that we're attempting the conversion ahead of time.
|
||||
// We can't do this afterwards as its possible for the conversion process to crash the script entirely.
|
||||
$DB->set_field('assignfeedback_editpdf_queue', 'attemptedconversions',
|
||||
$record->attemptedconversions + 1, ['id' => $record->id]);
|
||||
|
||||
$assignmentid = $submission->assignment;
|
||||
$attemptnumber = $record->submissionattempt;
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="submissionid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="submissionattempt" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="attemptedconversions" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
|
||||
@@ -62,5 +62,38 @@ function xmldb_assignfeedback_editpdf_upgrade($oldversion) {
|
||||
// Automatically generated Moodle v3.5.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
if ($oldversion < 2018051401) {
|
||||
$table = new xmldb_table('assignfeedback_editpdf_queue');
|
||||
$field = new xmldb_field('attemptedconversions', XMLDB_TYPE_INTEGER, '10', null,
|
||||
XMLDB_NOTNULL, null, 0, 'submissionattempt');
|
||||
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Attempts are removed from the queue after being processed, a duplicate row won't achieve anything productive.
|
||||
// So look for any duplicates and remove them so we can add a unique key.
|
||||
$sql = "SELECT MIN(id) as minid, submissionid, submissionattempt
|
||||
FROM {assignfeedback_editpdf_queue}
|
||||
GROUP BY submissionid, submissionattempt
|
||||
HAVING COUNT(id) > 1";
|
||||
|
||||
if ($duplicatedrows = $DB->get_recordset_sql($sql)) {
|
||||
foreach ($duplicatedrows as $row) {
|
||||
$DB->delete_records_select('assignfeedback_editpdf_queue',
|
||||
'submissionid = :submissionid AND submissionattempt = :submissionattempt AND id <> :minid', (array)$row);
|
||||
}
|
||||
}
|
||||
$duplicatedrows->close();
|
||||
|
||||
// Define key submissionid-submissionattempt to be added to assignfeedback_editpdf_queue.
|
||||
$table = new xmldb_table('assignfeedback_editpdf_queue');
|
||||
$key = new xmldb_key('submissionid-submissionattempt', XMLDB_KEY_UNIQUE, ['submissionid', 'submissionattempt']);
|
||||
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
upgrade_plugin_savepoint(true, 2018051401, 'assignfeedback', 'editpdf');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -338,6 +338,63 @@ class assignfeedback_editpdf_testcase extends advanced_testcase {
|
||||
$this->assertEmpty($file3);
|
||||
}
|
||||
|
||||
public function test_conversion_task() {
|
||||
global $DB;
|
||||
$this->require_ghostscript();
|
||||
$this->resetAfterTest();
|
||||
cron_setup_user();
|
||||
|
||||
$task = new \assignfeedback_editpdf\task\convert_submissions;
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
||||
$assignopts = [
|
||||
'assignsubmission_file_enabled' => 1,
|
||||
'assignsubmission_file_maxfiles' => 1,
|
||||
'assignfeedback_editpdf_enabled' => 1,
|
||||
'assignsubmission_file_maxsizebytes' => 1000000,
|
||||
];
|
||||
$assign = $this->create_instance($course, $assignopts);
|
||||
|
||||
// Add the standard submission.
|
||||
$this->add_file_submission($student, $assign);
|
||||
|
||||
// Run the conversion task.
|
||||
ob_start();
|
||||
$task->execute();
|
||||
$output = ob_get_clean();
|
||||
|
||||
// Verify it acted on both submissions in the queue.
|
||||
$this->assertContains("Convert 1 submission attempt(s) for assignment {$assign->get_instance()->id}", $output);
|
||||
$this->assertEquals(0, $DB->count_records('assignfeedback_editpdf_queue'));
|
||||
|
||||
// Set a known limit.
|
||||
set_config('conversionattemptlimit', 3);
|
||||
|
||||
// Trigger a re-queue by 'updating' a submission.
|
||||
$submission = $assign->get_user_submission($student->id, true);
|
||||
$plugin = $assign->get_submission_plugin_by_type('file');
|
||||
$plugin->save($submission, (new stdClass));
|
||||
|
||||
// Verify that queued a conversion task.
|
||||
$this->assertEquals(1, $DB->count_records('assignfeedback_editpdf_queue'));
|
||||
|
||||
// Fake some failed attempts for it.
|
||||
$queuerecord = $DB->get_record('assignfeedback_editpdf_queue', ['submissionid' => $submission->id]);
|
||||
$queuerecord->attemptedconversions = 3;
|
||||
$DB->update_record('assignfeedback_editpdf_queue', $queuerecord);
|
||||
|
||||
ob_start();
|
||||
$task->execute();
|
||||
$output = ob_get_clean();
|
||||
|
||||
// Verify that the cron task skipped the submission.
|
||||
$this->assertNotContains("Convert 1 submission attempt(s) for assignment {$assign->get_instance()->id}", $output);
|
||||
// And it removed it from the queue.
|
||||
$this->assertEquals(0, $DB->count_records('assignfeedback_editpdf_queue'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that modifying the annotated pdf form return true when modified
|
||||
* and false when not modified.
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2018051400;
|
||||
$plugin->version = 2018051401;
|
||||
$plugin->requires = 2018050800;
|
||||
$plugin->component = 'assignfeedback_editpdf';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user