From 59185593d9488687999640c1f2c42cb87fb86df6 Mon Sep 17 00:00:00 2001 From: Jane Adelmann Date: Tue, 5 Jul 2022 17:04:51 +0300 Subject: [PATCH] Add debug mode --- form/plagiarism_pchkorg_setup_form.php | 8 +++ lang/en/plagiarism_pchkorg.php | 11 ++++ lib.php | 74 +++++++++++++++++++++++--- version.php | 6 +-- 4 files changed, 89 insertions(+), 10 deletions(-) diff --git a/form/plagiarism_pchkorg_setup_form.php b/form/plagiarism_pchkorg_setup_form.php index cb0aeda..cee17f7 100644 --- a/form/plagiarism_pchkorg_setup_form.php +++ b/form/plagiarism_pchkorg_setup_form.php @@ -55,6 +55,14 @@ class plagiarism_pchkorg_setup_form extends moodleform { $mform->addRule('pchkorg_token', null, 'required', null, 'client'); $mform->setType('pchkorg_token', PARAM_TEXT); + $mform->addElement( + 'select', + 'pchkorg_enable_debug', + get_string('pchkorg_enable_debug', 'plagiarism_pchkorg'), + array(get_string('no'), get_string('yes')) + ); + $mform->addHelpButton('pchkorg_enable_debug', 'pchkorg_enable_debug', 'plagiarism_pchkorg'); + $mform->registerRule('check_pchkorg_min_percent', 'callback', 'pchkorg_check_pchkorg_min_percent'); $label = get_string('pchkorg_min_percent', 'plagiarism_pchkorg'); diff --git a/lang/en/plagiarism_pchkorg.php b/lang/en/plagiarism_pchkorg.php index bfc2101..c00573b 100644 --- a/lang/en/plagiarism_pchkorg.php +++ b/lang/en/plagiarism_pchkorg.php @@ -42,8 +42,19 @@ $string['pchkorg_min_percent_range'] = 'Must be between 0 and 99'; $string['pchkorg_exclude_self_plagiarism'] = 'Exclude self-plagiarism'; $string['pchkorg_include_referenced'] = 'Include References'; $string['pchkorg_include_citation'] = 'Include Quotes'; +$string['pchkorg_enable_debug'] = 'Enable debug information'; +$string['pchkorg_enable_debug_help'] = 'This information can help you to understand why something not work'; $string['pchkorg_enable_quiz'] = 'Enable PlagiarismCheck in Quizzes'; $string['pchkorg_enable_forum'] = 'Enable PlagiarismCheck in Forum Activity'; +$string['pchkorg_debug_mime'] = 'Mime of file is not supported'; +$string['pchkorg_debug_disabled'] = 'Plugin is disabled'; +$string['pchkorg_debug_empty_context'] = 'Plugin is not supported in this place'; +$string['pchkorg_debug_user_has_no_permission'] = 'User has no moodle-permission to see this'; +$string['pchkorg_debug_disabled_acitivity'] = 'Plugin is disabled for this activity'; +$string['pchkorg_debug_not_member'] = 'User is not a member of plagiarismcheck group'; +$string['pchkorg_debug_user_has_no_capability'] = 'User does not have capability'; +$string['pchkorg_debug_no_check'] = 'There is no checks for this activity'; +$string['pchkorg_debug_status_error'] = 'Some error for this file'; $string['pchkorg_disclosure'] = 'Submission will be sent to PlagiarismCheck.org for check.
By submitting assignment I agree with Terms & Conditions diff --git a/lib.php b/lib.php index 865d9bf..70cb335 100644 --- a/lib.php +++ b/lib.php @@ -187,6 +187,7 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { $pchkorgconfigmodel = new plagiarism_pchkorg_config_model(); $apitoken = $pchkorgconfigmodel->get_system_config('pchkorg_token'); + $isdebugenabled = $pchkorgconfigmodel->get_system_config('pchkorg_enable_debug') === '1'; $apiprovider = new plagiarism_pchkorg_api_provider($apitoken); $cmid = $linkarray['cmid']; @@ -199,13 +200,22 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { // We can do nothing with submissions which we can not handle. if (null !== $file && !$apiprovider->is_supported_mime($file->get_mimetype())) { - return ''; + return $this->exit_message( + sprintf( + '%s (%s)', + get_string('pchkorg_debug_mime', 'plagiarism_pchkorg'), + $file->get_mimetype()), + $isdebugenabled + ); } // SQL will be called only once, result is static. $config = $pchkorgconfigmodel->get_system_config('pchkorg_use'); if ('1' !== $config) { - return ''; + return $this->exit_message( + get_string('pchkorg_debug_disabled', 'plagiarism_pchkorg'), + $isdebugenabled + ); } $context = null; $component = !empty($linkarray['component']) ? $linkarray['component'] : ''; @@ -223,17 +233,26 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { } if (empty($context)) { - return ''; + return $this->exit_message( + get_string('pchkorg_debug_empty_context', 'plagiarism_pchkorg'), + $isdebugenabled + ); } $canview = has_capability(capability::VIEW_SIMILARITY, $context); if (!$canview) { - return ''; + return $this->exit_message( + get_string('pchkorg_debug_user_has_no_permission', 'plagiarism_pchkorg'), + $isdebugenabled + ); } // SQL will be called only once per page. There is static result inside. if (!$pchkorgconfigmodel->is_enabled_for_module($cmid)) { - return ''; + return $this->exit_message( + get_string('pchkorg_debug_disabled_acitivity', 'plagiarism_pchkorg'), + $isdebugenabled + ); } // Only for some type of account, method will call a remote HTTP API. @@ -242,12 +261,24 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin { // Even if service will be unavailable, method will try call API only once. // Also, we don't use raw user email. if (!$apiprovider->is_group_member($USER->email)) { - return ''; + return $this->exit_message( + sprintf( + '%s (%s)', + get_string('pchkorg_debug_not_member', 'plagiarism_pchkorg'), + $USER->email), + $isdebugenabled + ); } $isgranted = !empty($context) && has_capability('mod/assign:view', $context, null); if (!$isgranted) { - return ''; + return $this->exit_message( + sprintf( + '%s (%s)', + get_string('pchkorg_debug_user_has_no_capability', 'plagiarism_pchkorg'), + 'mod/assign:view'), + $isdebugenabled + ); } $where = new \stdClass(); @@ -426,9 +457,38 @@ display: inline-block;" logo ' . $label . ' '; + } else { + return $this->exit_message( + sprintf( + '%s (%s)', + get_string('pchkorg_debug_status_error', 'plagiarism_pchkorg'), + $filerecord->state), + $isdebugenabled + ); } } + return $this->exit_message( + sprintf( + '%s (%s)', + get_string('pchkorg_debug_no_check', 'plagiarism_pchkorg'), + $cmid), + $isdebugenabled + ); + } + + /** + * Render message with reason why do we stop plugin. + * + * @param string $message - exit message + * @param bool $debug - is debug enabled. + * @return string + */ + private function exit_message($message, $debug) { + if ($debug) { + return $message; + } + return ''; } diff --git a/version.php b/version.php index 058bd93..1f3bc0e 100644 --- a/version.php +++ b/version.php @@ -26,11 +26,11 @@ defined('MOODLE_INTERNAL') || die(); if (!isset($plugin)) { $plugin = new stdClass(); } -$plugin->version = 2022061418; +$plugin->version = 2022071720; $plugin->requires = 2020061501; // Requires Moodle 3.9 . -$plugin->release = 'v3.9.6'; +$plugin->release = 'v3.9.7'; $plugin->component = 'plagiarism_pchkorg'; $plugin->maturity = MATURITY_STABLE; $plugin->dependencies = array( - 'mod_assign' => ANY_VERSION, + 'mod_assign' => ANY_VERSION, );