From b41d6454ab319f13d5937e866f6732d72b356097 Mon Sep 17 00:00:00 2001 From: GaziYucel Date: Tue, 19 Mar 2024 12:30:34 +0100 Subject: [PATCH] isDebugMode moved to config.php and method from const --- CitationManagerPlugin.php | 33 +++++++++++--------------------- README.md | 9 +++++++-- classes/External/ApiAbstract.php | 2 +- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/CitationManagerPlugin.php b/CitationManagerPlugin.php index d8ab6f0f..f5e1339e 100755 --- a/CitationManagerPlugin.php +++ b/CitationManagerPlugin.php @@ -7,7 +7,7 @@ * @license Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. * * @class CitationManagerPlugin - * @brief Plugin for parsing Citations and submitting to Open Access websites. + * @brief Plugin for structuring, enriching and depositing Citations from and to external services. */ namespace APP\plugins\generic\citationManager; @@ -34,9 +34,6 @@ class CitationManagerPlugin extends GenericPlugin { - /** @var true Whether debugging mode is activated, careful with exposing secrets! */ - public const isDebugMode = false; - /** @var string Whether show the structured or the raw citations */ public const CITATION_MANAGER_FRONTEND_SHOW_STRUCTURED = CITATION_MANAGER_PLUGIN_NAME . '_FrontEndShowStructured'; /** @var string Key for the journal metadata saved in journal */ @@ -162,28 +159,20 @@ public function getDisplayName(): string } /** - * Load a setting or load it from the config.inc.php if it is specified there. - * - * @param int $contextId The context or journal identifier. - * @param string $name The name of the setting. - * @return mixed|null|false The setting value or null if not found. + * Get isDebugMode from config, return false if setting not present + * @return bool */ - public function getSetting($contextId, $name): mixed + public static function isDebugMode(): bool { - switch ($name) { - case 'isTestMode': - $config_value = Config::getVar(CITATION_MANAGER_PLUGIN_NAME, 'isTestMode'); - if (!empty($config_value) && (strtolower($config_value) === 'true' || (string)$config_value === '1')) { - $config_value = true; - } else if (!empty($config_value)) { - $config_value = false; - } - break; - default: - return parent::getSetting($contextId, $name); + $config_value = Config::getVar(CITATION_MANAGER_PLUGIN_NAME, 'isDebugMode'); + + if (!empty($config_value) + && (strtolower($config_value) === 'true' || (string)$config_value === '1') + ) { + return true; } - return $config_value ?: parent::getSetting($contextId, $name); + return false; } } diff --git a/README.md b/README.md index 585a4acb..17b7bcb3 100755 --- a/README.md +++ b/README.md @@ -267,13 +267,18 @@ Notes ## Debugging -There is a isDebugMode constant in file CitationManagerPlugin.php. -This constant puts the plugin in debugging mode. +There is a debug mode possibility in this plugin. This constant puts the plugin in debugging mode. Extra debug information will be written to the log file (see LogHelper class) such as API calls. Debug information is written to the log file in the `files_dir` directory of your OJS instance. You can find the `files_dir` constant in your config.inc.php file. +Please put the following in the file config.inc.php to enable this: +``` +[citationmanager] +isDebugMode=true +``` + _Careful with sensitive information, (passwords, tokens) will be written in plain text._ ## Tests diff --git a/classes/External/ApiAbstract.php b/classes/External/ApiAbstract.php index 69035a74..c766fe33 100755 --- a/classes/External/ApiAbstract.php +++ b/classes/External/ApiAbstract.php @@ -61,7 +61,7 @@ public function apiRequest(string $method, string $url, array $options): array if (empty($result) || json_last_error() !== JSON_ERROR_NONE) return []; - if (CitationManagerPlugin::isDebugMode) { + if (CitationManagerPlugin::isDebugMode()) { LogHelper::logInfo([$method, $url, $options, $response->getStatusCode(), $result]); }