Skip to content

Commit

Permalink
Merge pull request #54 from Copyleaks/bugfixes/1207271729983716-repor…
Browse files Browse the repository at this point in the history
…t-not-generating

1207271729983716-report-not-generating
  • Loading branch information
CL-BayanAbuawad authored Jul 10, 2024
2 parents f527798 + b2fed72 commit 1a6bf58
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
55 changes: 51 additions & 4 deletions classes/plagiarism_copyleaks_eventshandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ private function queue_files($data, $coursemodule, $authoruserid, $submitteruser

foreach ($data['other']['pathnamehashes'] as $pathnamehash) {

$hashedcontent = $this->check_existing_file_identifier($pathnamehash, $coursemodule, $authoruserid);

$filestorage = get_file_storage();
$fileref = $filestorage->get_file_by_hash($pathnamehash);

Expand Down Expand Up @@ -368,13 +370,52 @@ private function queue_files($data, $coursemodule, $authoruserid, $submitteruser
$pathnamehash,
'file',
$data['objectid'],
$cmdata
$cmdata,
$hashedcontent
);
}

return $result;
}

/**
* Check if same identifier already exists in copyleaks_files table,
* in case the content is different it will be deleted.
* @param string $pathnamehash
* @return string hashed content
*/
private function check_existing_file_identifier($pathnamehash, $coursemodule, $authoruserid) {
global $DB, $CFG;

$filerecord = $DB->get_record('files', array('pathnamehash' => $pathnamehash));
$hashedcontent = null;

if ($filerecord) {
$hashedcontent = $filerecord->contenthash;

$typefield = ($CFG->dbtype == "oci") ? " to_char(submissiontype) " : " submissiontype ";
$savedfile = $DB->get_record(
'plagiarism_copyleaks_files',
array(
"cm" => $coursemodule->id,
"userid" => $authoruserid,
$typefield => 'file',
"identifier" => $pathnamehash
),
);

if (isset($savedfile->hashedcontent) && $savedfile->hashedcontent != $hashedcontent) {
$DB->delete_records('plagiarism_copyleaks_files', array(
"cm" => $coursemodule->id,
"userid" => $authoruserid,
$typefield => 'file',
"identifier" => $pathnamehash
));
}
}
return $hashedcontent;
}

/**
* Queue submission to be submitted later to Copyleaks by submission task.
* @param object $coursemodule
Expand All @@ -393,7 +434,8 @@ private function queue_submission_to_copyleaks(
$identifier,
$subtype,
$itemid,
$cmdata
$cmdata,
$hashedcontent = null
) {
global $DB, $CFG;

Expand All @@ -419,7 +461,13 @@ private function queue_submission_to_copyleaks(
// Submission already exists, do not queue it again.
return true;
} else {
$submissionid = plagiarism_copyleaks_submissions::create($coursemodule, $authoruserid, $identifier, $subtype);
$submissionid = plagiarism_copyleaks_submissions::create(
$coursemodule,
$authoruserid,
$identifier,
$subtype,
$hashedcontent
);
}

// Check if file type is supported by Copyleaks.
Expand All @@ -443,7 +491,6 @@ private function queue_submission_to_copyleaks(

// Scan immediately.
$scheduledscandate = strtotime('- 1 minutes');

if (isset($cmdata->duedate)) {
// Get module settings.
$clmoduleconfig = $DB->get_records_menu(
Expand Down
3 changes: 2 additions & 1 deletion classes/plagiarism_copyleaks_submissions.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class plagiarism_copyleaks_submissions {
* @param string $identifier
* @param string $submissiontype
**/
public static function create($cm, $userid, $identifier, $submissiontype) {
public static function create($cm, $userid, $identifier, $submissiontype, $hashedcontent = null) {
global $DB;

$file = new stdClass();
Expand All @@ -49,6 +49,7 @@ public static function create($cm, $userid, $identifier, $submissiontype) {
$file->statuscode = "queued";
$file->similarityscore = null;
$file->submissiontype = $submissiontype;
$file->hashedcontent = $hashedcontent;

if (!$fileid = $DB->insert_record('plagiarism_copyleaks_files', $file)) {
\plagiarism_copyleaks_logs::add(
Expand Down
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="submitter" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="identifier" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="hashedcontent" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="externalid" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="statuscode" TYPE="char" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
Expand Down
18 changes: 17 additions & 1 deletion db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ function xmldb_plagiarism_copyleaks_upgrade($oldversion) {
null,
null,
null,
'aiscore');
'aiscore'
);
$grammarfield = new xmldb_field('grammarcases', XMLDB_TYPE_NUMBER, '10', null, null, null, null);

if ($dbman->table_exists($table)) {
Expand Down Expand Up @@ -492,5 +493,20 @@ function xmldb_plagiarism_copyleaks_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2024041700, 'plagiarism', 'copyleaks');
}

if ($oldversion < 2024070700) {
$table = new xmldb_table('plagiarism_copyleaks_files');
$hashedcontentfield = new xmldb_field('hashedcontent', XMLDB_TYPE_CHAR, '255', null, false, null, null, 'identifier');

if ($dbman->table_exists($table)) {
// Add hashed content field to files table.
if (!$dbman->field_exists($table, $hashedcontentfield)) {
$dbman->add_field($table, $hashedcontentfield);
}
}

// Copyleaks savepoint reached.
upgrade_plugin_savepoint(true, 2024070700, 'plagiarism', 'copyleaks');
}

return true;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024051600;
$plugin->version = 2024070700;
$plugin->release = "3.5+";
$plugin->requires = 2018051700;
$plugin->component = 'plagiarism_copyleaks';
Expand Down

0 comments on commit 1a6bf58

Please sign in to comment.