Пример #1
0
 /**
  * Hook for cron
  */
 public function cron()
 {
     mtrace('---Moss begins---');
     moss_clean_noise();
     moss_measure_all();
     mtrace('---Moss done---');
 }
/**
 * Clean up all data related with cmid
 *
 * @param int $cmid
 * @return true or false
 */
function moss_clean_cm($cmid)
{
    global $DB;
    if ($moss = $DB->get_record('plagiarism_moss', array('cmid' => $cmid))) {
        // clean up configs
        $DB->delete_records('plagiarism_moss_configs', array('moss' => $moss->id));
        // clean up results
        $results = $DB->get_records('plagiarism_moss_results', array('moss' => $moss->id));
        foreach ($results as $result) {
            $DB->delete_records('plagiarism_moss_matchedfiles', array('result' => $result->id));
        }
        // clean up files and results
        if ($moss->tag == 0) {
            // if no tag setted, no need to keep the files and moss record for further detection
            $fs = get_file_storage();
            $fs->delete_area_files(get_system_context()->id, 'plagiarism_moss', 'files', $cmid);
            $DB->delete_records('plagiarism_moss', array('cmid' => $cmid));
            // Clean results
            $DB->delete_records('plagiarism_moss_results', array('moss' => $moss->id));
        } else {
            moss_clean_noise($moss);
            // Disable moss record related with a deleted cm
            // The record will be reserved for further reference by other mosses
            // with the same tags
            $moss->enabled = 0;
            $DB->update_record('plagiarism_moss', $moss);
            // Clean results
            $DB->delete_records('plagiarism_moss_results', array('moss' => $moss->id));
        }
    }
    return true;
}