Skip to content

Commit

Permalink
isDebugMode moved to config.php and method from const
Browse files Browse the repository at this point in the history
  • Loading branch information
GaziYucel committed Mar 19, 2024
1 parent f7fcf54 commit b41d645
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
33 changes: 11 additions & 22 deletions CitationManagerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
}
}

Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion classes/External/ApiAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

Expand Down

0 comments on commit b41d645

Please sign in to comment.