From 3a06a2f7dd13a8f4864d5f0e8ba5359a4e06a653 Mon Sep 17 00:00:00 2001 From: Neill Magill Date: Mon, 17 Jul 2023 14:54:43 +0100 Subject: [PATCH] MDL-71909 assignfeedback_editpdf: Do not queue conversions when not on Before this change conversion tasks would be queued for assignments that did not have the pdf annotation method enabled. The change will also prevent queing when the plugin is disabled. --- .../editpdf/classes/event/observer.php | 8 +++++ .../feedback/editpdf/tests/feedback_test.php | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/mod/assign/feedback/editpdf/classes/event/observer.php b/mod/assign/feedback/editpdf/classes/event/observer.php index 278a694d5dac4..894ee73bb0e1a 100644 --- a/mod/assign/feedback/editpdf/classes/event/observer.php +++ b/mod/assign/feedback/editpdf/classes/event/observer.php @@ -51,6 +51,14 @@ public static function submission_updated(\mod_assign\event\submission_updated $ * @param \mod_assign\event\base $event The submission created/updated event. */ protected static function queue_conversion($event) { + $assign = $event->get_assign(); + $plugin = $assign->get_feedback_plugin_by_type('editpdf'); + + if (!$plugin->is_visible() || !$plugin->is_enabled()) { + // The plugin is not enabled on this assignment instance, so nothing should be queued. + return; + } + $data = [ 'submissionid' => $event->other['submissionid'], 'submissionattempt' => $event->other['submissionattempt'], diff --git a/mod/assign/feedback/editpdf/tests/feedback_test.php b/mod/assign/feedback/editpdf/tests/feedback_test.php index de03154fd084b..00004b104a84a 100644 --- a/mod/assign/feedback/editpdf/tests/feedback_test.php +++ b/mod/assign/feedback/editpdf/tests/feedback_test.php @@ -578,4 +578,33 @@ public function test_submission_file_overridden() { $conversions = \core_files\conversion::get_conversions_for_file($sourcefile, 'pdf'); $this->assertCount(0, $conversions); } + + /** + * Tests that when the plugin is not enabled for an assignment it does not create conversion tasks. + * + * @covers \assignfeedback_editpdf\event\observer + */ + public function test_submission_not_enabled() { + $this->require_ghostscript(); + $this->resetAfterTest(); + \core\cron::setup_user(); + + $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' => 0, + 'assignsubmission_file_maxsizebytes' => 1000000, + ]; + $assign = $this->create_instance($course, $assignopts); + + // Add the standard submission. + $this->add_file_submission($student, $assign); + + $task = \core\task\manager::get_next_adhoc_task(time()); + + // No task was created. + $this->assertNull($task); + } }