Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class provider implements
*/
public static function get_metadata($collection): \core_privacy\local\metadata\collection {
$collection->add_database_table(
'tool_pdfdetect_assigns',
'tool_corruptpdfdetector_assigns',
[
'email' => 'privacy:metadata:tool_corruppdfdetector:email',
'userfullname' => 'privacy:metadata:tool_corruppdfdetector:userfullname',
Expand Down
13 changes: 8 additions & 5 deletions classes/table/assignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assignments extends html_table {

/**
* Constructor
*/
Expand Down Expand Up @@ -89,7 +88,7 @@ public function __construct() {
private function get_detected_assignments() {
global $DB;

$records = $DB->get_records('tool_pdfdetect_assigns', [], 'detected ASC');
$records = $DB->get_records('tool_corruptpdfdetector_assigns', [], 'detected ASC');

return $records;
}
Expand All @@ -106,12 +105,16 @@ public function get_percentage() {
global $DB;

$submissioncount = $DB->count_records('assign_submission');
$filecount = $DB->count_records_select('tool_pdfdetect_assigns',
'fixed = ?', [false], 'COUNT(DISTINCT submissionid)');
$filecount = $DB->count_records_select(
'tool_corruptpdfdetector_assigns',
'fixed = ?',
[false],
'COUNT(DISTINCT submissionid)'
);

if ($filecount === 0 || $submissioncount === 0) {
return '0';
}
return round ($filecount * 100 / $submissioncount).'%';
return round($filecount * 100 / $submissioncount) . '%';
}
}
12 changes: 6 additions & 6 deletions classes/task/fix_assignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class fix_assignments extends \core\task\scheduled_task {

/**
* {@inheritDoc}
* @see \core\task\scheduled_task::get_name()
Expand All @@ -42,19 +41,20 @@ public function execute() {
global $DB;

// Fetch all broken assignment submissions.
$records = $DB->get_recordset('tool_pdfdetect_assigns', ['fixed' => false]);
$records = $DB->get_recordset('tool_corruptpdfdetector_assigns', ['fixed' => false]);

foreach ($records as $submission) {
$contenthash = $submission->filename;
$params['contenthash'] = $contenthash;
$DB->delete_records_select('files',
$DB->delete_records_select(
'files',
"contenthash = :contenthash AND filename = 'combined.pdf'
AND (filearea = 'combined' OR filearea = 'partial')",
$params);
$params
);
$submission->fixed = true;
$DB->update_record('tool_pdfdetect_assigns', $submission);
$DB->update_record('tool_corruptpdfdetector_assigns', $submission);
}
$records->close();
}

}
22 changes: 9 additions & 13 deletions classes/task/scan_assignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_once($CFG->dirroot . '/mod/assign/feedback/editpdf/fpdi/autoload.php');

define("ONE", 1);
define("NUMBER_OF_EACH_RUN", 1000);

/**
* Task to scan assignments.
*
Expand All @@ -37,7 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class scan_assignments extends \core\task\scheduled_task {

/**
* {@inheritDoc}
* @see \core\task\scheduled_task::get_name()
Expand All @@ -55,9 +51,9 @@ public function execute() {

// Get the last submission id that had been checked in last run.
$lastrun = $DB->get_records_sql('SELECT lastsubmissionid
FROM {tool_pdfdetect_runs}
FROM {tool_corruptpdfdetector_runs}
ORDER BY runtime
DESC LIMIT :one', ['one' => ONE]);
DESC LIMIT 1');

$lastsubmitid = 0;
if ($lastrun) {
Expand All @@ -69,7 +65,7 @@ public function execute() {
WHERE userid > 0
AND id > :id
ORDER BY timecreated
ASC LIMIT :num', ['id' => $lastsubmitid, 'num' => NUMBER_OF_EACH_RUN]);
ASC', ['id' => $lastsubmitid], 0, 1000);
$detectednum = 0;
$run = new \stdClass();

Expand All @@ -79,7 +75,7 @@ public function execute() {
$detectedsubmission = $this->detected_submission($submission);
if ($detectedsubmission != null) {
$pdfwitherror = $this->check_submission_combined_pdf($submission);
$detected = $DB->get_record('tool_pdfdetect_assigns', ['submissionid' => $submission->id]);
$detected = $DB->get_record('tool_corruptpdfdetector_assigns', ['submissionid' => $submission->id]);
$detected->submitted = $submission->timemodified;
if ($pdfwitherror != null) {
$detected->detected = $pdfwitherror->detected;
Expand All @@ -90,12 +86,12 @@ public function execute() {
} else {
$detected->fixed = true;
}
$DB->update_record('tool_pdfdetect_assigns', $detected);
$DB->update_record('tool_corruptpdfdetector_assigns', $detected);
} else {
$pdfwitherror = $this->check_submission_combined_pdf($submission);
if ($pdfwitherror != null) {
$detectednum++;
$DB->insert_record('tool_pdfdetect_assigns', $pdfwitherror);
$DB->insert_record('tool_corruptpdfdetector_assigns', $pdfwitherror);
}
}
}
Expand All @@ -105,7 +101,7 @@ public function execute() {
}
$run->runtime = time();
$run->detectednumber = $detectednum;
$DB->insert_record('tool_pdfdetect_runs', $run);
$DB->insert_record('tool_corruptpdfdetector_runs', $run);
}

/**
Expand Down Expand Up @@ -137,7 +133,7 @@ private function get_pdf_file_for_assignment(assign $assignment, stdClass $submi
}

/**
* Detects a previously recorded submission in the 'tool_pdfdetect_assigns' table.
* Detects a previously recorded submission in the 'tool_corruptpdfdetector_assigns' table.
*
* @param stdClass $submission The submission object containing the ID to look up in the database.
*
Expand All @@ -148,7 +144,7 @@ private function detected_submission(stdClass $submission): ?stdClass {

$params = ['submissionid' => $submission->id];
$select = $DB->sql_compare_text('submissionid') . ' = ' . $DB->sql_compare_text(':submissionid');
$detectedsubmission = $DB->get_record_select('tool_pdfdetect_assigns', $select, $params);
$detectedsubmission = $DB->get_record_select('tool_corruptpdfdetector_assigns', $select, $params);

if (!empty($detectedsubmission)) {
return $detectedsubmission;
Expand Down
4 changes: 2 additions & 2 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="tool_pdfdetect_assigns" COMMENT="Table to store affected assignments">
<TABLE NAME="tool_corruptpdfdetector_assigns" COMMENT="Table to store affected assignments">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="assignid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
Expand All @@ -27,7 +27,7 @@
<INDEX NAME="submissionid" UNIQUE="true" FIELDS="submissionid"/>
</INDEXES>
</TABLE>
<TABLE NAME="tool_pdfdetect_runs" COMMENT="Table to store completed runs">
<TABLE NAME="tool_corruptpdfdetector_runs" COMMENT="Table to store completed runs">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="lastsubmissionid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
Expand Down
58 changes: 58 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Upgrade logic.
*
* @package tool_corruptpdfdetector
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Performs data migrations and updates on upgrade.
*
* @param integer $oldversion
* @return boolean
*/
function xmldb_tool_corruptpdfdetector_upgrade($oldversion = 0) {
global $CFG, $DB;

require_once($CFG->libdir . '/db/upgradelib.php'); // Core Upgrade-related functions.

$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.

if ($oldversion < 2026042301) {
// Rename table tool_pdfdetect_assigns to tool_corruptpdfdetector_assigns.
$table = new xmldb_table('tool_pdfdetect_assigns');

if ($dbman->table_exists($table)) {
$dbman->rename_table($table, 'tool_corruptpdfdetector_assigns');
}

// Rename table tool_pdfdetect_runs to tool_corruptpdfdetector_runs.
$table = new xmldb_table('tool_pdfdetect_runs');

if ($dbman->table_exists($table)) {
$dbman->rename_table($table, 'tool_corruptpdfdetector_runs');
}

// Corruptpdfdetector savepoint reached.
upgrade_plugin_savepoint(true, 2026042301, 'tool', 'corruptpdfdetector');
}

return true;
}
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
require_capability('moodle/site:config', context_system::instance());
admin_externalpage_setup('tool_corruptpdfdetector');

$assignments = new tool_corruptpdfdetector\table\assignments;
$assignments = new tool_corruptpdfdetector\table\assignments();

echo $OUTPUT->header();
echo html_writer::tag('h1', get_string('h1_current', 'tool_corruptpdfdetector'));
Expand Down
7 changes: 5 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

if ($hassiteconfig) {
$url = new moodle_url("/admin/tool/corruptpdfdetector");
$ADMIN->add('server', new admin_externalpage('tool_corruptpdfdetector',
get_string('pluginname', 'tool_corruptpdfdetector'), $url));
$ADMIN->add('server', new admin_externalpage(
'tool_corruptpdfdetector',
get_string('pluginname', 'tool_corruptpdfdetector'),
$url
));
}
Loading
Loading